From 0f009514084cc5e897dc0fcbc97575331844fabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=C3=BCel=20van=20der=20Steege?= Date: Fri, 31 May 2024 16:39:31 +0200 Subject: [PATCH] Use pronamic/ideal-issuers for iDEAL issuers. --- composer.json | 6 +++-- src/OrderStandard/Config.php | 7 ++++++ src/OrderStandard/Gateway.php | 39 ++++++++++++------------------- src/OrderStandard/Integration.php | 4 ++-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 58fb792..e927166 100644 --- a/composer.json +++ b/composer.json @@ -35,12 +35,14 @@ "composer/installers": true, "dealerdirect/phpcodesniffer-composer-installer": true, "roots/wordpress-core-installer": true, - "bamarni/composer-bin-plugin": true + "bamarni/composer-bin-plugin": true, + "automattic/jetpack-autoloader": true } }, "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-simplexml": "*", + "pronamic/ideal-issuers": "^1.0", "pronamic/wp-http": "^1.2", "wp-pay/core": "^4.13" }, diff --git a/src/OrderStandard/Config.php b/src/OrderStandard/Config.php index 8b394aa..3d236fb 100644 --- a/src/OrderStandard/Config.php +++ b/src/OrderStandard/Config.php @@ -108,6 +108,13 @@ class Config extends Ingenico_Config { */ public $alias_usage = ''; + /** + * Live or test mode. + * + * @var string + */ + public $mode = ''; + /** * Get the Ogone e-Commerce direct query URL. * diff --git a/src/OrderStandard/Gateway.php b/src/OrderStandard/Gateway.php index 5c8e007..bb62acf 100644 --- a/src/OrderStandard/Gateway.php +++ b/src/OrderStandard/Gateway.php @@ -2,6 +2,7 @@ namespace Pronamic\WordPress\Pay\Gateways\Ingenico\OrderStandard; +use Pronamic\IDealIssuers\IDealIssuerService; use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; use Pronamic\WordPress\Pay\Core\PaymentMethod; use Pronamic\WordPress\Pay\Core\PaymentMethods as Core_PaymentMethods; @@ -55,6 +56,8 @@ public function __construct( Config $config ) { $this->config = $config; + $this->set_mode( $config->mode ); + $this->set_method( self::METHOD_HTML_FORM ); // Supported features. @@ -83,17 +86,10 @@ public function __construct( Config $config ) { $this->register_payment_method( new PaymentMethod( Core_PaymentMethods::PAYPAL ) ); // Payment method iDEAL. - $ideal_options = new CachedCallbackOptions( - function () { - return $this->get_ideal_issuers(); - }, - 'pronamic_pay_ideal_issuers_' . \md5( (string) \wp_json_encode( $config ) ) - ); - $payment_method_ideal = new PaymentMethod( Core_PaymentMethods::IDEAL ); $field_ideal_issuer = new IDealIssuerSelectField( 'pronamic_pay_ingenico_ideal_issuer' ); - $field_ideal_issuer->set_options( $ideal_options ); + $field_ideal_issuer->set_options( $this->get_ideal_issuers() ); $payment_method_ideal->add_field( $field_ideal_issuer ); @@ -113,22 +109,17 @@ private function get_ideal_issuers() { ]; } - return [ - new SelectFieldOption( 'ABNANL2A', \__( 'ABN AMRO', 'pronamic_ideal' ) ), - new SelectFieldOption( 'RABONL2U', \__( 'Rabobank', 'pronamic_ideal' ) ), - new SelectFieldOption( 'INGBNL2A', \__( 'ING', 'pronamic_ideal' ) ), - new SelectFieldOption( 'SNSBNL2A', \__( 'SNS Bank', 'pronamic_ideal' ) ), - new SelectFieldOption( 'RBRBNL21', \__( 'Regio Bank', 'pronamic_ideal' ) ), - new SelectFieldOption( 'ASNBNL21', \__( 'ASN Bank', 'pronamic_ideal' ) ), - new SelectFieldOption( 'BUNQNL2A', \__( 'Bunq', 'pronamic_ideal' ) ), - new SelectFieldOption( 'TRIONL2U', \__( 'Triodos Bank', 'pronamic_ideal' ) ), - new SelectFieldOption( 'FVLBNL22', \__( 'van Lanschot Bankiers', 'pronamic_ideal' ) ), - new SelectFieldOption( 'KNABNL2H', \__( 'Knab bank', 'pronamic_ideal' ) ), - new SelectFieldOption( 'REVOLT21', \__( 'Revolut', 'pronamic_ideal' ) ), - new SelectFieldOption( 'BITSNL2A', \__( 'Yoursafe', 'pronamic_ideal' ) ), - new SelectFieldOption( 'NTSBDEB1', \__( 'N26', 'pronamic_ideal' ) ), - new SelectFieldOption( 'NNBANL2G', \__( 'Nationale Nederlanden', 'pronamic_ideal' ) ), - ]; + $ideal_issuer_service = new IDealIssuerService(); + + $issuers = $ideal_issuer_service->get_issuers(); + + $items = []; + + foreach ( $issuers as $issuer ) { + $items[] = new SelectFieldOption( $issuer->code, $issuer->name ); + } + + return $items; } /** diff --git a/src/OrderStandard/Integration.php b/src/OrderStandard/Integration.php index 10dd68d..21fcf56 100644 --- a/src/OrderStandard/Integration.php +++ b/src/OrderStandard/Integration.php @@ -61,6 +61,8 @@ public function get_settings_fields() { public function get_config( $post_id ) { $config = new Config(); + $config->mode = $this->get_mode(); + $config->set_form_action_url( $this->action_url ); $config->set_direct_query_url( $this->direct_query_url ); @@ -95,8 +97,6 @@ public function get_config( $post_id ) { public function get_gateway( $post_id ) { $gateway = new Gateway( $this->get_config( $post_id ) ); - $gateway->set_mode( $this->get_mode() ); - return $gateway; } }