mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Merge pull request #3515 from woocommerce/PCP-4982-pay-pal-subscription-error-on-console-when-trying-pay-from-classic-cart
Broken PayPal Subscriptions payment in blocks and classic cart (4982, 4943, 4981)
This commit is contained in:
commit
80d7da4df3
4 changed files with 15 additions and 14 deletions
|
@ -81,14 +81,14 @@ export const paypalShippingToWc = ( shipping ) => {
|
|||
export const paypalPayerToWc = ( payer ) => {
|
||||
const firstName = payer?.name?.given_name ?? '';
|
||||
const lastName = payer?.name?.surname ?? '';
|
||||
const phone = payer?.phone?.phone_number?.national_number ?? '';
|
||||
const phone = payer?.phone?.phone_number?.national_number ?? '';
|
||||
const address = payer.address ? paypalAddressToWc( payer.address ) : {};
|
||||
return {
|
||||
...address,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
email: payer.email_address,
|
||||
phone: phone
|
||||
phone,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -115,7 +115,7 @@ export const paypalSubscriberToWc = ( subscriber ) => {
|
|||
* @return {Object}
|
||||
*/
|
||||
export const paypalOrderToWcShippingAddress = ( order ) => {
|
||||
const shipping = order.purchase_units[ 0 ].shipping;
|
||||
const shipping = order.purchase_units?.[ 0 ]?.shipping;
|
||||
if ( ! shipping ) {
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -8,14 +8,14 @@ class CartActionHandler {
|
|||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
subscriptionsConfiguration( subscription_plan_id ) {
|
||||
subscriptionsConfiguration( subscriptionPlanId ) {
|
||||
return {
|
||||
createSubscription: ( data, actions ) => {
|
||||
return actions.subscription.create( {
|
||||
plan_id: subscription_plan_id,
|
||||
plan_id: subscriptionPlanId,
|
||||
} );
|
||||
},
|
||||
onApprove: ( data, actions ) => {
|
||||
onApprove: ( data ) => {
|
||||
fetch( this.config.ajax.approve_subscription.endpoint, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
|
@ -24,7 +24,7 @@ class CartActionHandler {
|
|||
order_id: data.orderID,
|
||||
subscription_id: data.subscriptionID,
|
||||
should_create_wc_order:
|
||||
! context.config.vaultingEnabled ||
|
||||
! this.config.vaultingEnabled ||
|
||||
data.paymentSource !== 'venmo',
|
||||
} ),
|
||||
} )
|
||||
|
@ -33,7 +33,6 @@ class CartActionHandler {
|
|||
} )
|
||||
.then( ( data ) => {
|
||||
if ( ! data.success ) {
|
||||
console.log( data );
|
||||
throw Error( data.data.message );
|
||||
}
|
||||
|
||||
|
@ -41,7 +40,7 @@ class CartActionHandler {
|
|||
|
||||
location.href = orderReceivedUrl
|
||||
? orderReceivedUrl
|
||||
: context.config.redirect;
|
||||
: this.config.redirect;
|
||||
} );
|
||||
},
|
||||
onError: ( err ) => {
|
||||
|
@ -51,7 +50,7 @@ class CartActionHandler {
|
|||
}
|
||||
|
||||
configuration() {
|
||||
const createOrder = ( data, actions ) => {
|
||||
const createOrder = () => {
|
||||
const payer = payerData();
|
||||
const bnCode =
|
||||
typeof this.config.bn_codes[ this.config.context ] !==
|
||||
|
@ -89,7 +88,7 @@ class CartActionHandler {
|
|||
return {
|
||||
createOrder,
|
||||
onApprove: onApprove( this, this.errorHandler ),
|
||||
onError: ( error ) => {
|
||||
onError: () => {
|
||||
this.errorHandler.genericError();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -89,8 +89,9 @@ class WooCommerceOrderCreator {
|
|||
}
|
||||
|
||||
try {
|
||||
$payer = $order->payer();
|
||||
$shipping = $order->purchase_units()[0]->shipping();
|
||||
$payer = $order->payer();
|
||||
$purchase_units = $order->purchase_units();
|
||||
$shipping = ! empty( $purchase_units ) ? $purchase_units[0]->shipping() : null;
|
||||
|
||||
$this->configure_payment_source( $wc_order );
|
||||
$this->configure_customer( $wc_order );
|
||||
|
|
|
@ -501,9 +501,10 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
|
|||
if ( ! is_string( $hook ) || wcs_is_manual_renewal_enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
$subscription_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : '';
|
||||
if ( $hook !== 'post.php' && $hook !== 'post-new.php' && $subscription_mode !== 'subscriptions_api' ) {
|
||||
if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ), true ) || $subscription_mode !== 'subscriptions_api' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue