From a65d4fb2dc4c720058cb7b14aa06e09989963427 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 8 Aug 2024 14:24:47 +0200 Subject: [PATCH] Add wc payment gateway boilerplate --- .../services.php | 6 +- .../src/BancontactGateway.php | 72 +++++++++++++++++++ .../LocalAlternativePaymentMethodsModule.php | 4 ++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 modules/ppcp-local-alternative-payment-methods/src/BancontactGateway.php diff --git a/modules/ppcp-local-alternative-payment-methods/services.php b/modules/ppcp-local-alternative-payment-methods/services.php index 412f93edf..167916ae0 100644 --- a/modules/ppcp-local-alternative-payment-methods/services.php +++ b/modules/ppcp-local-alternative-payment-methods/services.php @@ -9,6 +9,10 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods; -return array( +use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +return array( + 'ppcp-local-apms.bancontact.wc-gateway' => static function ( ContainerInterface $container ): BancontactGateway { + return new BancontactGateway(); + }, ); diff --git a/modules/ppcp-local-alternative-payment-methods/src/BancontactGateway.php b/modules/ppcp-local-alternative-payment-methods/src/BancontactGateway.php new file mode 100644 index 000000000..54735b999 --- /dev/null +++ b/modules/ppcp-local-alternative-payment-methods/src/BancontactGateway.php @@ -0,0 +1,72 @@ +id = self::ID; + + $this->method_title = __( 'Bancontact', 'woocommerce-paypal-payments' ); + $this->method_description = __( 'Bancontact', 'woocommerce-paypal-payments' ); + + $this->title = $this->get_option( 'title', __( 'Bancontact', 'woocommerce-paypal-payments' ) ); + $this->description = $this->get_option( 'description', '' ); + + $this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_bancontact_color.svg' ); + + $this->init_form_fields(); + $this->init_settings(); + + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + } + + public function init_form_fields() { + $this->form_fields = array( + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Bancontact', 'woocommerce-paypal-payments' ), + 'default' => 'no', + 'desc_tip' => true, + 'description' => __( 'Enable/Disable Bancontact payment gateway.', 'woocommerce-paypal-payments' ), + ), + 'title' => array( + 'title' => __( 'Title', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'default' => $this->title, + 'desc_tip' => true, + 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ), + ), + 'description' => array( + 'title' => __( 'Description', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'default' => $this->description, + 'desc_tip' => true, + 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ), + ), + ); + } + + public function process_payment( $order_id ) { + $wc_order = wc_get_order( $order_id ); + + + + return array( + 'result' => 'success', + 'redirect' => $this->get_return_url( $wc_order ), + ); + } +} diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php index c8887bf5d..5674d90ae 100644 --- a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php +++ b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php @@ -30,6 +30,10 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface { } public function run(ContainerInterface $c): void { + add_filter('woocommerce_payment_gateways', function ($methods) use ($c) { + $methods[] = $c->get('ppcp-local-apms.bancontact.wc-gateway'); + return $methods; + }); } }