@@ -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', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
| 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'] ); |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | - * Retrieves payment details from cache. |
|
| 276 | - * |
|
| 277 | - * |
|
| 275 | + * Retrieves payment details from cache. |
|
| 276 | + * |
|
| 277 | + * |
|
| 278 | 278 | * @param array $payment_details. |
| 279 | - * @return array|false Profile id. |
|
| 280 | - */ |
|
| 281 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 279 | + * @return array|false Profile id. |
|
| 280 | + */ |
|
| 281 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 282 | 282 | |
| 283 | 283 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
| 284 | 284 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -303,13 +303,13 @@ discard block |
||
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
| 306 | - * Securely adds payment details to cache. |
|
| 307 | - * |
|
| 308 | - * |
|
| 306 | + * Securely adds payment details to cache. |
|
| 307 | + * |
|
| 308 | + * |
|
| 309 | 309 | * @param array $payment_details. |
| 310 | 310 | * @param string $payment_profile_id. |
| 311 | - */ |
|
| 312 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 311 | + */ |
|
| 312 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 313 | 313 | |
| 314 | 314 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
| 315 | 315 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -321,15 +321,15 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | - * Retrieves a customer payment profile. |
|
| 325 | - * |
|
| 326 | - * |
|
| 327 | - * @param string $customer_profile_id customer profile id. |
|
| 324 | + * Retrieves a customer payment profile. |
|
| 325 | + * |
|
| 326 | + * |
|
| 327 | + * @param string $customer_profile_id customer profile id. |
|
| 328 | 328 | * @param string $payment_profile_id payment profile id. |
| 329 | - * @return string|WP_Error Profile id. |
|
| 329 | + * @return string|WP_Error Profile id. |
|
| 330 | 330 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 331 | - */ |
|
| 332 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 331 | + */ |
|
| 332 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 333 | 333 | |
| 334 | 334 | // Generate args. |
| 335 | 335 | $args = array( |
@@ -345,15 +345,15 @@ discard block |
||
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
| 348 | - * Charges a customer payment profile. |
|
| 349 | - * |
|
| 348 | + * Charges a customer payment profile. |
|
| 349 | + * |
|
| 350 | 350 | * @param string $customer_profile_id customer profile id. |
| 351 | 351 | * @param string $payment_profile_id payment profile id. |
| 352 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 352 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 353 | 353 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 354 | - * @return WP_Error|object |
|
| 355 | - */ |
|
| 356 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 354 | + * @return WP_Error|object |
|
| 355 | + */ |
|
| 356 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 357 | 357 | |
| 358 | 358 | // Generate args. |
| 359 | 359 | $args = array( |
@@ -399,41 +399,41 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | - * Processes a customer charge. |
|
| 403 | - * |
|
| 402 | + * Processes a customer charge. |
|
| 403 | + * |
|
| 404 | 404 | * @param stdClass $result Api response. |
| 405 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 406 | - */ |
|
| 407 | - public function process_charge_response( $result, $invoice ) { |
|
| 405 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 406 | + */ |
|
| 407 | + public function process_charge_response( $result, $invoice ) { |
|
| 408 | 408 | |
| 409 | 409 | wpinv_clear_errors(); |
| 410 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
| 410 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
| 411 | 411 | |
| 412 | - // Succeeded. |
|
| 413 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 412 | + // Succeeded. |
|
| 413 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
| 414 | 414 | |
| 415 | - // Maybe set a transaction id. |
|
| 416 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 417 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 418 | - } |
|
| 415 | + // Maybe set a transaction id. |
|
| 416 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 417 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 420 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 421 | 421 | |
| 422 | - if ( 1 == $response_code ) { |
|
| 423 | - return $invoice->mark_paid(); |
|
| 424 | - } |
|
| 422 | + if ( 1 == $response_code ) { |
|
| 423 | + return $invoice->mark_paid(); |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 427 | - $invoice->add_note( |
|
| 426 | + $invoice->set_status( 'wpi-onhold' ); |
|
| 427 | + $invoice->add_note( |
|
| 428 | 428 | sprintf( |
| 429 | 429 | __( 'Held for review: %s', 'invoicing' ), |
| 430 | 430 | $result->transactionResponse->messages->message[0]->description |
| 431 | 431 | ) |
| 432 | - ); |
|
| 432 | + ); |
|
| 433 | 433 | |
| 434 | - return $invoice->save(); |
|
| 434 | + return $invoice->save(); |
|
| 435 | 435 | |
| 436 | - } |
|
| 436 | + } |
|
| 437 | 437 | |
| 438 | 438 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
| 439 | 439 | |
@@ -445,13 +445,13 @@ discard block |
||
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
| 448 | - * Returns payment information. |
|
| 449 | - * |
|
| 450 | - * |
|
| 451 | - * @param array $card Card details. |
|
| 452 | - * @return array |
|
| 453 | - */ |
|
| 454 | - public function get_payment_information( $card ) { |
|
| 448 | + * Returns payment information. |
|
| 449 | + * |
|
| 450 | + * |
|
| 451 | + * @param array $card Card details. |
|
| 452 | + * @return array |
|
| 453 | + */ |
|
| 454 | + public function get_payment_information( $card ) { |
|
| 455 | 455 | return array( |
| 456 | 456 | |
| 457 | 457 | 'creditCard' => array ( |
@@ -464,25 +464,25 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
| 467 | - * Returns the customer profile meta name. |
|
| 468 | - * |
|
| 469 | - * |
|
| 470 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 471 | - * @return string |
|
| 472 | - */ |
|
| 473 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 467 | + * Returns the customer profile meta name. |
|
| 468 | + * |
|
| 469 | + * |
|
| 470 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 471 | + * @return string |
|
| 472 | + */ |
|
| 473 | + public function get_customer_profile_meta_name( $invoice ) { |
|
| 474 | 474 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | - * Validates the submitted data. |
|
| 479 | - * |
|
| 480 | - * |
|
| 481 | - * @param array $submission_data Posted checkout fields. |
|
| 478 | + * Validates the submitted data. |
|
| 479 | + * |
|
| 480 | + * |
|
| 481 | + * @param array $submission_data Posted checkout fields. |
|
| 482 | 482 | * @param WPInv_Invoice $invoice |
| 483 | - * @return WP_Error|string The payment profile id |
|
| 484 | - */ |
|
| 485 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 483 | + * @return WP_Error|string The payment profile id |
|
| 484 | + */ |
|
| 485 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
| 486 | 486 | |
| 487 | 487 | // Validate authentication details. |
| 488 | 488 | $auth = $this->get_auth_params(); |
@@ -514,13 +514,13 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
| 517 | - * Returns invoice line items. |
|
| 518 | - * |
|
| 519 | - * |
|
| 520 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 521 | - * @return array |
|
| 522 | - */ |
|
| 523 | - public function get_line_items( $invoice ) { |
|
| 517 | + * Returns invoice line items. |
|
| 518 | + * |
|
| 519 | + * |
|
| 520 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 521 | + * @return array |
|
| 522 | + */ |
|
| 523 | + public function get_line_items( $invoice ) { |
|
| 524 | 524 | $items = array(); |
| 525 | 525 | |
| 526 | 526 | foreach ( $invoice->get_items() as $item ) { |
@@ -558,15 +558,15 @@ discard block |
||
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
| 561 | - * Process Payment. |
|
| 562 | - * |
|
| 563 | - * |
|
| 564 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 565 | - * @param array $submission_data Posted checkout fields. |
|
| 566 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 567 | - * @return array |
|
| 568 | - */ |
|
| 569 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 561 | + * Process Payment. |
|
| 562 | + * |
|
| 563 | + * |
|
| 564 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 565 | + * @param array $submission_data Posted checkout fields. |
|
| 566 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 567 | + * @return array |
|
| 568 | + */ |
|
| 569 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 570 | 570 | |
| 571 | 571 | // Validate the submitted data. |
| 572 | 572 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -599,45 +599,45 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | exit; |
| 601 | 601 | |
| 602 | - } |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * Processes the initial payment. |
|
| 606 | - * |
|
| 604 | + /** |
|
| 605 | + * Processes the initial payment. |
|
| 606 | + * |
|
| 607 | 607 | * @param WPInv_Invoice $invoice Invoice. |
| 608 | - */ |
|
| 609 | - protected function process_initial_payment( $invoice ) { |
|
| 608 | + */ |
|
| 609 | + protected function process_initial_payment( $invoice ) { |
|
| 610 | 610 | |
| 611 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 611 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 612 | 612 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
| 613 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 613 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 614 | 614 | |
| 615 | - // Do we have an error? |
|
| 616 | - if ( is_wp_error( $result ) ) { |
|
| 617 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 618 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 619 | - } |
|
| 615 | + // Do we have an error? |
|
| 616 | + if ( is_wp_error( $result ) ) { |
|
| 617 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 618 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | - // Process the response. |
|
| 622 | - $this->process_charge_response( $result, $invoice ); |
|
| 621 | + // Process the response. |
|
| 622 | + $this->process_charge_response( $result, $invoice ); |
|
| 623 | 623 | |
| 624 | - if ( wpinv_get_errors() ) { |
|
| 625 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 626 | - } |
|
| 624 | + if ( wpinv_get_errors() ) { |
|
| 625 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 626 | + } |
|
| 627 | 627 | |
| 628 | - } |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | 630 | /** |
| 631 | - * Processes recurring payments. |
|
| 632 | - * |
|
| 631 | + * Processes recurring payments. |
|
| 632 | + * |
|
| 633 | 633 | * @param WPInv_Invoice $invoice Invoice. |
| 634 | 634 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
| 635 | - */ |
|
| 636 | - public function process_subscription( $invoice, $subscriptions ) { |
|
| 635 | + */ |
|
| 636 | + public function process_subscription( $invoice, $subscriptions ) { |
|
| 637 | 637 | |
| 638 | 638 | // Check if there is an initial amount to charge. |
| 639 | 639 | if ( (float) $invoice->get_total() > 0 ) { |
| 640 | - $this->process_initial_payment( $invoice ); |
|
| 640 | + $this->process_initial_payment( $invoice ); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // Activate the subscriptions. |
@@ -655,19 +655,19 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - // Redirect to the success page. |
|
| 658 | + // Redirect to the success page. |
|
| 659 | 659 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - /** |
|
| 664 | - * (Maybe) renews an authorize.net subscription profile. |
|
| 665 | - * |
|
| 666 | - * |
|
| 667 | - * @param bool $should_expire |
|
| 663 | + /** |
|
| 664 | + * (Maybe) renews an authorize.net subscription profile. |
|
| 665 | + * |
|
| 666 | + * |
|
| 667 | + * @param bool $should_expire |
|
| 668 | 668 | * @param WPInv_Subscription $subscription |
| 669 | - */ |
|
| 670 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 669 | + */ |
|
| 670 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 671 | 671 | |
| 672 | 672 | // Ensure its our subscription && it's active. |
| 673 | 673 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -684,18 +684,18 @@ discard block |
||
| 684 | 684 | |
| 685 | 685 | return false; |
| 686 | 686 | |
| 687 | - } |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | 689 | /** |
| 690 | - * Renews a subscription. |
|
| 691 | - * |
|
| 690 | + * Renews a subscription. |
|
| 691 | + * |
|
| 692 | 692 | * @param WPInv_Subscription $subscription |
| 693 | - */ |
|
| 694 | - public function renew_subscription( $subscription ) { |
|
| 693 | + */ |
|
| 694 | + public function renew_subscription( $subscription ) { |
|
| 695 | 695 | |
| 696 | - // Generate the renewal invoice. |
|
| 697 | - $new_invoice = $subscription->create_payment(); |
|
| 698 | - $old_invoice = $subscription->get_parent_payment(); |
|
| 696 | + // Generate the renewal invoice. |
|
| 697 | + $new_invoice = $subscription->create_payment(); |
|
| 698 | + $old_invoice = $subscription->get_parent_payment(); |
|
| 699 | 699 | |
| 700 | 700 | if ( empty( $new_invoice ) ) { |
| 701 | 701 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -704,37 +704,37 @@ discard block |
||
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | // Charge the payment method. |
| 707 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 708 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 709 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 707 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 708 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 709 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 710 | 710 | |
| 711 | - // Do we have an error? |
|
| 712 | - if ( is_wp_error( $result ) ) { |
|
| 711 | + // Do we have an error? |
|
| 712 | + if ( is_wp_error( $result ) ) { |
|
| 713 | 713 | |
| 714 | - $old_invoice->add_note( |
|
| 715 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 716 | - true, |
|
| 717 | - false, |
|
| 718 | - true |
|
| 719 | - ); |
|
| 720 | - $subscription->failing(); |
|
| 721 | - return; |
|
| 714 | + $old_invoice->add_note( |
|
| 715 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 716 | + true, |
|
| 717 | + false, |
|
| 718 | + true |
|
| 719 | + ); |
|
| 720 | + $subscription->failing(); |
|
| 721 | + return; |
|
| 722 | 722 | |
| 723 | - } |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - // Process the response. |
|
| 726 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 725 | + // Process the response. |
|
| 726 | + $this->process_charge_response( $result, $new_invoice ); |
|
| 727 | 727 | |
| 728 | - if ( wpinv_get_errors() ) { |
|
| 728 | + if ( wpinv_get_errors() ) { |
|
| 729 | 729 | |
| 730 | - $old_invoice->add_note( |
|
| 731 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 732 | - true, |
|
| 733 | - false, |
|
| 734 | - true |
|
| 735 | - ); |
|
| 736 | - $subscription->failing(); |
|
| 737 | - return; |
|
| 730 | + $old_invoice->add_note( |
|
| 731 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 732 | + true, |
|
| 733 | + false, |
|
| 734 | + true |
|
| 735 | + ); |
|
| 736 | + $subscription->failing(); |
|
| 737 | + return; |
|
| 738 | 738 | |
| 739 | 739 | } |
| 740 | 740 | |
@@ -743,13 +743,13 @@ discard block |
||
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | /** |
| 746 | - * Processes invoice addons. |
|
| 747 | - * |
|
| 748 | - * @param WPInv_Invoice $invoice |
|
| 749 | - * @param GetPaid_Form_Item[] $items |
|
| 750 | - * @return WPInv_Invoice |
|
| 751 | - */ |
|
| 752 | - public function process_addons( $invoice, $items ) { |
|
| 746 | + * Processes invoice addons. |
|
| 747 | + * |
|
| 748 | + * @param WPInv_Invoice $invoice |
|
| 749 | + * @param GetPaid_Form_Item[] $items |
|
| 750 | + * @return WPInv_Invoice |
|
| 751 | + */ |
|
| 752 | + public function process_addons( $invoice, $items ) { |
|
| 753 | 753 | |
| 754 | 754 | global $getpaid_authorize_addons; |
| 755 | 755 | |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | $invoice->recalculate_total(); |
| 770 | 770 | |
| 771 | 771 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
| 772 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 772 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 773 | 773 | |
| 774 | 774 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
| 775 | 775 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -784,11 +784,11 @@ discard block |
||
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
| 787 | - * Processes invoice addons. |
|
| 788 | - * |
|
| 787 | + * Processes invoice addons. |
|
| 788 | + * |
|
| 789 | 789 | * @param array $args |
| 790 | - * @return array |
|
| 791 | - */ |
|
| 790 | + * @return array |
|
| 791 | + */ |
|
| 792 | 792 | public function filter_addons_request( $args ) { |
| 793 | 793 | |
| 794 | 794 | global $getpaid_authorize_addons; |
@@ -822,11 +822,11 @@ discard block |
||
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
| 825 | - * Filters the gateway settings. |
|
| 826 | - * |
|
| 827 | - * @param array $admin_settings |
|
| 828 | - */ |
|
| 829 | - public function admin_settings( $admin_settings ) { |
|
| 825 | + * Filters the gateway settings. |
|
| 826 | + * |
|
| 827 | + * @param array $admin_settings |
|
| 828 | + */ |
|
| 829 | + public function admin_settings( $admin_settings ) { |
|
| 830 | 830 | |
| 831 | 831 | $currencies = sprintf( |
| 832 | 832 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | 'readonly' => true, |
| 867 | 867 | ); |
| 868 | 868 | |
| 869 | - return $admin_settings; |
|
| 870 | - } |
|
| 869 | + return $admin_settings; |
|
| 870 | + } |
|
| 871 | 871 | |
| 872 | 872 | } |
@@ -13,30 +13,30 @@ discard block |
||
| 13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_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 = 'manual'; |
| 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', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - public $order = 11; |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + public $order = 11; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Class constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct() { |
|
| 37 | + * Class constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct() { |
|
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Process Payment. |
|
| 50 | - * |
|
| 51 | - * |
|
| 52 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | - * @param array $submission_data Posted checkout fields. |
|
| 54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 49 | + * Process Payment. |
|
| 50 | + * |
|
| 51 | + * |
|
| 52 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | + * @param array $submission_data Posted checkout fields. |
|
| 54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * (Maybe) renews a manual subscription profile. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param bool $should_expire |
|
| 88 | + * (Maybe) renews a manual subscription profile. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param bool $should_expire |
|
| 92 | 92 | * @param WPInv_Subscription $subscription |
| 93 | - */ |
|
| 94 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 93 | + */ |
|
| 94 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 95 | 95 | |
| 96 | 96 | // Ensure its our subscription && it's active. |
| 97 | 97 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * Processes invoice addons. |
|
| 123 | - * |
|
| 124 | - * @param WPInv_Invoice $invoice |
|
| 125 | - * @param GetPaid_Form_Item[] $items |
|
| 126 | - * @return WPInv_Invoice |
|
| 127 | - */ |
|
| 128 | - public function process_addons( $invoice, $items ) { |
|
| 122 | + * Processes invoice addons. |
|
| 123 | + * |
|
| 124 | + * @param WPInv_Invoice $invoice |
|
| 125 | + * @param GetPaid_Form_Item[] $items |
|
| 126 | + * @return WPInv_Invoice |
|
| 127 | + */ |
|
| 128 | + public function process_addons( $invoice, $items ) { |
|
| 129 | 129 | |
| 130 | 130 | foreach ( $items as $item ) { |
| 131 | 131 | $invoice->add_item( $item ); |