/
manual.php
executable file
·78 lines (71 loc) · 2.48 KB
/
manual.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Manual Gateway
*
* @package EDD
* @subpackage Gateways
* @copyright Copyright (c) 2015, Pippin Williamson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Manual Gateway does not need a CC form, so remove it.
*
* @since 1.0
* @return void
*/
add_action( 'edd_manual_cc_form', '__return_false' );
/**
* Processes the purchase data and uses the Manual Payment gateway to record
* the transaction in the Purchase History
*
* @since 1.0
* @param array $purchase_data Purchase Data
* @return void
*/
function edd_manual_payment( $purchase_data ) {
if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'edd-gateway' ) ) {
wp_die( __( 'Nonce verification has failed', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) );
}
/*
* Purchase data comes in like this
*
$purchase_data = array(
'downloads' => array of download IDs,
'price' => total price of cart contents,
'purchase_key' => // Random key
'user_email' => $user_email,
'date' => date('Y-m-d H:i:s'),
'user_id' => $user_id,
'post_data' => $_POST,
'user_info' => array of user's information and used discount code
'cart_details' => array of cart details,
);
*/
$payment_data = array(
'price' => $purchase_data['price'],
'date' => $purchase_data['date'],
'user_email' => $purchase_data['user_email'],
'purchase_key' => $purchase_data['purchase_key'],
'currency' => edd_get_currency(),
'downloads' => $purchase_data['downloads'],
'user_info' => $purchase_data['user_info'],
'cart_details' => $purchase_data['cart_details'],
'status' => 'pending',
);
// Record the pending payment
$payment = edd_insert_payment( $payment_data );
if ( $payment ) {
edd_update_payment_status( $payment, 'publish' );
// Empty the shopping cart
edd_empty_cart();
edd_send_to_success_page();
} else {
edd_record_gateway_error( __( 'Payment Error', 'easy-digital-downloads' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'easy-digital-downloads' ), json_encode( $payment_data ) ), $payment );
// If errors are present, send the user back to the purchase page so they can be corrected
edd_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['edd-gateway'] );
}
}
add_action( 'edd_gateway_manual', 'edd_manual_payment' );