mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'trunk' into PCP-2172-order-failed-after-changing-shipping-options-on-apple-pay-window-product-page
This commit is contained in:
commit
32e2fb5a43
29 changed files with 1148 additions and 330 deletions
|
@ -25,7 +25,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()
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import ErrorHandler from "../../../../ppcp-button/resources/js/modules/ErrorHandler";
|
||||
import CartActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler";
|
||||
import onApprove
|
||||
from "../../../../ppcp-button/resources/js/modules/OnApproveHandler/onApproveForContinue";
|
||||
|
||||
class BaseHandler {
|
||||
|
||||
|
@ -11,6 +9,10 @@ class BaseHandler {
|
|||
this.ppcpConfig = ppcpConfig;
|
||||
}
|
||||
|
||||
shippingAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
@ -42,30 +44,25 @@ class BaseHandler {
|
|||
}
|
||||
|
||||
createOrder() {
|
||||
const errorHandler = new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
|
||||
const actionHandler = new CartActionHandler(
|
||||
this.ppcpConfig,
|
||||
errorHandler,
|
||||
);
|
||||
|
||||
return actionHandler.configuration().createOrder(null, null);
|
||||
return this.actionHandler().configuration().createOrder(null, null);
|
||||
}
|
||||
|
||||
approveOrderForContinue(data, actions) {
|
||||
const errorHandler = new ErrorHandler(
|
||||
approveOrder(data, actions) {
|
||||
return this.actionHandler().configuration().onApprove(data, actions);
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CartActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
);
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
return new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
|
||||
let onApproveHandler = onApprove({
|
||||
config: this.ppcpConfig
|
||||
}, errorHandler);
|
||||
|
||||
return onApproveHandler(data, actions);
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import CheckoutHandler from "./CheckoutHandler";
|
|||
import CartBlockHandler from "./CartBlockHandler";
|
||||
import CheckoutBlockHandler from "./CheckoutBlockHandler";
|
||||
import MiniCartHandler from "./MiniCartHandler";
|
||||
import PayNowHandler from "./PayNowHandler";
|
||||
|
||||
class ContextHandlerFactory {
|
||||
|
||||
|
@ -14,8 +15,9 @@ class ContextHandlerFactory {
|
|||
case 'cart':
|
||||
return new CartHandler(buttonConfig, ppcpConfig);
|
||||
case 'checkout':
|
||||
case 'pay-now': // same as checkout
|
||||
return new CheckoutHandler(buttonConfig, ppcpConfig);
|
||||
case 'pay-now':
|
||||
return new PayNowHandler(buttonConfig, ppcpConfig);
|
||||
case 'mini-cart':
|
||||
return new MiniCartHandler(buttonConfig, ppcpConfig);
|
||||
case 'cart-block':
|
||||
|
|
35
modules/ppcp-applepay/resources/js/Context/PayNowHandler.js
Normal file
35
modules/ppcp-applepay/resources/js/Context/PayNowHandler.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import Spinner from "../../../../ppcp-button/resources/js/modules/Helper/Spinner";
|
||||
import BaseHandler from "./BaseHandler";
|
||||
import CheckoutActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler";
|
||||
|
||||
class PayNowHandler extends BaseHandler {
|
||||
|
||||
shippingAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const data = this.ppcpConfig['pay_now'];
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PayNowHandler;
|
|
@ -130,6 +130,24 @@ return array(
|
|||
return apply_filters(
|
||||
'woocommerce_paypal_payments_applepay_supported_country_currency_matrix',
|
||||
array(
|
||||
'CA' => array(
|
||||
'AUD',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'JPY',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'USD',
|
||||
),
|
||||
'GB' => array(
|
||||
'AUD',
|
||||
'CAD',
|
||||
|
@ -148,6 +166,24 @@ return array(
|
|||
'SGD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'JPY',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'USD',
|
||||
),
|
||||
'US' => array(
|
||||
'AUD',
|
||||
'CAD',
|
||||
|
@ -156,24 +192,6 @@ return array(
|
|||
'JPY',
|
||||
'USD',
|
||||
),
|
||||
'CA' => array(
|
||||
'AUD',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'JPY',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'USD',
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -84,12 +84,14 @@ class ApplepayModule implements ModuleInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
$module->load_assets( $c, $apple_payment_method );
|
||||
$module->handle_validation_file( $c );
|
||||
$module->render_buttons( $c, $apple_payment_method );
|
||||
|
||||
$apple_payment_method->bootstrap_ajax_request();
|
||||
}
|
||||
if ( $apple_payment_method->is_enabled() ) {
|
||||
$module->load_assets( $c, $apple_payment_method );
|
||||
$module->handle_validation_file( $c, $apple_payment_method );
|
||||
$module->render_buttons( $c, $apple_payment_method );
|
||||
$apple_payment_method->bootstrap_ajax_request();
|
||||
}
|
||||
},
|
||||
1
|
||||
);
|
||||
|
||||
add_filter(
|
||||
|
@ -214,9 +216,13 @@ class ApplepayModule implements ModuleInterface {
|
|||
* Handles the validation file.
|
||||
*
|
||||
* @param ContainerInterface $c The container.
|
||||
* @param ApplePayButton $button The button.
|
||||
* @return void
|
||||
*/
|
||||
public function handle_validation_file( ContainerInterface $c ): void {
|
||||
public function handle_validation_file( ContainerInterface $c, ApplePayButton $button ): void {
|
||||
if ( ! $button->is_enabled() ) {
|
||||
return;
|
||||
}
|
||||
$env = $c->get( 'onboarding.environment' );
|
||||
assert( $env instanceof Environment );
|
||||
$is_sandobx = $env->current_environment_is( Environment::SANDBOX );
|
||||
|
|
|
@ -148,6 +148,7 @@ class DataToAppleButtonScripts {
|
|||
'totalLabel' => $total_label,
|
||||
),
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'woocommerce-process_checkout' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -195,6 +196,7 @@ class DataToAppleButtonScripts {
|
|||
'totalLabel' => $total_label,
|
||||
),
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'woocommerce-process_checkout' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue