mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
Add GooglePay shipping option
This commit is contained in:
parent
ad08480b67
commit
eeaf38e4c4
3 changed files with 26 additions and 17 deletions
|
@ -185,7 +185,7 @@ class ApplePayButton implements ButtonInterface {
|
|||
'integration_method' => 'PAYPAL',
|
||||
'integration_type' => 'THIRD_PARTY',
|
||||
'third_party_details' => array(
|
||||
'features' => array(
|
||||
'features' => array(
|
||||
'PAYMENT',
|
||||
'REFUND',
|
||||
),
|
||||
|
|
|
@ -100,13 +100,18 @@ class GooglepayButton {
|
|||
}
|
||||
|
||||
initClient() {
|
||||
const callbacks = {
|
||||
onPaymentAuthorized: this.onPaymentAuthorized.bind(this)
|
||||
}
|
||||
|
||||
if ( this.buttonConfig.enable_shipping ) {
|
||||
callbacks['onPaymentDataChanged'] = this.onPaymentDataChanged.bind(this);
|
||||
}
|
||||
|
||||
this.paymentsClient = new google.payments.api.PaymentsClient({
|
||||
environment: this.buttonConfig.environment,
|
||||
// add merchant info maybe
|
||||
paymentDataCallbacks: {
|
||||
onPaymentDataChanged: this.onPaymentDataChanged.bind(this),
|
||||
onPaymentAuthorized: this.onPaymentAuthorized.bind(this),
|
||||
}
|
||||
paymentDataCallbacks: callbacks
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -186,14 +191,15 @@ class GooglepayButton {
|
|||
paymentDataRequest.allowedPaymentMethods = googlePayConfig.allowedPaymentMethods;
|
||||
paymentDataRequest.transactionInfo = await this.contextHandler.transactionInfo();
|
||||
paymentDataRequest.merchantInfo = googlePayConfig.merchantInfo;
|
||||
//paymentDataRequest.callbackIntents = ['PAYMENT_AUTHORIZATION'];
|
||||
|
||||
paymentDataRequest.callbackIntents = ["SHIPPING_ADDRESS", "SHIPPING_OPTION", "PAYMENT_AUTHORIZATION"];
|
||||
|
||||
|
||||
paymentDataRequest.shippingAddressRequired = true;
|
||||
paymentDataRequest.shippingAddressParameters = this.getGoogleShippingAddressParameters();
|
||||
paymentDataRequest.shippingOptionRequired = true;
|
||||
if ( this.buttonConfig.enable_shipping ) {
|
||||
paymentDataRequest.callbackIntents = ["SHIPPING_ADDRESS", "SHIPPING_OPTION", "PAYMENT_AUTHORIZATION"];
|
||||
paymentDataRequest.shippingAddressRequired = true;
|
||||
paymentDataRequest.shippingAddressParameters = this.getGoogleShippingAddressParameters();
|
||||
paymentDataRequest.shippingOptionRequired = true;
|
||||
} else {
|
||||
paymentDataRequest.callbackIntents = ['PAYMENT_AUTHORIZATION'];
|
||||
}
|
||||
|
||||
return paymentDataRequest;
|
||||
}
|
||||
|
|
|
@ -198,14 +198,14 @@ class Button implements ButtonInterface {
|
|||
}
|
||||
|
||||
$data['capabilities'][] = 'GOOGLE_PAY';
|
||||
$data['operations'][] = array(
|
||||
$data['operations'][] = array(
|
||||
'operation' => 'API_INTEGRATION',
|
||||
'api_integration_preference' => array(
|
||||
'rest_api_integration' => array(
|
||||
'integration_method' => 'PAYPAL',
|
||||
'integration_type' => 'THIRD_PARTY',
|
||||
'third_party_details' => array(
|
||||
'features' => array(
|
||||
'features' => array(
|
||||
'PAYMENT',
|
||||
'REFUND',
|
||||
),
|
||||
|
@ -407,14 +407,17 @@ class Button implements ButtonInterface {
|
|||
*/
|
||||
public function script_data(): array {
|
||||
return array(
|
||||
'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION',
|
||||
'sdk_url' => $this->sdk_url,
|
||||
'button' => array(
|
||||
'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION',
|
||||
'sdk_url' => $this->sdk_url,
|
||||
'button' => array(
|
||||
'wrapper' => '#ppc-button-googlepay-container',
|
||||
'style' => $this->button_styles_for_context( 'cart' ), // For now use cart. Pass the context if necessary.
|
||||
'mini_cart_wrapper' => '#ppc-button-googlepay-container-minicart',
|
||||
'mini_cart_style' => $this->button_styles_for_context( 'mini-cart' ),
|
||||
),
|
||||
'enable_shipping' => $this->settings->has( 'googlepay_button_shipping_enabled' )
|
||||
? $this->settings->get( 'googlepay_button_shipping_enabled' )
|
||||
: false,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue