mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Refactor options for release preparation
This commit is contained in:
parent
46f579c42f
commit
7d1f8b5187
14 changed files with 288 additions and 61 deletions
|
@ -13,10 +13,20 @@ use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
||||
return array(
|
||||
'wcgateway.settings.fields' => function ( ContainerInterface $container, array $fields ): array {
|
||||
|
||||
// Eligibility check.
|
||||
if ( ! $container->has( 'applepay.eligible' ) || ! $container->get( 'applepay.eligible' ) ) {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
$is_available = $container->get( 'applepay.enabled' );
|
||||
$is_referral = $container->get( 'applepay.is_referral' );
|
||||
|
||||
$insert_after = function ( array $array, string $key, array $new ): array {
|
||||
$keys = array_keys( $array );
|
||||
$index = array_search( $key, $keys, true );
|
||||
|
@ -27,7 +37,25 @@ return array(
|
|||
$display_manager = $container->get( 'wcgateway.display-manager' );
|
||||
assert( $display_manager instanceof DisplayManager );
|
||||
|
||||
if ( ! $container->has( 'applepay.eligible' ) || ! $container->get( 'applepay.eligible' ) ) {
|
||||
// Connection tab fields.
|
||||
$fields = $insert_after(
|
||||
$fields,
|
||||
'ppcp_dcc_status',
|
||||
array(
|
||||
'applepay_status' => array(
|
||||
'title' => __( 'Apple Pay Payments', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $container->get( 'applepay.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' );
|
||||
$connection_link = '<a href="' . $connection_url . '" target="_blank">';
|
||||
return $insert_after(
|
||||
|
@ -35,11 +63,11 @@ return array(
|
|||
'allow_card_button_gateway',
|
||||
array(
|
||||
'applepay_button_enabled' => array(
|
||||
'title' => __( 'Apple Pay Button', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'class' => array( 'ppcp-grayed-out-text' ),
|
||||
'input_class' => array( 'ppcp-disabled-checkbox' ),
|
||||
'label' => __( 'Enable Apple Pay button', 'woocommerce-paypal-payments' )
|
||||
'title' => __( 'Apple Pay Button', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'class' => array( 'ppcp-grayed-out-text' ),
|
||||
'input_class' => array( 'ppcp-disabled-checkbox' ),
|
||||
'label' => __( 'Enable Apple Pay button', 'woocommerce-paypal-payments' )
|
||||
. '<p class="description">'
|
||||
. sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
|
||||
|
@ -48,10 +76,21 @@ return array(
|
|||
'</a>'
|
||||
)
|
||||
. '</p>',
|
||||
'default' => 'yes',
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'paypal',
|
||||
'requirements' => array(),
|
||||
'default' => 'yes',
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'paypal',
|
||||
'requirements' => array(),
|
||||
'custom_attributes' => array(
|
||||
'data-ppcp-display' => wp_json_encode(
|
||||
array(
|
||||
$display_manager
|
||||
->rule()
|
||||
->condition_is_true( false )
|
||||
->action_enable( 'applepay_button_enabled' )
|
||||
->to_array(),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
|
|
@ -31,10 +31,16 @@ class ApplepayButton {
|
|||
this.updated_contact_info = []
|
||||
this.selectedShippingMethod = []
|
||||
this.nonce = document.getElementById('woocommerce-process-checkout-nonce').value
|
||||
|
||||
this.log = (message) => {
|
||||
if ( this.buttonConfig.is_debug ) {
|
||||
console.log('[ApplePayButton] ' + message, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(config) {
|
||||
console.log('[ApplePayButton] init', config);
|
||||
this.log('init', config);
|
||||
if (this.isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
@ -53,12 +59,12 @@ class ApplepayButton {
|
|||
const id = "#apple-" + this.buttonConfig.button.wrapper;
|
||||
|
||||
if (this.context === 'mini-cart') {
|
||||
document.querySelector(id_minicart).addEventListener('click', (evt) => {
|
||||
document.querySelector(id_minicart)?.addEventListener('click', (evt) => {
|
||||
evt.preventDefault();
|
||||
this.onButtonClick();
|
||||
});
|
||||
} else {
|
||||
document.querySelector(id).addEventListener('click', (evt) => {
|
||||
document.querySelector(id)?.addEventListener('click', (evt) => {
|
||||
evt.preventDefault();
|
||||
this.onButtonClick();
|
||||
});
|
||||
|
@ -150,7 +156,10 @@ class ApplepayButton {
|
|||
const language = this.buttonConfig.button.lang;
|
||||
const color = this.buttonConfig.button.color;
|
||||
const id = "apple-" + wrapper;
|
||||
appleContainer.innerHTML = `<apple-pay-button id="${id}" buttonstyle="${color}" type="${type}" locale="${language}">`;
|
||||
|
||||
if (appleContainer) {
|
||||
appleContainer.innerHTML = `<apple-pay-button id="${id}" buttonstyle="${color}" type="${type}" locale="${language}">`;
|
||||
}
|
||||
|
||||
jQuery('#' + wrapper).addClass('ppcp-button-' + shape);
|
||||
jQuery(wrapper).append(appleContainer);
|
||||
|
@ -180,7 +189,7 @@ class ApplepayButton {
|
|||
console.error(error);
|
||||
}
|
||||
const session = this.applePaySession(paymentDataRequest)
|
||||
console.log("session", session)
|
||||
this.log("session", session)
|
||||
const formValidator = PayPalCommerceGateway.early_checkout_validation_enabled ?
|
||||
new FormValidator(
|
||||
PayPalCommerceGateway.ajax.validate_checkout.endpoint,
|
||||
|
@ -242,7 +251,7 @@ class ApplepayButton {
|
|||
//------------------------
|
||||
|
||||
onvalidatemerchant(session) {
|
||||
console.log("onvalidatemerchant")
|
||||
this.log("onvalidatemerchant")
|
||||
return (applePayValidateMerchantEvent) => {
|
||||
paypal.Applepay().validateMerchant({
|
||||
validationUrl: applePayValidateMerchantEvent.validationURL
|
||||
|
@ -259,7 +268,7 @@ class ApplepayButton {
|
|||
'woocommerce-process-checkout-nonce': this.nonce,
|
||||
}
|
||||
})
|
||||
console.log('validated')
|
||||
this.log('validated')
|
||||
})
|
||||
.catch(validateError => {
|
||||
console.error(validateError);
|
||||
|
@ -279,7 +288,7 @@ class ApplepayButton {
|
|||
}
|
||||
onshippingmethodselected(session) {
|
||||
const ajax_url = this.buttonConfig.ajax_url
|
||||
console.log('[ApplePayButton] onshippingmethodselected');
|
||||
this.log('onshippingmethodselected');
|
||||
return (event) => {
|
||||
const data = this.getShippingMethodData(event);
|
||||
jQuery.ajax({
|
||||
|
@ -291,7 +300,7 @@ class ApplepayButton {
|
|||
if (applePayShippingMethodUpdate.success === false) {
|
||||
response.errors = createAppleErrors(response.errors)
|
||||
}
|
||||
console.log('shipping method update response', response, applePayShippingMethodUpdate)
|
||||
this.log('shipping method update response', response, applePayShippingMethodUpdate)
|
||||
this.selectedShippingMethod = event.shippingMethod
|
||||
//order the response shipping methods, so that the selected shipping method is the first one
|
||||
let orderedShippingMethods = response.newShippingMethods.sort((a, b) => {
|
||||
|
@ -316,10 +325,10 @@ class ApplepayButton {
|
|||
}
|
||||
onshippingcontactselected(session) {
|
||||
const ajax_url = this.buttonConfig.ajax_url
|
||||
console.log('[ApplePayButton] onshippingcontactselected', ajax_url, session)
|
||||
this.log('[ApplePayButton] onshippingcontactselected', ajax_url, session)
|
||||
return (event) => {
|
||||
const data = this.getShippingContactData(event);
|
||||
console.log('shipping contact selected', data, event)
|
||||
this.log('shipping contact selected', data, event)
|
||||
jQuery.ajax({
|
||||
url: ajax_url,
|
||||
method: 'POST',
|
||||
|
@ -327,7 +336,7 @@ class ApplepayButton {
|
|||
success: (applePayShippingContactUpdate, textStatus, jqXHR) => {
|
||||
let response = applePayShippingContactUpdate.data
|
||||
this.updated_contact_info = event.shippingContact
|
||||
console.log('shipping contact update response', response, applePayShippingContactUpdate, this.updated_contact_info)
|
||||
this.log('shipping contact update response', response, applePayShippingContactUpdate, this.updated_contact_info)
|
||||
if (applePayShippingContactUpdate.success === false) {
|
||||
response.errors = createAppleErrors(response.errors)
|
||||
}
|
||||
|
@ -421,7 +430,7 @@ class ApplepayButton {
|
|||
let createOrderInPayPal = actionHandler.createOrder()
|
||||
const processInWooAndCapture = async (data) => {
|
||||
try {
|
||||
console.log('processInWooAndCapture', data)
|
||||
this.log('processInWooAndCapture', data)
|
||||
const billingContact = data.billing_contact
|
||||
const shippingContact = data.shipping_contact
|
||||
jQuery.ajax({
|
||||
|
@ -443,7 +452,7 @@ class ApplepayButton {
|
|||
complete: (jqXHR, textStatus) => {
|
||||
},
|
||||
success: (authorizationResult, textStatus, jqXHR) => {
|
||||
console.log('success authorizationResult', authorizationResult)
|
||||
this.log('success authorizationResult', authorizationResult)
|
||||
if (authorizationResult.result === "success") {
|
||||
redirectionUrl = authorizationResult.redirect;
|
||||
//session.completePayment(ApplePaySession.STATUS_SUCCESS)
|
||||
|
@ -453,18 +462,18 @@ class ApplepayButton {
|
|||
}
|
||||
},
|
||||
error: (jqXHR, textStatus, errorThrown) => {
|
||||
console.log('error authorizationResult', errorThrown)
|
||||
this.log('error authorizationResult', errorThrown)
|
||||
session.completePayment(ApplePaySession.STATUS_FAILURE)
|
||||
console.warn(textStatus, errorThrown)
|
||||
session.abort()
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error) // handle error
|
||||
this.log(error) // handle error
|
||||
}
|
||||
}
|
||||
createOrderInPayPal([], []).then((orderId) => {
|
||||
console.log('createOrderInPayPal', orderId)
|
||||
this.log('createOrderInPayPal', orderId)
|
||||
paypal.Applepay().confirmOrder(
|
||||
{
|
||||
orderId: orderId,
|
||||
|
@ -488,31 +497,31 @@ class ApplepayButton {
|
|||
}
|
||||
);
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
console.error(error)
|
||||
session.abort()
|
||||
})
|
||||
};*/
|
||||
}
|
||||
/* onPaymentAuthorized(paymentData) {
|
||||
console.log('[ApplePayButton] onPaymentAuthorized', this.context);
|
||||
this.log('[ApplePayButton] onPaymentAuthorized', this.context);
|
||||
return this.processPayment(paymentData);
|
||||
}
|
||||
|
||||
async processPayment(paymentData) {
|
||||
console.log('[ApplePayButton] processPayment', this.context);
|
||||
this.log('[ApplePayButton] processPayment', this.context);
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let id = await this.contextHandler.createOrder();
|
||||
|
||||
console.log('[ApplePayButton] processPayment: createOrder', id, this.context);
|
||||
this.log('[ApplePayButton] processPayment: createOrder', id, this.context);
|
||||
|
||||
const confirmOrderResponse = await paypal.Applepay().confirmOrder({
|
||||
orderId: id,
|
||||
paymentMethodData: paymentData.paymentMethodData
|
||||
});
|
||||
|
||||
console.log('[ApplePayButton] processPayment: confirmOrder', confirmOrderResponse, this.context);
|
||||
this.log('[ApplePayButton] processPayment: confirmOrder', confirmOrderResponse, this.context);
|
||||
|
||||
/!** Capture the Order on the Server *!/
|
||||
if (confirmOrderResponse.status === "APPROVED") {
|
||||
|
@ -554,7 +563,7 @@ class ApplepayButton {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('[ApplePayButton] processPaymentResponse', response, this.context);
|
||||
this.log('processPaymentResponse', response, this.context);
|
||||
|
||||
return response;
|
||||
}*/
|
||||
|
|
|
@ -8,7 +8,7 @@ class ApplepayManager {
|
|||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.ApplePayConfig = null;
|
||||
console.log('Applepay manager', ppcpConfig, buttonConfig)
|
||||
//console.log('Applepay manager', ppcpConfig, buttonConfig)
|
||||
this.buttons = [];
|
||||
|
||||
buttonModuleWatcher.watchContextBootstrap((bootstrap) => {
|
||||
|
|
|
@ -14,13 +14,13 @@ if (typeof window.PayPalCommerceGateway === 'undefined') {
|
|||
window.PayPalCommerceGateway = ppcpConfig;
|
||||
}
|
||||
|
||||
console.log('ppcpData', ppcpData);
|
||||
console.log('ppcpConfig', ppcpConfig);
|
||||
console.log('buttonData', buttonData);
|
||||
console.log('buttonConfig', buttonConfig);
|
||||
//console.log('ppcpData', ppcpData);
|
||||
//console.log('ppcpConfig', ppcpConfig);
|
||||
//console.log('buttonData', buttonData);
|
||||
//console.log('buttonConfig', buttonConfig);
|
||||
|
||||
const ApplePayComponent = () => {
|
||||
console.log('ApplePayComponent render');
|
||||
//console.log('ApplePayComponent render');
|
||||
|
||||
const [bootstrapped, setBootstrapped] = useState(false);
|
||||
const [paypalLoaded, setPaypalLoaded] = useState(false);
|
||||
|
|
|
@ -25,7 +25,7 @@ import ApplepayManager from "./ApplepayManager";
|
|||
}
|
||||
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled;
|
||||
const isButton = jQuery('#' + buttonConfig.button.wrapper).length > 0;
|
||||
console.log('isbutton' ,isButton, buttonConfig.button.wrapper)
|
||||
//console.log('isbutton' ,isButton, buttonConfig.button.wrapper)
|
||||
// If button wrapper is not present then there is no need to load the scripts.
|
||||
// minicart loads later?
|
||||
if (!isMiniCart && !isButton) {
|
||||
|
|
|
@ -16,6 +16,9 @@ use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus;
|
|||
use WooCommerce\PayPalCommerce\Applepay\Assets\DataToAppleButtonScripts;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Assets\BlocksPaymentMethod;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Helper\ApmApplies;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
@ -36,6 +39,14 @@ return array(
|
|||
'applepay.status-cache' => static function( ContainerInterface $container ): Cache {
|
||||
return new Cache( 'ppcp-paypal-apple-status-cache' );
|
||||
},
|
||||
|
||||
// We assume it's a referral if we can check product status without API request failures.
|
||||
'applepay.is_referral' => static function ( ContainerInterface $container ): bool {
|
||||
$status = $container->get( 'applepay.apple-product-status' );
|
||||
assert( $status instanceof AppleProductStatus );
|
||||
|
||||
return ! $status->has_request_failure();
|
||||
},
|
||||
'applepay.apple-product-status' => static function( ContainerInterface $container ): AppleProductStatus {
|
||||
return new AppleProductStatus(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
|
@ -117,4 +128,52 @@ return array(
|
|||
)
|
||||
);
|
||||
},
|
||||
|
||||
'applepay.enable-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/add-product?product=payment_methods&capabilities=APPLE_PAY';
|
||||
},
|
||||
|
||||
'applepay.enable-url-live' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.paypal.com/bizsignup/add-product?product=payment_methods&capabilities=APPLE_PAY';
|
||||
},
|
||||
|
||||
'applepay.settings.connection.status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$product_status = $container->get( 'applepay.apple-product-status' );
|
||||
assert( $product_status instanceof AppleProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$enabled = $product_status->apple_is_active();
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Available', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$button_text = $enabled
|
||||
? esc_html__( 'Settings', 'woocommerce-paypal-payments' )
|
||||
: esc_html__( 'Enable Apple Pay', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enable_url = $environment->current_environment_is( Environment::PRODUCTION )
|
||||
? $container->get( 'applepay.enable-url-live' )
|
||||
: $container->get( 'applepay.enable-url-sandbox' );
|
||||
|
||||
$button_url = $enabled
|
||||
? admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway#field-alternative_payment_methods' )
|
||||
: $enable_url;
|
||||
|
||||
return sprintf(
|
||||
'<p>%1$s %2$s</p><p><a target="%3$s" href="%4$s" class="button">%5$s</a></p>',
|
||||
$enabled ? $enabled_status_text : $disabled_status_text,
|
||||
$enabled ? '<span class="dashicons dashicons-yes"></span>' : '<span class="dashicons dashicons-no"></span>',
|
||||
$enabled ? '_self' : '_blank',
|
||||
esc_url( $button_url ),
|
||||
esc_html( $button_text )
|
||||
);
|
||||
},
|
||||
|
||||
);
|
||||
|
|
|
@ -207,6 +207,10 @@ class ApplePayButton implements ButtonInterface {
|
|||
* @return string
|
||||
*/
|
||||
public function add_apple_onboarding_option( $options ): string {
|
||||
if ( ! apply_filters( 'woocommerce_paypal_payments_apple_pay_onboarding_option', false ) ) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
$checked = '';
|
||||
try {
|
||||
$onboard_with_apple = $this->settings->get( 'ppcp-onboarding-apple' );
|
||||
|
|
|
@ -127,6 +127,7 @@ class DataToAppleButtonScripts {
|
|||
|
||||
return array(
|
||||
'sdk_url' => $this->sdk_url,
|
||||
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
|
||||
'button' => array(
|
||||
'wrapper' => 'applepay-container',
|
||||
'mini_cart_wrapper' => 'applepay-container-minicart',
|
||||
|
@ -180,6 +181,7 @@ class DataToAppleButtonScripts {
|
|||
|
||||
return array(
|
||||
'sdk_url' => $this->sdk_url,
|
||||
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
|
||||
'button' => array(
|
||||
'wrapper' => 'applepay-container',
|
||||
'mini_cart_wrapper' => 'applepay-container-minicart',
|
||||
|
|
|
@ -13,6 +13,7 @@ use WooCommerce\PayPalCommerce\Googlepay\Helper\PropertiesDictionary;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
|
||||
return array(
|
||||
|
@ -38,6 +39,66 @@ return array(
|
|||
$display_manager = $container->get( 'wcgateway.display-manager' );
|
||||
assert( $display_manager instanceof DisplayManager );
|
||||
|
||||
// Connection tab fields.
|
||||
$fields = $insert_after(
|
||||
$fields,
|
||||
'ppcp_dcc_status',
|
||||
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' );
|
||||
$connection_link = '<a href="' . $connection_url . '" target="_blank">';
|
||||
return $insert_after(
|
||||
$fields,
|
||||
'allow_card_button_gateway',
|
||||
array(
|
||||
'googlepay_button_enabled' => array(
|
||||
'title' => __( 'Google Pay Button', 'woocommerce-paypal-payments' ),
|
||||
'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 ),
|
||||
'gateway' => 'paypal',
|
||||
'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(),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Standard Payments tab fields.
|
||||
return $insert_after(
|
||||
$fields,
|
||||
'allow_card_button_gateway',
|
||||
|
@ -69,15 +130,6 @@ return array(
|
|||
->action_visible( 'googlepay_button_language' )
|
||||
->action_visible( 'googlepay_button_shipping_enabled' )
|
||||
->to_array(),
|
||||
$display_manager
|
||||
->rule()
|
||||
->condition_is_true( $is_available || ! $is_referral )
|
||||
->action_enable( 'googlepay_button_enabled' )
|
||||
->action_enable( 'googlepay_button_type' )
|
||||
->action_enable( 'googlepay_button_color' )
|
||||
->action_enable( 'googlepay_button_language' )
|
||||
->action_enable( 'googlepay_button_shipping_enabled' )
|
||||
->to_array(),
|
||||
)
|
||||
),
|
||||
),
|
||||
|
|
|
@ -23,7 +23,11 @@ class GooglepayButton {
|
|||
this.externalHandler
|
||||
);
|
||||
|
||||
console.log('[GooglePayButton] new Button', this);
|
||||
this.log = (message) => {
|
||||
if ( this.buttonConfig.is_debug ) {
|
||||
console.log('[GooglePayButton] ' + message, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(config) {
|
||||
|
@ -144,7 +148,7 @@ class GooglepayButton {
|
|||
* Add a Google Pay purchase button
|
||||
*/
|
||||
addButton(baseCardPaymentMethod) {
|
||||
console.log('[GooglePayButton] addButton', this.context);
|
||||
this.log('addButton', this.context);
|
||||
|
||||
const { wrapper, ppcpStyle, buttonStyle } = this.contextConfig();
|
||||
|
||||
|
@ -171,10 +175,10 @@ class GooglepayButton {
|
|||
* Show Google Pay payment sheet when Google Pay payment button is clicked
|
||||
*/
|
||||
async onButtonClick() {
|
||||
console.log('[GooglePayButton] onButtonClick', this.context);
|
||||
this.log('onButtonClick', this.context);
|
||||
|
||||
const paymentDataRequest = await this.paymentDataRequest();
|
||||
console.log('[GooglePayButton] onButtonClick: paymentDataRequest', paymentDataRequest, this.context);
|
||||
this.log('onButtonClick: paymentDataRequest', paymentDataRequest, this.context);
|
||||
|
||||
window.ppcpFundingSource = 'googlepay'; // Do this on another place like on create order endpoint handler.
|
||||
|
||||
|
@ -217,8 +221,8 @@ class GooglepayButton {
|
|||
}
|
||||
|
||||
onPaymentDataChanged(paymentData) {
|
||||
console.log('[GooglePayButton] onPaymentDataChanged', this.context);
|
||||
console.log('[GooglePayButton] paymentData', paymentData);
|
||||
this.log('onPaymentDataChanged', this.context);
|
||||
this.log('paymentData', paymentData);
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let paymentDataRequestUpdate = {};
|
||||
|
@ -274,25 +278,25 @@ class GooglepayButton {
|
|||
//------------------------
|
||||
|
||||
onPaymentAuthorized(paymentData) {
|
||||
console.log('[GooglePayButton] onPaymentAuthorized', this.context);
|
||||
this.log('onPaymentAuthorized', this.context);
|
||||
return this.processPayment(paymentData);
|
||||
}
|
||||
|
||||
async processPayment(paymentData) {
|
||||
console.log('[GooglePayButton] processPayment', this.context);
|
||||
this.log('processPayment', this.context);
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let id = await this.contextHandler.createOrder();
|
||||
|
||||
console.log('[GooglePayButton] processPayment: createOrder', id, this.context);
|
||||
this.log('processPayment: createOrder', id, this.context);
|
||||
|
||||
const confirmOrderResponse = await widgetBuilder.paypal.Googlepay().confirmOrder({
|
||||
orderId: id,
|
||||
paymentMethodData: paymentData.paymentMethodData
|
||||
});
|
||||
|
||||
console.log('[GooglePayButton] processPayment: confirmOrder', confirmOrderResponse, this.context);
|
||||
this.log('processPayment: confirmOrder', confirmOrderResponse, this.context);
|
||||
|
||||
/** Capture the Order on the Server */
|
||||
if (confirmOrderResponse.status === "APPROVED") {
|
||||
|
@ -339,7 +343,7 @@ class GooglepayButton {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('[GooglePayButton] processPaymentResponse', response, this.context);
|
||||
this.log('processPaymentResponse', response, this.context);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -77,6 +77,10 @@ import widgetBuilder from "../../../ppcp-button/resources/js/modules/Renderer/Wi
|
|||
}
|
||||
|
||||
const bootstrap = async function () {
|
||||
if (!widgetBuilder.paypal) {
|
||||
return;
|
||||
}
|
||||
|
||||
googlePayConfig = await widgetBuilder.paypal.Googlepay().config();
|
||||
|
||||
let options;
|
||||
|
|
|
@ -18,6 +18,8 @@ use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
|
|||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmApplies;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
|
@ -182,4 +184,51 @@ return array(
|
|||
);
|
||||
},
|
||||
|
||||
'googlepay.enable-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/add-product?product=payment_methods&capabilities=GOOGLE_PAY';
|
||||
},
|
||||
|
||||
'googlepay.enable-url-live' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.paypal.com/bizsignup/add-product?product=payment_methods&capabilities=GOOGLE_PAY';
|
||||
},
|
||||
|
||||
'googlepay.settings.connection.status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$product_status = $container->get( 'googlepay.helpers.apm-product-status' );
|
||||
assert( $product_status instanceof ApmProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$enabled = $product_status->is_active();
|
||||
|
||||
$enabled_status_text = esc_html__( 'Status: Available', 'woocommerce-paypal-payments' );
|
||||
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
|
||||
|
||||
$button_text = $enabled
|
||||
? esc_html__( 'Settings', 'woocommerce-paypal-payments' )
|
||||
: esc_html__( 'Enable Google Pay', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enable_url = $environment->current_environment_is( Environment::PRODUCTION )
|
||||
? $container->get( 'googlepay.enable-url-live' )
|
||||
: $container->get( 'googlepay.enable-url-sandbox' );
|
||||
|
||||
$button_url = $enabled
|
||||
? admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway#field-alternative_payment_methods' )
|
||||
: $enable_url;
|
||||
|
||||
return sprintf(
|
||||
'<p>%1$s %2$s</p><p><a target="%3$s" href="%4$s" class="button">%5$s</a></p>',
|
||||
$enabled ? $enabled_status_text : $disabled_status_text,
|
||||
$enabled ? '<span class="dashicons dashicons-yes"></span>' : '<span class="dashicons dashicons-no"></span>',
|
||||
$enabled ? '_self' : '_blank',
|
||||
esc_url( $button_url ),
|
||||
esc_html( $button_text )
|
||||
);
|
||||
},
|
||||
|
||||
);
|
||||
|
|
|
@ -142,6 +142,10 @@ class Button implements ButtonInterface {
|
|||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
public function add_onboarding_options( $options ): string {
|
||||
if ( ! apply_filters( 'woocommerce_paypal_payments_google_pay_onboarding_option', false ) ) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
$checked = '';
|
||||
try {
|
||||
$onboard_with_google = $this->settings->get( 'ppcp-onboarding-google' );
|
||||
|
@ -420,6 +424,7 @@ class Button implements ButtonInterface {
|
|||
|
||||
return array(
|
||||
'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION',
|
||||
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
|
||||
'sdk_url' => $this->sdk_url,
|
||||
'button' => array(
|
||||
'wrapper' => '#ppc-button-googlepay-container',
|
||||
|
|
|
@ -456,7 +456,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'description' => __( 'If you use your PayPal account with more than one installation, please use a distinct prefix to separate those installations. Please use only English letters and "-", "_" characters.', 'woocommerce-paypal-payments' ),
|
||||
'maxlength' => 15,
|
||||
'custom_attributes' => array(
|
||||
'pattern' => '[a-zA-Z_-]+',
|
||||
'pattern' => '[a-zA-Z_\\-]+',
|
||||
),
|
||||
'default' => ( static function (): string {
|
||||
$site_url = get_site_url( get_current_blog_id() );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue