From 317a1b2efde39745e27cb544baf0c95058592c85 Mon Sep 17 00:00:00 2001 From: Hasan Hasanzade Date: Mon, 27 Jan 2025 15:43:32 +0400 Subject: [PATCH] Integrate Apple Pay as express payment method (#9) --- CHANGELOG.MD | 7 + bp-plugin-woocommerce-api2.php | 20 +- includes/api/apple-pay-session.php | 35 ++ .../api/betterpayment-payment-request.php | 29 ++ includes/{ => api}/webhook.php | 0 includes/blocks/assets/js/apple-pay.js | 279 +++++++++++++++ includes/blocks/payments/apple-pay.php | 95 +++++ includes/helpers/config-reader.php | 5 + .../abstract-betterpayment-gateway.php | 2 +- includes/payment-gateways/aiia-pay.php | 47 ++- includes/payment-gateways/apple-pay.php | 52 +++ includes/payment-gateways/credit-card.php | 47 ++- includes/payment-gateways/giropay.php | 47 ++- includes/payment-gateways/ideal.php | 47 ++- includes/payment-gateways/invoice-b2b.php | 191 +++++----- includes/payment-gateways/invoice.php | 283 ++++++++------- includes/payment-gateways/paydirekt.php | 47 ++- includes/payment-gateways/paypal.php | 47 ++- includes/payment-gateways/request-to-pay.php | 47 ++- .../sepa-direct-debit-b2b.php | 231 ++++++------- .../payment-gateways/sepa-direct-debit.php | 327 +++++++++--------- includes/payment-gateways/sofort.php | 47 ++- 22 files changed, 1205 insertions(+), 727 deletions(-) create mode 100644 includes/api/apple-pay-session.php create mode 100644 includes/api/betterpayment-payment-request.php rename includes/{ => api}/webhook.php (100%) create mode 100644 includes/blocks/assets/js/apple-pay.js create mode 100644 includes/blocks/payments/apple-pay.php create mode 100644 includes/payment-gateways/apple-pay.php diff --git a/CHANGELOG.MD b/CHANGELOG.MD index e531f49..83ba51b 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,5 +1,12 @@ This changelog follows the specifications of https://keepachangelog.com. Please, follow the specs when adding a new entry +## [1.3.0] - 2025-01-24 + +### Added + +- Apple Pay as express checkout + + ## [1.2.0] - 2024-10-23 ### Added diff --git a/bp-plugin-woocommerce-api2.php b/bp-plugin-woocommerce-api2.php index 663f9a3..6c5613a 100644 --- a/bp-plugin-woocommerce-api2.php +++ b/bp-plugin-woocommerce-api2.php @@ -3,14 +3,16 @@ * Plugin Name: Better Payment WooCommerce Extension * Plugin URI: https://github.com/better-payment/bp-plugin-woocommerce-api2 * Description: Better Payment plugin to implement payment methods using API2 - * Version: 1.2.0 + * Version: 1.3.0 * Author: Better Payment * Author URI: https://betterpayment.de * Text Domain: bp-plugin-woocommerce-api2 * Domain Path: /languages */ -//defined( 'ABSPATH' ) || exit; +if ( ! defined( 'ABSPATH' ) ) { + exit; +} use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; use Automattic\WooCommerce\Utilities\FeaturesUtil; @@ -44,6 +46,7 @@ public function init() { add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) ); // Include payment methods + include_once 'includes/payment-gateways/abstract-betterpayment-gateway.php'; include_once 'includes/payment-gateways/credit-card.php'; include_once 'includes/payment-gateways/paypal.php'; include_once 'includes/payment-gateways/paydirekt.php'; @@ -56,14 +59,18 @@ public function init() { include_once 'includes/payment-gateways/sepa-direct-debit-b2b.php'; include_once 'includes/payment-gateways/invoice.php'; include_once 'includes/payment-gateways/invoice-b2b.php'; + include_once 'includes/payment-gateways/apple-pay.php'; + // Register payment methods add_filter('woocommerce_payment_gateways', array($this, 'add_betterpayment_gateways')); // Include helpers include_once 'includes/helpers/config-reader.php'; - // Include webhook route endpoint - include_once 'includes/webhook.php'; + // Include custom endpoints + include_once 'includes/api/webhook.php'; + include_once 'includes/api/apple-pay-session.php'; + include_once 'includes/api/betterpayment-payment-request.php'; // Load translations load_plugin_textdomain( 'bp-plugin-woocommerce-api2', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); @@ -98,6 +105,7 @@ public function add_betterpayment_gateways($methods) { $methods[] = 'BetterPayment_Sepa_Direct_Debit_B2B'; $methods[] = 'BetterPayment_Invoice'; $methods[] = 'BetterPayment_Invoice_B2B'; + $methods[] = 'BetterPayment_Apple_Pay'; return $methods; } @@ -124,6 +132,8 @@ public function betterpayment_blocks_support() { include_once 'includes/blocks/payments/sepa-direct-debit.php'; include_once 'includes/blocks/payments/sepa-direct-debit-b2b.php'; + include_once 'includes/blocks/payments/apple-pay.php'; + add_action( 'woocommerce_blocks_payment_method_type_registration', function( PaymentMethodRegistry $payment_method_registry ) { @@ -140,6 +150,8 @@ function( PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( new BetterPayment_Invoice_B2B_Block() ); $payment_method_registry->register( new BetterPayment_Sepa_Direct_Debit_Block() ); $payment_method_registry->register( new BetterPayment_Sepa_Direct_Debit_B2B_Block() ); + + $payment_method_registry->register( new BetterPayment_ApplePay_Block() ); } ); } diff --git a/includes/api/apple-pay-session.php b/includes/api/apple-pay-session.php new file mode 100644 index 0000000..80346f5 --- /dev/null +++ b/includes/api/apple-pay-session.php @@ -0,0 +1,35 @@ + 'POST', + 'callback' => 'fetch_apple_pay_session', + 'permission_callback' => '__return_true', // Adjust permissions as needed + )); +}); + +function fetch_apple_pay_session(): WP_REST_Response { + $url = Config_Reader::get_api_url() . '/db_apple_pay_merchants'; + + $headers = [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode( Config_Reader::get_api_key() . ':' . Config_Reader::get_outgoing_key()) + ]; + + $body = wp_json_encode([ + 'initiative_context' => parse_url(home_url(), PHP_URL_HOST), + ]); + + $response = wp_remote_post( $url, [ + 'headers' => $headers, + 'body' => $body, + ]); + + if ( 200 === wp_remote_retrieve_response_code( $response ) ) { + $responseBody = json_decode( wp_remote_retrieve_body( $response ), true ); + + return new WP_REST_Response($responseBody, 200); + } + else { + return new WP_REST_Response(wp_remote_retrieve_body($response), wp_remote_retrieve_response_code($response)); + } +} diff --git a/includes/api/betterpayment-payment-request.php b/includes/api/betterpayment-payment-request.php new file mode 100644 index 0000000..818de9d --- /dev/null +++ b/includes/api/betterpayment-payment-request.php @@ -0,0 +1,29 @@ + 'POST', + 'callback' => 'payment', + 'permission_callback' => '__return_true', // Adjust permissions as needed + )); +}); + +// Only used for Apple Pay +function payment(WP_REST_Request $request): WP_REST_Response { + $url = Config_Reader::get_api_url() . '/rest/payment'; + $body = $request->get_body_params(); + + // Add the payment type to the body + $body['payment_type'] = 'applepay'; + + $headers = [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . base64_encode( Config_Reader::get_api_key() . ':' . Config_Reader::get_outgoing_key() ) + ]; + + $response = wp_remote_post( $url, [ + 'headers' => $headers, + 'body' => wp_json_encode($body), + ] ); + + return new WP_REST_Response(wp_remote_retrieve_body($response), wp_remote_retrieve_response_code($response)); +} diff --git a/includes/webhook.php b/includes/api/webhook.php similarity index 100% rename from includes/webhook.php rename to includes/api/webhook.php diff --git a/includes/blocks/assets/js/apple-pay.js b/includes/blocks/assets/js/apple-pay.js new file mode 100644 index 0000000..da8d3ce --- /dev/null +++ b/includes/blocks/assets/js/apple-pay.js @@ -0,0 +1,279 @@ +const applePayData = window.wc.wcSettings.getPaymentMethodData('betterpayment_applepay'); +const initialData = applePayData.initial_data; +const orderDescription = initialData.shop_name; + +let transaction_id = null; +let transaction_status = null; + +const APPLE_PAY_JS_API_VERSION = 14; +const REQUIRED_CONTACT_FIELDS = [ + "postalAddress", + "email", + "phone", +]; + +const ApplePayButton = (props) => { + const { onClick, onClose, onSubmit, eventRegistration, emitResponse, billing, shippingData} = props; + const { onPaymentProcessing } = eventRegistration; + const { billingAddress } = billing; + const { shippingAddress } = shippingData; + const { data } = window.wp; + const { CART_STORE_KEY, CHECKOUT_STORE_KEY } = window.wc.wcBlocksData; + + const buttonRef = React.useRef(null); + const initApplePay = async () => { + // WC Function + // Provided to express payment methods that should be triggered when the payment method button is clicked + // Which will signal to checkout the payment method has taken over payment processing + onClick(); + + const cartTotals = data.select(CART_STORE_KEY).getCartTotals(); + const currency = cartTotals.currency_code; + const totalAmount = cartTotals.total_price / 100; + const totalShipping = cartTotals.total_shipping / 100; + const totalTax = cartTotals.total_tax / 100; + + if (!ApplePaySession) { + onClose(); + return; + } + + try { + const requestBody = { + countryCode: initialData.country ?? "DE", + currencyCode: currency, + merchantCapabilities: applePayData.supports3DS ? ["supports3DS"] : [], + supportedNetworks: applePayData.supportedNetworks, + total: { + label: orderDescription, + amount: totalAmount, + }, + requiredShippingContactFields: REQUIRED_CONTACT_FIELDS, + requiredBillingContactFields: REQUIRED_CONTACT_FIELDS, + }; + + const session = new ApplePaySession( + APPLE_PAY_JS_API_VERSION, + requestBody + ); + + session.onvalidatemerchant = () => { + fetch('/wp-json/betterpayment/apple-pay-session', { + method: 'POST', + }) + .then(res => res.json()) + .then(data => { + const merchantSession = JSON.parse(atob(data.applepay_payment_session_token)); + session.completeMerchantValidation(merchantSession); + }) + .catch(err => { + console.error("Error fetching merchant session", err); + }); + }; + + session.onpaymentmethodselected = () => { + const update = { + newTotal: { + label: orderDescription, + amount: totalAmount, + }, + }; + + session.completePaymentMethodSelection(update); + }; + + session.onpaymentauthorized = async (event) => { + billingAddress.first_name = event.payment?.billingContact?.givenName ?? null; + billingAddress.last_name = event.payment?.billingContact?.familyName ?? null; + billingAddress.address_1 = event.payment?.billingContact?.addressLines?.[0] ?? null; + billingAddress.address_2 = event.payment?.billingContact?.addressLines?.[1] ?? null; + billingAddress.city = event.payment?.billingContact?.locality ?? null; + billingAddress.state = event.payment?.billingContact?.administrativeArea ?? null; + billingAddress.country = event.payment?.billingContact?.countryCode ?? "DE"; + billingAddress.postcode = event.payment?.billingContact?.postalCode ?? null; + billingAddress.email = event.payment?.shippingContact?.emailAddress ?? null; + billingAddress.phone = event.payment?.shippingContact?.phoneNumber ?? null; + + shippingAddress.first_name = event.payment?.shippingContact?.givenName ?? null; + shippingAddress.last_name = event.payment?.shippingContact?.familyName ?? null; + shippingAddress.address_1 = event.payment?.shippingContact?.addressLines?.[0] ?? null; + shippingAddress.address_2 = event.payment?.shippingContact?.addressLines?.[1] ?? null; + shippingAddress.city = event.payment?.shippingContact?.locality ?? null; + shippingAddress.state = event.payment?.shippingContact?.administrativeArea ?? null; + shippingAddress.country = event.payment?.shippingContact?.countryCode ?? "DE"; + shippingAddress.postcode = event.payment?.shippingContact?.postalCode ?? null; + shippingAddress.email = event.payment?.shippingContact?.emailAddress ?? null; + shippingAddress.phone = event.payment?.shippingContact?.phoneNumber ?? null; + + const payload = { + // common parameters + applepay_token: btoa(JSON.stringify(event.payment?.token)), + amount: totalAmount, + currency: currency, + postback_url: initialData.postback_url, + shipping_costs: totalShipping, + vat: totalTax, + order_id: initialData.order_id, + merchant_reference: initialData.order_id + ' - ' + initialData.shop_name, + customer_id: initialData.customer_id, + customer_ip: initialData.customer_ip, + app_name: initialData.app_name, + app_version: initialData.app_version, + + // billing address parameters + address: billingAddress.address_1, + address2: billingAddress.address_2, + city: billingAddress.city, + postal_code: billingAddress.postcode, + state: billingAddress.state, + country: billingAddress.country, + first_name: billingAddress.first_name, + last_name: billingAddress.last_name, + email: billingAddress.email, + phone: billingAddress.phone, + + // shipping address parameters + shipping_address: shippingAddress.address_1, + shipping_address2: shippingAddress.address_2, + shipping_city: shippingAddress.city, + shipping_postal_code: shippingAddress.postcode, + shipping_state: shippingAddress.state, + shipping_country: shippingAddress.country, + shipping_first_name: shippingAddress.first_name, + shipping_last_name: shippingAddress.last_name, + }; + + const response = await fetch('/wp-json/betterpayment/payment', { + method: 'POST', + body: JSON.stringify(payload), + }); + + if (response.ok) { + const data = JSON.parse(await response.json()); + + if (data.error_code === 0) { + session.completePayment({ + status: ApplePaySession.STATUS_SUCCESS + }); + + transaction_id = data.transaction_id; + transaction_status = data.status; + + // WC Function + // Submits the checkout and begins processing + onSubmit(); + } + else { + console.error('Payment Gateway request failed:', response.status, response.statusText); + console.error('Error details:', data); + + session.completePayment({ + status: ApplePaySession.STATUS_FAILURE + }); + + onClose(); + } + } + else { + const errorData = await response.json(); + console.error('Payment Gateway request failed:', response.status, response.statusText); + console.error('Error details:', errorData); + + session.completePayment({ + status: ApplePaySession.STATUS_FAILURE + }); + + onClose(); + } + }; + + session.oncancel = (event) => { + onClose(); + }; + + session.begin(); + } catch (e) { + onClose(); + } + } + + React.useEffect(() => { + // Dynamically load the Apple Pay SDK script + const script = document.createElement('script'); + script.src = 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js'; + script.crossOrigin = 'anonymous'; + document.head.appendChild(script); + + // Inject CSS styles for + const style = document.createElement('style'); + style.textContent = ` + apple-pay-button { + --apple-pay-button-width: 150px; + --apple-pay-button-height: 30px; + --apple-pay-button-border-radius: 3px; + --apple-pay-button-padding: 0px 0px; + --apple-pay-button-box-sizing: border-box; + } + `; + document.head.appendChild(style); + + // Add click event listener + const button = buttonRef.current; + if (button) { + button.addEventListener('click', initApplePay); + } + + // TODO: Make it specific to Apple Pay + // passes following metadata in other checkout payment methods (i.e. Credit Card) + const unsubscribe = onPaymentProcessing(async () => { + return { + type: emitResponse.responseTypes.SUCCESS, + meta: { + paymentMethodData: { + transaction_id: transaction_id ?? '', + transaction_status: transaction_status ?? '', + apple_pay_order_id: initialData.order_id, + }, + }, + }; + }); + + return () => { + // Cleanup script, style, and event listener + document.head.removeChild(script); + document.head.removeChild(style); + if (button) { + button.removeEventListener('click', initApplePay); + } + + unsubscribe(); + }; + }, [ + emitResponse.responseTypes.SUCCESS, + onPaymentProcessing, + ]); + + // TODO: Hide Apple Pay button when unable to generate Apple Pay merchant session + // Render the element + return React.createElement( + 'apple-pay-button', + { + buttonstyle: 'black', + type: 'plain', + locale: 'en-US', + ref: buttonRef, // Use ref to access DOM element + }, + null // No children + ); +}; + + +window.wc.wcBlocksRegistry.registerExpressPaymentMethod({ + name: 'betterpayment_applepay', + paymentMethodId: 'betterpayment_applepay', + title: applePayData.title, + description: applePayData.description, + content: Object( window.wp.element.createElement )( ApplePayButton, null ), + edit: Object( window.wp.element.createElement )( ApplePayButton, null ), + canMakePayment: () => true, +}); diff --git a/includes/blocks/payments/apple-pay.php b/includes/blocks/payments/apple-pay.php new file mode 100644 index 0000000..b05f9fc --- /dev/null +++ b/includes/blocks/payments/apple-pay.php @@ -0,0 +1,95 @@ +settings = get_option( 'woocommerce_' . $this->name . '_settings', [] ); + + // Bypass postcode and city validations. + // Because default woocommerce checkout form requires postcode and city fields being mandatory, + // while Apple Pay billing/shipping addresses doesn't require them to be mandatory fields + // https://developer.apple.com/documentation/apple_pay_on_the_web/applepaycontactfield + add_filter('woocommerce_validate_postcode', '__return_true'); + add_filter('woocommerce_default_address_fields', function ($fields) { + $fields['postcode']['required'] = false; + $fields['city']['required'] = false; + + return $fields; + }); + + add_action( + 'woocommerce_rest_checkout_process_payment_with_context', + function( PaymentContext $context, PaymentResult $result ) { + if ( $context->payment_method === $this->name ) { + // If the logic above was successful, we can set the status to success. + $order = $context->order; + $order->set_transaction_id($context->payment_data['transaction_id']); + $order->update_meta_data('apple_pay_order_id', $context->payment_data['apple_pay_order_id']); + $order->save(); + + $transaction_status = $context->payment_data['transaction_status']; + + // Map status from Better Payment to WooCommerce + if ( $transaction_status == 'completed' ) { + $order->payment_complete(); + } else { + $status = match ( $transaction_status ) { + 'started', 'pending' => 'on-hold', + 'error', 'declined', 'canceled' => 'failed', + 'refunded', 'chargeback' => 'refunded', + default => 'pending-payment', + }; + + $order->update_status( $status, 'Status updated from Payment Gateway.' ); + } + + $result->set_status( 'success' ); + $result->set_redirect_url($order->get_checkout_order_received_url()); + } + }, + 10, + 2 + ); + } + + public function is_active() { + return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN ); + } + + public function get_payment_method_script_handles() { + wp_register_script( + $this->name . '-blocks-integration', + plugin_dir_url(__DIR__) . 'assets/js/apple-pay.js', + [], + null, + true + ); + + return [ $this->name . '-blocks-integration' ]; + } + + + public function get_payment_method_data() { + return [ + 'title' => $this->get_setting( 'title' ), + 'description' => $this->get_setting( 'description' ), + 'supports3DS' => 'yes' == $this->get_setting( 'supports3DS' ), + 'supportedNetworks' => $this->get_setting( 'supported_networks' ), + 'initial_data' => [ + 'country' => WC()->countries->get_base_country(), + 'order_id' => wp_generate_uuid4(), + 'customer_id' => WC()->customer->get_id(), + 'customer_ip' => WC_Geolocation::get_ip_address(), + 'shop_name' => get_bloginfo('name'), + 'postback_url' => Config_Reader::get_postback_url(), + 'app_name' => Config_Reader::get_app_name(), + 'app_version' => Config_Reader::get_app_version(), + ], + ]; + } +} diff --git a/includes/helpers/config-reader.php b/includes/helpers/config-reader.php index befaf21..88ad950 100644 --- a/includes/helpers/config-reader.php +++ b/includes/helpers/config-reader.php @@ -17,6 +17,11 @@ public static function get_app_version(): string return 'WooCommerce ' . $woocommerce->version . ', Plugin ' . $plugin_data['Version']; } + public static function get_postback_url(): string + { + return set_url_scheme(get_rest_url(path: 'betterpayment/webhook'), 'https'); + } + public static function get_api_url() { $settings = get_option('woocommerce_betterpayment_settings'); $api_url = $settings['environment'] == 'test' ? $settings['testAPIUrl'] : $settings['productionAPIUrl']; diff --git a/includes/payment-gateways/abstract-betterpayment-gateway.php b/includes/payment-gateways/abstract-betterpayment-gateway.php index ce37aa7..2ab6e65 100644 --- a/includes/payment-gateways/abstract-betterpayment-gateway.php +++ b/includes/payment-gateways/abstract-betterpayment-gateway.php @@ -112,7 +112,7 @@ private function get_common_parameters($order_id): array // always enabled 'risk_check_approval' => '1', // The URL for updates about transaction status are posted - 'postback_url' => set_url_scheme(get_rest_url(path: 'betterpayment/webhook'), 'https'), + 'postback_url' => Config_Reader::get_postback_url(), // Any alphanumeric string to identify the Merchant’s order 'order_id' => $order->get_order_number(), // Any alphanumeric string to provide the customer number of a Merchant’s order (up to 40 characters) for factoring or debt collection diff --git a/includes/payment-gateways/aiia-pay.php b/includes/payment-gateways/aiia-pay.php index 07d320a..fa57efd 100644 --- a/includes/payment-gateways/aiia-pay.php +++ b/includes/payment-gateways/aiia-pay.php @@ -1,32 +1,29 @@ id = 'betterpayment_aiia'; - $this->method_title = __( 'Aiia Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Aiia Pay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_aiia'; + $this->method_title = __( 'Aiia Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Aiia Pay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Aiia Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Aiia Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/apple-pay.php b/includes/payment-gateways/apple-pay.php new file mode 100644 index 0000000..1544f10 --- /dev/null +++ b/includes/payment-gateways/apple-pay.php @@ -0,0 +1,52 @@ +id = 'betterpayment_applepay'; + $this->method_title = __( 'Apple Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Apple Pay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + + parent::__construct(); + } + + // Apple Pay is not available in shortcode (legacy) checkout + public function is_available(): bool { + if (is_checkout() && !WC_Blocks_Utils::has_block_in_page(get_the_ID(), 'woocommerce/checkout')) + return false; + + return true; + } + + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Apple Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ], + 'supports3DS' => [ + 'title' => __( '3DS Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => 'yes' + ], + 'supported_networks' => [ + 'title' => __( 'Supported Networks', 'bp-plugin-woocommerce-api2' ), + 'type' => 'multiselect', + 'options' => [ + 'visa' => 'VISA', + 'masterCard' => 'MASTERCARD', + ], + 'default' => [ + 'visa', + 'masterCard' + ] + ] + ]; + } +} diff --git a/includes/payment-gateways/credit-card.php b/includes/payment-gateways/credit-card.php index d71cf95..d19175d 100644 --- a/includes/payment-gateways/credit-card.php +++ b/includes/payment-gateways/credit-card.php @@ -1,32 +1,29 @@ id = 'betterpayment_cc'; - $this->method_title = __( 'Credit Card (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Credit Card payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_cc'; + $this->method_title = __( 'Credit Card (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Credit Card payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Credit Card (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Credit Card (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/giropay.php b/includes/payment-gateways/giropay.php index 1de8a53..7c6ebbd 100644 --- a/includes/payment-gateways/giropay.php +++ b/includes/payment-gateways/giropay.php @@ -1,32 +1,29 @@ id = 'betterpayment_giro'; - $this->method_title = __( 'Giropay (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Giropay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_giro'; + $this->method_title = __( 'Giropay (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Giropay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Giropay (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Giropay (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/ideal.php b/includes/payment-gateways/ideal.php index f62340d..3689a07 100644 --- a/includes/payment-gateways/ideal.php +++ b/includes/payment-gateways/ideal.php @@ -1,32 +1,29 @@ id = 'betterpayment_ideal'; - $this->method_title = __( 'iDEAL (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'iDEAL payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_ideal'; + $this->method_title = __( 'iDEAL (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'iDEAL payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'iDEAL (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'iDEAL (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/invoice-b2b.php b/includes/payment-gateways/invoice-b2b.php index 1b24fd4..e9ca75d 100644 --- a/includes/payment-gateways/invoice-b2b.php +++ b/includes/payment-gateways/invoice-b2b.php @@ -1,116 +1,113 @@ is_risk_check_agreement_required(); - } - public function __construct() { - $this->id = 'betterpayment_kar_b2b'; - $this->method_title = __( 'Invoice B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Invoice B2B payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); +class BetterPayment_Invoice_B2B extends Abstract_BetterPayment_Gateway { + protected string $shortcode = 'kar_b2b'; + protected bool $is_b2b = true; - parent::__construct(); + /** + * @return bool + */ + public function has_fields(): bool { + return $this->is_risk_check_agreement_required(); + } - add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); - } + public function __construct() { + $this->id = 'betterpayment_kar_b2b'; + $this->method_title = __( 'Invoice B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Invoice B2B payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + parent::__construct(); - public function is_available() { - $is_available = parent::is_available(); + add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); + } - $company = WC()->customer?->get_billing_company(); - return $is_available && $company; - } + public function is_available() { + $is_available = parent::is_available(); - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Invoice B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ], - 'risk_check_agreement' => [ - 'title' => __('Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2') - ], - 'display_payment_instruction' => [ - 'title' => __('Display payment instruction to the customer', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('When activated, we will be instructing the customer that they should send ORDER_ID as a reference with amount due to the given bank account below.', 'bp-plugin-woocommerce-api2') - ], - 'iban' => [ - 'title' => __('IBAN (optional)', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('IBAN of your company', 'bp-plugin-woocommerce-api2'), - ], - 'bic' => [ - 'title' => __('BIC (optional)', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('BIC of your company', 'bp-plugin-woocommerce-api2'), - ] - ]; - } + $company = WC()->customer?->get_billing_company(); - private function is_risk_check_agreement_required(): bool { - return get_option('woocommerce_betterpayment_kar_b2b_settings')['risk_check_agreement'] == 'yes'; - } + return $is_available && $company; + } - private function is_payment_instruction_displayed(): bool { - return get_option('woocommerce_betterpayment_kar_b2b_settings')['display_payment_instruction'] == 'yes'; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Invoice B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ], + 'risk_check_agreement' => [ + 'title' => __( 'Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2' ) + ], + 'display_payment_instruction' => [ + 'title' => __( 'Display payment instruction to the customer', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'When activated, we will be instructing the customer that they should send ORDER_ID as a reference with amount due to the given bank account below.', 'bp-plugin-woocommerce-api2' ) + ], + 'iban' => [ + 'title' => __( 'IBAN (optional)', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'IBAN of your company', 'bp-plugin-woocommerce-api2' ), + ], + 'bic' => [ + 'title' => __( 'BIC (optional)', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'BIC of your company', 'bp-plugin-woocommerce-api2' ), + ] + ]; + } + + private function is_risk_check_agreement_required(): bool { + return get_option( 'woocommerce_betterpayment_kar_b2b_settings' )['risk_check_agreement'] == 'yes'; + } - public function thankyou_page( $order_id ) { - if ( $this->is_payment_instruction_displayed() ) { - $title = __('Invoice payment instructions', 'bp-plugin-woocommerce-api2'); - $iban_label = __('IBAN: ', 'bp-plugin-woocommerce-api2'); - $bic_label = __('BIC: ', 'bp-plugin-woocommerce-api2'); - $reference_label = __('Reference: ', 'bp-plugin-woocommerce-api2'); - $description = __('Please, transfer the full invoice amount to the bank account displayed in this page. Include reference mentioned above, in your transfer. Your order will stay pending until the payment has been cleared.', 'bp-plugin-woocommerce-api2'); - - $html = "

$title

"; - $html .= "$iban_label" . get_option('woocommerce_betterpayment_kar_b2b_settings')['iban']; - $html .= "
"; - $html .= "$bic_label" . get_option('woocommerce_betterpayment_kar_b2b_settings')['bic']; - $html .= "
"; - $html .= "$reference_label$order_id"; - $html .= "

$description

"; - - echo wpautop( wptexturize( $html ) ); - } + private function is_payment_instruction_displayed(): bool { + return get_option( 'woocommerce_betterpayment_kar_b2b_settings' )['display_payment_instruction'] == 'yes'; + } + + public function thankyou_page( $order_id ) { + if ( $this->is_payment_instruction_displayed() ) { + $title = __( 'Invoice payment instructions', 'bp-plugin-woocommerce-api2' ); + $iban_label = __( 'IBAN: ', 'bp-plugin-woocommerce-api2' ); + $bic_label = __( 'BIC: ', 'bp-plugin-woocommerce-api2' ); + $reference_label = __( 'Reference: ', 'bp-plugin-woocommerce-api2' ); + $description = __( 'Please, transfer the full invoice amount to the bank account displayed in this page. Include reference mentioned above, in your transfer. Your order will stay pending until the payment has been cleared.', 'bp-plugin-woocommerce-api2' ); + + $html = "

$title

"; + $html .= "$iban_label" . get_option( 'woocommerce_betterpayment_kar_b2b_settings' )['iban']; + $html .= "
"; + $html .= "$bic_label" . get_option( 'woocommerce_betterpayment_kar_b2b_settings' )['bic']; + $html .= "
"; + $html .= "$reference_label$order_id"; + $html .= "

$description

"; + + echo wpautop( wptexturize( $html ) ); } + } - public function payment_fields() { - if ($this->is_risk_check_agreement_required()) { - woocommerce_form_field($this->id . '_risk_check_agreement', [ - 'type' => 'checkbox', - 'label' => __('Agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'required' => true, - ]); - } + public function payment_fields() { + if ( $this->is_risk_check_agreement_required() ) { + woocommerce_form_field( $this->id . '_risk_check_agreement', [ + 'type' => 'checkbox', + 'label' => __( 'Agree to risk check processing', 'bp-plugin-woocommerce-api2' ), + 'required' => true, + ] ); } + } - public function validate_fields() { - if ( $this->is_risk_check_agreement_required() && empty($_POST[$this->id . '_risk_check_agreement']) ) { - wc_add_notice( __('Risk check agreement is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + public function validate_fields() { + if ( $this->is_risk_check_agreement_required() && empty( $_POST[ $this->id . '_risk_check_agreement' ] ) ) { + wc_add_notice( __( 'Risk check agreement is required', 'bp-plugin-woocommerce-api2' ), 'error' ); } } } diff --git a/includes/payment-gateways/invoice.php b/includes/payment-gateways/invoice.php index fb5f34e..aee470a 100644 --- a/includes/payment-gateways/invoice.php +++ b/includes/payment-gateways/invoice.php @@ -1,170 +1,167 @@ is_date_of_birth_collected() || $this->is_gender_collected() || $this->is_risk_check_agreement_required(); - } + /** + * @return bool + */ + public function has_fields(): bool { + return $this->is_date_of_birth_collected() || $this->is_gender_collected() || $this->is_risk_check_agreement_required(); + } - public function __construct() { - $this->id = 'betterpayment_kar'; - $this->method_title = __( 'Invoice (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Invoice payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_kar'; + $this->method_title = __( 'Invoice (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Invoice payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); + parent::__construct(); - add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); - } + add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) ); + } - public function is_available() { - $is_available = parent::is_available(); + public function is_available() { + $is_available = parent::is_available(); - $company = WC()->customer?->get_billing_company(); + $company = WC()->customer?->get_billing_company(); - return $is_available && !$company; - } + return $is_available && ! $company; + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __('Enabled', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __('Title', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'default' => __('Invoice (Better Payment)', 'bp-plugin-woocommerce-api2'), - ], - 'collect_date_of_birth' => [ - 'title' => __('Collect date of birth', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you have configured risk checks with the payment provider, it may require date of birth from your customers.', 'bp-plugin-woocommerce-api2'), - ], - 'collect_gender' => [ - 'title' => __('Collect gender information', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you have configured risk checks with the payment provider, it may require gender from your customers.', 'bp-plugin-woocommerce-api2'), - ], - 'risk_check_agreement' => [ - 'title' => __('Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2'), - ], - 'display_payment_instruction' => [ - 'title' => __('Display payment instruction to the customer', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('When activated, we will be instructing the customer that they should send ORDER_ID as a reference with amount due to the given bank account below.', 'bp-plugin-woocommerce-api2'), - ], - 'iban' => [ - 'title' => __('IBAN (optional)', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('IBAN of your company', 'bp-plugin-woocommerce-api2'), - ], - 'bic' => [ - 'title' => __('BIC (optional)', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('BIC of your company', 'bp-plugin-woocommerce-api2'), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Invoice (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ], + 'collect_date_of_birth' => [ + 'title' => __( 'Collect date of birth', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you have configured risk checks with the payment provider, it may require date of birth from your customers.', 'bp-plugin-woocommerce-api2' ), + ], + 'collect_gender' => [ + 'title' => __( 'Collect gender information', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you have configured risk checks with the payment provider, it may require gender from your customers.', 'bp-plugin-woocommerce-api2' ), + ], + 'risk_check_agreement' => [ + 'title' => __( 'Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2' ), + ], + 'display_payment_instruction' => [ + 'title' => __( 'Display payment instruction to the customer', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'When activated, we will be instructing the customer that they should send ORDER_ID as a reference with amount due to the given bank account below.', 'bp-plugin-woocommerce-api2' ), + ], + 'iban' => [ + 'title' => __( 'IBAN (optional)', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'IBAN of your company', 'bp-plugin-woocommerce-api2' ), + ], + 'bic' => [ + 'title' => __( 'BIC (optional)', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'BIC of your company', 'bp-plugin-woocommerce-api2' ), + ] + ]; + } - private function is_date_of_birth_collected(): bool { - return get_option('woocommerce_betterpayment_kar_settings')['collect_date_of_birth'] == 'yes'; - } + private function is_date_of_birth_collected(): bool { + return get_option( 'woocommerce_betterpayment_kar_settings' )['collect_date_of_birth'] == 'yes'; + } + + private function is_gender_collected(): bool { + return get_option( 'woocommerce_betterpayment_kar_settings' )['collect_gender'] == 'yes'; + } + + private function is_risk_check_agreement_required(): bool { + return get_option( 'woocommerce_betterpayment_kar_settings' )['risk_check_agreement'] == 'yes'; + } - private function is_gender_collected(): bool { - return get_option('woocommerce_betterpayment_kar_settings')['collect_gender'] == 'yes'; + private function is_payment_instruction_displayed(): bool { + return get_option( 'woocommerce_betterpayment_kar_settings' )['display_payment_instruction'] == 'yes'; + } + + public function thankyou_page( $order_id ) { + if ( $this->is_payment_instruction_displayed() ) { + $title = __( 'Invoice payment instructions', 'bp-plugin-woocommerce-api2' ); + $iban_label = __( 'IBAN: ', 'bp-plugin-woocommerce-api2' ); + $bic_label = __( 'BIC: ', 'bp-plugin-woocommerce-api2' ); + $reference_label = __( 'Reference: ', 'bp-plugin-woocommerce-api2' ); + $description = __( 'Please, transfer the full invoice amount to the bank account displayed in this page. Include reference mentioned above, in your transfer. Your order will stay pending until the payment has been cleared.', 'bp-plugin-woocommerce-api2' ); + + $html = "

$title

"; + $html .= "$iban_label" . get_option( 'woocommerce_betterpayment_kar_settings' )['iban']; + $html .= "
"; + $html .= "$bic_label" . get_option( 'woocommerce_betterpayment_kar_settings' )['bic']; + $html .= "
"; + $html .= "$reference_label$order_id"; + $html .= "

$description

"; + + echo wpautop( wptexturize( $html ) ); } + } - private function is_risk_check_agreement_required(): bool { - return get_option('woocommerce_betterpayment_kar_settings')['risk_check_agreement'] == 'yes'; + public function payment_fields() { + // Risk check information + if ( $this->is_date_of_birth_collected() || $this->is_gender_collected() || $this->is_risk_check_agreement_required() ) { + $html = __( 'Risk check information', 'bp-plugin-woocommerce-api2' ); + echo wpautop( wptexturize( $html ) ); } - private function is_payment_instruction_displayed(): bool { - return get_option('woocommerce_betterpayment_kar_settings')['display_payment_instruction'] == 'yes'; + if ( $this->is_date_of_birth_collected() ) { + woocommerce_form_field( $this->id . '_date_of_birth', [ + 'type' => 'date', + 'required' => true, + 'label' => __( 'Date of birth', 'bp-plugin-woocommerce-api2' ), + ] ); } - public function thankyou_page( $order_id ) { - if ( $this->is_payment_instruction_displayed() ) { - $title = __('Invoice payment instructions', 'bp-plugin-woocommerce-api2'); - $iban_label = __('IBAN: ', 'bp-plugin-woocommerce-api2'); - $bic_label = __('BIC: ', 'bp-plugin-woocommerce-api2'); - $reference_label = __('Reference: ', 'bp-plugin-woocommerce-api2'); - $description = __('Please, transfer the full invoice amount to the bank account displayed in this page. Include reference mentioned above, in your transfer. Your order will stay pending until the payment has been cleared.', 'bp-plugin-woocommerce-api2'); - - $html = "

$title

"; - $html .= "$iban_label" . get_option('woocommerce_betterpayment_kar_settings')['iban']; - $html .= "
"; - $html .= "$bic_label" . get_option('woocommerce_betterpayment_kar_settings')['bic']; - $html .= "
"; - $html .= "$reference_label$order_id"; - $html .= "

$description

"; - - echo wpautop( wptexturize( $html ) ); - } + if ( $this->is_gender_collected() ) { + woocommerce_form_field( $this->id . '_gender', [ + 'type' => 'select', + 'options' => [ + '' => __( 'Select...', 'bp-plugin-woocommerce-api2' ), + 'm' => __( 'Male', 'bp-plugin-woocommerce-api2' ), + 'f' => __( 'Female', 'bp-plugin-woocommerce-api2' ), + 'd' => __( 'Diverse', 'bp-plugin-woocommerce-api2' ), + ], + 'required' => true, + 'label' => __( 'Gender', 'bp-plugin-woocommerce-api2' ), + ] ); } - public function payment_fields() { - // Risk check information - if ($this->is_date_of_birth_collected() || $this->is_gender_collected() || $this->is_risk_check_agreement_required()) { - $html = __('Risk check information', 'bp-plugin-woocommerce-api2'); - echo wpautop( wptexturize( $html ) ); - } - - if ($this->is_date_of_birth_collected()) { - woocommerce_form_field($this->id . '_date_of_birth', [ - 'type' => 'date', - 'required' => true, - 'label' => __('Date of birth', 'bp-plugin-woocommerce-api2'), - ]); - } - - if ($this->is_gender_collected()) { - woocommerce_form_field($this->id . '_gender', [ - 'type' => 'select', - 'options' => [ - '' => __('Select...', 'bp-plugin-woocommerce-api2'), - 'm' => __('Male', 'bp-plugin-woocommerce-api2'), - 'f' => __('Female', 'bp-plugin-woocommerce-api2'), - 'd' => __('Diverse', 'bp-plugin-woocommerce-api2'), - ], - 'required' => true, - 'label' => __('Gender', 'bp-plugin-woocommerce-api2'), - ]); - } - - if ($this->is_risk_check_agreement_required()) { - woocommerce_form_field($this->id . '_risk_check_agreement', [ - 'type' => 'checkbox', - 'label' => __('Agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'required' => true, - ]); - } + if ( $this->is_risk_check_agreement_required() ) { + woocommerce_form_field( $this->id . '_risk_check_agreement', [ + 'type' => 'checkbox', + 'label' => __( 'Agree to risk check processing', 'bp-plugin-woocommerce-api2' ), + 'required' => true, + ] ); } + } - public function validate_fields() { - if ( $this->is_date_of_birth_collected() && empty($_POST[$this->id . '_date_of_birth']) ) { - wc_add_notice( __('Date of birth is required', 'bp-plugin-woocommerce-api2' ), 'error' ); - } + public function validate_fields() { + if ( $this->is_date_of_birth_collected() && empty( $_POST[ $this->id . '_date_of_birth' ] ) ) { + wc_add_notice( __( 'Date of birth is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( $this->is_gender_collected() && empty($_POST[$this->id . '_gender']) ) { - wc_add_notice( __('Gender is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( $this->is_gender_collected() && empty( $_POST[ $this->id . '_gender' ] ) ) { + wc_add_notice( __( 'Gender is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( $this->is_risk_check_agreement_required() && empty($_POST[$this->id . '_risk_check_agreement']) ) { - wc_add_notice( __('Risk check agreement is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( $this->is_risk_check_agreement_required() && empty( $_POST[ $this->id . '_risk_check_agreement' ] ) ) { + wc_add_notice( __( 'Risk check agreement is required', 'bp-plugin-woocommerce-api2' ), 'error' ); } } } diff --git a/includes/payment-gateways/paydirekt.php b/includes/payment-gateways/paydirekt.php index 0563de4..fcfa430 100644 --- a/includes/payment-gateways/paydirekt.php +++ b/includes/payment-gateways/paydirekt.php @@ -1,32 +1,29 @@ id = 'betterpayment_paydirekt'; - $this->method_title = __( 'Paydirekt (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Paydirekt payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_paydirekt'; + $this->method_title = __( 'Paydirekt (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Paydirekt payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Paydirekt (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Paydirekt (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/paypal.php b/includes/payment-gateways/paypal.php index de91736..c598bc6 100644 --- a/includes/payment-gateways/paypal.php +++ b/includes/payment-gateways/paypal.php @@ -1,32 +1,29 @@ id = 'betterpayment_paypal'; - $this->method_title = __( 'PayPal (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'PayPal payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_paypal'; + $this->method_title = __( 'PayPal (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'PayPal payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields(): void { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'PayPal (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields(): void { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'PayPal (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/request-to-pay.php b/includes/payment-gateways/request-to-pay.php index 22925ae..3463d8d 100644 --- a/includes/payment-gateways/request-to-pay.php +++ b/includes/payment-gateways/request-to-pay.php @@ -1,32 +1,29 @@ id = 'betterpayment_rtp'; - $this->method_title = __( 'Request To Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Request To Pay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_rtp'; + $this->method_title = __( 'Request To Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Request To Pay payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Request To Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Request To Pay (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } } diff --git a/includes/payment-gateways/sepa-direct-debit-b2b.php b/includes/payment-gateways/sepa-direct-debit-b2b.php index a6bfd36..cc43c35 100644 --- a/includes/payment-gateways/sepa-direct-debit-b2b.php +++ b/includes/payment-gateways/sepa-direct-debit-b2b.php @@ -1,135 +1,132 @@ id = 'betterpayment_dd_b2b'; - $this->method_title = __( 'Sepa Direct Debit B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Sepa Direct Debit B2B payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - $this->has_fields = true; + public function __construct() { + $this->id = 'betterpayment_dd_b2b'; + $this->method_title = __( 'Sepa Direct Debit B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Sepa Direct Debit B2B payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + $this->has_fields = true; - parent::__construct(); - } + parent::__construct(); + } - public function is_available() { - $is_available = parent::is_available(); + public function is_available() { + $is_available = parent::is_available(); - $company = WC()->customer?->get_billing_company(); + $company = WC()->customer?->get_billing_company(); - return $is_available && $company; - } + return $is_available && $company; + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __('Enabled', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __('Title', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'default' => __('Sepa Direct Debit B2B (Better Payment)', 'bp-plugin-woocommerce-api2'), - ], - 'creditor_id' => [ - 'title' => __('Creditor ID', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('You need to provide a valid Creditor ID, to be shown in mandate agreement on the checkout page.', 'bp-plugin-woocommerce-api2'), - ], - 'company_name' => [ - 'title' => __('Company name', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('You need to provide Company Name, to be shown in mandate reference agreement on the checkout page.', 'bp-plugin-woocommerce-api2'), - ], - 'risk_check_agreement' => [ - 'title' => __('Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2'), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Sepa Direct Debit B2B (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ], + 'creditor_id' => [ + 'title' => __( 'Creditor ID', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'You need to provide a valid Creditor ID, to be shown in mandate agreement on the checkout page.', 'bp-plugin-woocommerce-api2' ), + ], + 'company_name' => [ + 'title' => __( 'Company name', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'You need to provide Company Name, to be shown in mandate reference agreement on the checkout page.', 'bp-plugin-woocommerce-api2' ), + ], + 'risk_check_agreement' => [ + 'title' => __( 'Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2' ), + ] + ]; + } - private function is_risk_check_agreement_required(): bool { - return get_option('woocommerce_betterpayment_dd_b2b_settings')['risk_check_agreement'] == 'yes'; - } + private function is_risk_check_agreement_required(): bool { + return get_option( 'woocommerce_betterpayment_dd_b2b_settings' )['risk_check_agreement'] == 'yes'; + } - public function payment_fields() { - woocommerce_form_field($this->id . '_iban', [ - 'type' => 'text', - 'required' => true, - 'label' => __('IBAN', 'bp-plugin-woocommerce-api2'), - ]); - - woocommerce_form_field($this->id . '_bic', [ - 'type' => 'text', - 'label' => __('BIC', 'bp-plugin-woocommerce-api2'), - ]); - - $account_holder = wp_get_current_user()->first_name . ' ' . wp_get_current_user()->last_name; - $creditor_id = get_option('woocommerce_betterpayment_dd_b2b_settings')['creditor_id']; - $company_name = get_option('woocommerce_betterpayment_dd_b2b_settings')['company_name']; - $mandate_reference = wp_generate_uuid4(); - - $label_account_holder = __('Account holder: ', 'bp-plugin-woocommerce-api2'); - $label_creditor_id = __('Creditor ID: ', 'bp-plugin-woocommerce-api2'); - $label_company_name = __('Company name: ', 'bp-plugin-woocommerce-api2'); - $label_mandate_reference = __('Mandate reference: ', 'bp-plugin-woocommerce-api2'); - - $html = "$label_account_holder$account_holder"; - $html .= "
"; - $html .= "$label_creditor_id$creditor_id"; - $html .= "
"; - $html .= "$label_company_name$company_name"; - $html .= "
"; - $html .= "$label_mandate_reference$mandate_reference"; - $html .= "
"; - $html .= "
"; - $html .= sprintf(__('By signing this mandate form, you authorise (A) %s to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from %s. This mandate is only intended for business-to-business transactions. You are not entitled to a refund from your bank after your account has been debited, but you are entitled to request your bank not to debit your account up until the day on which the payment is due.', 'bp-plugin-woocommerce-api2'), $company_name, $company_name); - - echo wpautop( wptexturize( $html ) ); - - woocommerce_form_field($this->id . '_account_holder', [ - 'type' => 'hidden', - 'default' => $account_holder, - ]); - - woocommerce_form_field($this->id . '_mandate_reference', [ - 'type' => 'hidden', - 'default' => $mandate_reference, - ]); - - woocommerce_form_field($this->id . '_mandate_agreement', [ - 'type' => 'checkbox', - 'label' => __('I agree to the following mandate', 'bp-plugin-woocommerce-api2'), + public function payment_fields() { + woocommerce_form_field( $this->id . '_iban', [ + 'type' => 'text', + 'required' => true, + 'label' => __( 'IBAN', 'bp-plugin-woocommerce-api2' ), + ] ); + + woocommerce_form_field( $this->id . '_bic', [ + 'type' => 'text', + 'label' => __( 'BIC', 'bp-plugin-woocommerce-api2' ), + ] ); + + $account_holder = wp_get_current_user()->first_name . ' ' . wp_get_current_user()->last_name; + $creditor_id = get_option( 'woocommerce_betterpayment_dd_b2b_settings' )['creditor_id']; + $company_name = get_option( 'woocommerce_betterpayment_dd_b2b_settings' )['company_name']; + $mandate_reference = wp_generate_uuid4(); + + $label_account_holder = __( 'Account holder: ', 'bp-plugin-woocommerce-api2' ); + $label_creditor_id = __( 'Creditor ID: ', 'bp-plugin-woocommerce-api2' ); + $label_company_name = __( 'Company name: ', 'bp-plugin-woocommerce-api2' ); + $label_mandate_reference = __( 'Mandate reference: ', 'bp-plugin-woocommerce-api2' ); + + $html = "$label_account_holder$account_holder"; + $html .= "
"; + $html .= "$label_creditor_id$creditor_id"; + $html .= "
"; + $html .= "$label_company_name$company_name"; + $html .= "
"; + $html .= "$label_mandate_reference$mandate_reference"; + $html .= "
"; + $html .= "
"; + $html .= sprintf( __( 'By signing this mandate form, you authorise (A) %s to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from %s. This mandate is only intended for business-to-business transactions. You are not entitled to a refund from your bank after your account has been debited, but you are entitled to request your bank not to debit your account up until the day on which the payment is due.', 'bp-plugin-woocommerce-api2' ), $company_name, $company_name ); + + echo wpautop( wptexturize( $html ) ); + + woocommerce_form_field( $this->id . '_account_holder', [ + 'type' => 'hidden', + 'default' => $account_holder, + ] ); + + woocommerce_form_field( $this->id . '_mandate_reference', [ + 'type' => 'hidden', + 'default' => $mandate_reference, + ] ); + + woocommerce_form_field( $this->id . '_mandate_agreement', [ + 'type' => 'checkbox', + 'label' => __( 'I agree to the following mandate', 'bp-plugin-woocommerce-api2' ), + 'required' => true, + ] ); + + if ( $this->is_risk_check_agreement_required() ) { + woocommerce_form_field( $this->id . '_risk_check_agreement', [ + 'type' => 'checkbox', + 'label' => __( 'Agree to risk check processing', 'bp-plugin-woocommerce-api2' ), 'required' => true, - ]); - - if ($this->is_risk_check_agreement_required()) { - woocommerce_form_field($this->id . '_risk_check_agreement', [ - 'type' => 'checkbox', - 'label' => __('Agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'required' => true, - ]); - } + ] ); } + } - public function validate_fields() { - if( empty($_POST[$this->id . '_iban']) ) { - wc_add_notice( __('IBAN is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + public function validate_fields() { + if ( empty( $_POST[ $this->id . '_iban' ] ) ) { + wc_add_notice( __( 'IBAN is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( empty($_POST[$this->id . '_mandate_agreement']) ) { - wc_add_notice( __('Mandate agreement is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( empty( $_POST[ $this->id . '_mandate_agreement' ] ) ) { + wc_add_notice( __( 'Mandate agreement is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( $this->is_risk_check_agreement_required() && empty($_POST[$this->id . '_risk_check_agreement']) ) { - wc_add_notice( __('Risk check agreement is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( $this->is_risk_check_agreement_required() && empty( $_POST[ $this->id . '_risk_check_agreement' ] ) ) { + wc_add_notice( __( 'Risk check agreement is required', 'bp-plugin-woocommerce-api2' ), 'error' ); } } } diff --git a/includes/payment-gateways/sepa-direct-debit.php b/includes/payment-gateways/sepa-direct-debit.php index 992e5b1..7ec9175 100644 --- a/includes/payment-gateways/sepa-direct-debit.php +++ b/includes/payment-gateways/sepa-direct-debit.php @@ -1,191 +1,188 @@ id = 'betterpayment_dd'; - $this->method_title = __( 'Sepa Direct Debit (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Sepa Direct Debit payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - $this->has_fields = true; + public function __construct() { + $this->id = 'betterpayment_dd'; + $this->method_title = __( 'Sepa Direct Debit (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Sepa Direct Debit payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + $this->has_fields = true; - parent::__construct(); - } - - public function is_available() { - $is_available = parent::is_available(); + parent::__construct(); + } - $company = WC()->customer?->get_billing_company(); + public function is_available() { + $is_available = parent::is_available(); - return $is_available && !$company; - } + $company = WC()->customer?->get_billing_company(); - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __('Enabled', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __('Title', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'default' => __('Sepa Direct Debit (Better Payment)', 'bp-plugin-woocommerce-api2'), - ], - 'creditor_id' => [ - 'title' => __('Creditor ID', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('You need to provide a valid Creditor ID, to be shown in mandate agreement on the checkout page.', 'bp-plugin-woocommerce-api2'), - ], - 'company_name' => [ - 'title' => __('Company name', 'bp-plugin-woocommerce-api2'), - 'type' => 'text', - 'description' => __('You need to provide Company Name, to be shown in mandate reference agreement on the checkout page.', 'bp-plugin-woocommerce-api2'), - ], - 'collect_date_of_birth' => [ - 'title' => __('Collect date of birth', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you have configured risk checks with the payment provider, it may require date of birth from your customers.', 'bp-plugin-woocommerce-api2'), - ], - 'collect_gender' => [ - 'title' => __('Collect gender information', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you have configured risk checks with the payment provider, it may require gender from your customers.', 'bp-plugin-woocommerce-api2'), - ], - 'risk_check_agreement' => [ - 'title' => __('Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'type' => 'checkbox', - 'default' => false, - 'description' => __('If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2'), - ] - ]; - } + return $is_available && ! $company; + } - private function is_date_of_birth_collected(): bool { - return get_option('woocommerce_betterpayment_dd_settings')['collect_date_of_birth'] == 'yes'; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Sepa Direct Debit (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ], + 'creditor_id' => [ + 'title' => __( 'Creditor ID', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'You need to provide a valid Creditor ID, to be shown in mandate agreement on the checkout page.', 'bp-plugin-woocommerce-api2' ), + ], + 'company_name' => [ + 'title' => __( 'Company name', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'description' => __( 'You need to provide Company Name, to be shown in mandate reference agreement on the checkout page.', 'bp-plugin-woocommerce-api2' ), + ], + 'collect_date_of_birth' => [ + 'title' => __( 'Collect date of birth', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you have configured risk checks with the payment provider, it may require date of birth from your customers.', 'bp-plugin-woocommerce-api2' ), + ], + 'collect_gender' => [ + 'title' => __( 'Collect gender information', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you have configured risk checks with the payment provider, it may require gender from your customers.', 'bp-plugin-woocommerce-api2' ), + ], + 'risk_check_agreement' => [ + 'title' => __( 'Require customers to agree to risk check processing', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false, + 'description' => __( 'If you turn this flag on, we will require the customer to agree to the risk check processing in the checkout page. Without agreement, payments will not go through. You can turn this field off, in case you provide it as part of your terms and conditions.', 'bp-plugin-woocommerce-api2' ), + ] + ]; + } - private function is_gender_collected(): bool { - return get_option('woocommerce_betterpayment_dd_settings')['collect_gender'] == 'yes'; - } + private function is_date_of_birth_collected(): bool { + return get_option( 'woocommerce_betterpayment_dd_settings' )['collect_date_of_birth'] == 'yes'; + } - private function is_risk_check_agreement_required(): bool { - return get_option('woocommerce_betterpayment_dd_settings')['risk_check_agreement'] == 'yes'; - } + private function is_gender_collected(): bool { + return get_option( 'woocommerce_betterpayment_dd_settings' )['collect_gender'] == 'yes'; + } - public function payment_fields() { - woocommerce_form_field($this->id . '_iban', [ - 'type' => 'text', - 'required' => true, - 'label' => __('IBAN', 'bp-plugin-woocommerce-api2'), - ]); - - woocommerce_form_field($this->id . '_bic', [ - 'type' => 'text', - 'label' => __('BIC', 'bp-plugin-woocommerce-api2'), - ]); - - $account_holder = wp_get_current_user()->first_name . ' ' . wp_get_current_user()->last_name; - $creditor_id = get_option('woocommerce_betterpayment_dd_settings')['creditor_id']; - $company_name = get_option('woocommerce_betterpayment_dd_settings')['company_name']; - $mandate_reference = wp_generate_uuid4(); - - $label_account_holder = __('Account holder: ', 'bp-plugin-woocommerce-api2'); - $label_creditor_id = __('Creditor ID: ', 'bp-plugin-woocommerce-api2'); - $label_company_name = __('Company name: ', 'bp-plugin-woocommerce-api2'); - $label_mandate_reference = __('Mandate reference: ', 'bp-plugin-woocommerce-api2'); - - $html = "$label_account_holder$account_holder"; - $html .= "
"; - $html .= "$label_creditor_id$creditor_id"; - $html .= "
"; - $html .= "$label_company_name$company_name"; - $html .= "
"; - $html .= "$label_mandate_reference$mandate_reference"; - $html .= "
"; - $html .= "
"; - $html .= sprintf(__('By signing this mandate form, you authorise (A) %s to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from %s. As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within eight weeks starting from the date on which your account was debited.', 'bp-plugin-woocommerce-api2'), $company_name, $company_name); + private function is_risk_check_agreement_required(): bool { + return get_option( 'woocommerce_betterpayment_dd_settings' )['risk_check_agreement'] == 'yes'; + } + public function payment_fields() { + woocommerce_form_field( $this->id . '_iban', [ + 'type' => 'text', + 'required' => true, + 'label' => __( 'IBAN', 'bp-plugin-woocommerce-api2' ), + ] ); + + woocommerce_form_field( $this->id . '_bic', [ + 'type' => 'text', + 'label' => __( 'BIC', 'bp-plugin-woocommerce-api2' ), + ] ); + + $account_holder = wp_get_current_user()->first_name . ' ' . wp_get_current_user()->last_name; + $creditor_id = get_option( 'woocommerce_betterpayment_dd_settings' )['creditor_id']; + $company_name = get_option( 'woocommerce_betterpayment_dd_settings' )['company_name']; + $mandate_reference = wp_generate_uuid4(); + + $label_account_holder = __( 'Account holder: ', 'bp-plugin-woocommerce-api2' ); + $label_creditor_id = __( 'Creditor ID: ', 'bp-plugin-woocommerce-api2' ); + $label_company_name = __( 'Company name: ', 'bp-plugin-woocommerce-api2' ); + $label_mandate_reference = __( 'Mandate reference: ', 'bp-plugin-woocommerce-api2' ); + + $html = "$label_account_holder$account_holder"; + $html .= "
"; + $html .= "$label_creditor_id$creditor_id"; + $html .= "
"; + $html .= "$label_company_name$company_name"; + $html .= "
"; + $html .= "$label_mandate_reference$mandate_reference"; + $html .= "
"; + $html .= "
"; + $html .= sprintf( __( 'By signing this mandate form, you authorise (A) %s to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from %s. As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within eight weeks starting from the date on which your account was debited.', 'bp-plugin-woocommerce-api2' ), $company_name, $company_name ); + + echo wpautop( wptexturize( $html ) ); + + woocommerce_form_field( $this->id . '_account_holder', [ + 'type' => 'hidden', + 'default' => $account_holder, + ] ); + + woocommerce_form_field( $this->id . '_mandate_reference', [ + 'type' => 'hidden', + 'default' => $mandate_reference, + ] ); + + woocommerce_form_field( $this->id . '_mandate_agreement', [ + 'type' => 'checkbox', + 'label' => __( 'I agree to the following mandate', 'bp-plugin-woocommerce-api2' ), + 'required' => true, + ] ); + + // Risk check information + if ( $this->is_date_of_birth_collected() || $this->is_gender_collected() || $this->is_risk_check_agreement_required() ) { + $html = '
'; + $html .= __( 'Risk check information', 'bp-plugin-woocommerce-api2' ); echo wpautop( wptexturize( $html ) ); + } - woocommerce_form_field($this->id . '_account_holder', [ - 'type' => 'hidden', - 'default' => $account_holder, - ]); + if ( $this->is_date_of_birth_collected() ) { + woocommerce_form_field( $this->id . '_date_of_birth', [ + 'type' => 'date', + 'required' => true, + 'label' => __( 'Date of birth', 'bp-plugin-woocommerce-api2' ), + ] ); + } - woocommerce_form_field($this->id . '_mandate_reference', [ - 'type' => 'hidden', - 'default' => $mandate_reference, - ]); + if ( $this->is_gender_collected() ) { + woocommerce_form_field( $this->id . '_gender', [ + 'type' => 'select', + 'options' => [ + '' => __( 'Select...', 'bp-plugin-woocommerce-api2' ), + 'm' => __( 'Male', 'bp-plugin-woocommerce-api2' ), + 'f' => __( 'Female', 'bp-plugin-woocommerce-api2' ), + 'd' => __( 'Diverse', 'bp-plugin-woocommerce-api2' ), + ], + 'required' => true, + 'label' => __( 'Gender', 'bp-plugin-woocommerce-api2' ), + ] ); + } - woocommerce_form_field($this->id . '_mandate_agreement', [ - 'type' => 'checkbox', - 'label' => __('I agree to the following mandate', 'bp-plugin-woocommerce-api2'), + if ( $this->is_risk_check_agreement_required() ) { + woocommerce_form_field( $this->id . '_risk_check_agreement', [ + 'type' => 'checkbox', + 'label' => __( 'Agree to risk check processing', 'bp-plugin-woocommerce-api2' ), 'required' => true, - ]); - - // Risk check information - if ($this->is_date_of_birth_collected() || $this->is_gender_collected() || $this->is_risk_check_agreement_required()) { - $html = '
'; - $html .= __('Risk check information', 'bp-plugin-woocommerce-api2'); - echo wpautop( wptexturize( $html ) ); - } - - if ($this->is_date_of_birth_collected()) { - woocommerce_form_field($this->id . '_date_of_birth', [ - 'type' => 'date', - 'required' => true, - 'label' => __('Date of birth', 'bp-plugin-woocommerce-api2'), - ]); - } - - if ($this->is_gender_collected()) { - woocommerce_form_field($this->id . '_gender', [ - 'type' => 'select', - 'options' => [ - '' => __('Select...', 'bp-plugin-woocommerce-api2'), - 'm' => __('Male', 'bp-plugin-woocommerce-api2'), - 'f' => __('Female', 'bp-plugin-woocommerce-api2'), - 'd' => __('Diverse', 'bp-plugin-woocommerce-api2'), - ], - 'required' => true, - 'label' => __('Gender', 'bp-plugin-woocommerce-api2'), - ]); - } - - if ($this->is_risk_check_agreement_required()) { - woocommerce_form_field($this->id . '_risk_check_agreement', [ - 'type' => 'checkbox', - 'label' => __('Agree to risk check processing', 'bp-plugin-woocommerce-api2'), - 'required' => true, - ]); - } + ] ); } + } - public function validate_fields() { - if( empty($_POST[$this->id . '_iban']) ) { - wc_add_notice( __('IBAN is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + public function validate_fields() { + if ( empty( $_POST[ $this->id . '_iban' ] ) ) { + wc_add_notice( __( 'IBAN is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( empty($_POST[$this->id . '_mandate_agreement']) ) { - wc_add_notice( __('Mandate agreement is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( empty( $_POST[ $this->id . '_mandate_agreement' ] ) ) { + wc_add_notice( __( 'Mandate agreement is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( $this->is_date_of_birth_collected() && empty($_POST[$this->id . '_date_of_birth']) ) { - wc_add_notice( __('Date of birth is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( $this->is_date_of_birth_collected() && empty( $_POST[ $this->id . '_date_of_birth' ] ) ) { + wc_add_notice( __( 'Date of birth is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( $this->is_gender_collected() && empty($_POST[$this->id . '_gender']) ) { - wc_add_notice( __('Gender is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( $this->is_gender_collected() && empty( $_POST[ $this->id . '_gender' ] ) ) { + wc_add_notice( __( 'Gender is required', 'bp-plugin-woocommerce-api2' ), 'error' ); + } - if ( $this->is_risk_check_agreement_required() && empty($_POST[$this->id . '_risk_check_agreement']) ) { - wc_add_notice( __('Risk check agreement is required', 'bp-plugin-woocommerce-api2'), 'error' ); - } + if ( $this->is_risk_check_agreement_required() && empty( $_POST[ $this->id . '_risk_check_agreement' ] ) ) { + wc_add_notice( __( 'Risk check agreement is required', 'bp-plugin-woocommerce-api2' ), 'error' ); } } } diff --git a/includes/payment-gateways/sofort.php b/includes/payment-gateways/sofort.php index a9eab93..1484e15 100644 --- a/includes/payment-gateways/sofort.php +++ b/includes/payment-gateways/sofort.php @@ -1,32 +1,29 @@ id = 'betterpayment_sofort'; - $this->method_title = __( 'Sofort (Better Payment)', 'bp-plugin-woocommerce-api2' ); - $this->method_description = __( 'Sofort payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); + public function __construct() { + $this->id = 'betterpayment_sofort'; + $this->method_title = __( 'Sofort (Better Payment)', 'bp-plugin-woocommerce-api2' ); + $this->method_description = __( 'Sofort payment method of Better Payment', 'bp-plugin-woocommerce-api2' ); - parent::__construct(); - } + parent::__construct(); + } - public function init_form_fields() { - $this->form_fields = [ - 'enabled' => [ - 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), - 'type' => 'checkbox', - 'default' => false - ], - 'title' => [ - 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), - 'type' => 'text', - 'default' => __( 'Sofort (Better Payment)', 'bp-plugin-woocommerce-api2' ), - ] - ]; - } + public function init_form_fields() { + $this->form_fields = [ + 'enabled' => [ + 'title' => __( 'Enabled', 'bp-plugin-woocommerce-api2' ), + 'type' => 'checkbox', + 'default' => false + ], + 'title' => [ + 'title' => __( 'Title', 'bp-plugin-woocommerce-api2' ), + 'type' => 'text', + 'default' => __( 'Sofort (Better Payment)', 'bp-plugin-woocommerce-api2' ), + ] + ]; } }