@@ 7-44 (lines=38) @@ | ||
4 | ||
5 | add_action( 'wpinv_bank_transfer_cc_form', '__return_false' ); |
|
6 | ||
7 | function wpinv_process_bank_transfer_payment( $purchase_data ) { |
|
8 | if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
10 | } |
|
11 | ||
12 | // Collect payment data |
|
13 | $payment_data = array( |
|
14 | 'price' => $purchase_data['price'], |
|
15 | 'date' => $purchase_data['date'], |
|
16 | 'user_email' => $purchase_data['user_email'], |
|
17 | 'invoice_key' => $purchase_data['invoice_key'], |
|
18 | 'currency' => wpinv_get_currency(), |
|
19 | 'items' => $purchase_data['items'], |
|
20 | 'user_info' => $purchase_data['user_info'], |
|
21 | 'cart_details' => $purchase_data['cart_details'], |
|
22 | 'gateway' => 'bank_transfer', |
|
23 | 'status' => 'wpi-pending' |
|
24 | ); |
|
25 | ||
26 | // Record the pending payment |
|
27 | $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
28 | ||
29 | if ( !empty( $invoice ) ) { |
|
30 | wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
31 | wpinv_update_payment_status( $invoice, 'wpi-pending' ); |
|
32 | ||
33 | // Empty the shopping cart |
|
34 | wpinv_empty_cart(); |
|
35 | ||
36 | do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
37 | ||
38 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
39 | } else { |
|
40 | wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
41 | // If errors are present, send the user back to the purchase page so they can be corrected |
|
42 | wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
43 | } |
|
44 | } |
|
45 | add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' ); |
|
46 | ||
47 | function wpinv_show_bank_info( $invoice ) { |
@@ 7-61 (lines=55) @@ | ||
4 | ||
5 | add_action( 'wpinv_manual_cc_form', '__return_false' ); |
|
6 | ||
7 | function wpinv_process_manual_payment( $purchase_data ) { |
|
8 | if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
10 | } |
|
11 | ||
12 | /* |
|
13 | * Purchase data comes in like this |
|
14 | * |
|
15 | $purchase_data = array( |
|
16 | 'items' => array of item IDs, |
|
17 | 'price' => total price of cart contents, |
|
18 | 'invoice_key' => // Random key |
|
19 | 'user_email' => $user_email, |
|
20 | 'date' => date('Y-m-d H:i:s'), |
|
21 | 'user_id' => $user_id, |
|
22 | 'post_data' => $_POST, |
|
23 | 'user_info' => array of user's information and used discount code |
|
24 | 'cart_details' => array of cart details, |
|
25 | 'gateway' => payment gateway, |
|
26 | ); |
|
27 | */ |
|
28 | ||
29 | // Collect payment data |
|
30 | $payment_data = array( |
|
31 | 'price' => $purchase_data['price'], |
|
32 | 'date' => $purchase_data['date'], |
|
33 | 'user_email' => $purchase_data['user_email'], |
|
34 | 'invoice_key' => $purchase_data['invoice_key'], |
|
35 | 'currency' => wpinv_get_currency(), |
|
36 | 'items' => $purchase_data['items'], |
|
37 | 'user_info' => $purchase_data['user_info'], |
|
38 | 'cart_details' => $purchase_data['cart_details'], |
|
39 | 'gateway' => 'manual', |
|
40 | 'status' => 'wpi-pending' |
|
41 | ); |
|
42 | ||
43 | // Record the pending payment |
|
44 | $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
45 | ||
46 | if ( !empty( $invoice ) ) { |
|
47 | wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
48 | wpinv_update_payment_status( $invoice, 'publish' ); |
|
49 | ||
50 | // Empty the shopping cart |
|
51 | wpinv_empty_cart(); |
|
52 | ||
53 | do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
54 | ||
55 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
56 | } else { |
|
57 | wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
58 | // If errors are present, send the user back to the purchase page so they can be corrected |
|
59 | wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
60 | } |
|
61 | } |
|
62 | add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |