mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge branch 'trunk' into PCP-2186-apple-pay-button-preview
This commit is contained in:
commit
06087f7e67
22 changed files with 391 additions and 103 deletions
|
@ -26,7 +26,7 @@ class ApplepayButton {
|
|||
|
||||
this.updated_contact_info = []
|
||||
this.selectedShippingMethod = []
|
||||
this.nonce = document.getElementById('woocommerce-process-checkout-nonce')?.value
|
||||
this.nonce = document.getElementById('woocommerce-process-checkout-nonce')?.value || buttonConfig.nonce
|
||||
|
||||
this.log = function() {
|
||||
if ( this.buttonConfig.is_debug ) {
|
||||
|
@ -243,6 +243,11 @@ class ApplepayButton {
|
|||
requiredShippingContactFields: ["postalAddress", "email", "phone"],
|
||||
requiredBillingContactFields: ["postalAddress", "email", "phone"],
|
||||
}
|
||||
|
||||
if (!this.contextHandler.shippingAllowed()) {
|
||||
baseRequest.requiredShippingContactFields = [];
|
||||
}
|
||||
|
||||
const paymentDataRequest = Object.assign({}, baseRequest);
|
||||
paymentDataRequest.currencyCode = buttonConfig.shop.currencyCode;
|
||||
paymentDataRequest.total = {
|
||||
|
@ -512,18 +517,53 @@ class ApplepayButton {
|
|||
if (confirmOrderResponse && confirmOrderResponse.approveApplePayPayment) {
|
||||
if (confirmOrderResponse.approveApplePayPayment.status === "APPROVED") {
|
||||
try {
|
||||
let data = {
|
||||
billing_contact: event.payment.billingContact,
|
||||
shipping_contact: event.payment.shippingContact,
|
||||
paypal_order_id: id,
|
||||
};
|
||||
let authorizationResult = await processInWooAndCapture(data);
|
||||
if (authorizationResult.result === "success") {
|
||||
session.completePayment(ApplePaySession.STATUS_SUCCESS)
|
||||
window.location.href = authorizationResult.redirect
|
||||
|
||||
if (!this.contextHandler.shippingAllowed()) {
|
||||
// No shipping, expect immediate capture, ex: PayNow.
|
||||
|
||||
let approveFailed = false;
|
||||
await this.contextHandler.approveOrder({
|
||||
orderID: id
|
||||
}, { // actions mock object.
|
||||
restart: () => new Promise((resolve, reject) => {
|
||||
approveFailed = true;
|
||||
resolve();
|
||||
}),
|
||||
order: {
|
||||
get: () => new Promise((resolve, reject) => {
|
||||
resolve(null);
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
if (!approveFailed) {
|
||||
this.log('onpaymentauthorized approveOrder OK');
|
||||
session.completePayment(ApplePaySession.STATUS_SUCCESS);
|
||||
} else {
|
||||
this.log('onpaymentauthorized approveOrder FAIL');
|
||||
session.completePayment(ApplePaySession.STATUS_FAILURE);
|
||||
session.abort()
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
} else {
|
||||
session.completePayment(ApplePaySession.STATUS_FAILURE)
|
||||
// Default payment.
|
||||
|
||||
let data = {
|
||||
billing_contact: event.payment.billingContact,
|
||||
shipping_contact: event.payment.shippingContact,
|
||||
paypal_order_id: id,
|
||||
};
|
||||
let authorizationResult = await processInWooAndCapture(data);
|
||||
if (authorizationResult.result === "success") {
|
||||
session.completePayment(ApplePaySession.STATUS_SUCCESS)
|
||||
window.location.href = authorizationResult.redirect
|
||||
} else {
|
||||
session.completePayment(ApplePaySession.STATUS_FAILURE)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
session.completePayment(ApplePaySession.STATUS_FAILURE);
|
||||
session.abort()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue