@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
6 | 8 |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_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 ) ); |
|
7 | +function wpinv_process_worldpay_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 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,120 +24,120 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
144 | 143 | \ No newline at end of file |
144 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
145 | 145 | \ No newline at end of file |
@@ -182,7 +182,7 @@ |
||
182 | 182 | $string = ""; |
183 | 183 | foreach ($array as $key => $value) { |
184 | 184 | if ($value) { |
185 | - $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'">'; |
|
185 | + $string .= '<input type="hidden" name="' . $key . '" value="' . $value . '">'; |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | return $string; |
@@ -91,13 +91,13 @@ |
||
91 | 91 | return $this->_sendRequest(); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * |
|
96 | - * |
|
97 | - * @param string $response |
|
98 | - * |
|
99 | - * @return AuthorizeNetARB_Response |
|
100 | - */ |
|
94 | + /** |
|
95 | + * |
|
96 | + * |
|
97 | + * @param string $response |
|
98 | + * |
|
99 | + * @return AuthorizeNetARB_Response |
|
100 | + */ |
|
101 | 101 | protected function _handleResponse($response) |
102 | 102 | { |
103 | 103 | return new AuthorizeNetARB_Response($response); |
@@ -116,7 +116,7 @@ |
||
116 | 116 | */ |
117 | 117 | protected function _setPostString() |
118 | 118 | { |
119 | - $this->_post_string =<<<XML |
|
119 | + $this->_post_string = <<<XML |
|
120 | 120 | <?xml version="1.0" encoding="utf-8"?> |
121 | 121 | <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> |
122 | 122 | <merchantAuthentication> |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | { |
65 | 65 | $month = ($month ? $month : date('m')); |
66 | 66 | $year = ($year ? $year : date('Y')); |
67 | - $firstSettlementDate = substr(date('c',mktime(0, 0, 0, $month, 1, $year)),0,-6); |
|
68 | - $lastSettlementDate = substr(date('c',mktime(0, 0, 0, $month+1, 0, $year)),0,-6); |
|
67 | + $firstSettlementDate = substr(date('c', mktime(0, 0, 0, $month, 1, $year)), 0, -6); |
|
68 | + $lastSettlementDate = substr(date('c', mktime(0, 0, 0, $month + 1, 0, $year)), 0, -6); |
|
69 | 69 | return $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); |
70 | 70 | } |
71 | 71 | |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | $month = ($month ? $month : date('m')); |
99 | 99 | $day = ($day ? $day : date('d')); |
100 | 100 | $year = ($year ? $year : date('Y')); |
101 | - $firstSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); |
|
102 | - $lastSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); |
|
101 | + $firstSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); |
|
102 | + $lastSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); |
|
103 | 103 | $response = $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); |
104 | 104 | $batches = $response->xpath("batchList/batch"); |
105 | 105 | foreach ($batches as $batch) { |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | */ |
188 | 188 | private function _constructXml($request_type) |
189 | 189 | { |
190 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
190 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
191 | 191 | $this->_xml = @new SimpleXMLElement($string); |
192 | 192 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
193 | - $merchant->addChild('name',$this->_api_login); |
|
194 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
193 | + $merchant->addChild('name', $this->_api_login); |
|
194 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $string = ""; |
52 | 52 | $types = $this->__getTypes(); |
53 | 53 | foreach ($types as $type) { |
54 | - if (preg_match("/struct /",$type)) { |
|
55 | - $type = preg_replace("/struct /","class ",$type); |
|
56 | - $type = preg_replace("/ (\w+) (\w+);/"," // $1\n public \$$2;",$type); |
|
57 | - $string .= $type ."\n"; |
|
54 | + if (preg_match("/struct /", $type)) { |
|
55 | + $type = preg_replace("/struct /", "class ", $type); |
|
56 | + $type = preg_replace("/ (\w+) (\w+);/", " // $1\n public \$$2;", $type); |
|
57 | + $string .= $type . "\n"; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | return $string; |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function saveSoapDocumentation($path) |
86 | 86 | { |
87 | - $string = "<?php\n"; |
|
87 | + $string = "<?php\n"; |
|
88 | 88 | $string .= "/**\n"; |
89 | 89 | $string .= " * Auto generated documentation for the AuthorizeNetSOAP API.\n"; |
90 | 90 | $string .= " * Generated " . date("m/d/Y") . "\n"; |
91 | 91 | $string .= " */\n"; |
92 | 92 | $string .= "class AuthorizeNetSOAP\n"; |
93 | - $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>"; |
|
93 | + $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() . "\n\n ?>"; |
|
94 | 94 | return file_put_contents($path, $string); |
95 | 95 | } |
96 | 96 |
@@ -76,7 +76,7 @@ |
||
76 | 76 | } |
77 | 77 | else |
78 | 78 | { |
79 | - echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
|
79 | + echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | else |
58 | 58 | { |
59 | 59 | // Redirect to error page. |
60 | - $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; |
|
60 | + $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text; |
|
61 | 61 | } |
62 | 62 | // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. |
63 | 63 | echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); |
@@ -179,54 +179,54 @@ discard block |
||
179 | 179 | -moz-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); |
180 | 180 | box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); } |
181 | 181 | </style> |
182 | - <form method="post" action="'.$post_url.'"> |
|
183 | - '.$hidden_fields.' |
|
182 | + <form method="post" action="'.$post_url . '"> |
|
183 | + '.$hidden_fields . ' |
|
184 | 184 | <fieldset> |
185 | 185 | <div> |
186 | 186 | <label>Credit Card Number</label> |
187 | - <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input> |
|
187 | + <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '') . '"></input> |
|
188 | 188 | </div> |
189 | 189 | <div> |
190 | 190 | <label>Exp.</label> |
191 | - <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input> |
|
191 | + <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '') . '"></input> |
|
192 | 192 | </div> |
193 | 193 | <div> |
194 | 194 | <label>CCV</label> |
195 | - <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input> |
|
195 | + <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '') . '"></input> |
|
196 | 196 | </div> |
197 | 197 | </fieldset> |
198 | 198 | <fieldset> |
199 | 199 | <div> |
200 | 200 | <label>First Name</label> |
201 | - <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input> |
|
201 | + <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '') . '"></input> |
|
202 | 202 | </div> |
203 | 203 | <div> |
204 | 204 | <label>Last Name</label> |
205 | - <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input> |
|
205 | + <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '') . '"></input> |
|
206 | 206 | </div> |
207 | 207 | </fieldset> |
208 | 208 | <fieldset> |
209 | 209 | <div> |
210 | 210 | <label>Address</label> |
211 | - <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input> |
|
211 | + <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '') . '"></input> |
|
212 | 212 | </div> |
213 | 213 | <div> |
214 | 214 | <label>City</label> |
215 | - <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input> |
|
215 | + <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '') . '"></input> |
|
216 | 216 | </div> |
217 | 217 | </fieldset> |
218 | 218 | <fieldset> |
219 | 219 | <div> |
220 | 220 | <label>State</label> |
221 | - <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input> |
|
221 | + <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '') . '"></input> |
|
222 | 222 | </div> |
223 | 223 | <div> |
224 | 224 | <label>Zip Code</label> |
225 | - <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input> |
|
225 | + <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '') . '"></input> |
|
226 | 226 | </div> |
227 | 227 | <div> |
228 | 228 | <label>Country</label> |
229 | - <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input> |
|
229 | + <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '') . '"></input> |
|
230 | 230 | </div> |
231 | 231 | </fieldset> |
232 | 232 | <input type="submit" value="BUY" class="submit buy"> |
@@ -53,16 +53,14 @@ discard block |
||
53 | 53 | { |
54 | 54 | // Do your processing here. |
55 | 55 | $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; |
56 | - } |
|
57 | - else |
|
56 | + } else |
|
58 | 57 | { |
59 | 58 | // Redirect to error page. |
60 | 59 | $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; |
61 | 60 | } |
62 | 61 | // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. |
63 | 62 | echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); |
64 | - } |
|
65 | - else |
|
63 | + } else |
|
66 | 64 | { |
67 | 65 | echo "Error -- not AuthorizeNet. Check your MD5 Setting."; |
68 | 66 | } |
@@ -73,8 +71,7 @@ discard block |
||
73 | 71 | if ($_GET['response_code'] == 1) |
74 | 72 | { |
75 | 73 | echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); |
76 | - } |
|
77 | - else |
|
74 | + } else |
|
78 | 75 | { |
79 | 76 | echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
80 | 77 | } |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
6 | 8 |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-8"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-8"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-2"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-8"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,174 +83,174 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
110 | 110 | |
111 | 111 | $authorizeAIM = wpinv_authorizenet_AIM(); |
112 | - $authorizeAIM->first_name = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 ); |
|
113 | - $authorizeAIM->last_name = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 ); |
|
114 | - $authorizeAIM->company = wpinv_utf8_substr( $invoice->company, 0, 50 ); |
|
115 | - $authorizeAIM->address = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 ); |
|
116 | - $authorizeAIM->city = wpinv_utf8_substr( $invoice->city, 0, 40 ); |
|
117 | - $authorizeAIM->state = wpinv_utf8_substr( $invoice->state, 0, 40 ); |
|
118 | - $authorizeAIM->zip = wpinv_utf8_substr( $invoice->zip, 0, 40 ); |
|
119 | - $authorizeAIM->country = wpinv_utf8_substr( $invoice->country, 0, 60 ); |
|
120 | - $authorizeAIM->phone = wpinv_utf8_substr( $invoice->phone, 0, 25 ); |
|
121 | - $authorizeAIM->email = wpinv_utf8_substr( $invoice->get_email(), 0, 255 ); |
|
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
112 | + $authorizeAIM->first_name = wpinv_utf8_substr($invoice->get_first_name(), 0, 50); |
|
113 | + $authorizeAIM->last_name = wpinv_utf8_substr($invoice->get_last_name(), 0, 50); |
|
114 | + $authorizeAIM->company = wpinv_utf8_substr($invoice->company, 0, 50); |
|
115 | + $authorizeAIM->address = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60); |
|
116 | + $authorizeAIM->city = wpinv_utf8_substr($invoice->city, 0, 40); |
|
117 | + $authorizeAIM->state = wpinv_utf8_substr($invoice->state, 0, 40); |
|
118 | + $authorizeAIM->zip = wpinv_utf8_substr($invoice->zip, 0, 40); |
|
119 | + $authorizeAIM->country = wpinv_utf8_substr($invoice->country, 0, 60); |
|
120 | + $authorizeAIM->phone = wpinv_utf8_substr($invoice->phone, 0, 25); |
|
121 | + $authorizeAIM->email = wpinv_utf8_substr($invoice->get_email(), 0, 255); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_name = wpinv_utf8_substr( $item['name'], 0, 31 ); |
|
132 | - $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_name = wpinv_utf8_substr($item['name'], 0, 31); |
|
132 | + $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
133 | 133 | |
134 | - $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
134 | + $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
135 | 135 | } |
136 | 136 | |
137 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
137 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
138 | 138 | |
139 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
140 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
139 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
140 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
141 | 141 | |
142 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
142 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $invoice->get_discount() > 0 ) { |
|
146 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
145 | + if ($invoice->get_discount() > 0) { |
|
146 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
147 | 147 | } |
148 | 148 | |
149 | - $item_description = wpinv_utf8_substr( $item_desc, 0, 255 ); |
|
150 | - $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
149 | + $item_description = wpinv_utf8_substr($item_desc, 0, 255); |
|
150 | + $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
151 | 151 | |
152 | - $authorizeAIM->description = wpinv_utf8_substr( $item_description, 0, 255 ); |
|
152 | + $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255); |
|
153 | 153 | |
154 | 154 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
155 | 155 | |
156 | - if ( $is_recurring ) { |
|
156 | + if ($is_recurring) { |
|
157 | 157 | $authorizeAIM->recurring_billing = true; |
158 | 158 | } |
159 | 159 | |
160 | 160 | try { |
161 | - if ( $is_recurring ) { |
|
161 | + if ($is_recurring) { |
|
162 | 162 | $response = $authorizeAIM->authorizeOnly(); |
163 | 163 | } else { |
164 | 164 | $response = $authorizeAIM->authorizeAndCapture(); |
165 | 165 | } |
166 | 166 | |
167 | - if ( $response->approved || $response->held ) { |
|
168 | - if ( $response->approved ) { |
|
169 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
167 | + if ($response->approved || $response->held) { |
|
168 | + if ($response->approved) { |
|
169 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
170 | 170 | } |
171 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
171 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
172 | 172 | |
173 | - $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ); |
|
173 | + $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code); |
|
174 | 174 | |
175 | - wpinv_insert_payment_note( $invoice_id, $message ); |
|
175 | + wpinv_insert_payment_note($invoice_id, $message); |
|
176 | 176 | |
177 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
177 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
178 | 178 | |
179 | 179 | wpinv_clear_errors(); |
180 | 180 | wpinv_empty_cart(); |
181 | 181 | |
182 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
182 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
183 | 183 | } else { |
184 | - if ( !empty( $response->response_reason_text ) ) { |
|
185 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
186 | - } else if ( !empty( $response->error_message ) ) { |
|
187 | - $error = __( $response->error_message, 'invoicing' ); |
|
184 | + if (!empty($response->response_reason_text)) { |
|
185 | + $error = __($response->response_reason_text, 'invoicing'); |
|
186 | + } else if (!empty($response->error_message)) { |
|
187 | + $error = __($response->error_message, 'invoicing'); |
|
188 | 188 | } else { |
189 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
189 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
190 | 190 | } |
191 | 191 | |
192 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
192 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
193 | 193 | |
194 | - wpinv_set_error( 'payment_error', $error ); |
|
195 | - wpinv_record_gateway_error( $error, $response ); |
|
196 | - wpinv_insert_payment_note( $invoice_id, $error ); |
|
194 | + wpinv_set_error('payment_error', $error); |
|
195 | + wpinv_record_gateway_error($error, $response); |
|
196 | + wpinv_insert_payment_note($invoice_id, $error); |
|
197 | 197 | |
198 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
198 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
199 | 199 | } |
200 | - } catch ( AuthorizeNetException $e ) { |
|
201 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
202 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
203 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
200 | + } catch (AuthorizeNetException $e) { |
|
201 | + wpinv_set_error('request_error', $e->getMessage()); |
|
202 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
203 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
204 | 204 | } |
205 | 205 | } else { |
206 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
206 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
207 | 207 | } |
208 | 208 | } else { |
209 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
210 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
209 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
210 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
211 | 211 | } |
212 | 212 | } |
213 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
213 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
214 | 214 | |
215 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
216 | - if ( empty( $subscription_id ) ) { |
|
215 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
216 | + if (empty($subscription_id)) { |
|
217 | 217 | return false; |
218 | 218 | } |
219 | 219 | |
220 | 220 | try { |
221 | 221 | $authnetXML = wpinv_authorizenet_XML(); |
222 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
222 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
223 | 223 | |
224 | 224 | return $authnetXML->isSuccessful(); |
225 | - } catch( Exception $e ) { |
|
226 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
225 | + } catch (Exception $e) { |
|
226 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | return false; |
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
233 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
234 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
232 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
233 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
234 | + if (empty($authorizenet_md5_hash)) { |
|
235 | 235 | return true; |
236 | 236 | } |
237 | 237 | |
238 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
238 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
239 | 239 | |
240 | - return hash_equals( $compare_md5, $md5_hash ); |
|
240 | + return hash_equals($compare_md5, $md5_hash); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | function wpinv_authorizenet_AIM() { |
244 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
245 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
244 | + if (!class_exists('AuthorizeNetException')) { |
|
245 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
246 | 246 | } |
247 | 247 | |
248 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
248 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
249 | 249 | |
250 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
251 | - $authorizeAIM->setSandbox( true ); |
|
250 | + if (wpinv_is_test_mode('authorizenet')) { |
|
251 | + $authorizeAIM->setSandbox(true); |
|
252 | 252 | } else { |
253 | - $authorizeAIM->setSandbox( false ); |
|
253 | + $authorizeAIM->setSandbox(false); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -259,164 +259,164 @@ discard block |
||
259 | 259 | } |
260 | 260 | |
261 | 261 | function wpinv_authorizenet_XML() { |
262 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
263 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
262 | + if (!class_exists('AuthnetXML')) { |
|
263 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
264 | 264 | } |
265 | 265 | |
266 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
266 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
267 | 267 | |
268 | 268 | return $authnetXML; |
269 | 269 | } |
270 | 270 | |
271 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
272 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
271 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
272 | + if (empty($response) || empty($invoice)) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - if ( $invoice->is_recurring() && !empty( $response->approved ) ) { |
|
277 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
276 | + if ($invoice->is_recurring() && !empty($response->approved)) { |
|
277 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
278 | 278 | |
279 | - if ( !empty( $subscription ) && $subscription->isSuccessful() ) { |
|
280 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
279 | + if (!empty($subscription) && $subscription->isSuccessful()) { |
|
280 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
281 | 281 | |
282 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
282 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
283 | 283 | |
284 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
284 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
285 | 285 | } else { |
286 | - if ( isset( $subscription->messages->message ) ) { |
|
286 | + if (isset($subscription->messages->message)) { |
|
287 | 287 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
288 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
288 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
289 | 289 | } else { |
290 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
291 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
290 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
291 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
292 | 292 | } |
293 | 293 | |
294 | - wpinv_record_gateway_error( $error, $subscription ); |
|
294 | + wpinv_record_gateway_error($error, $subscription); |
|
295 | 295 | |
296 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) ); |
|
296 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error)); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | } |
300 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
300 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
301 | 301 | |
302 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
303 | - if ( empty( $invoice ) ) { |
|
302 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
303 | + if (empty($invoice)) { |
|
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | |
307 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
307 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
308 | 308 | |
309 | 309 | try { |
310 | 310 | $authnetXML = wpinv_authorizenet_XML(); |
311 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
312 | - } catch( Exception $e ) { |
|
311 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
312 | + } catch (Exception $e) { |
|
313 | 313 | $authnetXML = array(); |
314 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
314 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | return $authnetXML; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
321 | - if ( empty( $invoice ) ) { |
|
320 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
321 | + if (empty($invoice)) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | 324 | |
325 | - $subscription_item = $invoice->get_recurring( true ); |
|
326 | - if ( empty( $subscription_item ) ) { |
|
325 | + $subscription_item = $invoice->get_recurring(true); |
|
326 | + if (empty($subscription_item)) { |
|
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | |
330 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
330 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
331 | 331 | $subscription_name = $invoice->get_subscription_name(); |
332 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
333 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
332 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
333 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
334 | 334 | $interval = $subscription_item->get_recurring_interval(); |
335 | 335 | $period = $subscription_item->get_recurring_period(); |
336 | 336 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
337 | 337 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
338 | 338 | |
339 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
339 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
340 | 340 | $interval = $time_period['interval']; |
341 | 341 | $period = $time_period['period']; |
342 | 342 | |
343 | 343 | $current_tz = date_default_timezone_get(); |
344 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
345 | - $today = date( 'Y-m-d' ); |
|
346 | - date_default_timezone_set( $current_tz ); |
|
344 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
345 | + $today = date('Y-m-d'); |
|
346 | + date_default_timezone_set($current_tz); |
|
347 | 347 | |
348 | 348 | $free_trial = $invoice->is_free_trial(); |
349 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
349 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
350 | 350 | $trial_interval = $subscription_item->get_trial_interval(); |
351 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
351 | + $trial_period = $subscription_item->get_trial_period(true); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | $subscription = array(); |
355 | 355 | $subscription['name'] = $subscription_name; |
356 | 356 | |
357 | 357 | $subscription['paymentSchedule'] = array( |
358 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
358 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
359 | 359 | 'startDate' => $today, |
360 | 360 | 'totalOccurrences' => $bill_times, |
361 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
361 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
362 | 362 | ); |
363 | 363 | |
364 | 364 | $subscription['amount'] = $recurring_amount; |
365 | 365 | $subscription['trialAmount'] = $initial_amount; |
366 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
367 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
368 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
366 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
367 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
368 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
369 | 369 | |
370 | 370 | $subscription['billTo'] = array( |
371 | 371 | 'firstName' => $invoice->get_first_name(), |
372 | 372 | 'lastName' => $invoice->get_last_name(), |
373 | 373 | 'company' => $invoice->company, |
374 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
374 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
375 | 375 | 'city' => $invoice->city, |
376 | 376 | 'state' => $invoice->state, |
377 | 377 | 'zip' => $invoice->zip, |
378 | 378 | 'country' => $invoice->country, |
379 | 379 | ); |
380 | 380 | |
381 | - $params = array( 'subscription' => $subscription ); |
|
381 | + $params = array('subscription' => $subscription); |
|
382 | 382 | |
383 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
383 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
384 | 384 | } |
385 | 385 | |
386 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
387 | - $card_defaults = array( |
|
386 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
387 | + $card_defaults = array( |
|
388 | 388 | 'cc_owner' => null, |
389 | 389 | 'cc_number' => null, |
390 | 390 | 'cc_expire_month' => null, |
391 | 391 | 'cc_expire_year' => null, |
392 | 392 | 'cc_cvv2' => null, |
393 | 393 | ); |
394 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
394 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
395 | 395 | |
396 | 396 | $card_details = array( |
397 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
398 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
399 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
397 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
398 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
399 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
400 | 400 | ); |
401 | 401 | |
402 | 402 | return $card_details; |
403 | 403 | } |
404 | 404 | |
405 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
406 | - if ( empty( $invoice ) || empty( $subscription ) ) { |
|
405 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
406 | + if (empty($invoice) || empty($subscription)) { |
|
407 | 407 | return false; |
408 | 408 | } |
409 | 409 | |
410 | - $subscription_item = $invoice->get_recurring( true ); |
|
411 | - if ( empty( $subscription_item ) ) { |
|
410 | + $subscription_item = $invoice->get_recurring(true); |
|
411 | + if (empty($subscription_item)) { |
|
412 | 412 | return false; |
413 | 413 | } |
414 | 414 | |
415 | 415 | $invoice_id = $invoice->ID; |
416 | 416 | $subscriptionId = (array)$subscription->subscriptionId; |
417 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id; |
|
417 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id; |
|
418 | 418 | |
419 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) ); |
|
419 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id)); |
|
420 | 420 | |
421 | 421 | $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active'; |
422 | 422 | |
@@ -424,16 +424,16 @@ discard block |
||
424 | 424 | 'profile_id' => $subscription_id, |
425 | 425 | 'item_id' => $subscription_item->ID, |
426 | 426 | 'initial_amount' => $invoice->get_total(), |
427 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
427 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
428 | 428 | 'period' => $subscription_item->get_recurring_period(), |
429 | 429 | 'interval' => $subscription_item->get_recurring_interval(), |
430 | 430 | 'bill_times' => $subscription_item->get_recurring_limit(), |
431 | - 'expiration' => $invoice->get_new_expiration( $subscription_item->ID ), |
|
431 | + 'expiration' => $invoice->get_new_expiration($subscription_item->ID), |
|
432 | 432 | 'status' => $status, |
433 | - 'created' => current_time( 'mysql', 0 ) |
|
433 | + 'created' => current_time('mysql', 0) |
|
434 | 434 | ); |
435 | 435 | |
436 | - if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) { |
|
436 | + if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) { |
|
437 | 437 | $args['trial_period'] = $subscription_item->get_trial_period(); |
438 | 438 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
439 | 439 | } else { |
@@ -441,58 +441,58 @@ discard block |
||
441 | 441 | $args['trial_interval'] = 0; |
442 | 442 | } |
443 | 443 | |
444 | - return $invoice->update_subscription( $args ); |
|
444 | + return $invoice->update_subscription($args); |
|
445 | 445 | } |
446 | 446 | |
447 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
448 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
447 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
448 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
449 | 449 | $error = false; |
450 | 450 | |
451 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
451 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
452 | 452 | $error = true; |
453 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
453 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
454 | 454 | } |
455 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
455 | + if (empty($post['authorizenet']['cc_number'])) { |
|
456 | 456 | $error = true; |
457 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
457 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
458 | 458 | } |
459 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
459 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
460 | 460 | $error = true; |
461 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
461 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
462 | 462 | } |
463 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
463 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
464 | 464 | $error = true; |
465 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
465 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
466 | 466 | } |
467 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
467 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
468 | 468 | $error = true; |
469 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
469 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
470 | 470 | } |
471 | 471 | |
472 | - if ( $error ) { |
|
472 | + if ($error) { |
|
473 | 473 | return; |
474 | 474 | } |
475 | 475 | |
476 | 476 | $invoice = wpinv_get_invoice_cart(); |
477 | 477 | |
478 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
479 | - $subscription_item = $invoice->get_recurring( true ); |
|
478 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
479 | + $subscription_item = $invoice->get_recurring(true); |
|
480 | 480 | |
481 | 481 | $interval = $subscription_item->get_recurring_interval(); |
482 | 482 | $period = $subscription_item->get_recurring_period(); |
483 | 483 | |
484 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
485 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
484 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
485 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | } |
489 | 489 | } |
490 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
490 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
491 | 491 | |
492 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
493 | - $subscription_interval = absint( $subscription_interval ); |
|
492 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
493 | + $subscription_interval = absint($subscription_interval); |
|
494 | 494 | |
495 | - switch( $subscription_period ) { |
|
495 | + switch ($subscription_period) { |
|
496 | 496 | case 'W': |
497 | 497 | case 'week': |
498 | 498 | case 'weeks': |
@@ -502,14 +502,14 @@ discard block |
||
502 | 502 | case 'M': |
503 | 503 | case 'month': |
504 | 504 | case 'months': |
505 | - if ( $subscription_interval > 12 ) { |
|
505 | + if ($subscription_interval > 12) { |
|
506 | 506 | $subscription_interval = 12; |
507 | 507 | } |
508 | 508 | |
509 | 509 | $interval = $subscription_interval; |
510 | 510 | $period = 'months'; |
511 | 511 | |
512 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
512 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
513 | 513 | $interval = $subscription_interval * 30; |
514 | 514 | $period = 'days'; |
515 | 515 | } |
@@ -526,40 +526,40 @@ discard block |
||
526 | 526 | break; |
527 | 527 | } |
528 | 528 | |
529 | - return compact( 'interval', 'period' ); |
|
529 | + return compact('interval', 'period'); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | function wpinv_authorizenet_process_ipn() { |
533 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
533 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
534 | 534 | return; |
535 | 535 | } |
536 | 536 | |
537 | - $subscription_id = intval( $_POST['x_subscription_id'] ); |
|
537 | + $subscription_id = intval($_POST['x_subscription_id']); |
|
538 | 538 | |
539 | - if ( $subscription_id ) { |
|
540 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
541 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
542 | - $response_code = intval( $_POST['x_response_code'] ); |
|
543 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
539 | + if ($subscription_id) { |
|
540 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
541 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
542 | + $response_code = intval($_POST['x_response_code']); |
|
543 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
544 | 544 | |
545 | - if ( 1 == $response_code ) { |
|
545 | + if (1 == $response_code) { |
|
546 | 546 | // Approved |
547 | - do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id ); |
|
548 | - } else if ( 2 == $response_code ) { |
|
547 | + do_action('wpinv_authorizenet_renewal_payment', $transaction_id); |
|
548 | + } else if (2 == $response_code) { |
|
549 | 549 | // Declined |
550 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
551 | - do_action( 'wpinv_authorizenet_renewal_error', $transaction_id ); |
|
552 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
550 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
551 | + do_action('wpinv_authorizenet_renewal_error', $transaction_id); |
|
552 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
553 | 553 | // An expired card |
554 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
555 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id ); |
|
554 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
555 | + do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id); |
|
556 | 556 | |
557 | 557 | } else { |
558 | 558 | // Other Error |
559 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
559 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | } |
565 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
566 | 565 | \ No newline at end of file |
566 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
567 | 567 | \ No newline at end of file |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_manual_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
6 | 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 ) ); |
|
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 | 10 | } |
11 | 11 | |
12 | 12 | /* |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | // Record the pending payment |
44 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
44 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
45 | 45 | |
46 | - if ( !empty( $invoice ) ) { |
|
47 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
48 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
46 | + if (!empty($invoice)) { |
|
47 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
48 | + wpinv_update_payment_status($invoice, 'publish'); |
|
49 | 49 | |
50 | 50 | // Empty the shopping cart |
51 | 51 | wpinv_empty_cart(); |
52 | 52 | |
53 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
53 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
54 | 54 | } else { |
55 | - 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 ); |
|
55 | + 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); |
|
56 | 56 | // If errors are present, send the user back to the purchase page so they can be corrected |
57 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
57 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
58 | 58 | } |
59 | 59 | } |
60 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
61 | 60 | \ No newline at end of file |
61 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
62 | 62 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_action( 'wpinv_manual_cc_form', '__return_false' ); |
6 | 8 |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_bank_transfer_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_bank_transfer_cc_form', '__return_false'); |
|
6 | 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 ) ); |
|
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 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,37 +24,37 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
30 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
31 | - wpinv_update_payment_status( $invoice, 'pending' ); |
|
29 | + if (!empty($invoice)) { |
|
30 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
31 | + wpinv_update_payment_status($invoice, 'pending'); |
|
32 | 32 | |
33 | 33 | // Empty the shopping cart |
34 | 34 | wpinv_empty_cart(); |
35 | 35 | |
36 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
36 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
37 | 37 | } else { |
38 | - 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 ); |
|
38 | + 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); |
|
39 | 39 | // If errors are present, send the user back to the purchase page so they can be corrected |
40 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
40 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
41 | 41 | } |
42 | 42 | } |
43 | -add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' ); |
|
43 | +add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment'); |
|
44 | 44 | |
45 | -function wpinv_show_bank_info( $invoice ) { |
|
46 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending' ) { |
|
47 | - $bank_info = wpinv_get_bank_info( true ); |
|
45 | +function wpinv_show_bank_info($invoice) { |
|
46 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending') { |
|
47 | + $bank_info = wpinv_get_bank_info(true); |
|
48 | 48 | ?> |
49 | 49 | <div class="wpinv-bank-details"> |
50 | - <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?> |
|
51 | - <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div> |
|
50 | + <?php if ($instructions = wpinv_get_bank_instructions()) { ?> |
|
51 | + <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div> |
|
52 | 52 | <?php } ?> |
53 | - <?php if ( !empty( $bank_info ) ) { ?> |
|
54 | - <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3> |
|
53 | + <?php if (!empty($bank_info)) { ?> |
|
54 | + <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3> |
|
55 | 55 | <table class="table table-bordered table-sm wpi-bank-details"> |
56 | - <?php foreach ( $bank_info as $key => $info ) { ?> |
|
57 | - <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr> |
|
56 | + <?php foreach ($bank_info as $key => $info) { ?> |
|
57 | + <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr> |
|
58 | 58 | <?php } ?> |
59 | 59 | </table> |
60 | 60 | <?php } ?> |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | <?php |
63 | 63 | } |
64 | 64 | } |
65 | -add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 ); |
|
65 | +add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1); |
|
66 | 66 | |
67 | -function wpinv_invoice_print_bank_info( $invoice ) { |
|
68 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending' ) { |
|
67 | +function wpinv_invoice_print_bank_info($invoice) { |
|
68 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending') { |
|
69 | 69 | ?> |
70 | 70 | <div class="row wpinv-bank-info"> |
71 | - <?php echo wpinv_show_bank_info( $invoice ); ?> |
|
71 | + <?php echo wpinv_show_bank_info($invoice); ?> |
|
72 | 72 | </div> |
73 | 73 | <?php |
74 | 74 | } |
75 | 75 | } |
76 | -add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 ); |
|
77 | 76 | \ No newline at end of file |
77 | +add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1); |
|
78 | 78 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_action( 'wpinv_bank_transfer_cc_form', '__return_false' ); |
6 | 8 |