2023-08-22 08:44:32 +01:00
< ? php
/**
* The Googlepay module extensions .
*
* @ package WooCommerce\PayPalCommerce\Googlepay
*/
declare ( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Googlepay ;
2023-09-08 18:43:33 +01:00
use WooCommerce\PayPalCommerce\Googlepay\Helper\PropertiesDictionary ;
2023-08-22 08:44:32 +01:00
use WooCommerce\PayPalCommerce\Onboarding\State ;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface ;
2023-09-15 17:32:00 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager ;
2023-10-12 15:27:55 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings ;
2023-08-22 08:44:32 +01:00
return array (
2023-08-30 11:28:18 +01:00
2023-12-19 17:26:09 +00:00
'wcgateway.settings.fields' => function ( array $fields , ContainerInterface $container ) : array {
2023-09-13 10:15:32 +01:00
2024-06-07 12:28:49 +02:00
// Used in various places to mark fields for the preview button.
$apm_name = 'GooglePay' ;
2023-09-13 10:15:32 +01:00
// Eligibility check.
if ( ! $container -> has ( 'googlepay.eligible' ) || ! $container -> get ( 'googlepay.eligible' ) ) {
return $fields ;
}
2023-09-21 18:30:43 +01:00
$is_available = $container -> get ( 'googlepay.available' );
2023-10-11 08:51:22 +01:00
$is_referral = $container -> get ( 'googlepay.is_referral' );
2023-09-21 18:30:43 +01:00
2023-08-30 11:28:18 +01:00
$insert_after = function ( array $array , string $key , array $new ) : array {
$keys = array_keys ( $array );
$index = array_search ( $key , $keys , true );
$pos = false === $index ? count ( $array ) : $index + 1 ;
return array_merge ( array_slice ( $array , 0 , $pos ), $new , array_slice ( $array , $pos ) );
};
2023-09-15 17:32:00 +01:00
$display_manager = $container -> get ( 'wcgateway.display-manager' );
assert ( $display_manager instanceof DisplayManager );
2023-09-14 17:48:46 +01:00
2024-04-10 15:51:19 +01:00
$module_url = $container -> get ( 'googlepay.url' );
2023-10-12 15:27:55 +01:00
// Connection tab fields.
$fields = $insert_after (
$fields ,
2024-01-16 14:24:34 +00:00
'ppcp_reference_transactions_status' ,
2023-10-12 15:27:55 +01:00
array (
'googlepay_status' => array (
'title' => __ ( 'Google Pay Payments' , 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text' ,
'text' => $container -> get ( 'googlepay.settings.connection.status-text' ),
'screens' => array (
State :: STATE_ONBOARDED ,
),
'requirements' => array (),
'gateway' => Settings :: CONNECTION_TAB_ID ,
),
)
);
if ( ! $is_available && $is_referral ) {
$connection_url = admin_url ( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-connection#field-credentials_feature_onboarding_heading' );
2023-10-16 17:06:55 +01:00
$connection_link = '<a href="' . $connection_url . '" style="pointer-events: auto">' ;
2023-10-12 15:27:55 +01:00
return $insert_after (
$fields ,
2024-03-01 15:05:17 +00:00
'digital_wallet_heading' ,
2023-10-12 15:27:55 +01:00
array (
'googlepay_button_enabled' => array (
'title' => __ ( 'Google Pay Button' , 'woocommerce-paypal-payments' ),
2024-04-10 15:51:19 +01:00
'title_html' => sprintf (
2024-08-13 11:41:32 +04:00
'<img src="%sassets/images/googlepay.svg" alt="%s" style="max-width: 150px; max-height: 45px;" />' ,
2024-04-10 15:51:19 +01:00
$module_url ,
__ ( 'Google Pay' , 'woocommerce-paypal-payments' )
),
2023-10-12 15:27:55 +01:00
'type' => 'checkbox' ,
'class' => array ( 'ppcp-grayed-out-text' ),
'input_class' => array ( 'ppcp-disabled-checkbox' ),
'label' => __ ( 'Enable Google Pay button' , 'woocommerce-paypal-payments' )
. '<p class="description">'
. sprintf (
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
__ ( 'Your PayPal account %1$srequires additional permissions%2$s to enable Google Pay.' , 'woocommerce-paypal-payments' ),
$connection_link ,
'</a>'
)
. '</p>' ,
'default' => 'yes' ,
'screens' => array ( State :: STATE_ONBOARDED ),
2024-03-01 15:05:17 +00:00
'gateway' => 'dcc' ,
2023-10-12 15:27:55 +01:00
'requirements' => array (),
'custom_attributes' => array (
'data-ppcp-display' => wp_json_encode (
array (
$display_manager
-> rule ()
-> condition_is_true ( false )
-> action_enable ( 'googlepay_button_enabled' )
-> to_array (),
)
),
),
2024-04-11 18:07:20 +01:00
'classes' => array ( 'ppcp-valign-label-middle' , 'ppcp-align-label-center' ),
2023-10-12 15:27:55 +01:00
),
)
);
}
// Standard Payments tab fields.
2023-08-30 11:28:18 +01:00
return $insert_after (
$fields ,
2024-03-01 15:05:17 +00:00
'digital_wallet_heading' ,
2023-08-30 11:28:18 +01:00
array (
2023-09-06 11:55:26 +01:00
'googlepay_button_enabled' => array (
2023-08-30 16:38:00 +01:00
'title' => __ ( 'Google Pay Button' , 'woocommerce-paypal-payments' ),
2024-04-10 15:51:19 +01:00
'title_html' => sprintf (
2024-08-13 11:41:32 +04:00
'<img src="%sassets/images/googlepay.svg" alt="%s" style="max-width: 150px; max-height: 45px;" />' ,
2024-04-10 15:51:19 +01:00
$module_url ,
__ ( 'Google Pay' , 'woocommerce-paypal-payments' )
),
2023-08-30 16:38:00 +01:00
'type' => 'checkbox' ,
2023-09-11 17:42:54 +01:00
'label' => __ ( 'Enable Google Pay button' , 'woocommerce-paypal-payments' )
. '<p class="description">'
. sprintf (
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
__ ( 'Buyers can use %1$sGoogle Pay%2$s to make payments on the web using a web browser.' , 'woocommerce-paypal-payments' ),
'<a href="https://woocommerce.com/document/woocommerce-paypal-payments/#google-pay" target="_blank">' ,
'</a>'
)
. '</p>' ,
2023-08-30 16:38:00 +01:00
'default' => 'yes' ,
'screens' => array ( State :: STATE_ONBOARDED ),
2024-03-01 15:05:17 +00:00
'gateway' => 'dcc' ,
2023-08-30 16:38:00 +01:00
'requirements' => array (),
'custom_attributes' => array (
2024-06-12 18:12:07 +02:00
'data-ppcp-display' => wp_json_encode (
2023-08-30 16:38:00 +01:00
array (
2023-09-15 17:32:00 +01:00
$display_manager
2023-09-14 17:48:46 +01:00
-> rule ()
2023-09-15 17:32:00 +01:00
-> condition_element ( 'googlepay_button_enabled' , '1' )
-> action_visible ( 'googlepay_button_type' )
-> action_visible ( 'googlepay_button_color' )
-> action_visible ( 'googlepay_button_language' )
-> action_visible ( 'googlepay_button_shipping_enabled' )
2024-06-07 12:28:49 +02:00
-> action_visible ( 'googlepay_button_preview' )
2024-02-16 15:04:36 +00:00
-> action_class ( 'googlepay_button_enabled' , 'active' )
2023-09-14 17:48:46 +01:00
-> to_array (),
2023-08-30 16:38:00 +01:00
)
),
2024-06-12 18:12:07 +02:00
'data-ppcp-apm-name' => $apm_name ,
'data-ppcp-field-name' => 'is_enabled' ,
2023-08-30 16:38:00 +01:00
),
2024-04-11 18:07:20 +01:00
'classes' => array ( 'ppcp-valign-label-middle' , 'ppcp-align-label-center' ),
2023-08-30 16:38:00 +01:00
),
2023-09-11 17:42:54 +01:00
'googlepay_button_type' => array (
2024-06-07 12:28:49 +02:00
'title' => __ ( 'Button Label' , 'woocommerce-paypal-payments' ),
'type' => 'select' ,
'desc_tip' => true ,
'description' => __ (
2023-09-11 17:42:54 +01:00
'This controls the label of the Google Pay button.' ,
'woocommerce-paypal-payments'
),
2024-06-07 12:28:49 +02:00
'classes' => array ( 'ppcp-field-indent' ),
'class' => array (),
'input_class' => array ( 'wc-enhanced-select' ),
2024-07-31 11:53:13 +04:00
'default' => 'plain' ,
2024-06-07 12:28:49 +02:00
'options' => PropertiesDictionary :: button_types (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'dcc' ,
'requirements' => array (),
'custom_attributes' => array (
'data-ppcp-apm-name' => $apm_name ,
'data-ppcp-field-name' => 'type' ,
),
2023-08-30 16:38:00 +01:00
),
2023-09-11 17:42:54 +01:00
'googlepay_button_color' => array (
2024-06-07 12:28:49 +02:00
'title' => __ ( 'Button Color' , 'woocommerce-paypal-payments' ),
'type' => 'select' ,
'desc_tip' => true ,
'description' => __ (
2023-09-11 17:42:54 +01:00
'Google Pay payment buttons exist in two styles: dark and light. To provide contrast, use dark buttons on light backgrounds and light buttons on dark or colorful backgrounds.' ,
'woocommerce-paypal-payments'
),
2024-06-07 12:28:49 +02:00
'label' => '' ,
'input_class' => array ( 'wc-enhanced-select' ),
'classes' => array ( 'ppcp-field-indent' ),
'class' => array (),
'default' => 'black' ,
'options' => PropertiesDictionary :: button_colors (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'dcc' ,
'requirements' => array (),
'custom_attributes' => array (
'data-ppcp-apm-name' => $apm_name ,
'data-ppcp-field-name' => 'color' ,
),
2023-08-24 17:30:29 +01:00
),
2023-09-12 18:09:58 +01:00
'googlepay_button_language' => array (
2024-06-07 12:28:49 +02:00
'title' => __ ( 'Button Language' , 'woocommerce-paypal-payments' ),
'type' => 'select' ,
'desc_tip' => true ,
'description' => __ (
2023-09-12 18:09:58 +01:00
'The language and region used for the displayed Google Pay button. The default value is the current language and region setting in a browser.' ,
'woocommerce-paypal-payments'
),
2024-06-07 12:28:49 +02:00
'classes' => array ( 'ppcp-field-indent' ),
'class' => array (),
'input_class' => array ( 'wc-enhanced-select' ),
'default' => 'en' ,
'options' => PropertiesDictionary :: button_languages (),
'screens' => array ( State :: STATE_ONBOARDED ),
'gateway' => 'dcc' ,
'requirements' => array (),
'custom_attributes' => array (
'data-ppcp-apm-name' => $apm_name ,
'data-ppcp-field-name' => 'language' ,
),
2023-09-12 18:09:58 +01:00
),
2023-09-06 11:55:26 +01:00
'googlepay_button_shipping_enabled' => array (
2023-11-08 18:07:19 +00:00
'title' => __ ( 'Shipping Callback' , 'woocommerce-paypal-payments' ),
2023-09-06 11:55:26 +01:00
'type' => 'checkbox' ,
2023-09-11 17:42:54 +01:00
'desc_tip' => true ,
'description' => __ (
'Synchronizes your available shipping options with Google Pay. Enabling this may impact the buyer experience.' ,
'woocommerce-paypal-payments'
),
2024-06-07 12:28:49 +02:00
'classes' => array ( 'ppcp-field-indent ppcp' ),
2023-09-06 11:55:26 +01:00
'label' => __ ( 'Enable Google Pay shipping callback' , 'woocommerce-paypal-payments' ),
'default' => 'no' ,
'screens' => array ( State :: STATE_ONBOARDED ),
2024-03-01 15:05:17 +00:00
'gateway' => 'dcc' ,
2023-09-06 11:55:26 +01:00
'requirements' => array (),
),
2024-06-07 12:28:49 +02:00
'googlepay_button_preview' => array (
2024-06-27 18:00:37 +02:00
'type' => 'ppcp-preview' ,
'preview' => array (
'id' => 'ppcp' . $apm_name . 'ButtonPreview' ,
'type' => 'button' ,
'message' => __ ( 'Button Styling Preview' , 'woocommerce-paypal-payments' ),
'apm' => $apm_name ,
'single' => true ,
2024-06-07 12:28:49 +02:00
),
'screens' => array (
State :: STATE_ONBOARDED ,
),
'requirements' => array (),
'gateway' => 'dcc' ,
),
2023-08-30 11:28:18 +01:00
)
2023-08-24 17:30:29 +01:00
);
},
2023-08-30 11:28:18 +01:00
2023-08-22 08:44:32 +01:00
);