From ae30f4346dd9f0e7c715e45bdf2d0105ab743bf5 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Wed, 13 Apr 2022 11:53:44 +0200 Subject: [PATCH] Add experience context fields --- .../PayUponInvoice/PayUponInvoiceGateway.php | 86 +++++++++++-------- .../PayUponInvoice/PaymentSourceFactory.php | 11 ++- 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php index dab06489c..4249042d0 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PayUponInvoiceGateway.php @@ -60,8 +60,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { $this->method_title = __( 'Pay Upon Invoice', 'woocommerce-paypal-payments' ); $this->method_description = __( 'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.', 'woocommerce-paypal-payments' ); - $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); - $this->title = $gateway_settings['title'] ?? $this->method_title; + $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); + $this->title = $gateway_settings['title'] ?? $this->method_title; $this->description = $gateway_settings['description'] ?? __( 'Once you place an order, pay within 30 days. Our payment partner Ratepay will send you payment instructions.', 'woocommerce-paypal-payments' ); $this->init_form_fields(); @@ -79,7 +79,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { $this->purchase_unit_factory = $purchase_unit_factory; $this->payment_source_factory = $payment_source_factory; $this->logger = $logger; - $this->environment = $environment; + $this->environment = $environment; } /** @@ -87,39 +87,53 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { */ public function init_form_fields() { $this->form_fields = array( - 'enabled' => array( - 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ), - 'type' => 'checkbox', - 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ), - 'default' => 'no', - 'desc_tip' => true, - 'description' => __('Enable/Disable Pay Upon Invoice payment gateway.', 'woocommerce-paypal-payments'), + 'enabled' => array( + 'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ), + 'type' => 'checkbox', + 'label' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ), + 'default' => 'no', + 'desc_tip' => true, + 'description' => __( 'Enable/Disable Pay Upon Invoice 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'), + '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'), + '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' ), ), - 'experience_context' => array( + 'experience_context' => array( 'title' => __( 'Experience Context', 'woocommerce' ), 'type' => 'title', - 'description' => __("Specify brand name, logo and customer service instructions to be presented on Ratepay's payment instruction email sent to the buyer.", 'woocommerce-paypal-payments'), + 'description' => __( "Specify brand name, logo and customer service instructions to be presented on Ratepay's payment instructions.", 'woocommerce-paypal-payments' ), ), - 'brand_name' => array( - 'title' => __( 'Brand name', 'woocommerce-paypal-payments' ), - 'type' => 'text', - 'default' => '', - 'desc_tip' => true, - 'description' => __('Merchant name displayed in the email.', 'woocommerce-paypal-payments'), + 'brand_name' => array( + 'title' => __( 'Brand name', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'default' => get_bloginfo( 'name' ) ?? '', + 'desc_tip' => true, + 'description' => __( 'Merchant name displayed in Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ), + ), + 'logo_url' => array( + 'title' => __( 'Logo URL', 'woocommerce-paypal-payments' ), + 'type' => 'url', + 'default' => '', + 'desc_tip' => true, + 'description' => __( 'Logo to be presented on Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ), + ), + 'customer_service_instructions' => array( + 'title' => __( 'Customer service instructions', 'woocommerce-paypal-payments' ), + 'type' => 'text', + 'default' => '', + 'desc_tip' => true, + 'description' => __( 'Customer service instructions to be presented on Ratepay\'s payment instructions.', 'woocommerce-paypal-payments' ), ), ); } @@ -132,7 +146,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { $payment_source = $this->payment_source_factory->from_wc_order( $wc_order ); try { - $fraudnet_session_id = filter_input(INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING) ?? ''; + $fraudnet_session_id = filter_input( INPUT_POST, 'fraudnet-session-id', FILTER_SANITIZE_STRING ) ?? ''; $order = $this->order_endpoint->create( array( $purchase_unit ), $payment_source, $fraudnet_session_id ); $this->add_paypal_meta( $wc_order, $order, $this->environment ); @@ -146,13 +160,13 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway { } catch ( RuntimeException $exception ) { $error = $exception->getMessage(); - if(is_a($exception, PayPalApiException::class) && is_array($exception->details())) { + if ( is_a( $exception, PayPalApiException::class ) && is_array( $exception->details() ) ) { $details = ''; - foreach ($exception->details() as $detail) { - $issue = $detail->issue ?? ''; - $field = $detail->field ?? ''; + foreach ( $exception->details() as $detail ) { + $issue = $detail->issue ?? ''; + $field = $detail->field ?? ''; $description = $detail->description ?? ''; - $details .= $issue . ' ' . $field . ' ' . $description . '
'; + $details .= $issue . ' ' . $field . ' ' . $description . '
'; } $error = $details; diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php index ccacd8a16..8577c3f9b 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php +++ b/modules/ppcp-wc-gateway/src/Gateway/PayUponInvoice/PaymentSourceFactory.php @@ -11,6 +11,11 @@ class PaymentSourceFactory { $birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ); $phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ?? '' ); + $gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' ); + $merchant_name = $gateway_settings['brand_name'] ?? ''; + $logo_url = $gateway_settings['logo_url'] ?? ''; + $customer_service_instructions = $gateway_settings['customer_service_instructions'] ?? ''; + return new PaymentSource( $address['first_name'] ?? '', $address['last_name'] ?? '', @@ -23,9 +28,9 @@ class PaymentSourceFactory { $address['postcode'] ?? '', $address['country'] ?? '', 'en-DE', - 'EXAMPLE INC', - 'https://example.com/logoUrl.svg', - array('Customer service phone is +49 6912345678.') + $merchant_name, + $logo_url, + array($customer_service_instructions) ); } }