|
@@ -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. |
|
@@ -61,7 +61,7 @@ discard block |
|
|
block discarded – undo |
|
61
|
61
|
* |
|
62
|
62
|
* @var array |
|
63
|
63
|
*/ |
|
64
|
|
- public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
|
64
|
+ public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
65
|
65
|
|
|
66
|
66
|
/** |
|
67
|
67
|
* URL to view a transaction. |
|
@@ -75,12 +75,12 @@ discard block |
|
|
block discarded – undo |
|
75
|
75
|
*/ |
|
76
|
76
|
public function __construct() { |
|
77
|
77
|
|
|
78
|
|
- $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
79
|
|
- $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
80
|
|
- $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
|
78
|
+ $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
|
79
|
+ $this->method_title = __('Authorize.Net', 'invoicing'); |
|
|
80
|
+ $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
81
|
81
|
|
|
82
|
|
- add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
83
|
|
- add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
|
82
|
+ add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
|
83
|
+ add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
84
|
84
|
parent::__construct(); |
|
85
|
85
|
} |
|
86
|
86
|
|
|
@@ -90,13 +90,13 @@ discard block |
|
|
block discarded – undo |
|
90
|
90
|
* @param int $invoice_id 0 or invoice id. |
|
91
|
91
|
* @param GetPaid_Payment_Form $form Current payment form. |
|
92
|
92
|
*/ |
|
93
|
|
- public function payment_fields( $invoice_id, $form ) { |
|
|
93
|
+ public function payment_fields($invoice_id, $form) { |
|
94
|
94
|
|
|
95
|
95
|
// Let the user select a payment method. |
|
96
|
96
|
$this->saved_payment_methods(); |
|
97
|
97
|
|
|
98
|
98
|
// Show the credit card entry form. |
|
99
|
|
- $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
|
99
|
+ $this->new_payment_method_entry($this->get_cc_form(true)); |
|
100
|
100
|
} |
|
101
|
101
|
|
|
102
|
102
|
/** |
|
@@ -109,79 +109,79 @@ discard block |
|
|
block discarded – undo |
|
109
|
109
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
|
110
|
110
|
* @return string|WP_Error Payment profile id. |
|
111
|
111
|
*/ |
|
112
|
|
- public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
|
112
|
+ public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
113
|
113
|
|
|
114
|
114
|
// Remove non-digits from the number |
|
115
|
|
- $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
|
115
|
+ $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
116
|
116
|
|
|
117
|
117
|
// Generate args. |
|
118
|
118
|
$args = array( |
|
119
|
119
|
'createCustomerProfileRequest' => array( |
|
120
|
120
|
'merchantAuthentication' => $this->get_auth_params(), |
|
121
|
121
|
'profile' => array( |
|
122
|
|
- 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
123
|
|
- 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
124
|
|
- 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
|
122
|
+ 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
|
123
|
+ 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
|
124
|
+ 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
125
|
125
|
'paymentProfiles' => array( |
|
126
|
126
|
'customerType' => 'individual', |
|
127
|
127
|
|
|
128
|
128
|
// Billing information. |
|
129
|
129
|
'billTo' => array( |
|
130
|
|
- 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
131
|
|
- 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
132
|
|
- 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
133
|
|
- 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
134
|
|
- 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
135
|
|
- 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
136
|
|
- 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
|
130
|
+ 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
|
131
|
+ 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
|
132
|
+ 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
|
133
|
+ 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
|
134
|
+ 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
|
135
|
+ 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
|
136
|
+ 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
137
|
137
|
), |
|
138
|
138
|
|
|
139
|
139
|
// Payment information. |
|
140
|
|
- 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
|
140
|
+ 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
141
|
141
|
), |
|
142
|
142
|
), |
|
143
|
|
- 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
|
143
|
+ 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
144
|
144
|
), |
|
145
|
145
|
); |
|
146
|
146
|
|
|
147
|
|
- $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
|
147
|
+ $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
148
|
148
|
|
|
149
|
|
- if ( is_wp_error( $response ) ) { |
|
|
149
|
+ if (is_wp_error($response)) { |
|
150
|
150
|
|
|
151
|
151
|
// In case the payment profile already exists remotely. |
|
152
|
|
- if ( 'dup_payment_profile' === $response->get_error_code() ) { |
|
153
|
|
- $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
154
|
|
- update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
155
|
|
- return strtok( '.' ); |
|
|
152
|
+ if ('dup_payment_profile' === $response->get_error_code()) { |
|
|
153
|
+ $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
|
154
|
+ update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
|
155
|
+ return strtok('.'); |
|
156
|
156
|
} |
|
157
|
157
|
|
|
158
|
158
|
// In case the customer profile already exists remotely. |
|
159
|
|
- if ( 'E00039' === $response->get_error_code() ) { |
|
160
|
|
- $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
161
|
|
- $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
162
|
|
- return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
|
159
|
+ if ('E00039' === $response->get_error_code()) { |
|
|
160
|
+ $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
|
161
|
+ $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
|
162
|
+ return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
163
|
163
|
} |
|
164
|
164
|
|
|
165
|
165
|
return $response; |
|
166
|
166
|
} |
|
167
|
167
|
|
|
168
|
|
- update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
|
168
|
+ update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
169
|
169
|
|
|
170
|
170
|
// Save the payment token. |
|
171
|
|
- if ( $save ) { |
|
|
171
|
+ if ($save) { |
|
172
|
172
|
$this->save_token( |
|
173
|
173
|
array( |
|
174
|
174
|
'id' => $response->customerPaymentProfileIdList[0], |
|
175
|
|
- 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
|
175
|
+ 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
176
|
176
|
'default' => true, |
|
177
|
|
- 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
|
177
|
+ 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
178
|
178
|
) |
|
179
|
179
|
); |
|
180
|
180
|
} |
|
181
|
181
|
|
|
182
|
182
|
// Add a note about the validation response. |
|
183
|
183
|
$invoice->add_note( |
|
184
|
|
- sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
|
184
|
+ sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
185
|
185
|
false, |
|
186
|
186
|
false, |
|
187
|
187
|
true |
|
@@ -198,7 +198,7 @@ discard block |
|
|
block discarded – undo |
|
198
|
198
|
* @return string|WP_Error Profile id. |
|
199
|
199
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
|
200
|
200
|
*/ |
|
201
|
|
- public function get_customer_profile( $profile_id ) { |
|
|
201
|
+ public function get_customer_profile($profile_id) { |
|
202
|
202
|
|
|
203
|
203
|
// Generate args. |
|
204
|
204
|
$args = array( |
|
@@ -208,7 +208,7 @@ discard block |
|
|
block discarded – undo |
|
208
|
208
|
), |
|
209
|
209
|
); |
|
210
|
210
|
|
|
211
|
|
- return $this->post( $args, false ); |
|
|
211
|
+ return $this->post($args, false); |
|
212
|
212
|
|
|
213
|
213
|
} |
|
214
|
214
|
|
|
@@ -223,18 +223,18 @@ discard block |
|
|
block discarded – undo |
|
223
|
223
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
|
224
|
224
|
* @return string|WP_Error Profile id. |
|
225
|
225
|
*/ |
|
226
|
|
- public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
|
226
|
+ public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
227
|
227
|
|
|
228
|
228
|
// Remove non-digits from the number |
|
229
|
|
- $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
|
229
|
+ $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
230
|
230
|
|
|
231
|
231
|
// Prepare card details. |
|
232
|
|
- $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
|
232
|
+ $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
233
|
233
|
|
|
234
|
234
|
// Authorize.NET does not support saving the same card twice. |
|
235
|
|
- $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
|
235
|
+ $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
236
|
236
|
|
|
237
|
|
- if ( $cached_information ) { |
|
|
237
|
+ if ($cached_information) { |
|
238
|
238
|
return $cached_information; |
|
239
|
239
|
} |
|
240
|
240
|
|
|
@@ -247,34 +247,34 @@ discard block |
|
|
block discarded – undo |
|
247
|
247
|
|
|
248
|
248
|
// Billing information. |
|
249
|
249
|
'billTo' => array( |
|
250
|
|
- 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
251
|
|
- 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
252
|
|
- 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
253
|
|
- 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
254
|
|
- 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
255
|
|
- 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
256
|
|
- 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
|
250
|
+ 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
|
251
|
+ 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
|
252
|
+ 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
|
253
|
+ 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
|
254
|
+ 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
|
255
|
+ 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
|
256
|
+ 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
257
|
257
|
), |
|
258
|
258
|
|
|
259
|
259
|
// Payment information. |
|
260
|
260
|
'payment' => $payment_information, |
|
261
|
261
|
), |
|
262
|
|
- 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
|
262
|
+ 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
263
|
263
|
), |
|
264
|
264
|
); |
|
265
|
265
|
|
|
266
|
|
- $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
|
266
|
+ $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
267
|
267
|
|
|
268
|
|
- if ( is_wp_error( $response ) ) { |
|
|
268
|
+ if (is_wp_error($response)) { |
|
269
|
269
|
|
|
270
|
270
|
// In case the payment profile already exists remotely. |
|
271
|
|
- if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
272
|
|
- $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
273
|
|
- $payment_profile_id = strtok( '.' ); |
|
274
|
|
- update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
|
271
|
+ if ('dup_payment_profile' == $response->get_error_code()) { |
|
|
272
|
+ $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
|
273
|
+ $payment_profile_id = strtok('.'); |
|
|
274
|
+ update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
275
|
275
|
|
|
276
|
276
|
// Cache payment profile id. |
|
277
|
|
- $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
|
277
|
+ $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
278
|
278
|
|
|
279
|
279
|
return $payment_profile_id; |
|
280
|
280
|
} |
|
@@ -283,29 +283,29 @@ discard block |
|
|
block discarded – undo |
|
283
|
283
|
} |
|
284
|
284
|
|
|
285
|
285
|
// Save the payment token. |
|
286
|
|
- if ( $save ) { |
|
|
286
|
+ if ($save) { |
|
287
|
287
|
$this->save_token( |
|
288
|
288
|
array( |
|
289
|
289
|
'id' => $response->customerPaymentProfileId, |
|
290
|
|
- 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
|
290
|
+ 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
291
|
291
|
'default' => true, |
|
292
|
|
- 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
|
292
|
+ 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
293
|
293
|
) |
|
294
|
294
|
); |
|
295
|
295
|
} |
|
296
|
296
|
|
|
297
|
297
|
// Cache payment profile id. |
|
298
|
|
- $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
|
298
|
+ $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
299
|
299
|
|
|
300
|
300
|
// Add a note about the validation response. |
|
301
|
301
|
$invoice->add_note( |
|
302
|
|
- sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
|
302
|
+ sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
303
|
303
|
false, |
|
304
|
304
|
false, |
|
305
|
305
|
true |
|
306
|
306
|
); |
|
307
|
307
|
|
|
308
|
|
- update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
|
308
|
+ update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
309
|
309
|
|
|
310
|
310
|
return $response->customerPaymentProfileId; |
|
311
|
311
|
} |
|
@@ -317,12 +317,12 @@ discard block |
|
|
block discarded – undo |
|
317
|
317
|
* @param array $payment_details. |
|
318
|
318
|
* @return array|false Profile id. |
|
319
|
319
|
*/ |
|
320
|
|
- public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
|
320
|
+ public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
321
|
321
|
|
|
322
|
|
- $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
323
|
|
- $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
|
322
|
+ $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
|
323
|
+ $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
324
|
324
|
|
|
325
|
|
- if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
|
325
|
+ if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
326
|
326
|
return false; |
|
327
|
327
|
} |
|
328
|
328
|
|
|
@@ -331,13 +331,13 @@ discard block |
|
|
block discarded – undo |
|
331
|
331
|
'getCustomerPaymentProfileRequest' => array( |
|
332
|
332
|
'merchantAuthentication' => $this->get_auth_params(), |
|
333
|
333
|
'customerProfileId' => $customer_profile, |
|
334
|
|
- 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
|
334
|
+ 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
335
|
335
|
), |
|
336
|
336
|
); |
|
337
|
337
|
|
|
338
|
|
- $response = $this->post( $args, $invoice ); |
|
|
338
|
+ $response = $this->post($args, $invoice); |
|
339
|
339
|
|
|
340
|
|
- return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
|
340
|
+ return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
341
|
341
|
|
|
342
|
342
|
} |
|
343
|
343
|
|
|
@@ -348,14 +348,14 @@ discard block |
|
|
block discarded – undo |
|
348
|
348
|
* @param array $payment_details. |
|
349
|
349
|
* @param string $payment_profile_id. |
|
350
|
350
|
*/ |
|
351
|
|
- public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
|
351
|
+ public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
352
|
352
|
|
|
353
|
|
- $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
354
|
|
- $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
355
|
|
- $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
|
353
|
+ $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
|
354
|
+ $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
|
355
|
+ $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
356
|
356
|
|
|
357
|
|
- $cached_information[ $payment_details ] = $payment_profile_id; |
|
358
|
|
- update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
|
357
|
+ $cached_information[$payment_details] = $payment_profile_id; |
|
|
358
|
+ update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
359
|
359
|
|
|
360
|
360
|
} |
|
361
|
361
|
|
|
@@ -368,7 +368,7 @@ discard block |
|
|
block discarded – undo |
|
368
|
368
|
* @return string|WP_Error Profile id. |
|
369
|
369
|
* @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
|
370
|
370
|
*/ |
|
371
|
|
- public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
|
371
|
+ public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
372
|
372
|
|
|
373
|
373
|
// Generate args. |
|
374
|
374
|
$args = array( |
|
@@ -379,7 +379,7 @@ discard block |
|
|
block discarded – undo |
|
379
|
379
|
), |
|
380
|
380
|
); |
|
381
|
381
|
|
|
382
|
|
- return $this->post( $args, false ); |
|
|
382
|
+ return $this->post($args, false); |
|
383
|
383
|
|
|
384
|
384
|
} |
|
385
|
385
|
|
|
@@ -392,7 +392,7 @@ discard block |
|
|
block discarded – undo |
|
392
|
392
|
* @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
|
393
|
393
|
* @return WP_Error|object |
|
394
|
394
|
*/ |
|
395
|
|
- public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
|
395
|
+ public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
396
|
396
|
|
|
397
|
397
|
// Generate args. |
|
398
|
398
|
$args = array( |
|
@@ -412,28 +412,28 @@ discard block |
|
|
block discarded – undo |
|
412
|
412
|
), |
|
413
|
413
|
), |
|
414
|
414
|
'order' => array( |
|
415
|
|
- 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
|
415
|
+ 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
416
|
416
|
), |
|
417
|
|
- 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
|
417
|
+ 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
418
|
418
|
'tax' => array( |
|
419
|
419
|
'amount' => $invoice->get_total_tax(), |
|
420
|
|
- 'name' => __( 'TAX', 'invoicing' ), |
|
|
420
|
+ 'name' => __('TAX', 'invoicing'), |
|
421
|
421
|
), |
|
422
|
|
- 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
|
422
|
+ 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
423
|
423
|
'customer' => array( |
|
424
|
|
- 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
425
|
|
- 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
|
424
|
+ 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
|
425
|
+ 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
426
|
426
|
), |
|
427
|
427
|
'customerIP' => $invoice->get_ip(), |
|
428
|
428
|
), |
|
429
|
429
|
), |
|
430
|
430
|
); |
|
431
|
431
|
|
|
432
|
|
- if ( 0 == $invoice->get_total_tax() ) { |
|
433
|
|
- unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
|
432
|
+ if (0 == $invoice->get_total_tax()) { |
|
|
433
|
+ unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
434
|
434
|
} |
|
435
|
435
|
|
|
436
|
|
- return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
|
436
|
+ return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
437
|
437
|
|
|
438
|
438
|
} |
|
439
|
439
|
|
|
@@ -443,31 +443,31 @@ discard block |
|
|
block discarded – undo |
|
443
|
443
|
* @param stdClass $result Api response. |
|
444
|
444
|
* @param WPInv_Invoice $invoice Invoice. |
|
445
|
445
|
*/ |
|
446
|
|
- public function process_charge_response( $result, $invoice ) { |
|
|
446
|
+ public function process_charge_response($result, $invoice) { |
|
447
|
447
|
|
|
448
|
448
|
wpinv_clear_errors(); |
|
449
|
449
|
$response_code = (int) $result->transactionResponse->responseCode; |
|
450
|
450
|
|
|
451
|
|
- $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true ); |
|
|
451
|
+ $invoice->add_note('Transaction Response: ' . print_r($result->transactionResponse, true), false, false, true); |
|
452
|
452
|
|
|
453
|
453
|
// Succeeded. |
|
454
|
|
- if ( 1 == $response_code || 4 == $response_code ) { |
|
|
454
|
+ if (1 == $response_code || 4 == $response_code) { |
|
455
|
455
|
|
|
456
|
456
|
// Maybe set a transaction id. |
|
457
|
|
- if ( ! empty( $result->transactionResponse->transId ) ) { |
|
458
|
|
- $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
|
457
|
+ if (!empty($result->transactionResponse->transId)) { |
|
|
458
|
+ $invoice->set_transaction_id($result->transactionResponse->transId); |
|
459
|
459
|
} |
|
460
|
460
|
|
|
461
|
|
- $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
|
461
|
+ $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
462
|
462
|
|
|
463
|
|
- if ( 1 == $response_code ) { |
|
|
463
|
+ if (1 == $response_code) { |
|
464
|
464
|
return $invoice->mark_paid(); |
|
465
|
465
|
} |
|
466
|
466
|
|
|
467
|
|
- $invoice->set_status( 'wpi-onhold' ); |
|
|
467
|
+ $invoice->set_status('wpi-onhold'); |
|
468
|
468
|
$invoice->add_note( |
|
469
|
469
|
sprintf( |
|
470
|
|
- __( 'Held for review: %s', 'invoicing' ), |
|
|
470
|
+ __('Held for review: %s', 'invoicing'), |
|
471
|
471
|
$result->transactionResponse->messages->message[0]->description |
|
472
|
472
|
) |
|
473
|
473
|
); |
|
@@ -476,11 +476,11 @@ discard block |
|
|
block discarded – undo |
|
476
|
476
|
|
|
477
|
477
|
} |
|
478
|
478
|
|
|
479
|
|
- wpinv_set_error( 'card_declined' ); |
|
|
479
|
+ wpinv_set_error('card_declined'); |
|
480
|
480
|
|
|
481
|
|
- if ( ! empty( $result->transactionResponse->errors ) ) { |
|
|
481
|
+ if (!empty($result->transactionResponse->errors)) { |
|
482
|
482
|
$errors = (object) $result->transactionResponse->errors; |
|
483
|
|
- wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
|
483
|
+ wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
484
|
484
|
} |
|
485
|
485
|
|
|
486
|
486
|
} |
|
@@ -492,7 +492,7 @@ discard block |
|
|
block discarded – undo |
|
492
|
492
|
* @param array $card Card details. |
|
493
|
493
|
* @return array |
|
494
|
494
|
*/ |
|
495
|
|
- public function get_payment_information( $card ) { |
|
|
495
|
+ public function get_payment_information($card) { |
|
496
|
496
|
return array( |
|
497
|
497
|
|
|
498
|
498
|
'creditCard' => array( |
|
@@ -511,8 +511,8 @@ discard block |
|
|
block discarded – undo |
|
511
|
511
|
* @param WPInv_Invoice $invoice Invoice. |
|
512
|
512
|
* @return string |
|
513
|
513
|
*/ |
|
514
|
|
- public function get_customer_profile_meta_name( $invoice ) { |
|
515
|
|
- return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
|
514
|
+ public function get_customer_profile_meta_name($invoice) { |
|
|
515
|
+ return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
516
|
516
|
} |
|
517
|
517
|
|
|
518
|
518
|
/** |
|
@@ -523,34 +523,34 @@ discard block |
|
|
block discarded – undo |
|
523
|
523
|
* @param WPInv_Invoice $invoice |
|
524
|
524
|
* @return WP_Error|string The payment profile id |
|
525
|
525
|
*/ |
|
526
|
|
- public function validate_submission_data( $submission_data, $invoice ) { |
|
|
526
|
+ public function validate_submission_data($submission_data, $invoice) { |
|
527
|
527
|
|
|
528
|
528
|
// Validate authentication details. |
|
529
|
529
|
$auth = $this->get_auth_params(); |
|
530
|
530
|
|
|
531
|
|
- if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
532
|
|
- return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
|
531
|
+ if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
|
532
|
+ return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
533
|
533
|
} |
|
534
|
534
|
|
|
535
|
535
|
// Validate the payment method. |
|
536
|
|
- if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
537
|
|
- return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
|
536
|
+ if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
|
537
|
+ return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
538
|
538
|
} |
|
539
|
539
|
|
|
540
|
540
|
// Are we adding a new payment method? |
|
541
|
|
- if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
|
541
|
+ if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
542
|
542
|
return $submission_data['getpaid-authorizenet-payment-method']; |
|
543
|
543
|
} |
|
544
|
544
|
|
|
545
|
545
|
// Retrieve the customer profile id. |
|
546
|
|
- $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
|
546
|
+ $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
547
|
547
|
|
|
548
|
548
|
// Create payment method. |
|
549
|
|
- if ( empty( $profile_id ) ) { |
|
550
|
|
- return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
|
549
|
+ if (empty($profile_id)) { |
|
|
550
|
+ return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
551
|
551
|
} |
|
552
|
552
|
|
|
553
|
|
- return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
|
553
|
+ return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
554
|
554
|
|
|
555
|
555
|
} |
|
556
|
556
|
|
|
@@ -561,32 +561,32 @@ discard block |
|
|
block discarded – undo |
|
561
|
561
|
* @param WPInv_Invoice $invoice Invoice. |
|
562
|
562
|
* @return array |
|
563
|
563
|
*/ |
|
564
|
|
- public function get_line_items( $invoice ) { |
|
|
564
|
+ public function get_line_items($invoice) { |
|
565
|
565
|
$items = array(); |
|
566
|
566
|
|
|
567
|
|
- foreach ( $invoice->get_items() as $item ) { |
|
|
567
|
+ foreach ($invoice->get_items() as $item) { |
|
568
|
568
|
|
|
569
|
569
|
$amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
|
570
|
570
|
$items[] = array( |
|
571
|
|
- 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
572
|
|
- 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
573
|
|
- 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
574
|
|
- 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
|
571
|
+ 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
|
572
|
+ 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
|
573
|
+ 'description' => getpaid_limit_length($item->get_description(), 255), |
|
|
574
|
+ 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
575
|
575
|
'unitPrice' => (float) $amount, |
|
576
|
576
|
'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
|
577
|
577
|
); |
|
578
|
578
|
|
|
579
|
579
|
} |
|
580
|
580
|
|
|
581
|
|
- foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
|
581
|
+ foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
582
|
582
|
|
|
583
|
|
- $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
|
583
|
+ $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
584
|
584
|
|
|
585
|
|
- if ( $amount > 0 ) { |
|
|
585
|
+ if ($amount > 0) { |
|
586
|
586
|
$items[] = array( |
|
587
|
|
- 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
588
|
|
- 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
589
|
|
- 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
|
587
|
+ 'itemId' => getpaid_limit_length($fee_name, 31), |
|
|
588
|
+ 'name' => getpaid_limit_length($fee_name, 31), |
|
|
589
|
+ 'description' => getpaid_limit_length($fee_name, 255), |
|
590
|
590
|
'quantity' => '1', |
|
591
|
591
|
'unitPrice' => (float) $amount, |
|
592
|
592
|
'taxable' => false, |
|
@@ -606,36 +606,36 @@ discard block |
|
|
block discarded – undo |
|
606
|
606
|
* @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
607
|
607
|
* @return array |
|
608
|
608
|
*/ |
|
609
|
|
- public function process_payment( $invoice, $submission_data, $submission ) { |
|
|
609
|
+ public function process_payment($invoice, $submission_data, $submission) { |
|
610
|
610
|
|
|
611
|
611
|
// Validate the submitted data. |
|
612
|
|
- $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
|
612
|
+ $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
613
|
613
|
|
|
614
|
614
|
// Do we have an error? |
|
615
|
|
- if ( is_wp_error( $payment_profile_id ) ) { |
|
616
|
|
- wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
617
|
|
- wpinv_send_back_to_checkout( $invoice ); |
|
|
615
|
+ if (is_wp_error($payment_profile_id)) { |
|
|
616
|
+ wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
|
617
|
+ wpinv_send_back_to_checkout($invoice); |
|
618
|
618
|
} |
|
619
|
619
|
|
|
620
|
620
|
// Save the payment method to the order. |
|
621
|
|
- update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
|
621
|
+ update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
622
|
622
|
|
|
623
|
623
|
// Check if this is a subscription or not. |
|
624
|
|
- $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
625
|
|
- if ( ! empty( $subscriptions ) ) { |
|
626
|
|
- $this->process_subscription( $invoice, $subscriptions ); |
|
|
624
|
+ $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
|
625
|
+ if (!empty($subscriptions)) { |
|
|
626
|
+ $this->process_subscription($invoice, $subscriptions); |
|
627
|
627
|
} |
|
628
|
628
|
|
|
629
|
629
|
// If it is free, send to the success page. |
|
630
|
|
- if ( ! $invoice->needs_payment() ) { |
|
|
630
|
+ if (!$invoice->needs_payment()) { |
|
631
|
631
|
$invoice->mark_paid(); |
|
632
|
|
- wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
|
632
|
+ wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
633
|
633
|
} |
|
634
|
634
|
|
|
635
|
635
|
// Charge the payment profile. |
|
636
|
|
- $this->process_initial_payment( $invoice ); |
|
|
636
|
+ $this->process_initial_payment($invoice); |
|
637
|
637
|
|
|
638
|
|
- wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
|
638
|
+ wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
639
|
639
|
|
|
640
|
640
|
exit; |
|
641
|
641
|
|
|
@@ -646,23 +646,23 @@ discard block |
|
|
block discarded – undo |
|
646
|
646
|
* |
|
647
|
647
|
* @param WPInv_Invoice $invoice Invoice. |
|
648
|
648
|
*/ |
|
649
|
|
- protected function process_initial_payment( $invoice ) { |
|
|
649
|
+ protected function process_initial_payment($invoice) { |
|
650
|
650
|
|
|
651
|
|
- $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
652
|
|
- $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
653
|
|
- $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
|
651
|
+ $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
|
652
|
+ $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
|
653
|
+ $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
654
|
654
|
|
|
655
|
655
|
// Do we have an error? |
|
656
|
|
- if ( is_wp_error( $result ) ) { |
|
657
|
|
- wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
658
|
|
- wpinv_send_back_to_checkout( $invoice ); |
|
|
656
|
+ if (is_wp_error($result)) { |
|
|
657
|
+ wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
|
658
|
+ wpinv_send_back_to_checkout($invoice); |
|
659
|
659
|
} |
|
660
|
660
|
|
|
661
|
661
|
// Process the response. |
|
662
|
|
- $this->process_charge_response( $result, $invoice ); |
|
|
662
|
+ $this->process_charge_response($result, $invoice); |
|
663
|
663
|
|
|
664
|
|
- if ( wpinv_get_errors() ) { |
|
665
|
|
- wpinv_send_back_to_checkout( $invoice ); |
|
|
664
|
+ if (wpinv_get_errors()) { |
|
|
665
|
+ wpinv_send_back_to_checkout($invoice); |
|
666
|
666
|
} |
|
667
|
667
|
|
|
668
|
668
|
} |
|
@@ -673,30 +673,30 @@ discard block |
|
|
block discarded – undo |
|
673
|
673
|
* @param WPInv_Invoice $invoice Invoice. |
|
674
|
674
|
* @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
|
675
|
675
|
*/ |
|
676
|
|
- public function process_subscription( $invoice, $subscriptions ) { |
|
|
676
|
+ public function process_subscription($invoice, $subscriptions) { |
|
677
|
677
|
|
|
678
|
678
|
// Check if there is an initial amount to charge. |
|
679
|
|
- if ( (float) $invoice->get_total() > 0 ) { |
|
680
|
|
- $this->process_initial_payment( $invoice ); |
|
|
679
|
+ if ((float) $invoice->get_total() > 0) { |
|
|
680
|
+ $this->process_initial_payment($invoice); |
|
681
|
681
|
} |
|
682
|
682
|
|
|
683
|
683
|
// Activate the subscriptions. |
|
684
|
|
- $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
|
684
|
+ $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
685
|
685
|
|
|
686
|
|
- foreach ( $subscriptions as $subscription ) { |
|
687
|
|
- if ( $subscription->exists() ) { |
|
688
|
|
- $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
689
|
|
- $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
|
686
|
+ foreach ($subscriptions as $subscription) { |
|
|
687
|
+ if ($subscription->exists()) { |
|
|
688
|
+ $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
|
689
|
+ $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
690
|
690
|
|
|
691
|
|
- $subscription->set_next_renewal_date( $expiry ); |
|
692
|
|
- $subscription->set_date_created( current_time( 'mysql' ) ); |
|
693
|
|
- $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
|
691
|
+ $subscription->set_next_renewal_date($expiry); |
|
|
692
|
+ $subscription->set_date_created(current_time('mysql')); |
|
|
693
|
+ $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
694
|
694
|
$subscription->activate(); |
|
695
|
695
|
} |
|
696
|
696
|
} |
|
697
|
697
|
|
|
698
|
698
|
// Redirect to the success page. |
|
699
|
|
- wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
|
699
|
+ wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
700
|
700
|
|
|
701
|
701
|
} |
|
702
|
702
|
|
|
@@ -706,11 +706,11 @@ discard block |
|
|
block discarded – undo |
|
706
|
706
|
* |
|
707
|
707
|
* @param WPInv_Subscription $subscription |
|
708
|
708
|
*/ |
|
709
|
|
- public function maybe_renew_subscription( $subscription ) { |
|
|
709
|
+ public function maybe_renew_subscription($subscription) { |
|
710
|
710
|
|
|
711
|
711
|
// Ensure its our subscription && it's active. |
|
712
|
|
- if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
713
|
|
- $this->renew_subscription( $subscription ); |
|
|
712
|
+ if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
|
713
|
+ $this->renew_subscription($subscription); |
|
714
|
714
|
} |
|
715
|
715
|
|
|
716
|
716
|
} |
|
@@ -720,28 +720,28 @@ discard block |
|
|
block discarded – undo |
|
720
|
720
|
* |
|
721
|
721
|
* @param WPInv_Subscription $subscription |
|
722
|
722
|
*/ |
|
723
|
|
- public function renew_subscription( $subscription ) { |
|
|
723
|
+ public function renew_subscription($subscription) { |
|
724
|
724
|
|
|
725
|
725
|
// Generate the renewal invoice. |
|
726
|
726
|
$new_invoice = $subscription->create_payment(); |
|
727
|
727
|
$old_invoice = $subscription->get_parent_payment(); |
|
728
|
728
|
|
|
729
|
|
- if ( empty( $new_invoice ) ) { |
|
730
|
|
- $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
|
729
|
+ if (empty($new_invoice)) { |
|
|
730
|
+ $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
731
|
731
|
$subscription->failing(); |
|
732
|
732
|
return; |
|
733
|
733
|
} |
|
734
|
734
|
|
|
735
|
735
|
// Charge the payment method. |
|
736
|
|
- $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
737
|
|
- $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
738
|
|
- $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
|
736
|
+ $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
|
737
|
+ $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
|
738
|
+ $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
739
|
739
|
|
|
740
|
740
|
// Do we have an error? |
|
741
|
|
- if ( is_wp_error( $result ) ) { |
|
|
741
|
+ if (is_wp_error($result)) { |
|
742
|
742
|
|
|
743
|
743
|
$old_invoice->add_note( |
|
744
|
|
- sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
|
744
|
+ sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
745
|
745
|
true, |
|
746
|
746
|
false, |
|
747
|
747
|
true |
|
@@ -752,12 +752,12 @@ discard block |
|
|
block discarded – undo |
|
752
|
752
|
} |
|
753
|
753
|
|
|
754
|
754
|
// Process the response. |
|
755
|
|
- $this->process_charge_response( $result, $new_invoice ); |
|
|
755
|
+ $this->process_charge_response($result, $new_invoice); |
|
756
|
756
|
|
|
757
|
|
- if ( wpinv_get_errors() ) { |
|
|
757
|
+ if (wpinv_get_errors()) { |
|
758
|
758
|
|
|
759
|
759
|
$old_invoice->add_note( |
|
760
|
|
- sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
|
760
|
+ sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
761
|
761
|
true, |
|
762
|
762
|
false, |
|
763
|
763
|
true |
|
@@ -767,9 +767,9 @@ discard block |
|
|
block discarded – undo |
|
767
|
767
|
|
|
768
|
768
|
} |
|
769
|
769
|
|
|
770
|
|
- if ( ! $new_invoice->needs_payment() ) { |
|
|
770
|
+ if (!$new_invoice->needs_payment()) { |
|
771
|
771
|
$subscription->renew(); |
|
772
|
|
- $subscription->after_add_payment( $new_invoice ); |
|
|
772
|
+ $subscription->after_add_payment($new_invoice); |
|
773
|
773
|
} else { |
|
774
|
774
|
$subscription->failing(); |
|
775
|
775
|
} |
|
@@ -782,33 +782,33 @@ discard block |
|
|
block discarded – undo |
|
782
|
782
|
* @param GetPaid_Form_Item[] $items |
|
783
|
783
|
* @return WPInv_Invoice |
|
784
|
784
|
*/ |
|
785
|
|
- public function process_addons( $invoice, $items ) { |
|
|
785
|
+ public function process_addons($invoice, $items) { |
|
786
|
786
|
|
|
787
|
787
|
global $getpaid_authorize_addons; |
|
788
|
788
|
|
|
789
|
789
|
$getpaid_authorize_addons = array(); |
|
790
|
|
- foreach ( $items as $item ) { |
|
|
790
|
+ foreach ($items as $item) { |
|
791
|
791
|
|
|
792
|
|
- if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
|
792
|
+ if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
793
|
793
|
$getpaid_authorize_addons[] = $item; |
|
794
|
794
|
} |
|
795
|
795
|
} |
|
796
|
796
|
|
|
797
|
|
- if ( empty( $getpaid_authorize_addons ) ) { |
|
|
797
|
+ if (empty($getpaid_authorize_addons)) { |
|
798
|
798
|
return; |
|
799
|
799
|
} |
|
800
|
800
|
|
|
801
|
801
|
$invoice->recalculate_total(); |
|
802
|
802
|
|
|
803
|
|
- $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
804
|
|
- $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
|
803
|
+ $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
|
804
|
+ $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
805
|
805
|
|
|
806
|
|
- add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
807
|
|
- $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
808
|
|
- remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
|
806
|
+ add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
|
807
|
+ $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
|
808
|
+ remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
809
|
809
|
|
|
810
|
|
- if ( is_wp_error( $result ) ) { |
|
811
|
|
- wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
|
810
|
+ if (is_wp_error($result)) { |
|
|
811
|
+ wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
812
|
812
|
return; |
|
813
|
813
|
} |
|
814
|
814
|
|
|
@@ -821,19 +821,19 @@ discard block |
|
|
block discarded – undo |
|
821
|
821
|
* @param array $args |
|
822
|
822
|
* @return array |
|
823
|
823
|
*/ |
|
824
|
|
- public function filter_addons_request( $args ) { |
|
|
824
|
+ public function filter_addons_request($args) { |
|
825
|
825
|
|
|
826
|
826
|
global $getpaid_authorize_addons; |
|
827
|
827
|
$total = 0; |
|
828
|
828
|
|
|
829
|
|
- foreach ( $getpaid_authorize_addons as $addon ) { |
|
|
829
|
+ foreach ($getpaid_authorize_addons as $addon) { |
|
830
|
830
|
$total += $addon->get_sub_total(); |
|
831
|
831
|
} |
|
832
|
832
|
|
|
833
|
833
|
$args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
|
834
|
834
|
|
|
835
|
|
- if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
836
|
|
- unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
|
835
|
+ if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
|
836
|
+ unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
837
|
837
|
} |
|
838
|
838
|
|
|
839
|
839
|
return $args; |
|
@@ -846,7 +846,7 @@ discard block |
|
|
block discarded – undo |
|
846
|
846
|
public function sandbox_notice() { |
|
847
|
847
|
|
|
848
|
848
|
return sprintf( |
|
849
|
|
- __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
|
849
|
+ __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
850
|
850
|
'<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
|
851
|
851
|
'</a>' |
|
852
|
852
|
); |
|
@@ -858,42 +858,42 @@ discard block |
|
|
block discarded – undo |
|
858
|
858
|
* |
|
859
|
859
|
* @param array $admin_settings |
|
860
|
860
|
*/ |
|
861
|
|
- public function admin_settings( $admin_settings ) { |
|
|
861
|
+ public function admin_settings($admin_settings) { |
|
862
|
862
|
|
|
863
|
863
|
$currencies = sprintf( |
|
864
|
|
- __( 'Supported Currencies: %s', 'invoicing' ), |
|
865
|
|
- implode( ', ', $this->currencies ) |
|
|
864
|
+ __('Supported Currencies: %s', 'invoicing'), |
|
|
865
|
+ implode(', ', $this->currencies) |
|
866
|
866
|
); |
|
867
|
867
|
|
|
868
|
868
|
$admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
|
869
|
|
- $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
|
869
|
+ $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
870
|
870
|
|
|
871
|
871
|
$admin_settings['authorizenet_login_id'] = array( |
|
872
|
872
|
'type' => 'text', |
|
873
|
873
|
'id' => 'authorizenet_login_id', |
|
874
|
|
- 'name' => __( 'API Login ID', 'invoicing' ), |
|
875
|
|
- 'desc' => '<a href="https://support.authorize.net/knowledgebase/Knowledgearticle/?code=000001271"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
|
874
|
+ 'name' => __('API Login ID', 'invoicing'), |
|
|
875
|
+ 'desc' => '<a href="https://support.authorize.net/knowledgebase/Knowledgearticle/?code=000001271"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
876
|
876
|
); |
|
877
|
877
|
|
|
878
|
878
|
$admin_settings['authorizenet_transaction_key'] = array( |
|
879
|
879
|
'type' => 'text', |
|
880
|
880
|
'id' => 'authorizenet_transaction_key', |
|
881
|
|
- 'name' => __( 'Transaction Key', 'invoicing' ), |
|
|
881
|
+ 'name' => __('Transaction Key', 'invoicing'), |
|
882
|
882
|
); |
|
883
|
883
|
|
|
884
|
884
|
$admin_settings['authorizenet_signature_key'] = array( |
|
885
|
885
|
'type' => 'text', |
|
886
|
886
|
'id' => 'authorizenet_signature_key', |
|
887
|
|
- 'name' => __( 'Signature Key', 'invoicing' ), |
|
888
|
|
- 'desc' => '<a href="https://support.authorize.net/knowledgebase/Knowledgearticle/?code=000001271"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
|
887
|
+ 'name' => __('Signature Key', 'invoicing'), |
|
|
888
|
+ 'desc' => '<a href="https://support.authorize.net/knowledgebase/Knowledgearticle/?code=000001271"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
889
|
889
|
); |
|
890
|
890
|
|
|
891
|
891
|
$admin_settings['authorizenet_ipn_url'] = array( |
|
892
|
892
|
'type' => 'ipn_url', |
|
893
|
893
|
'id' => 'authorizenet_ipn_url', |
|
894
|
|
- 'name' => __( 'Webhook URL', 'invoicing' ), |
|
|
894
|
+ 'name' => __('Webhook URL', 'invoicing'), |
|
895
|
895
|
'std' => $this->notify_url, |
|
896
|
|
- '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/knowledgebase/Knowledgearticle/?code=000001542"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
|
896
|
+ '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/knowledgebase/Knowledgearticle/?code=000001542"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
897
|
897
|
'custom' => 'authorizenet', |
|
898
|
898
|
'readonly' => true, |
|
899
|
899
|
); |