diff --git a/modules/ppcp-local-alternative-payment-methods/resources/js/eps-block.js b/modules/ppcp-local-alternative-payment-methods/resources/js/eps-block.js
new file mode 100644
index 000000000..051ec8730
--- /dev/null
+++ b/modules/ppcp-local-alternative-payment-methods/resources/js/eps-block.js
@@ -0,0 +1,9 @@
+export function EPS( { config, components } ) {
+ const { PaymentMethodIcons } = components;
+
+ return (
+
+ );
+}
diff --git a/modules/ppcp-local-alternative-payment-methods/resources/js/eps-payment-method.js b/modules/ppcp-local-alternative-payment-methods/resources/js/eps-payment-method.js
new file mode 100644
index 000000000..19d26d971
--- /dev/null
+++ b/modules/ppcp-local-alternative-payment-methods/resources/js/eps-payment-method.js
@@ -0,0 +1,18 @@
+import { registerPaymentMethod } from '@woocommerce/blocks-registry';
+import { EPS } from './eps-block';
+
+const config = wc.wcSettings.getSetting( 'ppcp-eps_data' );
+
+registerPaymentMethod( {
+ name: config.id,
+ label: ,
+ content: ,
+ edit: ,
+ ariaLabel: config.title,
+ canMakePayment: () => {
+ return true;
+ },
+ supports: {
+ features: config.supports,
+ },
+} );
diff --git a/modules/ppcp-local-alternative-payment-methods/services.php b/modules/ppcp-local-alternative-payment-methods/services.php
index d3589dc73..38806ac5e 100644
--- a/modules/ppcp-local-alternative-payment-methods/services.php
+++ b/modules/ppcp-local-alternative-payment-methods/services.php
@@ -39,6 +39,14 @@ return array(
$container->get( 'wcgateway.transaction-url-provider' )
);
},
+ 'ppcp-local-apms.eps.wc-gateway' => static function ( ContainerInterface $container ): EPSGateway {
+ return new EPSGateway(
+ $container->get( 'api.endpoint.orders' ),
+ $container->get( 'api.factory.purchase-unit' ),
+ $container->get( 'wcgateway.processor.refunds' ),
+ $container->get( 'wcgateway.transaction-url-provider' )
+ );
+ },
'ppcp-local-apms.bancontact.payment-method' => static function( ContainerInterface $container ): BancontactPaymentMethod {
return new BancontactPaymentMethod(
$container->get( 'ppcp-local-apms.url' ),
@@ -53,4 +61,11 @@ return array(
$container->get( 'ppcp-local-apms.blik.wc-gateway' )
);
},
+ 'ppcp-local-apms.eps.payment-method' => static function( ContainerInterface $container ): EPSPaymentMethod {
+ return new EPSPaymentMethod(
+ $container->get( 'ppcp-local-apms.url' ),
+ $container->get( 'ppcp.asset-version' ),
+ $container->get( 'ppcp-local-apms.eps.wc-gateway' )
+ );
+ },
);
diff --git a/modules/ppcp-local-alternative-payment-methods/src/EPSGateway.php b/modules/ppcp-local-alternative-payment-methods/src/EPSGateway.php
new file mode 100644
index 000000000..ef3094463
--- /dev/null
+++ b/modules/ppcp-local-alternative-payment-methods/src/EPSGateway.php
@@ -0,0 +1,226 @@
+id = self::ID;
+
+ $this->supports = array(
+ 'refunds',
+ 'products',
+ );
+
+ $this->method_title = __( 'EPS', 'woocommerce-paypal-payments' );
+ $this->method_description = __( 'EPS', 'woocommerce-paypal-payments' );
+
+ $this->title = $this->get_option( 'title', __( 'EPS', 'woocommerce-paypal-payments' ) );
+ $this->description = $this->get_option( 'description', '' );
+
+ $this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_eps_color.svg' );
+
+ $this->init_form_fields();
+ $this->init_settings();
+
+ add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
+
+ $this->orders_endpoint = $orders_endpoint;
+ $this->purchase_unit_factory = $purchase_unit_factory;
+ $this->refund_processor = $refund_processor;
+ $this->transaction_url_provider = $transaction_url_provider;
+ }
+
+ /**
+ * Initialize the form fields.
+ */
+ public function init_form_fields() {
+ $this->form_fields = array(
+ 'enabled' => array(
+ 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
+ 'type' => 'checkbox',
+ 'label' => __( 'EPS', 'woocommerce-paypal-payments' ),
+ 'default' => 'no',
+ 'desc_tip' => true,
+ 'description' => __( 'Enable/Disable EPS 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' ),
+ ),
+ );
+ }
+
+ /**
+ * Processes the order.
+ *
+ * @param int $order_id The WC order ID.
+ * @return array
+ */
+ public function process_payment( $order_id ) {
+ $wc_order = wc_get_order( $order_id );
+ $wc_order->update_status( 'on-hold', __( 'Awaiting EPS to confirm the payment.', 'woocommerce-paypal-payments' ) );
+
+ $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
+ $amount = $purchase_unit->amount()->to_array();
+
+ $request_body = array(
+ 'intent' => 'CAPTURE',
+ 'payment_source' => array(
+ 'eps' => array(
+ 'country_code' => 'AT',
+ 'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(),
+ ),
+ ),
+ 'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
+ 'purchase_units' => array(
+ array(
+ 'reference_id' => $purchase_unit->reference_id(),
+ 'amount' => array(
+ 'currency_code' => $amount['currency_code'],
+ 'value' => $amount['value'],
+ ),
+ 'custom_id' => $purchase_unit->custom_id(),
+ 'invoice_id' => $purchase_unit->invoice_id(),
+ ),
+ ),
+ 'application_context' => array(
+ 'locale' => 'en-AT',
+ 'return_url' => $this->get_return_url( $wc_order ),
+ 'cancel_url' => add_query_arg( 'cancelled', 'true', $this->get_return_url( $wc_order ) ),
+ ),
+ );
+
+ try {
+ $response = $this->orders_endpoint->create( $request_body );
+ } catch ( RuntimeException $exception ) {
+ $wc_order->update_status(
+ 'failed',
+ $exception->getMessage()
+ );
+
+ return array(
+ 'result' => 'failure',
+ 'redirect' => wc_get_checkout_url(),
+ );
+ }
+
+ $body = json_decode( $response['body'] );
+
+ $payer_action = '';
+ foreach ( $body->links as $link ) {
+ if ( $link->rel === 'payer-action' ) {
+ $payer_action = $link->href;
+ }
+ }
+
+ WC()->cart->empty_cart();
+
+ return array(
+ 'result' => 'success',
+ 'redirect' => esc_url( $payer_action ),
+ );
+ }
+
+ /**
+ * Process refund.
+ *
+ * If the gateway declares 'refunds' support, this will allow it to refund.
+ * a passed in amount.
+ *
+ * @param int $order_id Order ID.
+ * @param float $amount Refund amount.
+ * @param string $reason Refund reason.
+ * @return boolean True or false based on success, or a WP_Error object.
+ */
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
+ $order = wc_get_order( $order_id );
+ if ( ! is_a( $order, \WC_Order::class ) ) {
+ return false;
+ }
+ return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
+ }
+
+ /**
+ * Return transaction url for this gateway and given order.
+ *
+ * @param \WC_Order $order WC order to get transaction url by.
+ *
+ * @return string
+ */
+ public function get_transaction_url( $order ): string {
+ $this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
+
+ return parent::get_transaction_url( $order );
+ }
+}
diff --git a/modules/ppcp-local-alternative-payment-methods/src/EPSPaymentMethod.php b/modules/ppcp-local-alternative-payment-methods/src/EPSPaymentMethod.php
new file mode 100644
index 000000000..c00abdb7d
--- /dev/null
+++ b/modules/ppcp-local-alternative-payment-methods/src/EPSPaymentMethod.php
@@ -0,0 +1,97 @@
+module_url = $module_url;
+ $this->version = $version;
+ $this->gateway = $gateway;
+
+ $this->name = EPSGateway::ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function initialize() {}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function is_active() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_payment_method_script_handles() {
+ wp_register_script(
+ 'ppcp-eps-payment-method',
+ trailingslashit( $this->module_url ) . 'assets/js/eps-payment-method.js',
+ array(),
+ $this->version,
+ true
+ );
+
+ return array( 'ppcp-eps-payment-method' );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_payment_method_data() {
+ return array(
+ 'id' => $this->name,
+ 'title' => $this->gateway->title,
+ 'description' => $this->gateway->description,
+ 'icon' => esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_eps_color.svg' ),
+ );
+ }
+}
diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
index e0d19b01f..d921458f9 100644
--- a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
+++ b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php
@@ -49,6 +49,7 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface {
$methods[] = $c->get( 'ppcp-local-apms.bancontact.wc-gateway' );
$methods[] = $c->get( 'ppcp-local-apms.blik.wc-gateway' );
+ $methods[] = $c->get( 'ppcp-local-apms.eps.wc-gateway' );
return $methods;
}
@@ -76,6 +77,9 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface {
if ( $customer_country !== 'PL' || $site_currency !== 'PLN' ) {
unset( $methods[ BlikGateway::ID ] );
}
+ if ( $customer_country !== 'AT' || $site_currency !== 'EUR' ) {
+ unset( $methods[ EPSGateway::ID ] );
+ }
}
return $methods;
@@ -87,6 +91,7 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface {
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
$payment_method_registry->register( $c->get( 'ppcp-local-apms.bancontact.payment-method' ) );
$payment_method_registry->register( $c->get( 'ppcp-local-apms.blik.payment-method' ) );
+ $payment_method_registry->register( $c->get( 'ppcp-local-apms.eps.payment-method' ) );
}
);
@@ -94,7 +99,7 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface {
'woocommerce_paypal_payments_localized_script_data',
function ( array $data ) {
$default_disable_funding = $data['url_params']['disable-funding'] ?? '';
- $disable_funding = array_merge( array( 'bancontact', 'blik' ), array_filter( explode( ',', $default_disable_funding ) ) );
+ $disable_funding = array_merge( array( 'bancontact', 'blik', 'eps' ), array_filter( explode( ',', $default_disable_funding ) ) );
$data['url_params']['disable-funding'] = implode( ',', array_unique( $disable_funding ) );
return $data;
diff --git a/modules/ppcp-local-alternative-payment-methods/webpack.config.js b/modules/ppcp-local-alternative-payment-methods/webpack.config.js
index 4e57fe054..c44f4d81d 100644
--- a/modules/ppcp-local-alternative-payment-methods/webpack.config.js
+++ b/modules/ppcp-local-alternative-payment-methods/webpack.config.js
@@ -15,6 +15,9 @@ module.exports = {
'blik-payment-method': path.resolve(
'./resources/js/blik-payment-method.js'
),
+ 'eps-payment-method': path.resolve(
+ './resources/js/eps-payment-method.js'
+ ),
},
output: {
path: path.resolve( __dirname, 'assets/' ),