|
@@ -4,7 +4,7 @@ discard block |
|
|
block discarded – undo |
|
4
|
4
|
* |
|
5
|
5
|
*/ |
|
6
|
6
|
|
|
7
|
|
-defined( 'ABSPATH' ) || exit; |
|
|
7
|
+defined('ABSPATH') || exit; |
|
8
|
8
|
|
|
9
|
9
|
/** |
|
10
|
10
|
* Authorize.net Payment Gateway class. |
|
@@ -24,7 +24,7 @@ discard block |
|
|
block discarded – undo |
|
24
|
24
|
* |
|
25
|
25
|
* @var array |
|
26
|
26
|
*/ |
|
27
|
|
- protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
|
27
|
+ protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28
|
28
|
|
|
29
|
29
|
/** |
|
30
|
30
|
* Payment method order. |
|
@@ -52,7 +52,7 @@ discard block |
|
|
block discarded – undo |
|
52
|
52
|
* |
|
53
|
53
|
* @var array |
|
54
|
54
|
*/ |
|
55
|
|
- public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
|
55
|
+ public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56
|
56
|
|
|
57
|
57
|
/** |
|
58
|
58
|
* URL to view a transaction. |
|
@@ -66,12 +66,12 @@ discard block |
|
|
block discarded – undo |
|
66
|
66
|
*/ |
|
67
|
67
|
public function __construct() { |
|
68
|
68
|
|
|
69
|
|
- $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70
|
|
- $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71
|
|
- $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
|
69
|
+ $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
|
70
|
+ $this->method_title = __('Authorize.Net', 'invoicing'); |
|
|
71
|
+ $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72
|
72
|
|
|
73
|
|
- add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 ); |
|
74
|
|
- add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
|
73
|
+ add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2); |
|
|
74
|
+ add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75
|
75
|
parent::__construct(); |
|
76
|
76
|
} |
|
77
|
77
|
|
|
@@ -81,13 +81,13 @@ discard block |
|
|
block discarded – undo |
|
81
|
81
|
* @param int $invoice_id 0 or invoice id. |
|
82
|
82
|
* @param GetPaid_Payment_Form $form Current payment form. |
|
83
|
83
|
*/ |
|
84
|
|
- public function payment_fields( $invoice_id, $form ) { |
|
|
84
|
+ public function payment_fields($invoice_id, $form) { |
|
85
|
85
|
|
|
86
|
86
|
// Let the user select a payment method. |
|
87
|
87
|
echo $this->saved_payment_methods(); |
|
88
|
88
|
|
|
89
|
89
|
// Show the credit card entry form. |
|
90
|
|
- echo $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
|
90
|
+ echo $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91
|
91
|
} |
|
92
|
92
|
|
|
93
|
93
|
/** |
|
@@ -100,72 +100,72 @@ discard block |
|
|
block discarded – undo |
|
100
|
100
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
|
101
|
101
|
* @return string|WP_Error Payment profile id. |
|
102
|
102
|
*/ |
|
103
|
|
- public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
|
103
|
+ public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104
|
104
|
|
|
105
|
105
|
// Remove non-digits from the number |
|
106
|
|
- $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
|
106
|
+ $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107
|
107
|
|
|
108
|
108
|
// Generate args. |
|
109
|
109
|
$args = array( |
|
110
|
110
|
'createCustomerProfileRequest' => array( |
|
111
|
111
|
'merchantAuthentication' => $this->get_auth_params(), |
|
112
|
112
|
'profile' => array( |
|
113
|
|
- 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114
|
|
- 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115
|
|
- 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
|
113
|
+ 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
|
114
|
+ 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
|
115
|
+ 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116
|
116
|
'paymentProfiles' => array( |
|
117
|
117
|
'customerType' => 'individual', |
|
118
|
118
|
|
|
119
|
119
|
// Billing information. |
|
120
|
120
|
'billTo' => array( |
|
121
|
|
- 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122
|
|
- 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123
|
|
- 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124
|
|
- 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125
|
|
- 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126
|
|
- 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127
|
|
- 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
|
121
|
+ 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
|
122
|
+ 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
|
123
|
+ 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
|
124
|
+ 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
|
125
|
+ 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
|
126
|
+ 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
|
127
|
+ 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128
|
128
|
), |
|
129
|
129
|
|
|
130
|
130
|
// Payment information. |
|
131
|
|
- 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
|
131
|
+ 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132
|
132
|
) |
|
133
|
133
|
), |
|
134
|
|
- 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
|
134
|
+ 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135
|
135
|
) |
|
136
|
136
|
); |
|
137
|
137
|
|
|
138
|
|
- $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
|
138
|
+ $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139
|
139
|
|
|
140
|
|
- if ( is_wp_error( $response ) ) { |
|
|
140
|
+ if (is_wp_error($response)) { |
|
141
|
141
|
|
|
142
|
142
|
// In case the customer profile already exists remotely. |
|
143
|
|
- if ( 'E00039' == $response->get_error_code() ) { |
|
144
|
|
- $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
145
|
|
- $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
146
|
|
- return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
|
143
|
+ if ('E00039' == $response->get_error_code()) { |
|
|
144
|
+ $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
|
145
|
+ $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
|
146
|
+ return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
147
|
147
|
} |
|
148
|
148
|
|
|
149
|
149
|
return $response; |
|
150
|
150
|
} |
|
151
|
151
|
|
|
152
|
|
- update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
|
152
|
+ update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
153
|
153
|
|
|
154
|
154
|
// Save the payment token. |
|
155
|
|
- if ( $save ) { |
|
|
155
|
+ if ($save) { |
|
156
|
156
|
$this->save_token( |
|
157
|
157
|
array( |
|
158
|
158
|
'id' => $response->customerPaymentProfileIdList[0], |
|
159
|
|
- 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
|
159
|
+ 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
160
|
160
|
'default' => true, |
|
161
|
|
- 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
|
161
|
+ 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
162
|
162
|
) |
|
163
|
163
|
); |
|
164
|
164
|
} |
|
165
|
165
|
|
|
166
|
166
|
// Add a note about the validation response. |
|
167
|
167
|
$invoice->add_note( |
|
168
|
|
- sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
|
168
|
+ sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
169
|
169
|
false, |
|
170
|
170
|
false, |
|
171
|
171
|
true |
|
@@ -182,7 +182,7 @@ discard block |
|
|
block discarded – undo |
|
182
|
182
|
* @return string|WP_Error Profile id. |
|
183
|
183
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
|
184
|
184
|
*/ |
|
185
|
|
- public function get_customer_profile( $profile_id ) { |
|
|
185
|
+ public function get_customer_profile($profile_id) { |
|
186
|
186
|
|
|
187
|
187
|
// Generate args. |
|
188
|
188
|
$args = array( |
|
@@ -192,7 +192,7 @@ discard block |
|
|
block discarded – undo |
|
192
|
192
|
) |
|
193
|
193
|
); |
|
194
|
194
|
|
|
195
|
|
- return $this->post( $args, false ); |
|
|
195
|
+ return $this->post($args, false); |
|
196
|
196
|
|
|
197
|
197
|
} |
|
198
|
198
|
|
|
@@ -207,18 +207,18 @@ discard block |
|
|
block discarded – undo |
|
207
|
207
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
|
208
|
208
|
* @return string|WP_Error Profile id. |
|
209
|
209
|
*/ |
|
210
|
|
- public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
|
210
|
+ public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
211
|
211
|
|
|
212
|
212
|
// Remove non-digits from the number |
|
213
|
|
- $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
|
213
|
+ $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
214
|
214
|
|
|
215
|
215
|
// Prepare card details. |
|
216
|
|
- $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
|
216
|
+ $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
217
|
217
|
|
|
218
|
218
|
// Authorize.NET does not support saving the same card twice. |
|
219
|
|
- $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
|
219
|
+ $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
220
|
220
|
|
|
221
|
|
- if ( $cached_information ) { |
|
|
221
|
+ if ($cached_information) { |
|
222
|
222
|
return $cached_information; |
|
223
|
223
|
} |
|
224
|
224
|
|
|
@@ -231,46 +231,46 @@ discard block |
|
|
block discarded – undo |
|
231
|
231
|
|
|
232
|
232
|
// Billing information. |
|
233
|
233
|
'billTo' => array( |
|
234
|
|
- 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
235
|
|
- 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
236
|
|
- 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
237
|
|
- 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
238
|
|
- 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
239
|
|
- 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
240
|
|
- 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
|
234
|
+ 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
|
235
|
+ 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
|
236
|
+ 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
|
237
|
+ 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
|
238
|
+ 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
|
239
|
+ 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
|
240
|
+ 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
241
|
241
|
), |
|
242
|
242
|
|
|
243
|
243
|
// Payment information. |
|
244
|
244
|
'payment' => $payment_information |
|
245
|
245
|
), |
|
246
|
|
- 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
|
246
|
+ 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
247
|
247
|
) |
|
248
|
248
|
); |
|
249
|
249
|
|
|
250
|
|
- $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
|
250
|
+ $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
251
|
251
|
|
|
252
|
|
- if ( is_wp_error( $response ) ) { |
|
|
252
|
+ if (is_wp_error($response)) { |
|
253
|
253
|
return $response; |
|
254
|
254
|
} |
|
255
|
255
|
|
|
256
|
256
|
// Save the payment token. |
|
257
|
|
- if ( $save ) { |
|
|
257
|
+ if ($save) { |
|
258
|
258
|
$this->save_token( |
|
259
|
259
|
array( |
|
260
|
260
|
'id' => $response->customerPaymentProfileId, |
|
261
|
|
- 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
|
261
|
+ 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
262
|
262
|
'default' => true, |
|
263
|
|
- 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
|
263
|
+ 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
264
|
264
|
) |
|
265
|
265
|
); |
|
266
|
266
|
} |
|
267
|
267
|
|
|
268
|
268
|
// Cache payment profile id. |
|
269
|
|
- $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
|
269
|
+ $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
270
|
270
|
|
|
271
|
271
|
// Add a note about the validation response. |
|
272
|
272
|
$invoice->add_note( |
|
273
|
|
- sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
|
273
|
+ sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
274
|
274
|
false, |
|
275
|
275
|
false, |
|
276
|
276
|
true |
|
@@ -287,12 +287,12 @@ discard block |
|
|
block discarded – undo |
|
287
|
287
|
* @param array $payment_details. |
|
288
|
288
|
* @return array|false Profile id. |
|
289
|
289
|
*/ |
|
290
|
|
- public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
|
290
|
+ public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
291
|
291
|
|
|
292
|
|
- $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
293
|
|
- $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
|
292
|
+ $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
|
293
|
+ $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
294
|
294
|
|
|
295
|
|
- if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
|
295
|
+ if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
296
|
296
|
return false; |
|
297
|
297
|
} |
|
298
|
298
|
|
|
@@ -301,13 +301,13 @@ discard block |
|
|
block discarded – undo |
|
301
|
301
|
'getCustomerPaymentProfileRequest' => array( |
|
302
|
302
|
'merchantAuthentication' => $this->get_auth_params(), |
|
303
|
303
|
'customerProfileId' => $customer_profile, |
|
304
|
|
- 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
|
304
|
+ 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
305
|
305
|
) |
|
306
|
306
|
); |
|
307
|
307
|
|
|
308
|
|
- $response = $this->post( $args, $invoice ); |
|
|
308
|
+ $response = $this->post($args, $invoice); |
|
309
|
309
|
|
|
310
|
|
- return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
|
310
|
+ return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
311
|
311
|
|
|
312
|
312
|
} |
|
313
|
313
|
|
|
@@ -318,14 +318,14 @@ discard block |
|
|
block discarded – undo |
|
318
|
318
|
* @param array $payment_details. |
|
319
|
319
|
* @param string $payment_profile_id. |
|
320
|
320
|
*/ |
|
321
|
|
- public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
|
321
|
+ public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
322
|
322
|
|
|
323
|
|
- $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
324
|
|
- $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
325
|
|
- $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
|
323
|
+ $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
|
324
|
+ $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
|
325
|
+ $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
326
|
326
|
|
|
327
|
|
- $cached_information[ $payment_details ] = $payment_profile_id; |
|
328
|
|
- update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
|
327
|
+ $cached_information[$payment_details] = $payment_profile_id; |
|
|
328
|
+ update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
329
|
329
|
|
|
330
|
330
|
} |
|
331
|
331
|
|
|
@@ -338,7 +338,7 @@ discard block |
|
|
block discarded – undo |
|
338
|
338
|
* @return string|WP_Error Profile id. |
|
339
|
339
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
|
340
|
340
|
*/ |
|
341
|
|
- public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
|
341
|
+ public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
342
|
342
|
|
|
343
|
343
|
// Generate args. |
|
344
|
344
|
$args = array( |
|
@@ -349,7 +349,7 @@ discard block |
|
|
block discarded – undo |
|
349
|
349
|
) |
|
350
|
350
|
); |
|
351
|
351
|
|
|
352
|
|
- return $this->post( $args, false ); |
|
|
352
|
+ return $this->post($args, false); |
|
353
|
353
|
|
|
354
|
354
|
} |
|
355
|
355
|
|
|
@@ -362,7 +362,7 @@ discard block |
|
|
block discarded – undo |
|
362
|
362
|
* @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
|
363
|
363
|
* @return WP_Error|object |
|
364
|
364
|
*/ |
|
365
|
|
- public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
|
365
|
+ public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
366
|
366
|
|
|
367
|
367
|
// Generate args. |
|
368
|
368
|
$args = array( |
|
@@ -382,28 +382,28 @@ discard block |
|
|
block discarded – undo |
|
382
|
382
|
) |
|
383
|
383
|
), |
|
384
|
384
|
'order' => array( |
|
385
|
|
- 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
|
385
|
+ 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
386
|
386
|
), |
|
387
|
|
- 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
|
387
|
+ 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
388
|
388
|
'tax' => array( |
|
389
|
389
|
'amount' => $invoice->get_total_tax(), |
|
390
|
|
- 'name' => __( 'TAX', 'invoicing' ), |
|
|
390
|
+ 'name' => __('TAX', 'invoicing'), |
|
391
|
391
|
), |
|
392
|
|
- 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
|
392
|
+ 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
393
|
393
|
'customer' => array( |
|
394
|
|
- 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
395
|
|
- 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
|
394
|
+ 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
|
395
|
+ 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
396
|
396
|
), |
|
397
|
397
|
'customerIP' => $invoice->get_ip(), |
|
398
|
398
|
) |
|
399
|
399
|
) |
|
400
|
400
|
); |
|
401
|
401
|
|
|
402
|
|
- if ( 0 == $invoice->get_total_tax() ) { |
|
403
|
|
- unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
|
402
|
+ if (0 == $invoice->get_total_tax()) { |
|
|
403
|
+ unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
404
|
404
|
} |
|
405
|
405
|
|
|
406
|
|
- return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
|
406
|
+ return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
407
|
407
|
|
|
408
|
408
|
} |
|
409
|
409
|
|
|
@@ -413,29 +413,29 @@ discard block |
|
|
block discarded – undo |
|
413
|
413
|
* @param stdClass $result Api response. |
|
414
|
414
|
* @param WPInv_Invoice $invoice Invoice. |
|
415
|
415
|
*/ |
|
416
|
|
- public function process_charge_response( $result, $invoice ) { |
|
|
416
|
+ public function process_charge_response($result, $invoice) { |
|
417
|
417
|
|
|
418
|
418
|
wpinv_clear_errors(); |
|
419
|
419
|
$response_code = (int) $result->transactionResponse->responseCode; |
|
420
|
420
|
|
|
421
|
421
|
// Succeeded. |
|
422
|
|
- if ( 1 == $response_code || 4 == $response_code ) { |
|
|
422
|
+ if (1 == $response_code || 4 == $response_code) { |
|
423
|
423
|
|
|
424
|
424
|
// Maybe set a transaction id. |
|
425
|
|
- if ( ! empty( $result->transactionResponse->transId ) ) { |
|
426
|
|
- $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
|
425
|
+ if (!empty($result->transactionResponse->transId)) { |
|
|
426
|
+ $invoice->set_transaction_id($result->transactionResponse->transId); |
|
427
|
427
|
} |
|
428
|
428
|
|
|
429
|
|
- $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
|
429
|
+ $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
430
|
430
|
|
|
431
|
|
- if ( 1 == $response_code ) { |
|
|
431
|
+ if (1 == $response_code) { |
|
432
|
432
|
return $invoice->mark_paid(); |
|
433
|
433
|
} |
|
434
|
434
|
|
|
435
|
|
- $invoice->set_status( 'wpi-onhold' ); |
|
|
435
|
+ $invoice->set_status('wpi-onhold'); |
|
436
|
436
|
$invoice->add_note( |
|
437
|
437
|
sprintf( |
|
438
|
|
- __( 'Held for review: %s', 'invoicing' ), |
|
|
438
|
+ __('Held for review: %s', 'invoicing'), |
|
439
|
439
|
$result->transactionResponse->messages->message[0]->description |
|
440
|
440
|
) |
|
441
|
441
|
); |
|
@@ -444,11 +444,11 @@ discard block |
|
|
block discarded – undo |
|
444
|
444
|
|
|
445
|
445
|
} |
|
446
|
446
|
|
|
447
|
|
- wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
|
447
|
+ wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
448
|
448
|
|
|
449
|
|
- if ( ! empty( $result->transactionResponse->errors ) ) { |
|
|
449
|
+ if (!empty($result->transactionResponse->errors)) { |
|
450
|
450
|
$errors = (object) $result->transactionResponse->errors; |
|
451
|
|
- wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
|
451
|
+ wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
452
|
452
|
} |
|
453
|
453
|
|
|
454
|
454
|
} |
|
@@ -460,10 +460,10 @@ discard block |
|
|
block discarded – undo |
|
460
|
460
|
* @param array $card Card details. |
|
461
|
461
|
* @return array |
|
462
|
462
|
*/ |
|
463
|
|
- public function get_payment_information( $card ) { |
|
|
463
|
+ public function get_payment_information($card) { |
|
464
|
464
|
return array( |
|
465
|
465
|
|
|
466
|
|
- 'creditCard' => array ( |
|
|
466
|
+ 'creditCard' => array( |
|
467
|
467
|
'cardNumber' => $card['cc_number'], |
|
468
|
468
|
'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'], |
|
469
|
469
|
'cardCode' => $card['cc_cvv2'], |
|
@@ -479,8 +479,8 @@ discard block |
|
|
block discarded – undo |
|
479
|
479
|
* @param WPInv_Invoice $invoice Invoice. |
|
480
|
480
|
* @return string |
|
481
|
481
|
*/ |
|
482
|
|
- public function get_customer_profile_meta_name( $invoice ) { |
|
483
|
|
- return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
|
482
|
+ public function get_customer_profile_meta_name($invoice) { |
|
|
483
|
+ return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
484
|
484
|
} |
|
485
|
485
|
|
|
486
|
486
|
/** |
|
@@ -491,34 +491,34 @@ discard block |
|
|
block discarded – undo |
|
491
|
491
|
* @param WPInv_Invoice $invoice |
|
492
|
492
|
* @return WP_Error|string The payment profile id |
|
493
|
493
|
*/ |
|
494
|
|
- public function validate_submission_data( $submission_data, $invoice ) { |
|
|
494
|
+ public function validate_submission_data($submission_data, $invoice) { |
|
495
|
495
|
|
|
496
|
496
|
// Validate authentication details. |
|
497
|
497
|
$auth = $this->get_auth_params(); |
|
498
|
498
|
|
|
499
|
|
- if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
500
|
|
- return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') ); |
|
|
499
|
+ if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
|
500
|
+ return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
501
|
501
|
} |
|
502
|
502
|
|
|
503
|
503
|
// Validate the payment method. |
|
504
|
|
- if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
505
|
|
- return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') ); |
|
|
504
|
+ if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
|
505
|
+ return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
506
|
506
|
} |
|
507
|
507
|
|
|
508
|
508
|
// Are we adding a new payment method? |
|
509
|
|
- if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
|
509
|
+ if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
510
|
510
|
return $submission_data['getpaid-authorizenet-payment-method']; |
|
511
|
511
|
} |
|
512
|
512
|
|
|
513
|
513
|
// Retrieve the customer profile id. |
|
514
|
|
- $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
|
514
|
+ $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
515
|
515
|
|
|
516
|
516
|
// Create payment method. |
|
517
|
|
- if ( empty( $profile_id ) ) { |
|
518
|
|
- return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
|
517
|
+ if (empty($profile_id)) { |
|
|
518
|
+ return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
519
|
519
|
} |
|
520
|
520
|
|
|
521
|
|
- return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
|
521
|
+ return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
522
|
522
|
|
|
523
|
523
|
} |
|
524
|
524
|
|
|
@@ -529,32 +529,32 @@ discard block |
|
|
block discarded – undo |
|
529
|
529
|
* @param WPInv_Invoice $invoice Invoice. |
|
530
|
530
|
* @return array |
|
531
|
531
|
*/ |
|
532
|
|
- public function get_line_items( $invoice ) { |
|
|
532
|
+ public function get_line_items($invoice) { |
|
533
|
533
|
$items = array(); |
|
534
|
534
|
|
|
535
|
|
- foreach ( $invoice->get_items() as $item ) { |
|
|
535
|
+ foreach ($invoice->get_items() as $item) { |
|
536
|
536
|
|
|
537
|
537
|
$amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
538
|
538
|
$items[] = array( |
|
539
|
|
- 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
540
|
|
- 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
541
|
|
- 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
542
|
|
- 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
|
539
|
+ 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
|
540
|
+ 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
|
541
|
+ 'description' => getpaid_limit_length($item->get_description(), 255), |
|
|
542
|
+ 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
543
|
543
|
'unitPrice' => (float) $amount, |
|
544
|
544
|
'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
|
545
|
545
|
); |
|
546
|
546
|
|
|
547
|
547
|
} |
|
548
|
548
|
|
|
549
|
|
- foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
|
549
|
+ foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
550
|
550
|
|
|
551
|
|
- $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
|
551
|
+ $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
552
|
552
|
|
|
553
|
|
- if ( $amount > 0 ) { |
|
|
553
|
+ if ($amount > 0) { |
|
554
|
554
|
$items[] = array( |
|
555
|
|
- 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
556
|
|
- 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
557
|
|
- 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
|
555
|
+ 'itemId' => getpaid_limit_length($fee_name, 31), |
|
|
556
|
+ 'name' => getpaid_limit_length($fee_name, 31), |
|
|
557
|
+ 'description' => getpaid_limit_length($fee_name, 255), |
|
558
|
558
|
'quantity' => '1', |
|
559
|
559
|
'unitPrice' => (float) $amount, |
|
560
|
560
|
'taxable' => false, |
|
@@ -575,36 +575,36 @@ discard block |
|
|
block discarded – undo |
|
575
|
575
|
* @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
576
|
576
|
* @return array |
|
577
|
577
|
*/ |
|
578
|
|
- public function process_payment( $invoice, $submission_data, $submission ) { |
|
|
578
|
+ public function process_payment($invoice, $submission_data, $submission) { |
|
579
|
579
|
|
|
580
|
580
|
// Validate the submitted data. |
|
581
|
|
- $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
|
581
|
+ $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
582
|
582
|
|
|
583
|
583
|
// Do we have an error? |
|
584
|
|
- if ( is_wp_error( $payment_profile_id ) ) { |
|
585
|
|
- wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
586
|
|
- wpinv_send_back_to_checkout( $invoice ); |
|
|
584
|
+ if (is_wp_error($payment_profile_id)) { |
|
|
585
|
+ wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
|
586
|
+ wpinv_send_back_to_checkout($invoice); |
|
587
|
587
|
} |
|
588
|
588
|
|
|
589
|
589
|
// Save the payment method to the order. |
|
590
|
|
- update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
|
590
|
+ update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
591
|
591
|
|
|
592
|
592
|
// Check if this is a subscription or not. |
|
593
|
|
- $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
594
|
|
- if ( ! empty( $subscriptions ) ) { |
|
595
|
|
- $this->process_subscription( $invoice, $subscriptions ); |
|
|
593
|
+ $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
|
594
|
+ if (!empty($subscriptions)) { |
|
|
595
|
+ $this->process_subscription($invoice, $subscriptions); |
|
596
|
596
|
} |
|
597
|
597
|
|
|
598
|
598
|
// If it is free, send to the success page. |
|
599
|
|
- if ( ! $invoice->needs_payment() ) { |
|
|
599
|
+ if (!$invoice->needs_payment()) { |
|
600
|
600
|
$invoice->mark_paid(); |
|
601
|
|
- wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
|
601
|
+ wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
602
|
602
|
} |
|
603
|
603
|
|
|
604
|
604
|
// Charge the payment profile. |
|
605
|
|
- $this->process_initial_payment( $invoice ); |
|
|
605
|
+ $this->process_initial_payment($invoice); |
|
606
|
606
|
|
|
607
|
|
- wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
|
607
|
+ wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
608
|
608
|
|
|
609
|
609
|
exit; |
|
610
|
610
|
|
|
@@ -615,23 +615,23 @@ discard block |
|
|
block discarded – undo |
|
615
|
615
|
* |
|
616
|
616
|
* @param WPInv_Invoice $invoice Invoice. |
|
617
|
617
|
*/ |
|
618
|
|
- protected function process_initial_payment( $invoice ) { |
|
|
618
|
+ protected function process_initial_payment($invoice) { |
|
619
|
619
|
|
|
620
|
|
- $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
621
|
|
- $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
622
|
|
- $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
|
620
|
+ $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
|
621
|
+ $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
|
622
|
+ $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
623
|
623
|
|
|
624
|
624
|
// Do we have an error? |
|
625
|
|
- if ( is_wp_error( $result ) ) { |
|
626
|
|
- wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
627
|
|
- wpinv_send_back_to_checkout( $invoice ); |
|
|
625
|
+ if (is_wp_error($result)) { |
|
|
626
|
+ wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
|
627
|
+ wpinv_send_back_to_checkout($invoice); |
|
628
|
628
|
} |
|
629
|
629
|
|
|
630
|
630
|
// Process the response. |
|
631
|
|
- $this->process_charge_response( $result, $invoice ); |
|
|
631
|
+ $this->process_charge_response($result, $invoice); |
|
632
|
632
|
|
|
633
|
|
- if ( wpinv_get_errors() ) { |
|
634
|
|
- wpinv_send_back_to_checkout( $invoice ); |
|
|
633
|
+ if (wpinv_get_errors()) { |
|
|
634
|
+ wpinv_send_back_to_checkout($invoice); |
|
635
|
635
|
} |
|
636
|
636
|
|
|
637
|
637
|
} |
|
@@ -642,30 +642,30 @@ discard block |
|
|
block discarded – undo |
|
642
|
642
|
* @param WPInv_Invoice $invoice Invoice. |
|
643
|
643
|
* @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
|
644
|
644
|
*/ |
|
645
|
|
- public function process_subscription( $invoice, $subscriptions ) { |
|
|
645
|
+ public function process_subscription($invoice, $subscriptions) { |
|
646
|
646
|
|
|
647
|
647
|
// Check if there is an initial amount to charge. |
|
648
|
|
- if ( (float) $invoice->get_total() > 0 ) { |
|
649
|
|
- $this->process_initial_payment( $invoice ); |
|
|
648
|
+ if ((float) $invoice->get_total() > 0) { |
|
|
649
|
+ $this->process_initial_payment($invoice); |
|
650
|
650
|
} |
|
651
|
651
|
|
|
652
|
652
|
// Activate the subscriptions. |
|
653
|
|
- $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
|
653
|
+ $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
654
|
654
|
|
|
655
|
|
- foreach ( $subscriptions as $subscription ) { |
|
656
|
|
- if ( $subscription->exists() ) { |
|
657
|
|
- $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
658
|
|
- $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
|
655
|
+ foreach ($subscriptions as $subscription) { |
|
|
656
|
+ if ($subscription->exists()) { |
|
|
657
|
+ $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
|
658
|
+ $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
659
|
659
|
|
|
660
|
|
- $subscription->set_next_renewal_date( $expiry ); |
|
661
|
|
- $subscription->set_date_created( current_time( 'mysql' ) ); |
|
662
|
|
- $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
|
660
|
+ $subscription->set_next_renewal_date($expiry); |
|
|
661
|
+ $subscription->set_date_created(current_time('mysql')); |
|
|
662
|
+ $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
663
|
663
|
$subscription->activate(); |
|
664
|
664
|
} |
|
665
|
665
|
} |
|
666
|
666
|
|
|
667
|
667
|
// Redirect to the success page. |
|
668
|
|
- wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
|
668
|
+ wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
669
|
669
|
|
|
670
|
670
|
} |
|
671
|
671
|
|
|
@@ -676,20 +676,20 @@ discard block |
|
|
block discarded – undo |
|
676
|
676
|
* @param bool $should_expire |
|
677
|
677
|
* @param WPInv_Subscription $subscription |
|
678
|
678
|
*/ |
|
679
|
|
- public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
|
679
|
+ public function maybe_renew_subscription($should_expire, $subscription) { |
|
680
|
680
|
|
|
681
|
681
|
// Ensure its our subscription && it's active. |
|
682
|
|
- if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
|
|
682
|
+ if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) { |
|
683
|
683
|
return $should_expire; |
|
684
|
684
|
} |
|
685
|
685
|
|
|
686
|
686
|
// If this is the last renewal, complete the subscription. |
|
687
|
|
- if ( $subscription->is_last_renewal() ) { |
|
|
687
|
+ if ($subscription->is_last_renewal()) { |
|
688
|
688
|
$subscription->complete(); |
|
689
|
689
|
return false; |
|
690
|
690
|
} |
|
691
|
691
|
|
|
692
|
|
- $this->renew_subscription( $subscription ); |
|
|
692
|
+ $this->renew_subscription($subscription); |
|
693
|
693
|
|
|
694
|
694
|
return false; |
|
695
|
695
|
|
|
@@ -700,28 +700,28 @@ discard block |
|
|
block discarded – undo |
|
700
|
700
|
* |
|
701
|
701
|
* @param WPInv_Subscription $subscription |
|
702
|
702
|
*/ |
|
703
|
|
- public function renew_subscription( $subscription ) { |
|
|
703
|
+ public function renew_subscription($subscription) { |
|
704
|
704
|
|
|
705
|
705
|
// Generate the renewal invoice. |
|
706
|
706
|
$new_invoice = $subscription->create_payment(); |
|
707
|
707
|
$old_invoice = $subscription->get_parent_payment(); |
|
708
|
708
|
|
|
709
|
|
- if ( empty( $new_invoice ) ) { |
|
710
|
|
- $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
|
709
|
+ if (empty($new_invoice)) { |
|
|
710
|
+ $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
711
|
711
|
$subscription->failing(); |
|
712
|
712
|
return; |
|
713
|
713
|
} |
|
714
|
714
|
|
|
715
|
715
|
// Charge the payment method. |
|
716
|
|
- $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
717
|
|
- $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
718
|
|
- $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
|
716
|
+ $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
|
717
|
+ $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
|
718
|
+ $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
719
|
719
|
|
|
720
|
720
|
// Do we have an error? |
|
721
|
|
- if ( is_wp_error( $result ) ) { |
|
|
721
|
+ if (is_wp_error($result)) { |
|
722
|
722
|
|
|
723
|
723
|
$old_invoice->add_note( |
|
724
|
|
- sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
|
724
|
+ sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
725
|
725
|
true, |
|
726
|
726
|
false, |
|
727
|
727
|
true |
|
@@ -732,12 +732,12 @@ discard block |
|
|
block discarded – undo |
|
732
|
732
|
} |
|
733
|
733
|
|
|
734
|
734
|
// Process the response. |
|
735
|
|
- $this->process_charge_response( $result, $new_invoice ); |
|
|
735
|
+ $this->process_charge_response($result, $new_invoice); |
|
736
|
736
|
|
|
737
|
|
- if ( wpinv_get_errors() ) { |
|
|
737
|
+ if (wpinv_get_errors()) { |
|
738
|
738
|
|
|
739
|
739
|
$old_invoice->add_note( |
|
740
|
|
- sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
|
740
|
+ sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
741
|
741
|
true, |
|
742
|
742
|
false, |
|
743
|
743
|
true |
|
@@ -747,7 +747,7 @@ discard block |
|
|
block discarded – undo |
|
747
|
747
|
|
|
748
|
748
|
} |
|
749
|
749
|
|
|
750
|
|
- $subscription->add_payment( array(), $new_invoice ); |
|
|
750
|
+ $subscription->add_payment(array(), $new_invoice); |
|
751
|
751
|
$subscription->renew(); |
|
752
|
752
|
} |
|
753
|
753
|
|
|
@@ -758,34 +758,34 @@ discard block |
|
|
block discarded – undo |
|
758
|
758
|
* @param GetPaid_Form_Item[] $items |
|
759
|
759
|
* @return WPInv_Invoice |
|
760
|
760
|
*/ |
|
761
|
|
- public function process_addons( $invoice, $items ) { |
|
|
761
|
+ public function process_addons($invoice, $items) { |
|
762
|
762
|
|
|
763
|
763
|
global $getpaid_authorize_addons; |
|
764
|
764
|
|
|
765
|
765
|
$getpaid_authorize_addons = array(); |
|
766
|
|
- foreach ( $items as $item ) { |
|
|
766
|
+ foreach ($items as $item) { |
|
767
|
767
|
|
|
768
|
|
- if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
|
768
|
+ if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
769
|
769
|
$getpaid_authorize_addons[] = $item; |
|
770
|
770
|
} |
|
771
|
771
|
|
|
772
|
772
|
} |
|
773
|
773
|
|
|
774
|
|
- if ( empty( $getpaid_authorize_addons ) ) { |
|
|
774
|
+ if (empty($getpaid_authorize_addons)) { |
|
775
|
775
|
return; |
|
776
|
776
|
} |
|
777
|
777
|
|
|
778
|
778
|
$invoice->recalculate_total(); |
|
779
|
779
|
|
|
780
|
|
- $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
781
|
|
- $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
|
780
|
+ $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
|
781
|
+ $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
782
|
782
|
|
|
783
|
|
- add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
784
|
|
- $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
785
|
|
- remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
|
783
|
+ add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
|
784
|
+ $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
|
785
|
+ remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
786
|
786
|
|
|
787
|
|
- if ( is_wp_error( $result ) ) { |
|
788
|
|
- wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
|
787
|
+ if (is_wp_error($result)) { |
|
|
788
|
+ wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
789
|
789
|
return; |
|
790
|
790
|
} |
|
791
|
791
|
|
|
@@ -798,19 +798,19 @@ discard block |
|
|
block discarded – undo |
|
798
|
798
|
* @param array $args |
|
799
|
799
|
* @return array |
|
800
|
800
|
*/ |
|
801
|
|
- public function filter_addons_request( $args ) { |
|
|
801
|
+ public function filter_addons_request($args) { |
|
802
|
802
|
|
|
803
|
803
|
global $getpaid_authorize_addons; |
|
804
|
804
|
$total = 0; |
|
805
|
805
|
|
|
806
|
|
- foreach ( $getpaid_authorize_addons as $addon ) { |
|
|
806
|
+ foreach ($getpaid_authorize_addons as $addon) { |
|
807
|
807
|
$total += $addon->get_sub_total(); |
|
808
|
808
|
} |
|
809
|
809
|
|
|
810
|
810
|
$args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
|
811
|
811
|
|
|
812
|
|
- if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
813
|
|
- unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
|
812
|
+ if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
|
813
|
+ unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
814
|
814
|
} |
|
815
|
815
|
|
|
816
|
816
|
return $args; |
|
@@ -823,7 +823,7 @@ discard block |
|
|
block discarded – undo |
|
823
|
823
|
public function sandbox_notice() { |
|
824
|
824
|
|
|
825
|
825
|
return sprintf( |
|
826
|
|
- __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
|
826
|
+ __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
827
|
827
|
'<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
|
828
|
828
|
'</a>' |
|
829
|
829
|
); |
|
@@ -835,42 +835,42 @@ discard block |
|
|
block discarded – undo |
|
835
|
835
|
* |
|
836
|
836
|
* @param array $admin_settings |
|
837
|
837
|
*/ |
|
838
|
|
- public function admin_settings( $admin_settings ) { |
|
|
838
|
+ public function admin_settings($admin_settings) { |
|
839
|
839
|
|
|
840
|
840
|
$currencies = sprintf( |
|
841
|
|
- __( 'Supported Currencies: %s', 'invoicing' ), |
|
842
|
|
- implode( ', ', $this->currencies ) |
|
|
841
|
+ __('Supported Currencies: %s', 'invoicing'), |
|
|
842
|
+ implode(', ', $this->currencies) |
|
843
|
843
|
); |
|
844
|
844
|
|
|
845
|
845
|
$admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
|
846
|
|
- $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
|
846
|
+ $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
847
|
847
|
|
|
848
|
848
|
$admin_settings['authorizenet_login_id'] = array( |
|
849
|
849
|
'type' => 'text', |
|
850
|
850
|
'id' => 'authorizenet_login_id', |
|
851
|
|
- 'name' => __( 'API Login ID', 'invoicing' ), |
|
852
|
|
- 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
|
851
|
+ 'name' => __('API Login ID', 'invoicing'), |
|
|
852
|
+ 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
853
|
853
|
); |
|
854
|
854
|
|
|
855
|
855
|
$admin_settings['authorizenet_transaction_key'] = array( |
|
856
|
856
|
'type' => 'text', |
|
857
|
857
|
'id' => 'authorizenet_transaction_key', |
|
858
|
|
- 'name' => __( 'Transaction Key', 'invoicing' ), |
|
|
858
|
+ 'name' => __('Transaction Key', 'invoicing'), |
|
859
|
859
|
); |
|
860
|
860
|
|
|
861
|
861
|
$admin_settings['authorizenet_signature_key'] = array( |
|
862
|
862
|
'type' => 'text', |
|
863
|
863
|
'id' => 'authorizenet_signature_key', |
|
864
|
|
- 'name' => __( 'Signature Key', 'invoicing' ), |
|
865
|
|
- 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
|
864
|
+ 'name' => __('Signature Key', 'invoicing'), |
|
|
865
|
+ 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
866
|
866
|
); |
|
867
|
867
|
|
|
868
|
868
|
$admin_settings['authorizenet_ipn_url'] = array( |
|
869
|
869
|
'type' => 'ipn_url', |
|
870
|
870
|
'id' => 'authorizenet_ipn_url', |
|
871
|
|
- 'name' => __( 'Webhook URL', 'invoicing' ), |
|
|
871
|
+ 'name' => __('Webhook URL', 'invoicing'), |
|
872
|
872
|
'std' => $this->notify_url, |
|
873
|
|
- 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
|
873
|
+ 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
874
|
874
|
'custom' => 'authorizenet', |
|
875
|
875
|
'readonly' => true, |
|
876
|
876
|
); |