@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Retrieves a customer profile. |
|
171 | - * |
|
172 | - * |
|
173 | - * @param string $profile_id profile id. |
|
174 | - * @return string|WP_Error Profile id. |
|
170 | + * Retrieves a customer profile. |
|
171 | + * |
|
172 | + * |
|
173 | + * @param string $profile_id profile id. |
|
174 | + * @return string|WP_Error Profile id. |
|
175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
176 | - */ |
|
177 | - public function get_customer_profile( $profile_id ) { |
|
176 | + */ |
|
177 | + public function get_customer_profile( $profile_id ) { |
|
178 | 178 | |
179 | 179 | // Generate args. |
180 | 180 | $args = array( |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * Creates a customer profile. |
|
193 | - * |
|
194 | - * |
|
192 | + * Creates a customer profile. |
|
193 | + * |
|
194 | + * |
|
195 | 195 | * @param string $profile_id profile id. |
196 | - * @param WPInv_Invoice $invoice Invoice. |
|
196 | + * @param WPInv_Invoice $invoice Invoice. |
|
197 | 197 | * @param array $submission_data Posted checkout fields. |
198 | 198 | * @param bool $save Whether or not to save the payment as a token. |
199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
200 | - * @return string|WP_Error Profile id. |
|
201 | - */ |
|
202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
200 | + * @return string|WP_Error Profile id. |
|
201 | + */ |
|
202 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
203 | 203 | |
204 | 204 | // Remove non-digits from the number |
205 | 205 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
262 | - * Retrieves a customer payment profile. |
|
263 | - * |
|
264 | - * |
|
265 | - * @param string $customer_profile_id customer profile id. |
|
262 | + * Retrieves a customer payment profile. |
|
263 | + * |
|
264 | + * |
|
265 | + * @param string $customer_profile_id customer profile id. |
|
266 | 266 | * @param string $payment_profile_id payment profile id. |
267 | - * @return string|WP_Error Profile id. |
|
267 | + * @return string|WP_Error Profile id. |
|
268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
269 | - */ |
|
270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
269 | + */ |
|
270 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
271 | 271 | |
272 | 272 | // Generate args. |
273 | 273 | $args = array( |
@@ -283,15 +283,15 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Charges a customer payment profile. |
|
287 | - * |
|
286 | + * Charges a customer payment profile. |
|
287 | + * |
|
288 | 288 | * @param string $customer_profile_id customer profile id. |
289 | 289 | * @param string $payment_profile_id payment profile id. |
290 | - * @param WPInv_Invoice $invoice Invoice. |
|
290 | + * @param WPInv_Invoice $invoice Invoice. |
|
291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
292 | - * @return WP_Error|object |
|
293 | - */ |
|
294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
292 | + * @return WP_Error|object |
|
293 | + */ |
|
294 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
295 | 295 | |
296 | 296 | // Generate args. |
297 | 297 | $args = array( |
@@ -333,41 +333,41 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Processes a customer charge. |
|
337 | - * |
|
336 | + * Processes a customer charge. |
|
337 | + * |
|
338 | 338 | * @param stdClass $result Api response. |
339 | - * @param WPInv_Invoice $invoice Invoice. |
|
340 | - */ |
|
341 | - public function process_charge_response( $result, $invoice ) { |
|
339 | + * @param WPInv_Invoice $invoice Invoice. |
|
340 | + */ |
|
341 | + public function process_charge_response( $result, $invoice ) { |
|
342 | 342 | |
343 | 343 | wpinv_clear_errors(); |
344 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
344 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
345 | 345 | |
346 | - // Succeeded. |
|
347 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
346 | + // Succeeded. |
|
347 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
348 | 348 | |
349 | - // Maybe set a transaction id. |
|
350 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
351 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
352 | - } |
|
349 | + // Maybe set a transaction id. |
|
350 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
351 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
352 | + } |
|
353 | 353 | |
354 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
354 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
355 | 355 | |
356 | - if ( 1 == $response_code ) { |
|
357 | - return $invoice->mark_paid(); |
|
358 | - } |
|
356 | + if ( 1 == $response_code ) { |
|
357 | + return $invoice->mark_paid(); |
|
358 | + } |
|
359 | 359 | |
360 | - $invoice->set_status( 'wpi-onhold' ); |
|
361 | - $invoice->add_note( |
|
360 | + $invoice->set_status( 'wpi-onhold' ); |
|
361 | + $invoice->add_note( |
|
362 | 362 | sprintf( |
363 | 363 | __( 'Held for review: %s', 'invoicing' ), |
364 | 364 | $result->transactionResponse->messages->message[0]->description |
365 | 365 | ) |
366 | - ); |
|
366 | + ); |
|
367 | 367 | |
368 | - return $invoice->save(); |
|
368 | + return $invoice->save(); |
|
369 | 369 | |
370 | - } |
|
370 | + } |
|
371 | 371 | |
372 | 372 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
373 | 373 | |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
382 | - * Returns payment information. |
|
383 | - * |
|
384 | - * |
|
385 | - * @param array $card Card details. |
|
386 | - * @return array |
|
387 | - */ |
|
388 | - public function get_payment_information( $card ) { |
|
382 | + * Returns payment information. |
|
383 | + * |
|
384 | + * |
|
385 | + * @param array $card Card details. |
|
386 | + * @return array |
|
387 | + */ |
|
388 | + public function get_payment_information( $card ) { |
|
389 | 389 | return array( |
390 | 390 | |
391 | 391 | 'creditCard' => array ( |
@@ -398,25 +398,25 @@ discard block |
||
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
401 | - * Returns the customer profile meta name. |
|
402 | - * |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice Invoice. |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - public function get_customer_profile_meta_name( $invoice ) { |
|
401 | + * Returns the customer profile meta name. |
|
402 | + * |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice Invoice. |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + public function get_customer_profile_meta_name( $invoice ) { |
|
408 | 408 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Validates the submitted data. |
|
413 | - * |
|
414 | - * |
|
415 | - * @param array $submission_data Posted checkout fields. |
|
412 | + * Validates the submitted data. |
|
413 | + * |
|
414 | + * |
|
415 | + * @param array $submission_data Posted checkout fields. |
|
416 | 416 | * @param WPInv_Invoice $invoice |
417 | - * @return WP_Error|string The payment profile id |
|
418 | - */ |
|
419 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
417 | + * @return WP_Error|string The payment profile id |
|
418 | + */ |
|
419 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
420 | 420 | |
421 | 421 | // Validate authentication details. |
422 | 422 | $auth = $this->get_auth_params(); |
@@ -448,13 +448,13 @@ discard block |
||
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
451 | - * Returns invoice line items. |
|
452 | - * |
|
453 | - * |
|
454 | - * @param WPInv_Invoice $invoice Invoice. |
|
455 | - * @return array |
|
456 | - */ |
|
457 | - public function get_line_items( $invoice ) { |
|
451 | + * Returns invoice line items. |
|
452 | + * |
|
453 | + * |
|
454 | + * @param WPInv_Invoice $invoice Invoice. |
|
455 | + * @return array |
|
456 | + */ |
|
457 | + public function get_line_items( $invoice ) { |
|
458 | 458 | $items = array(); |
459 | 459 | |
460 | 460 | foreach ( $invoice->get_items() as $item ) { |
@@ -474,15 +474,15 @@ discard block |
||
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Process Payment. |
|
478 | - * |
|
479 | - * |
|
480 | - * @param WPInv_Invoice $invoice Invoice. |
|
481 | - * @param array $submission_data Posted checkout fields. |
|
482 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
483 | - * @return array |
|
484 | - */ |
|
485 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
477 | + * Process Payment. |
|
478 | + * |
|
479 | + * |
|
480 | + * @param WPInv_Invoice $invoice Invoice. |
|
481 | + * @param array $submission_data Posted checkout fields. |
|
482 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
483 | + * @return array |
|
484 | + */ |
|
485 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
486 | 486 | |
487 | 487 | // Validate the submitted data. |
488 | 488 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -515,69 +515,69 @@ discard block |
||
515 | 515 | |
516 | 516 | exit; |
517 | 517 | |
518 | - } |
|
518 | + } |
|
519 | 519 | |
520 | - /** |
|
521 | - * Processes the initial payment. |
|
522 | - * |
|
520 | + /** |
|
521 | + * Processes the initial payment. |
|
522 | + * |
|
523 | 523 | * @param WPInv_Invoice $invoice Invoice. |
524 | - */ |
|
525 | - protected function process_initial_payment( $invoice ) { |
|
524 | + */ |
|
525 | + protected function process_initial_payment( $invoice ) { |
|
526 | 526 | |
527 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
527 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
528 | 528 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
529 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
529 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
530 | 530 | |
531 | - // Do we have an error? |
|
532 | - if ( is_wp_error( $result ) ) { |
|
533 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
534 | - wpinv_send_back_to_checkout(); |
|
535 | - } |
|
531 | + // Do we have an error? |
|
532 | + if ( is_wp_error( $result ) ) { |
|
533 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
534 | + wpinv_send_back_to_checkout(); |
|
535 | + } |
|
536 | 536 | |
537 | - // Process the response. |
|
538 | - $this->process_charge_response( $result, $invoice ); |
|
537 | + // Process the response. |
|
538 | + $this->process_charge_response( $result, $invoice ); |
|
539 | 539 | |
540 | - if ( wpinv_get_errors() ) { |
|
541 | - wpinv_send_back_to_checkout(); |
|
542 | - } |
|
540 | + if ( wpinv_get_errors() ) { |
|
541 | + wpinv_send_back_to_checkout(); |
|
542 | + } |
|
543 | 543 | |
544 | - } |
|
544 | + } |
|
545 | 545 | |
546 | 546 | /** |
547 | - * Processes recurring payments. |
|
548 | - * |
|
547 | + * Processes recurring payments. |
|
548 | + * |
|
549 | 549 | * @param WPInv_Invoice $invoice Invoice. |
550 | 550 | * @param WPInv_Subscription $subscription Subscription. |
551 | - */ |
|
552 | - public function process_subscription( $invoice, $subscription ) { |
|
551 | + */ |
|
552 | + public function process_subscription( $invoice, $subscription ) { |
|
553 | 553 | |
554 | 554 | // Check if there is an initial amount to charge. |
555 | 555 | if ( (float) $invoice->get_total() > 0 ) { |
556 | - $this->process_initial_payment( $invoice ); |
|
556 | + $this->process_initial_payment( $invoice ); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | // Activate the subscription. |
560 | 560 | $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
561 | 561 | $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
562 | 562 | |
563 | - $subscription->set_next_renewal_date( $expiry ); |
|
564 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
565 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
566 | - $subscription->activate(); |
|
563 | + $subscription->set_next_renewal_date( $expiry ); |
|
564 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
565 | + $subscription->set_profile_id( $invoice->generate_key() ); |
|
566 | + $subscription->activate(); |
|
567 | 567 | |
568 | - // Redirect to the success page. |
|
568 | + // Redirect to the success page. |
|
569 | 569 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
570 | 570 | |
571 | 571 | } |
572 | 572 | |
573 | - /** |
|
574 | - * (Maybe) renews an authorize.net subscription profile. |
|
575 | - * |
|
576 | - * |
|
577 | - * @param bool $should_expire |
|
573 | + /** |
|
574 | + * (Maybe) renews an authorize.net subscription profile. |
|
575 | + * |
|
576 | + * |
|
577 | + * @param bool $should_expire |
|
578 | 578 | * @param WPInv_Subscription $subscription |
579 | - */ |
|
580 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
579 | + */ |
|
580 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
581 | 581 | |
582 | 582 | // Ensure its our subscription && it's active. |
583 | 583 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | return false; |
591 | 591 | } |
592 | 592 | |
593 | - $this->renew_subscription( $subscription ); |
|
593 | + $this->renew_subscription( $subscription ); |
|
594 | 594 | // Renew the subscription. |
595 | 595 | $subscription->add_payment( |
596 | 596 | array( |
@@ -603,18 +603,18 @@ discard block |
||
603 | 603 | |
604 | 604 | return false; |
605 | 605 | |
606 | - } |
|
606 | + } |
|
607 | 607 | |
608 | 608 | /** |
609 | - * Renews a subscription. |
|
610 | - * |
|
609 | + * Renews a subscription. |
|
610 | + * |
|
611 | 611 | * @param WPInv_Subscription $subscription |
612 | - */ |
|
613 | - public function renew_subscription( $subscription ) { |
|
612 | + */ |
|
613 | + public function renew_subscription( $subscription ) { |
|
614 | 614 | |
615 | - // Generate the renewal invoice. |
|
616 | - $new_invoice = $subscription->create_payment(); |
|
617 | - $old_invoice = $subscription->get_parent_payment(); |
|
615 | + // Generate the renewal invoice. |
|
616 | + $new_invoice = $subscription->create_payment(); |
|
617 | + $old_invoice = $subscription->get_parent_payment(); |
|
618 | 618 | |
619 | 619 | if ( empty( $new_invoice ) ) { |
620 | 620 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -622,40 +622,40 @@ discard block |
||
622 | 622 | return; |
623 | 623 | } |
624 | 624 | |
625 | - // Charge the payment method. |
|
626 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
627 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
628 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
625 | + // Charge the payment method. |
|
626 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
627 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
628 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
629 | 629 | |
630 | - // Do we have an error? |
|
631 | - if ( is_wp_error( $result ) ) { |
|
630 | + // Do we have an error? |
|
631 | + if ( is_wp_error( $result ) ) { |
|
632 | 632 | |
633 | - $old_invoice->add_note( |
|
634 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
635 | - true, |
|
636 | - false, |
|
637 | - true |
|
638 | - ); |
|
639 | - $subscription->failing(); |
|
640 | - return; |
|
633 | + $old_invoice->add_note( |
|
634 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
635 | + true, |
|
636 | + false, |
|
637 | + true |
|
638 | + ); |
|
639 | + $subscription->failing(); |
|
640 | + return; |
|
641 | 641 | |
642 | - } |
|
642 | + } |
|
643 | 643 | |
644 | - // Process the response. |
|
645 | - $this->process_charge_response( $result, $new_invoice ); |
|
644 | + // Process the response. |
|
645 | + $this->process_charge_response( $result, $new_invoice ); |
|
646 | 646 | |
647 | - if ( wpinv_get_errors() ) { |
|
647 | + if ( wpinv_get_errors() ) { |
|
648 | 648 | |
649 | - $old_invoice->add_note( |
|
650 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
651 | - true, |
|
652 | - false, |
|
653 | - true |
|
654 | - ); |
|
655 | - $subscription->failing(); |
|
656 | - return; |
|
649 | + $old_invoice->add_note( |
|
650 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
651 | + true, |
|
652 | + false, |
|
653 | + true |
|
654 | + ); |
|
655 | + $subscription->failing(); |
|
656 | + return; |
|
657 | 657 | |
658 | - } |
|
658 | + } |
|
659 | 659 | |
660 | 660 | } |
661 | 661 | |
@@ -676,11 +676,11 @@ discard block |
||
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
679 | - * Filters the gateway settings. |
|
680 | - * |
|
681 | - * @param array $admin_settings |
|
682 | - */ |
|
683 | - public function admin_settings( $admin_settings ) { |
|
679 | + * Filters the gateway settings. |
|
680 | + * |
|
681 | + * @param array $admin_settings |
|
682 | + */ |
|
683 | + public function admin_settings( $admin_settings ) { |
|
684 | 684 | |
685 | 685 | $currencies = sprintf( |
686 | 686 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | 'readonly' => true, |
721 | 721 | ); |
722 | 722 | |
723 | - return $admin_settings; |
|
724 | - } |
|
723 | + return $admin_settings; |
|
724 | + } |
|
725 | 725 | |
726 | 726 | } |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | - * Returns the API authentication params. |
|
85 | - * |
|
86 | - * |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function get_auth_params() { |
|
84 | + * Returns the API authentication params. |
|
85 | + * |
|
86 | + * |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function get_auth_params() { |
|
90 | 90 | |
91 | 91 | return array( |
92 | 92 | 'name' => $this->get_option( 'login_id' ), |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | - * Cancels a subscription remotely |
|
100 | - * |
|
101 | - * |
|
102 | - * @param WPInv_Subscription $subscription Subscription. |
|
99 | + * Cancels a subscription remotely |
|
100 | + * |
|
101 | + * |
|
102 | + * @param WPInv_Subscription $subscription Subscription. |
|
103 | 103 | * @param WPInv_Invoice $invoice Invoice. |
104 | - */ |
|
105 | - public function cancel_subscription( $subscription, $invoice ) { |
|
104 | + */ |
|
105 | + public function cancel_subscription( $subscription, $invoice ) { |
|
106 | 106 | |
107 | 107 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
108 | 108 | $this->post( |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Processes ipns. |
|
122 | - * |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function verify_ipn() { |
|
121 | + * Processes ipns. |
|
122 | + * |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function verify_ipn() { |
|
126 | 126 | |
127 | 127 | $this->maybe_process_old_ipn(); |
128 | 128 | |
129 | 129 | // Validate the IPN. |
130 | 130 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
131 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
131 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Event type. |
@@ -167,24 +167,24 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Validates IPN invoices. |
|
171 | - * |
|
170 | + * Validates IPN invoices. |
|
171 | + * |
|
172 | 172 | * @param WPInv_Invoice $invoice |
173 | 173 | * @param object $payload |
174 | - * @return void |
|
175 | - */ |
|
176 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
177 | 177 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
178 | 178 | exit; |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Process subscriptio IPNS. |
|
184 | - * |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - public function maybe_process_old_ipn() { |
|
183 | + * Process subscriptio IPNS. |
|
184 | + * |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + public function maybe_process_old_ipn() { |
|
188 | 188 | |
189 | 189 | $data = wp_unslash( $_POST ); |
190 | 190 | |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | - * Validates the old IPN signature. |
|
229 | + * Validates the old IPN signature. |
|
230 | 230 | * |
231 | 231 | * @param array $posted |
232 | - */ |
|
233 | - public function validate_old_ipn_signature( $posted ) { |
|
232 | + */ |
|
233 | + public function validate_old_ipn_signature( $posted ) { |
|
234 | 234 | |
235 | 235 | $signature = $this->get_option( 'signature_key' ); |
236 | 236 | if ( ! empty( $signature ) ) { |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
252 | - * Check Authorize.NET IPN validity. |
|
253 | - */ |
|
254 | - public function validate_ipn() { |
|
252 | + * Check Authorize.NET IPN validity. |
|
253 | + */ |
|
254 | + public function validate_ipn() { |
|
255 | 255 | |
256 | 256 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
257 | 257 |