♻️ Use new definition service in REST endpoint

This commit is contained in:
Philipp Stracker 2025-02-13 19:06:12 +01:00
parent 7908a1c56a
commit b5d717cac0
No known key found for this signature in database
2 changed files with 39 additions and 561 deletions

View file

@ -109,7 +109,10 @@ return array(
return new CommonRestEndpoint( $container->get( 'settings.data.general' ) );
},
'settings.rest.payment' => static function ( ContainerInterface $container ) : PaymentRestEndpoint {
return new PaymentRestEndpoint( $container->get( 'settings.data.payment' ) );
return new PaymentRestEndpoint(
$container->get( 'settings.data.payment' ),
$container->get( 'settings.data.definition.methods' )
);
},
'settings.rest.styling' => static function ( ContainerInterface $container ) : StylingRestEndpoint {
return new StylingRestEndpoint(

View file

@ -29,6 +29,7 @@ use WP_REST_Response;
use WP_REST_Request;
use WooCommerce\PayPalCommerce\Applepay\ApplePayGateway;
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\EPSGateway;
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
/**
* REST controller for the "Payment Methods" settings tab.
@ -51,6 +52,13 @@ class PaymentRestEndpoint extends RestEndpoint {
*/
protected PaymentSettings $settings;
/**
* The payment method details.
*
* @var PaymentMethodsDefinition
*/
protected PaymentMethodsDefinition $methods_definition;
/**
* Field mapping for request to profile transformation.
*
@ -78,10 +86,12 @@ class PaymentRestEndpoint extends RestEndpoint {
/**
* Constructor.
*
* @param PaymentSettings $settings The settings instance.
* @param PaymentSettings $settings The settings instance.
* @param PaymentMethodsDefinition $methods_definition Payment Method details.
*/
public function __construct( PaymentSettings $settings ) {
$this->settings = $settings;
public function __construct( PaymentSettings $settings, PaymentMethodsDefinition $methods_definition ) {
$this->settings = $settings;
$this->methods_definition = $methods_definition;
}
/**
@ -89,515 +99,8 @@ class PaymentRestEndpoint extends RestEndpoint {
*
* @return array[]
*/
protected function gateways():array {
return array(
// PayPal checkout.
PayPalGateway::ID => array(
'id' => PayPalGateway::ID,
'title' => __( 'PayPal', 'woocommerce-paypal-payments' ),
'description' => __(
'Our all-in-one checkout solution lets you offer PayPal, Venmo, Pay Later options, and more to help maximize conversion.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-paypal',
'itemTitle' => __( 'PayPal', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'Our all-in-one checkout solution lets you offer PayPal, Venmo, Pay Later options, and more to help maximize conversion.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( PayPalGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( PayPalGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
'paypalShowLogo' => array(
'type' => 'toggle',
'default' => $this->settings->get_paypal_show_logo(),
'label' => __( 'Show logo', 'woocommerce-paypal-payments' ),
),
),
),
'venmo' => array(
'id' => 'venmo',
'itemTitle' => __( 'Venmo', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'Offer Venmo at checkout to millions of active users.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-venmo',
'enabled' => $this->settings->get_venmo_enabled(),
),
'pay-later' => array(
'id' => 'pay-later',
'itemTitle' => __( 'Pay Later', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'Get paid in full at checkout while giving your customers the flexibility to pay in installments over time with no late fees.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-paypal',
'enabled' => $this->settings->get_paylater_enabled(),
),
CardButtonGateway::ID => array(
'id' => CardButtonGateway::ID,
'title' => __(
'Credit and debit card payments',
'woocommerce-paypal-payments'
),
'description' => __(
"Accept all major credit and debit cards - even if your customer doesn't have a PayPal account.",
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-cards',
'itemTitle' => __(
'Credit and debit card payments',
'woocommerce-paypal-payments'
),
'itemDescription' => __(
"Accept all major credit and debit cards - even if your customer doesn't have a PayPal account.",
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( CardButtonGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( CardButtonGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
// Online card Payments.
CreditCardGateway::ID => array(
'id' => CreditCardGateway::ID,
'title' => __(
'Advanced Credit and Debit Card Payments',
'woocommerce-paypal-payments'
),
'description' => __(
"Present custom credit and debit card fields to your payers so they can pay with credit and debit cards using your site's branding.",
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-advanced-cards',
'itemTitle' => __(
'Advanced Credit and Debit Card Payments',
'woocommerce-paypal-payments'
),
'itemDescription' => __(
"Present custom credit and debit card fields to your payers so they can pay with credit and debit cards using your site's branding.",
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( CreditCardGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( CreditCardGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
'threeDSecure' => array(
'type' => 'radio',
'default' => $this->settings->get_three_d_secure(),
'label' => __( '3D Secure', 'woocommerce-paypal-payments' ),
'description' => __(
'Authenticate cardholders through their card issuers to reduce fraud and improve transaction security. Successful 3D Secure authentication can shift liability for fraudulent chargebacks to the card issuer.',
'woocommerce-paypal-payments'
),
'options' => array(
array(
'label' => __(
'No 3D Secure',
'woocommerce-paypal-payments'
),
'value' => 'no-3d-secure',
),
array(
'label' => __(
'Only when required',
'woocommerce-paypal-payments'
),
'value' => 'only-required-3d-secure',
),
array(
'label' => __(
'Always require 3D Secure',
'woocommerce-paypal-payments'
),
'value' => 'always-3d-secure',
),
),
),
),
),
AxoGateway::ID => array(
'id' => AxoGateway::ID,
'title' => __( 'Fastlane by PayPal', 'woocommerce-paypal-payments' ),
'description' => __(
"Tap into the scale and trust of PayPal's customer network to recognize shoppers and make guest checkout more seamless than ever.",
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-fastlane',
'itemTitle' => __( 'Fastlane by PayPal', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
"Tap into the scale and trust of PayPal's customer network to recognize shoppers and make guest checkout more seamless than ever.",
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( AxoGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( AxoGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
'fastlaneCardholderName' => array(
'type' => 'toggle',
'default' => $this->settings->get_fastlane_cardholder_name(),
'label' => __(
'Display cardholder name',
'woocommerce-paypal-payments'
),
),
'fastlaneDisplayWatermark' => array(
'type' => 'toggle',
'default' => $this->settings->get_fastlane_display_watermark(),
'label' => __(
'Display Fastlane Watermark',
'woocommerce-paypal-payments'
),
),
),
),
ApplePayGateway::ID => array(
'id' => ApplePayGateway::ID,
'title' => __( 'Apple Pay', 'woocommerce-paypal-payments' ),
'description' => __(
'Allow customers to pay via their Apple Pay digital wallet.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-apple-pay',
'itemTitle' => __( 'Apple Pay', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'Allow customers to pay via their Apple Pay digital wallet.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( ApplePayGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( ApplePayGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
GooglePayGateway::ID => array(
'id' => GooglePayGateway::ID,
'title' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
'description' => __(
'Allow customers to pay via their Google Pay digital wallet.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-google-pay',
'itemTitle' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'Allow customers to pay via their Google Pay digital wallet.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( GooglePayGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( GooglePayGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
// Alternative payment methods.
BancontactGateway::ID => array(
'id' => BancontactGateway::ID,
'title' => __( 'Bancontact', 'woocommerce-paypal-payments' ),
'description' => __(
'Bancontact is the most widely used, accepted and trusted electronic payment method in Belgium. Bancontact makes it possible to pay directly through the online payment systems of all major Belgian banks.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-bancontact',
'itemTitle' => __( 'Bancontact', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'Bancontact is the most widely used, accepted and trusted electronic payment method in Belgium. Bancontact makes it possible to pay directly through the online payment systems of all major Belgian banks.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( BancontactGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( BancontactGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
BlikGateway::ID => array(
'id' => BlikGateway::ID,
'title' => __( 'BLIK', 'woocommerce-paypal-payments' ),
'description' => __(
'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-blik',
'itemTitle' => __( 'BLIK', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( BlikGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( BlikGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
EPSGateway::ID => array(
'id' => EPSGateway::ID,
'title' => __( 'eps', 'woocommerce-paypal-payments' ),
'description' => __(
'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-eps',
'itemTitle' => __( 'eps', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( EPSGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( EPSGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
IDealGateway::ID => array(
'id' => IDealGateway::ID,
'title' => __( 'iDEAL', 'woocommerce-paypal-payments' ),
'description' => __(
'iDEAL is a payment method in the Netherlands that allows buyers to select their issuing bank from a list of options.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-ideal',
'itemTitle' => __( 'iDEAL', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'iDEAL is a payment method in the Netherlands that allows buyers to select their issuing bank from a list of options.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( IDealGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( IDealGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
MyBankGateway::ID => array(
'id' => MyBankGateway::ID,
'title' => __( 'MyBank', 'woocommerce-paypal-payments' ),
'description' => __(
'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-mybank',
'itemTitle' => __( 'MyBank', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( MyBankGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( MyBankGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
P24Gateway::ID => array(
'id' => P24Gateway::ID,
'title' => __( 'Przelewy24', 'woocommerce-paypal-payments' ),
'description' => __(
'A popular online payment gateway in Poland, offering various payment options for Polish customers. Transactions can be processed in PLN or EUR.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-przelewy24',
'itemTitle' => __( 'Przelewy24', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'A popular online payment gateway in Poland, offering various payment options for Polish customers. Transactions can be processed in PLN or EUR.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( P24Gateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( P24Gateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
TrustlyGateway::ID => array(
'id' => TrustlyGateway::ID,
'title' => __( 'Trustly', 'woocommerce-paypal-payments' ),
'description' => __(
'A European payment method that allows buyers to make payments directly from their bank accounts, suitable for customers across multiple European countries. Supported currencies include EUR, DKK, SEK, GBP, and NOK.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-trustly',
'itemTitle' => __( 'Trustly', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'A European payment method that allows buyers to make payments directly from their bank accounts, suitable for customers across multiple European countries. Supported currencies include EUR, DKK, SEK, GBP, and NOK.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( TrustlyGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( TrustlyGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
MultibancoGateway::ID => array(
'id' => MultibancoGateway::ID,
'title' => __( 'Multibanco', 'woocommerce-paypal-payments' ),
'description' => __(
'An online payment method in Portugal, enabling Portuguese buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-multibanco',
'itemTitle' => __( 'Multibanco', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'An online payment method in Portugal, enabling Portuguese buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( MultibancoGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( MultibancoGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
PayUponInvoiceGateway::ID => array(
'id' => PayUponInvoiceGateway::ID,
'title' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'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'
),
'icon' => '',
'itemTitle' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'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'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( PayUponInvoiceGateway::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( PayUponInvoiceGateway::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
OXXO::ID => array(
'id' => OXXO::ID,
'title' => __( 'OXXO', 'woocommerce-paypal-payments' ),
'description' => __(
'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 8009250304',
'woocommerce-paypal-payments'
),
'icon' => 'payment-method-oxxo',
'itemTitle' => __( 'OXXO', 'woocommerce-paypal-payments' ),
'itemDescription' => __(
'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 8009250304',
'woocommerce-paypal-payments'
),
'fields' => array(
'checkoutPageTitle' => array(
'type' => 'text',
'default' => $this->getPaymentTitle( OXXO::ID ) ?? '',
'label' => __( 'Checkout page title', 'woocommerce-paypal-payments' ),
),
'checkoutPageDescription' => array(
'type' => 'text',
'default' => $this->getPaymentDescription( OXXO::ID ) ?? '',
'label' => __( 'Checkout page description', 'woocommerce-paypal-payments' ),
),
),
),
);
protected function gateways() : array {
return $this->methods_definition->get_definitions();
}
/**
@ -644,25 +147,25 @@ class PaymentRestEndpoint extends RestEndpoint {
* @return WP_REST_Response The current payment methods details.
*/
public function get_details() : WP_REST_Response {
$all_gateways = WC()->payment_gateways->payment_gateways();
$all_gateways = WC()->payment_gateways->payment_gateways();
$gateway_settings = array();
$all_methods = $this->gateways();
foreach ( $this->gateways() as $key => $value ) {
foreach ( $all_methods as $key => $method ) {
// Here we handle the payment methods that are listed on the page but not registered as WooCommerce Payment gateways.
if ( ! isset( $all_gateways[ $key ] ) ) {
$gateway_settings[ $key ] = array(
'id' => $this->gateways()[ $key ]['id'] ?? '',
'title' => $this->gateways()[ $key ]['title'] ?? '',
'description' => $this->gateways()[ $key ]['description'] ?? '',
'enabled' => $this->gateways()[ $key ]['enabled'] ?? false,
'icon' => $this->gateways()[ $key ]['icon'] ?? '',
'itemTitle' => $this->gateways()[ $key ]['itemTitle'] ?? '',
'itemDescription' => $this->gateways()[ $key ]['itemDescription'] ?? '',
'id' => $method['id'] ?? '',
'title' => $method['title'] ?? '',
'description' => $method['description'] ?? '',
'enabled' => $method['enabled'] ?? false,
'icon' => $method['icon'] ?? '',
'itemTitle' => $method['itemTitle'] ?? '',
'itemDescription' => $method['itemDescription'] ?? '',
);
if ( isset( $this->gateways()[ $key ]['fields'] ) ) {
$gateway_settings[ $key ]['fields'] = $this->gateways()[ $key ]['fields'];
if ( isset( $method['fields'] ) ) {
$gateway_settings[ $key ]['fields'] = $method['fields'];
}
continue;
@ -674,14 +177,14 @@ class PaymentRestEndpoint extends RestEndpoint {
'enabled' => 'yes' === $gateway->enabled,
'title' => str_replace( '&', '&', $gateway->get_title() ),
'description' => $gateway->get_description(),
'id' => $this->gateways()[ $key ]['id'] ?? $key,
'icon' => $this->gateways()[ $key ]['icon'] ?? '',
'itemTitle' => $this->gateways()[ $key ]['itemTitle'] ?? '',
'itemDescription' => $this->gateways()[ $key ]['itemDescription'] ?? '',
'id' => $method['id'] ?? $key,
'icon' => $method['icon'] ?? '',
'itemTitle' => $method['itemTitle'] ?? '',
'itemDescription' => $method['itemDescription'] ?? '',
);
if ( isset( $this->gateways()[ $key ]['fields'] ) ) {
$gateway_settings[ $key ]['fields'] = $this->gateways()[ $key ]['fields'];
if ( isset( $method['fields'] ) ) {
$gateway_settings[ $key ]['fields'] = $method['fields'];
}
}
@ -702,10 +205,10 @@ class PaymentRestEndpoint extends RestEndpoint {
*/
public function update_details( WP_REST_Request $request ) : WP_REST_Response {
$all_gateways = WC()->payment_gateways->payment_gateways();
$request_data = $request->get_params();
$all_methods = $this->gateways();
foreach ( $this->gateways() as $key => $value ) {
foreach ( $all_methods as $key => $value ) {
// Here we handle the payment methods that are listed on the page but not registered as WooCommerce Payment gateways.
if ( ! isset( $all_gateways[ $key ] ) && isset( $request_data[ $key ] ) ) {
switch ( $key ) {
@ -759,32 +262,4 @@ class PaymentRestEndpoint extends RestEndpoint {
return $this->get_details();
}
/**
* Returns title for the given gateway.
*
* @param string $id Gateway ID.
* @return string
*/
private function getPaymentTitle( string $id ): string {
if ( ! isset( WC()->payment_gateways()->payment_gateways()[ $id ] ) ) {
return '';
}
return WC()->payment_gateways()->payment_gateways()[ $id ]->get_title() ?? '';
}
/**
* Returns title for the given gateway.
*
* @param string $id Gateway ID.
* @return string
*/
private function getPaymentDescription( string $id ): string {
if ( ! isset( WC()->payment_gateways()->payment_gateways()[ $id ] ) ) {
return '';
}
return WC()->payment_gateways()->payment_gateways()[ $id ]->get_description() ?? '';
}
}