From dcfdbb578c69192cbf9462113a4a735f8af30c6e Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Fri, 8 Jul 2022 10:53:29 +0200 Subject: [PATCH 01/23] Use new register payment method function. --- src/Gateway.php | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 0c0f785..833307d 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -4,6 +4,7 @@ use Pronamic\WordPress\Pay\Banks\BankAccountDetails; use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; +use Pronamic\WordPress\Pay\Core\PaymentMethod; use Pronamic\WordPress\Pay\Core\PaymentMethods; use Pronamic\WordPress\Pay\Core\Server; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\DirectTransactionRequestMessage; @@ -53,6 +54,22 @@ public function __construct( Config $config ) { 'payment_status_request', ); + // Payment methods. + $this->register_payment_method( new PaymentMethod(PaymentMethods::ALIPAY ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::BANCONTACT ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::BANK_TRANSFER ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::BELFIUS ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::CREDIT_CARD ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::DIRECT_DEBIT ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::IDEAL ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::IDEALQR ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::IN3 ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::GIROPAY ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::KBC ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::PAYPAL ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::SANTANDER ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::SOFORT ) ); + // Client. $this->client = new Client(); @@ -138,31 +155,6 @@ public function get_available_payment_methods() { return $payment_methods; } - /** - * Get supported payment methods - * - * @see Core_Gateway::get_supported_payment_methods() - * @return array - */ - public function get_supported_payment_methods() { - return array( - PaymentMethods::ALIPAY, - PaymentMethods::BANCONTACT, - PaymentMethods::BANK_TRANSFER, - PaymentMethods::BELFIUS, - PaymentMethods::CREDIT_CARD, - PaymentMethods::DIRECT_DEBIT, - PaymentMethods::IDEAL, - PaymentMethods::IDEALQR, - PaymentMethods::IN3, - PaymentMethods::GIROPAY, - PaymentMethods::KBC, - PaymentMethods::PAYPAL, - PaymentMethods::SANTANDER, - PaymentMethods::SOFORT, - ); - } - /** * Start payment. * From 885c279c5a936446f31e0c9a4b7627abad52df28 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:01:14 +0200 Subject: [PATCH 02/23] Payment method iDEAL issuer field. --- src/Gateway.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Gateway.php b/src/Gateway.php index 833307d..08ada76 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -6,6 +6,7 @@ use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; use Pronamic\WordPress\Pay\Core\PaymentMethod; use Pronamic\WordPress\Pay\Core\PaymentMethods; +use Pronamic\WordPress\Pay\Core\SelectField; use Pronamic\WordPress\Pay\Core\Server; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\DirectTransactionRequestMessage; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\RedirectTransactionRequestMessage; @@ -55,13 +56,23 @@ public function __construct( Config $config ) { ); // Payment methods. + $ideal_payment_method = new PaymentMethod( PaymentMethods::IDEAL ); + + $ideal_issuer_field = new SelectField( 'ideal-issuer' ); + + $ideal_issuer_field->set_options_callback( function() { + return $this->get_issuers(); + } ); + + $ideal_payment_method->add_field( $ideal_issuer_field ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::ALIPAY ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BANCONTACT ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BANK_TRANSFER ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BELFIUS ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::CREDIT_CARD ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::DIRECT_DEBIT ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::IDEAL ) ); + $this->register_payment_method( $ideal_payment_method ); $this->register_payment_method( new PaymentMethod(PaymentMethods::IDEALQR ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::IN3 ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::GIROPAY ) ); From 4745bc003076072d8eeaafa1ae38331be9bd3403 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:02:53 +0200 Subject: [PATCH 03/23] Payment method credit card issuer field. --- src/Gateway.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Gateway.php b/src/Gateway.php index 08ada76..c939643 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -66,11 +66,21 @@ public function __construct( Config $config ) { $ideal_payment_method->add_field( $ideal_issuer_field ); + $credit_card_payment_method = new PaymentMethod( PaymentMethods::CREDIT_CARD ); + + $credit_card_issuer_field = new SelectField( 'credit-card-issuer' ); + + $credit_card_issuer_field->set_options_callback( function() { + return $this->get_credit_card_issuers(); + } ); + + $credit_card_payment_method->add_field( $credit_card_issuer_field ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::ALIPAY ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BANCONTACT ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BANK_TRANSFER ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BELFIUS ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::CREDIT_CARD ) ); + $this->register_payment_method( $credit_card_payment_method ); $this->register_payment_method( new PaymentMethod(PaymentMethods::DIRECT_DEBIT ) ); $this->register_payment_method( $ideal_payment_method ); $this->register_payment_method( new PaymentMethod(PaymentMethods::IDEALQR ) ); From 4d3297998a62da02f84f43f96a08acde9b3f4869 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:03:35 +0200 Subject: [PATCH 04/23] Update Gateway.php --- src/Gateway.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Gateway.php b/src/Gateway.php index c939643..155ccde 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -55,7 +55,7 @@ public function __construct( Config $config ) { 'payment_status_request', ); - // Payment methods. + // Payment method iDEAL. $ideal_payment_method = new PaymentMethod( PaymentMethods::IDEAL ); $ideal_issuer_field = new SelectField( 'ideal-issuer' ); @@ -66,6 +66,7 @@ public function __construct( Config $config ) { $ideal_payment_method->add_field( $ideal_issuer_field ); + // Payment method credit card. $credit_card_payment_method = new PaymentMethod( PaymentMethods::CREDIT_CARD ); $credit_card_issuer_field = new SelectField( 'credit-card-issuer' ); @@ -76,6 +77,7 @@ public function __construct( Config $config ) { $credit_card_payment_method->add_field( $credit_card_issuer_field ); + // Payment methods. $this->register_payment_method( new PaymentMethod(PaymentMethods::ALIPAY ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BANCONTACT ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::BANK_TRANSFER ) ); From 5a63df948df1f3221a9bdd7907739c75910b8f7a Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Mon, 11 Jul 2022 13:22:01 +0200 Subject: [PATCH 05/23] Mark `$gateway->get_issuers()` as private. --- src/Gateway.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 155ccde..3e529b2 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -100,13 +100,12 @@ public function __construct( Config $config ) { } /** - * Get iDEAL issuers + * Get iDEAL issuers. * - * @see Core_Gateway::get_issuers() * @return array> * @since 1.2.0 */ - public function get_issuers() { + private function get_issuers() { $groups = array(); // Merchant. From 30332df5bc93131a38cc374098910facfac3ad4c Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Wed, 13 Jul 2022 16:11:03 +0200 Subject: [PATCH 06/23] Clarify iDEAL issuers method. --- src/Gateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 3e529b2..6e023e6 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -61,7 +61,7 @@ public function __construct( Config $config ) { $ideal_issuer_field = new SelectField( 'ideal-issuer' ); $ideal_issuer_field->set_options_callback( function() { - return $this->get_issuers(); + return $this->get_ideal_issuers(); } ); $ideal_payment_method->add_field( $ideal_issuer_field ); @@ -105,7 +105,7 @@ public function __construct( Config $config ) { * @return array> * @since 1.2.0 */ - private function get_issuers() { + private function get_ideal_issuers() { $groups = array(); // Merchant. From 3762ef517a6551a96236e36c901faad6cd58f26b Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:59:37 +0200 Subject: [PATCH 07/23] Use new Fields API. --- src/Gateway.php | 57 +++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 6e023e6..bf651da 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -6,8 +6,11 @@ use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; use Pronamic\WordPress\Pay\Core\PaymentMethod; use Pronamic\WordPress\Pay\Core\PaymentMethods; -use Pronamic\WordPress\Pay\Core\SelectField; +use Pronamic\WordPress\Pay\Fields\CachedCallbackOptions; +use Pronamic\WordPress\Pay\Fields\IDealIssuerSelectField; +use Pronamic\WordPress\Pay\Fields\SelectField; use Pronamic\WordPress\Pay\Core\Server; +use Pronamic\WordPress\Pay\Fields\SelectFieldOption; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\DirectTransactionRequestMessage; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\RedirectTransactionRequestMessage; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\StatusRequestMessage; @@ -58,11 +61,14 @@ public function __construct( Config $config ) { // Payment method iDEAL. $ideal_payment_method = new PaymentMethod( PaymentMethods::IDEAL ); - $ideal_issuer_field = new SelectField( 'ideal-issuer' ); + $ideal_issuer_field = new IDealIssuerSelectField( 'ideal-issuer' ); - $ideal_issuer_field->set_options_callback( function() { - return $this->get_ideal_issuers(); - } ); + $ideal_issuer_field->set_options( new CachedCallbackOptions( + function() { + return $this->get_ideal_issuers(); + }, + 'pronamic_pay_ideal_issuers_' . \md5( \wp_json_encode( $config ) ) + ) ); $ideal_payment_method->add_field( $ideal_issuer_field ); @@ -71,9 +77,12 @@ public function __construct( Config $config ) { $credit_card_issuer_field = new SelectField( 'credit-card-issuer' ); - $credit_card_issuer_field->set_options_callback( function() { - return $this->get_credit_card_issuers(); - } ); + $credit_card_issuer_field->set_options( new CachedCallbackOptions( + function() { + return $this->get_credit_card_issuers(); + }, + 'pronamic_pay_credit_card_issuers_' . \md5( \wp_json_encode( $config ) ) + ) ); $credit_card_payment_method->add_field( $credit_card_issuer_field ); @@ -106,23 +115,25 @@ public function __construct( Config $config ) { * @since 1.2.0 */ private function get_ideal_issuers() { - $groups = array(); + $merchant = new Merchant(); - // Merchant. - $merchant = new Merchant(); $merchant->account = $this->config->account_id; $merchant->site_id = $this->config->site_id; $merchant->site_secure_code = $this->config->site_code; $result = $this->client->get_ideal_issuers( $merchant ); - if ( $result ) { - $groups[] = array( - 'options' => $result, - ); + if ( false === $result ) { + return []; + } + + $options = []; + + foreach ( $result as $key => $value ) { + $options[] = new SelectFieldOption( $key, $value ); } - return $groups; + return $options; } /** @@ -131,19 +142,19 @@ private function get_ideal_issuers() { * @see Core_Gateway::get_credit_card_issuers() * @return array> */ - public function get_credit_card_issuers() { + private function get_credit_card_issuers() { // Get active card issuers. $issuers = \array_intersect_key( $this->get_gateways(), Methods::get_cards() ); sort( $issuers ); - $groups = array( - array( - 'options' => $issuers, - ), - ); + $options = []; + + foreach ( $issuers as $key => $value ) { + $options[] = new SelectFieldOption( $key, $value ); + } - return $groups; + return $options; } /** From c37f5ee36b531cd5228563e09b7b04ef4ac572e2 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:01:34 +0200 Subject: [PATCH 08/23] Register VOID payment method. --- src/Gateway.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Gateway.php b/src/Gateway.php index bf651da..baae11e 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -101,6 +101,7 @@ function() { $this->register_payment_method( new PaymentMethod(PaymentMethods::PAYPAL ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::SANTANDER ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::SOFORT ) ); + $this->register_payment_method( new PaymentMethod(PaymentMethods::VOID ) ); // Client. $this->client = new Client(); From bc8682beb8b5fc0cb7600aadb34d41d043745fc4 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Tue, 23 Aug 2022 11:36:54 +0200 Subject: [PATCH 09/23] The `is_array()` check was not working. --- src/XML/GatewaysResponseMessage.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/XML/GatewaysResponseMessage.php b/src/XML/GatewaysResponseMessage.php index 5143a8b..20e42e6 100644 --- a/src/XML/GatewaysResponseMessage.php +++ b/src/XML/GatewaysResponseMessage.php @@ -34,13 +34,11 @@ public static function parse( SimpleXMLElement $xml ) { $message->gateways = array(); - if ( \is_array( $xml->gateways->gateway ) ) { - foreach ( $xml->gateways->gateway as $gateway ) { - $id = Security::filter( $gateway->id ); - $description = Security::filter( $gateway->description ); + foreach ( $xml->gateways->gateway as $gateway ) { + $id = Security::filter( $gateway->id ); + $description = Security::filter( $gateway->description ); - $message->gateways[ $id ] = $description; - } + $message->gateways[ $id ] = $description; } return $message; From 75b5961d640f19284223cc416fd110e5415d0d0b Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Tue, 23 Aug 2022 11:37:32 +0200 Subject: [PATCH 10/23] Enrich payment methods. --- src/Gateway.php | 59 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index baae11e..92fcc7b 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -101,7 +101,11 @@ function() { $this->register_payment_method( new PaymentMethod(PaymentMethods::PAYPAL ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::SANTANDER ) ); $this->register_payment_method( new PaymentMethod(PaymentMethods::SOFORT ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::VOID ) ); + + $payment_method_void = new PaymentMethod(PaymentMethods::VOID ); + $payment_method_void->set_status( 'active' ); + + $this->register_payment_method( $payment_method_void ); // Client. $this->client = new Client(); @@ -159,34 +163,53 @@ private function get_credit_card_issuers() { } /** - * Get payment methods + * Get payment methods. + * + * @param array $args Query arguments. + * @return PaymentMethod[] + */ + public function get_payment_methods( $args = [] ) { + $this->maybe_enrich_payment_methods(); + + return parent::get_payment_methods( $args ); + } + + /** + * Maybe enrich payment methods. * - * @see Core_Gateway::get_payment_methods() - * @return array + * @return void */ - public function get_available_payment_methods() { - $payment_methods = array(); + private function maybe_enrich_payment_methods() { + $cache_key = 'pronamic_pay_multisafepay_payment_methods_' . \md5( \wp_json_encode( $this->config ) ); - $gateways = $this->get_gateways(); + $multisafepay_payment_methods = \get_transient( $cache_key ); - foreach ( $gateways as $method => $title ) { - $payment_method = Methods::transform_gateway_method( $method ); + if ( false === $multisafepay_payment_methods ) { + $multisafepay_payment_methods = $this->get_gateways(); + + \set_transient( $cache_key, $multisafepay_payment_methods, \DAY_IN_SECONDS ); + } + + foreach ( $multisafepay_payment_methods as $method => $title ) { + $core_payment_method_id = Methods::transform_gateway_method( $method ); // Handle cards, as no general method for credit cards is returned by gateway. - if ( null === $payment_method && \array_key_exists( $method, Methods::get_cards() ) ) { - $payment_method = PaymentMethods::CREDIT_CARD; + if ( null === $core_payment_method_id && \array_key_exists( $method, Methods::get_cards() ) ) { + $core_payment_method_id = PaymentMethods::CREDIT_CARD; } - // Check valid payment method. - if ( null === $payment_method ) { - continue; - } + $core_payment_method = $this->get_payment_method( $core_payment_method_id ); - // Add available payment method. - $payment_methods[] = $payment_method; + if ( null !== $core_payment_method ) { + $core_payment_method->set_status( 'active' ); + } } - return $payment_methods; + foreach ( $this->payment_methods as $payment_method ) { + if ( '' === $payment_method->get_status() ) { + $payment_method->set_status( 'inactive' ); + } + } } /** From c2448d1a938caac86c0dcd4d48a8304973055f52 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Wed, 24 Aug 2022 13:57:33 +0200 Subject: [PATCH 11/23] Update Gateway.php --- src/Gateway.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Gateway.php b/src/Gateway.php index 92fcc7b..1666580 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -77,6 +77,8 @@ function() { $credit_card_issuer_field = new SelectField( 'credit-card-issuer' ); + $credit_card_issuer_field->meta_key = 'issuer'; + $credit_card_issuer_field->set_options( new CachedCallbackOptions( function() { return $this->get_credit_card_issuers(); From 19d8279ddb77c1521b948403c2a32156edf30bd8 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:14:46 +0200 Subject: [PATCH 12/23] Update Gateway.php --- src/Gateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 1666580..9855e41 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -61,7 +61,7 @@ public function __construct( Config $config ) { // Payment method iDEAL. $ideal_payment_method = new PaymentMethod( PaymentMethods::IDEAL ); - $ideal_issuer_field = new IDealIssuerSelectField( 'ideal-issuer' ); + $ideal_issuer_field = new IDealIssuerSelectField( 'pronamic_pay_multisafepay_ideal_issuer' ); $ideal_issuer_field->set_options( new CachedCallbackOptions( function() { @@ -75,7 +75,7 @@ function() { // Payment method credit card. $credit_card_payment_method = new PaymentMethod( PaymentMethods::CREDIT_CARD ); - $credit_card_issuer_field = new SelectField( 'credit-card-issuer' ); + $credit_card_issuer_field = new SelectField( 'pronamic_pay_multisafepay_credit_card_issuer' ); $credit_card_issuer_field->meta_key = 'issuer'; From 000f9239bc6c0c75c9a71e8cc88b6914a7a1731b Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Thu, 25 Aug 2022 13:22:52 +0200 Subject: [PATCH 13/23] Update Gateway.php --- src/Gateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gateway.php b/src/Gateway.php index 9855e41..e0bc398 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -47,7 +47,7 @@ class Gateway extends Core_Gateway { * @param Config $config Config. */ public function __construct( Config $config ) { - parent::__construct( $config ); + parent::__construct(); $this->set_method( self::METHOD_HTTP_REDIRECT ); From e49c1b99c303c858988febbcd6ec9bda4542e451 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Thu, 25 Aug 2022 13:32:59 +0200 Subject: [PATCH 14/23] Catch exceptions. --- src/Gateway.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Gateway.php b/src/Gateway.php index e0bc398..e3dcd74 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -171,7 +171,11 @@ private function get_credit_card_issuers() { * @return PaymentMethod[] */ public function get_payment_methods( $args = [] ) { - $this->maybe_enrich_payment_methods(); + try { + $this->maybe_enrich_payment_methods(); + } catch ( \Exception $e ) { + // No problem. + } return parent::get_payment_methods( $args ); } From 9ebcb8e92ac4d5d336baf0a932787865ed0bd95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Wed, 31 Aug 2022 13:58:16 +0200 Subject: [PATCH 15/23] Coding standards / code quality. --- src/Gateway.php | 80 ++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index e3dcd74..dd72086 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -6,10 +6,11 @@ use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; use Pronamic\WordPress\Pay\Core\PaymentMethod; use Pronamic\WordPress\Pay\Core\PaymentMethods; +use Pronamic\WordPress\Pay\Core\PaymentMethodsCollection; +use Pronamic\WordPress\Pay\Core\Server; use Pronamic\WordPress\Pay\Fields\CachedCallbackOptions; use Pronamic\WordPress\Pay\Fields\IDealIssuerSelectField; use Pronamic\WordPress\Pay\Fields\SelectField; -use Pronamic\WordPress\Pay\Core\Server; use Pronamic\WordPress\Pay\Fields\SelectFieldOption; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\DirectTransactionRequestMessage; use Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML\RedirectTransactionRequestMessage; @@ -32,14 +33,14 @@ class Gateway extends Core_Gateway { * * @var Client */ - protected $client; + protected Client $client; /** * Config * * @var Config */ - protected $config; + protected Config $config; /** * Constructs and initializes an MultiSafepay Connect gateway @@ -54,21 +55,23 @@ public function __construct( Config $config ) { $this->config = $config; // Supported features. - $this->supports = array( + $this->supports = [ 'payment_status_request', - ); + ]; // Payment method iDEAL. $ideal_payment_method = new PaymentMethod( PaymentMethods::IDEAL ); $ideal_issuer_field = new IDealIssuerSelectField( 'pronamic_pay_multisafepay_ideal_issuer' ); - $ideal_issuer_field->set_options( new CachedCallbackOptions( - function() { - return $this->get_ideal_issuers(); - }, - 'pronamic_pay_ideal_issuers_' . \md5( \wp_json_encode( $config ) ) - ) ); + $ideal_issuer_field->set_options( + new CachedCallbackOptions( + function() { + return $this->get_ideal_issuers(); + }, + 'pronamic_pay_ideal_issuers_' . \md5( \wp_json_encode( $config ) ) + ) + ); $ideal_payment_method->add_field( $ideal_issuer_field ); @@ -79,32 +82,34 @@ function() { $credit_card_issuer_field->meta_key = 'issuer'; - $credit_card_issuer_field->set_options( new CachedCallbackOptions( - function() { - return $this->get_credit_card_issuers(); - }, - 'pronamic_pay_credit_card_issuers_' . \md5( \wp_json_encode( $config ) ) - ) ); + $credit_card_issuer_field->set_options( + new CachedCallbackOptions( + function() { + return $this->get_credit_card_issuers(); + }, + 'pronamic_pay_credit_card_issuers_' . \md5( \wp_json_encode( $config ) ) + ) + ); $credit_card_payment_method->add_field( $credit_card_issuer_field ); // Payment methods. - $this->register_payment_method( new PaymentMethod(PaymentMethods::ALIPAY ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::BANCONTACT ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::BANK_TRANSFER ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::BELFIUS ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::ALIPAY ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::BANCONTACT ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::BANK_TRANSFER ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::BELFIUS ) ); $this->register_payment_method( $credit_card_payment_method ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::DIRECT_DEBIT ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::DIRECT_DEBIT ) ); $this->register_payment_method( $ideal_payment_method ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::IDEALQR ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::IN3 ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::GIROPAY ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::KBC ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::PAYPAL ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::SANTANDER ) ); - $this->register_payment_method( new PaymentMethod(PaymentMethods::SOFORT ) ); - - $payment_method_void = new PaymentMethod(PaymentMethods::VOID ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::IDEALQR ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::IN3 ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::GIROPAY ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::KBC ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::PAYPAL ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::SANTANDER ) ); + $this->register_payment_method( new PaymentMethod( PaymentMethods::SOFORT ) ); + + $payment_method_void = new PaymentMethod( PaymentMethods::VOID ); $payment_method_void->set_status( 'active' ); $this->register_payment_method( $payment_method_void ); @@ -121,7 +126,7 @@ function() { * @return array> * @since 1.2.0 */ - private function get_ideal_issuers() { + private function get_ideal_issuers() : array { $merchant = new Merchant(); $merchant->account = $this->config->account_id; @@ -146,10 +151,9 @@ private function get_ideal_issuers() { /** * Get credit card issuers * - * @see Core_Gateway::get_credit_card_issuers() * @return array> */ - private function get_credit_card_issuers() { + private function get_credit_card_issuers() : array { // Get active card issuers. $issuers = \array_intersect_key( $this->get_gateways(), Methods::get_cards() ); @@ -168,9 +172,9 @@ private function get_credit_card_issuers() { * Get payment methods. * * @param array $args Query arguments. - * @return PaymentMethod[] + * @return PaymentMethodsCollection */ - public function get_payment_methods( $args = [] ) { + public function get_payment_methods( array $args = [] ) : PaymentMethodsCollection { try { $this->maybe_enrich_payment_methods(); } catch ( \Exception $e ) { @@ -383,7 +387,7 @@ public function update_status( Payment $payment ) { * * @return array */ - private function get_gateways() { + private function get_gateways() : array { // Merchant. $merchant = new Merchant(); $merchant->account = $this->config->account_id; @@ -394,7 +398,7 @@ private function get_gateways() { $customer = new Customer(); // Get gateways. - $gateways = array(); + $gateways = []; $result = $this->client->get_gateways( $merchant, $customer ); From 15b3d70848f767cd09f01b167d5d87731994a775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Wed, 31 Aug 2022 14:41:10 +0200 Subject: [PATCH 16/23] Add credit card issuers field label. --- src/Gateway.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Gateway.php b/src/Gateway.php index dd72086..d1905f7 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -80,6 +80,8 @@ function() { $credit_card_issuer_field = new SelectField( 'pronamic_pay_multisafepay_credit_card_issuer' ); + $credit_card_issuer_field->set_label( __( 'Card Brand', 'pronamic_ideal' ) ); + $credit_card_issuer_field->meta_key = 'issuer'; $credit_card_issuer_field->set_options( From 76c281eb4d8f3fd94e04407af3c93be16400dae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Wed, 31 Aug 2022 14:42:04 +0200 Subject: [PATCH 17/23] Maintain index association when sorting credit card issuers. --- src/Gateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gateway.php b/src/Gateway.php index d1905f7..42ba6d2 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -159,7 +159,7 @@ private function get_credit_card_issuers() : array { // Get active card issuers. $issuers = \array_intersect_key( $this->get_gateways(), Methods::get_cards() ); - sort( $issuers ); + asort( $issuers ); $options = []; From a86de6912fb90d533bc54d4c727e8040fe7cfc8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Wed, 31 Aug 2022 14:42:38 +0200 Subject: [PATCH 18/23] Simplify setting transaction gateway on payment start. --- src/Gateway.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 42ba6d2..fcac045 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -271,11 +271,10 @@ public function start( Payment $payment ) { $transaction->currency = $payment->get_total_amount()->get_currency()->get_alphabetic_code(); $transaction->amount = $payment->get_total_amount()->get_minor_units()->format( 0, '', '' ); $transaction->description = $transaction_description; + $transaction->gateway = Methods::transform( $payment_method ); switch ( $payment_method ) { case PaymentMethods::IDEAL: - $transaction->gateway = Methods::IDEAL; - $issuer = $payment->get_meta( 'issuer' ); if ( empty( $issuer ) ) { @@ -290,15 +289,9 @@ public function start( Payment $payment ) { break; case PaymentMethods::CREDIT_CARD: - $gateway = Methods::transform( $payment_method ); - $issuer = $payment->get_meta( 'issuer' ); - if ( empty( $issuer ) ) { - if ( $gateway ) { - $transaction->gateway = $gateway; - } - } else { + if ( ! empty( $issuer ) ) { $transaction->gateway = $issuer; } @@ -306,12 +299,6 @@ public function start( Payment $payment ) { break; default: - $gateway = Methods::transform( $payment_method ); - - if ( $gateway ) { - $transaction->gateway = $gateway; - } - if ( ! isset( $transaction->gateway ) && ! empty( $payment_method ) ) { // Leap of faith if the WordPress payment method could not transform to a Mollie method? $transaction->gateway = $payment_method; From eec27a50617586ee1d1b1b35163270ae81006f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Thu, 1 Sep 2022 17:00:41 +0200 Subject: [PATCH 19/23] Remove void payment method. --- src/Gateway.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index fcac045..497b49e 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -111,11 +111,6 @@ function() { $this->register_payment_method( new PaymentMethod( PaymentMethods::SANTANDER ) ); $this->register_payment_method( new PaymentMethod( PaymentMethods::SOFORT ) ); - $payment_method_void = new PaymentMethod( PaymentMethods::VOID ); - $payment_method_void->set_status( 'active' ); - - $this->register_payment_method( $payment_method_void ); - // Client. $this->client = new Client(); From 29b6d96f0df80502592ead35e3abbfc2f49c23ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Thu, 1 Sep 2022 23:26:46 +0200 Subject: [PATCH 20/23] phpcbf --- src/Client.php | 4 +-- src/Integration.php | 32 +++++++++---------- src/Methods.php | 8 ++--- src/Signature.php | 4 +-- src/XML/DirectTransactionRequestMessage.php | 16 +++++----- src/XML/GatewaysRequestMessage.php | 8 ++--- src/XML/GatewaysResponseMessage.php | 2 +- src/XML/IDealIssuersRequestMessage.php | 4 +-- src/XML/IDealIssuersResponseMessage.php | 2 +- src/XML/RedirectTransactionRequestMessage.php | 12 +++---- src/XML/StatusRequestMessage.php | 8 ++--- tests/src/DirectTransactionTest.php | 2 +- tests/src/GatewayTest.php | 14 ++++---- tests/src/GatewaysTest.php | 6 ++-- tests/src/IDealIssuersParserTest.php | 4 +-- tests/src/StatusesTest.php | 20 ++++++------ 16 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/Client.php b/src/Client.php index 196c779..a6093e2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -77,10 +77,10 @@ private function request( $message ) { $result = Core_Util::remote_get_body( $this->api_url, 200, - array( + [ 'method' => 'POST', 'body' => (string) $message, - ) + ] ); if ( is_wp_error( $result ) ) { diff --git a/src/Integration.php b/src/Integration.php index 6d5ee8d..76ebfcc 100644 --- a/src/Integration.php +++ b/src/Integration.php @@ -27,10 +27,10 @@ class Integration extends AbstractGatewayIntegration { * * @param array $args Arguments. */ - public function __construct( $args = array() ) { + public function __construct( $args = [] ) { $args = wp_parse_args( $args, - array( + [ 'id' => 'multisafepay-connect', 'name' => 'MultiSafepay - Connect', 'api_url' => MultiSafepay::API_PRODUCTION_URL, @@ -38,13 +38,13 @@ public function __construct( $args = array() ) { 'product_url' => \__( 'http://www.multisafepay.com/', 'pronamic_ideal' ), 'dashboard_url' => 'https://merchant.multisafepay.com/', 'provider' => 'multisafepay', - 'supports' => array( + 'supports' => [ 'payment_status_request', 'webhook', 'webhook_no_config', - ), + ], 'manual_url' => \__( 'https://www.pronamic.eu/support/how-to-connect-multisafepay-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ), - ) + ] ); parent::__construct( $args ); @@ -52,7 +52,7 @@ public function __construct( $args = array() ) { $this->api_url = $args['api_url']; // Filters. - $function = array( WooCommerce::class, 'woocommerce_available_payment_gateways' ); + $function = [ WooCommerce::class, 'woocommerce_available_payment_gateways' ]; if ( ! \has_filter( 'woocommerce_available_payment_gateways', $function ) ) { \add_filter( 'woocommerce_available_payment_gateways', $function, 10 ); @@ -65,55 +65,55 @@ public function __construct( $args = array() ) { * @return array */ public function get_settings_fields() { - $fields = array(); + $fields = []; // Account ID. - $fields[] = array( + $fields[] = [ 'section' => 'general', 'filter' => FILTER_SANITIZE_STRING, 'meta_key' => '_pronamic_gateway_multisafepay_account_id', 'title' => __( 'Account ID', 'pronamic_ideal' ), 'type' => 'text', - 'classes' => array( 'code' ), + 'classes' => [ 'code' ], 'tooltip' => sprintf( '%s %s.', __( 'Account ID', 'pronamic_ideal' ), /* translators: %s: payment provider name */ sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) ) ), - ); + ]; // Site ID. - $fields[] = array( + $fields[] = [ 'section' => 'general', 'filter' => FILTER_SANITIZE_STRING, 'meta_key' => '_pronamic_gateway_multisafepay_site_id', 'title' => __( 'Site ID', 'pronamic_ideal' ), 'type' => 'text', - 'classes' => array( 'code' ), + 'classes' => [ 'code' ], 'tooltip' => sprintf( '%s %s.', __( 'Site ID', 'pronamic_ideal' ), /* translators: %s: payment provider name */ sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) ) ), - ); + ]; // Site Security Code. - $fields[] = array( + $fields[] = [ 'section' => 'general', 'filter' => FILTER_SANITIZE_STRING, 'meta_key' => '_pronamic_gateway_multisafepay_site_code', 'title' => __( 'Site Security Code', 'pronamic_ideal' ), 'type' => 'text', - 'classes' => array( 'code' ), + 'classes' => [ 'code' ], 'tooltip' => sprintf( '%s %s.', __( 'Site Security Code', 'pronamic_ideal' ), /* translators: %s: payment provider name */ sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) ) ), - ); + ]; return $fields; } diff --git a/src/Methods.php b/src/Methods.php index 4018293..8e5076c 100644 --- a/src/Methods.php +++ b/src/Methods.php @@ -167,7 +167,7 @@ class Methods { * * @var array */ - private static $map = array( + private static $map = [ PaymentMethods::ALIPAY => self::ALIPAY, PaymentMethods::BANCONTACT => self::BANCONTACT, PaymentMethods::BANK_TRANSFER => self::BANK_TRANSFER, @@ -182,7 +182,7 @@ class Methods { PaymentMethods::PAYPAL => self::PAYPAL, PaymentMethods::SANTANDER => self::SANTANDER, PaymentMethods::SOFORT => self::SOFORT, - ); + ]; /** * Transform WordPress payment method to MultiSafepay method. @@ -229,11 +229,11 @@ public static function transform_gateway_method( $method ) { * @return array */ public static function get_cards() { - return array( + return [ self::AMEX => _x( 'American Express', 'Payment method name', 'pronamic_ideal' ), self::MAESTRO => _x( 'Maestro', 'Payment method name', 'pronamic_ideal' ), self::MASTERCARD => _x( 'Mastercard', 'Payment method name', 'pronamic_ideal' ), self::VISA => _x( 'Visa', 'Payment method name', 'pronamic_ideal' ), - ); + ]; } } diff --git a/src/Signature.php b/src/Signature.php index 261fd88..cb478ca 100644 --- a/src/Signature.php +++ b/src/Signature.php @@ -41,13 +41,13 @@ class Signature { * @return string */ public static function generate( $amount, $currency, $account, $site_id, $transaction_id ) { - $values = array( + $values = [ $amount, $currency, $account, $site_id, $transaction_id, - ); + ]; $string = implode( '', $values ); diff --git a/src/XML/DirectTransactionRequestMessage.php b/src/XML/DirectTransactionRequestMessage.php index 7fa8bd8..64ed52f 100644 --- a/src/XML/DirectTransactionRequestMessage.php +++ b/src/XML/DirectTransactionRequestMessage.php @@ -71,7 +71,7 @@ public function get_document() { XML_Util::add_elements( $document, $merchant, - array( + [ 'account' => $this->merchant->account, 'site_id' => $this->merchant->site_id, 'site_secure_code' => $this->merchant->site_secure_code, @@ -79,7 +79,7 @@ public function get_document() { 'redirect_url' => $this->merchant->redirect_url, 'cancel_url' => $this->merchant->cancel_url, 'close_window' => $this->merchant->close_window, - ) + ] ); // Customer. @@ -88,7 +88,7 @@ public function get_document() { XML_Util::add_elements( $document, $customer, - array( + [ 'locale' => $this->customer->locale, 'ipaddress' => $this->customer->ip_address, 'forwardedip' => $this->customer->forwarded_ip, @@ -102,7 +102,7 @@ public function get_document() { 'country' => $this->customer->country, 'phone' => $this->customer->phone, 'email' => $this->customer->email, - ) + ] ); // Transaction. @@ -111,7 +111,7 @@ public function get_document() { XML_Util::add_elements( $document, $transaction, - array( + [ 'id' => $this->transaction->id, 'currency' => $this->transaction->currency, 'amount' => $this->transaction->amount, @@ -123,7 +123,7 @@ public function get_document() { 'manual' => $this->transaction->manual, 'gateway' => $this->transaction->gateway, 'daysactive' => $this->transaction->days_active, - ) + ] ); // Gateway info. @@ -133,9 +133,9 @@ public function get_document() { XML_Util::add_elements( $document, $gateway_info, - array( + [ 'issuerid' => $this->gateway_info->issuer_id, - ) + ] ); } diff --git a/src/XML/GatewaysRequestMessage.php b/src/XML/GatewaysRequestMessage.php index 17cc500..9221c01 100644 --- a/src/XML/GatewaysRequestMessage.php +++ b/src/XML/GatewaysRequestMessage.php @@ -51,11 +51,11 @@ public function get_document() { XML_Util::add_elements( $document, $merchant, - array( + [ 'account' => $this->merchant->account, 'site_id' => $this->merchant->site_id, 'site_secure_code' => $this->merchant->site_secure_code, - ) + ] ); // Customer. @@ -64,10 +64,10 @@ public function get_document() { XML_Util::add_elements( $document, $customer, - array( + [ 'country' => $this->customer->country, 'locale' => $this->customer->locale, - ) + ] ); return $document; diff --git a/src/XML/GatewaysResponseMessage.php b/src/XML/GatewaysResponseMessage.php index 20e42e6..7e3a9a8 100644 --- a/src/XML/GatewaysResponseMessage.php +++ b/src/XML/GatewaysResponseMessage.php @@ -32,7 +32,7 @@ class GatewaysResponseMessage { public static function parse( SimpleXMLElement $xml ) { $message = new GatewaysResponseMessage(); - $message->gateways = array(); + $message->gateways = []; foreach ( $xml->gateways->gateway as $gateway ) { $id = Security::filter( $gateway->id ); diff --git a/src/XML/IDealIssuersRequestMessage.php b/src/XML/IDealIssuersRequestMessage.php index 0308842..7fdcbea 100644 --- a/src/XML/IDealIssuersRequestMessage.php +++ b/src/XML/IDealIssuersRequestMessage.php @@ -55,11 +55,11 @@ public function get_document() { XML_Util::add_elements( $document, $merchant, - array( + [ 'account' => $this->merchant->account, 'site_id' => $this->merchant->site_id, 'site_secure_code' => $this->merchant->site_secure_code, - ) + ] ); return $document; diff --git a/src/XML/IDealIssuersResponseMessage.php b/src/XML/IDealIssuersResponseMessage.php index 4ee539c..8b6f044 100644 --- a/src/XML/IDealIssuersResponseMessage.php +++ b/src/XML/IDealIssuersResponseMessage.php @@ -32,7 +32,7 @@ class IDealIssuersResponseMessage { public static function parse( SimpleXMLElement $xml ) { $message = new IDealIssuersResponseMessage(); - $message->issuers = array(); + $message->issuers = []; foreach ( $xml->issuers->issuer as $issuer ) { $code = Security::filter( $issuer->code ); diff --git a/src/XML/RedirectTransactionRequestMessage.php b/src/XML/RedirectTransactionRequestMessage.php index 6454ccb..930cc18 100644 --- a/src/XML/RedirectTransactionRequestMessage.php +++ b/src/XML/RedirectTransactionRequestMessage.php @@ -54,7 +54,7 @@ public function get_document() { XML_Util::add_elements( $document, $merchant, - array( + [ 'account' => $this->merchant->account, 'site_id' => $this->merchant->site_id, 'site_secure_code' => $this->merchant->site_secure_code, @@ -62,7 +62,7 @@ public function get_document() { 'redirect_url' => $this->merchant->redirect_url, 'cancel_url' => $this->merchant->cancel_url, 'close_window' => $this->merchant->close_window, - ) + ] ); // Customer. @@ -71,7 +71,7 @@ public function get_document() { XML_Util::add_elements( $document, $customer, - array( + [ 'locale' => $this->customer->locale, 'ipaddress' => $this->customer->ip_address, 'forwardedip' => $this->customer->forwarded_ip, @@ -85,7 +85,7 @@ public function get_document() { 'country' => $this->customer->country, 'phone' => $this->customer->phone, 'email' => $this->customer->email, - ) + ] ); // Transaction. @@ -94,7 +94,7 @@ public function get_document() { XML_Util::add_elements( $document, $transaction, - array( + [ 'id' => $this->transaction->id, 'currency' => $this->transaction->currency, 'amount' => $this->transaction->amount, @@ -106,7 +106,7 @@ public function get_document() { 'manual' => $this->transaction->manual, 'gateway' => $this->transaction->gateway, 'daysactive' => $this->transaction->days_active, - ) + ] ); // Signature. diff --git a/src/XML/StatusRequestMessage.php b/src/XML/StatusRequestMessage.php index b70c13d..04c7ed1 100644 --- a/src/XML/StatusRequestMessage.php +++ b/src/XML/StatusRequestMessage.php @@ -57,11 +57,11 @@ public function get_document() { XML_Util::add_elements( $document, $merchant, - array( + [ 'account' => $this->merchant->account, 'site_id' => $this->merchant->site_id, 'site_secure_code' => $this->merchant->site_secure_code, - ) + ] ); // Transaction. @@ -70,9 +70,9 @@ public function get_document() { XML_Util::add_elements( $document, $transaction, - array( + [ 'id' => $this->transaction_id, - ) + ] ); return $document; diff --git a/tests/src/DirectTransactionTest.php b/tests/src/DirectTransactionTest.php index 9cdc426..74249cf 100644 --- a/tests/src/DirectTransactionTest.php +++ b/tests/src/DirectTransactionTest.php @@ -35,7 +35,7 @@ public function http_api_debug( $response, $context, $class, $args, $url ) { public function test_init() { // Actions //add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 ); - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); // Config $config = new Config(); diff --git a/tests/src/GatewayTest.php b/tests/src/GatewayTest.php index fc7b585..e280286 100644 --- a/tests/src/GatewayTest.php +++ b/tests/src/GatewayTest.php @@ -38,7 +38,7 @@ public function pre_http_request( $preempt, $request, $url ) { public function test_init() { // Mock HTTP request //add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 ); - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); // Other $config = new Config(); @@ -62,13 +62,13 @@ public function test_init() { $issuers = null; } - $expected = array( - array( - 'options' => array( + $expected = [ + [ + 'options' => [ '3151' => 'Test bank', - ), - ), - ); + ], + ], + ]; $this->assertEquals( $expected, $issuers ); } diff --git a/tests/src/GatewaysTest.php b/tests/src/GatewaysTest.php index e908811..c2cefdb 100644 --- a/tests/src/GatewaysTest.php +++ b/tests/src/GatewaysTest.php @@ -33,7 +33,7 @@ public function http_api_debug( $response, $context, $class, $args, $url ) { public function test_init() { // Mock HTTP request //add_action( 'http_api_debug', array( $this, 'http_api_debug' ), 10, 5 ); - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); // Config $config = new Config(); @@ -69,7 +69,7 @@ public function test_init() { // Gateways $gateways = $client->get_gateways( $merchant, $customer ); - $expected = array( + $expected = [ 'VISA' => 'Visa', 'GIROPAY' => 'Giropay', 'PAYAFTER' => 'Pay After Delivery', @@ -77,7 +77,7 @@ public function test_init() { 'DIRECTBANK' => 'SOFORT Banking', 'BANKTRANS' => 'Wire Transfer', 'MASTERCARD' => 'MasterCard', - ); + ]; $this->assertEquals( $expected, $gateways ); } diff --git a/tests/src/IDealIssuersParserTest.php b/tests/src/IDealIssuersParserTest.php index 979110b..7aed646 100644 --- a/tests/src/IDealIssuersParserTest.php +++ b/tests/src/IDealIssuersParserTest.php @@ -40,7 +40,7 @@ public function test_parser( $simplexml ) { public function test_values( $message ) { $expected = new IDealIssuersResponseMessage(); - $expected->issuers = array( + $expected->issuers = [ '0031' => 'ABN AMRO', '0751' => 'SNS Bank', '0721' => 'ING', @@ -50,7 +50,7 @@ public function test_values( $message ) { '0771' => 'SNS Regio Bank', '0511' => 'Triodos Bank', '0161' => 'Van Lanschot Bankiers', - ); + ]; $this->assertEquals( $expected, $message ); } diff --git a/tests/src/StatusesTest.php b/tests/src/StatusesTest.php index 5976466..558e47d 100644 --- a/tests/src/StatusesTest.php +++ b/tests/src/StatusesTest.php @@ -28,15 +28,15 @@ public function test_transform( $status, $expected ) { } public function status_matrix_provider() { - return array( - array( Statuses::COMPLETED, Core_Statuses::SUCCESS ), - array( Statuses::INITIALIZED, Core_Statuses::OPEN ), - array( Statuses::UNCLEARED, Core_Statuses::OPEN ), - array( Statuses::VOID, Core_Statuses::CANCELLED ), - array( Statuses::DECLINED, Core_Statuses::FAILURE ), - array( Statuses::REFUNDED, Core_Statuses::CANCELLED ), - array( Statuses::EXPIRED, Core_Statuses::EXPIRED ), - array( 'not existing response code', null ), - ); + return [ + [ Statuses::COMPLETED, Core_Statuses::SUCCESS ], + [ Statuses::INITIALIZED, Core_Statuses::OPEN ], + [ Statuses::UNCLEARED, Core_Statuses::OPEN ], + [ Statuses::VOID, Core_Statuses::CANCELLED ], + [ Statuses::DECLINED, Core_Statuses::FAILURE ], + [ Statuses::REFUNDED, Core_Statuses::CANCELLED ], + [ Statuses::EXPIRED, Core_Statuses::EXPIRED ], + [ 'not existing response code', null ], + ]; } } From 66f8455266020e88f815106101deb8aed44d42d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Mon, 26 Sep 2022 10:28:22 +0200 Subject: [PATCH 21/23] Disable Xdebug in `phpcbf` Composer command. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 05ce95a..cd03e91 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ }, "scripts": { "coveralls": "vendor/bin/php-coveralls -v", - "phpcbf": "vendor/bin/phpcbf", + "phpcbf": "XDEBUG_MODE=off vendor/bin/phpcbf", "phpcs": "XDEBUG_MODE=off vendor/bin/phpcs -s -v", "phplint": "vendor/bin/phplint", "phpmd": "vendor/bin/phpmd src,tests text phpmd.ruleset.xml --suffixes php", From e2aa9fb5fe8e70f81ab21614594032be6bd8a541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Mon, 26 Sep 2022 13:35:18 +0200 Subject: [PATCH 22/23] Coding standards. --- phpcs.xml.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 5515be9..82adb4c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -6,6 +6,10 @@ tests/bootstrap.php tests/wp-config.php + + src/Gateway.php + + From edec9a1a787b3ae6a1608fa5c799802464ec8829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reu=CC=88el=20van=20der=20Steege?= Date: Mon, 26 Sep 2022 13:37:13 +0200 Subject: [PATCH 23/23] Getting ready for version 4.2.0. --- CHANGELOG.md | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ccee95..76445c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C ## [Unreleased][unreleased] - +## [4.2.0] - 2022-09-26 +- Updated payment methods registration. + ## [4.1.2] - 2022-08-15 - Fixed parsing gateways response message ([pronamic/wp-pronamic-pay-multisafepay#3](https://github.com/pronamic/wp-pronamic-pay-multisafepay/issues/3)). @@ -89,7 +92,8 @@ This projects adheres to [Semantic Versioning](http://semver.org/) and [Keep a C ## 1.0.0 - 2015-01-19 - First release. -[unreleased]: https://github.com/pronamic/wp-pronamic-pay-multisafepay/compare/4.1.2...HEAD +[unreleased]: https://github.com/pronamic/wp-pronamic-pay-multisafepay/compare/4.2.0...HEAD +[4.2.0]: https://github.com/pronamic/wp-pronamic-pay-multisafepay/compare/4.1.2...4.2.0 [4.1.2]: https://github.com/pronamic/wp-pronamic-pay-multisafepay/compare/4.1.1...4.1.2 [4.1.1]: https://github.com/pronamic/wp-pronamic-pay-multisafepay/compare/4.1.0...4.1.1 [4.1.0]: https://github.com/pronamic/wp-pronamic-pay-multisafepay/compare/4.0.1...4.1.0 diff --git a/package.json b/package.json index e494735..4ea174d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multisafepay", - "version": "4.1.2", + "version": "4.2.0", "description": "MultiSafepay driver for the WordPress payment processing library.", "repository": { "type": "git",