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:
Emili Castells 2025-07-10 09:58:05 +02:00 committed by GitHub
commit 80d7da4df3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 14 deletions

View file

@ -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 {};
}

View file

@ -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();
},
};

View file

@ -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 );

View file

@ -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;
}