Skip to content

Commit 5fbe0b8

Browse files
committed
Merge remote-tracking branch 'origin/release/8.8.0' into trunk
2 parents 5451cb5 + d609f22 commit 5fbe0b8

File tree

121 files changed

+7048
-1279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+7048
-1279
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = {
1818
node: true,
1919
},
2020
rules: {
21-
'require-await': 'error',
2221
'react-hooks/exhaustive-deps': 'error',
2322
'react-hooks/rules-of-hooks': 'error',
2423
'react/jsx-curly-brace-presence': [

.github/workflows/compatibility.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
beta-compatibility:
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99
strategy:
1010
fail-fast: false
1111
matrix:

.github/workflows/php-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
test:
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99
strategy:
1010
fail-fast: false
1111
max-parallel: 10

.jshintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"esversion": 6,
2+
"esversion": 11,
33
"boss": true,
44
"curly": true,
55
"eqeqeq": true,
@@ -13,6 +13,9 @@
1313

1414
"browser": true,
1515

16+
"mocha": true,
17+
"jasmine": true,
18+
1619
"globals": {
1720
"_": false,
1821
"Backbone": false,

assets/js/stripe-payment-request.js

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ jQuery( function( $ ) {
6969
};
7070
},
7171

72-
processSource: function( source, paymentRequestType ) {
73-
var data = wc_stripe_payment_request.getOrderData( source, paymentRequestType );
72+
processPaymentMethod: function( paymentMethod, paymentRequestType ) {
73+
var data = wc_stripe_payment_request.getOrderData( paymentMethod, paymentRequestType );
7474

7575
return $.ajax( {
7676
type: 'POST',
@@ -85,46 +85,49 @@ jQuery( function( $ ) {
8585
*
8686
* @since 3.1.0
8787
* @version 4.0.0
88-
* @param {PaymentResponse} source Payment Response instance.
88+
* @param {Object} evt The event object containing payment details and user information.
89+
* @param {string} paymentRequestType The type of payment request, either 'google_pay' or 'apple_pay'.
8990
*
90-
* @return {Object}
91+
* @return {Object} Processed order data for further handling, including shipping, billing, and payment method information.
9192
*/
9293
getOrderData: function( evt, paymentRequestType ) {
93-
var source = evt.source;
94-
var email = source.owner.email;
95-
var phone = source.owner.phone;
96-
var billing = source.owner.address;
97-
var name = source.owner.name ?? evt.payerName;
98-
var shipping = evt.shippingAddress;
99-
var data = {
100-
_wpnonce: wc_stripe_payment_request_params.nonce.checkout,
101-
billing_first_name: name?.split( ' ' )?.slice( 0, 1 )?.join( ' ' ) ?? '',
102-
billing_last_name: name?.split( ' ' )?.slice( 1 )?.join( ' ' ) || '-',
103-
billing_company: '',
104-
billing_email: null !== email ? email : evt.payerEmail,
105-
billing_phone: null !== phone ? phone : evt.payerPhone && evt.payerPhone.replace( '/[() -]/g', '' ),
106-
billing_country: null !== billing ? billing.country : '',
107-
billing_address_1: null !== billing ? billing.line1 : '',
108-
billing_address_2: null !== billing ? billing.line2 : '',
109-
billing_city: null !== billing ? billing.city : '',
110-
billing_state: null !== billing ? billing.state : '',
111-
billing_postcode: null !== billing ? billing.postal_code : '',
112-
shipping_first_name: '',
113-
shipping_last_name: '',
114-
shipping_company: '',
115-
shipping_country: '',
116-
shipping_address_1: '',
117-
shipping_address_2: '',
118-
shipping_city: '',
119-
shipping_state: '',
120-
shipping_postcode: '',
121-
shipping_method: [ null === evt.shippingOption ? null : evt.shippingOption.id ],
122-
order_comments: '',
123-
payment_method: 'stripe',
124-
ship_to_different_address: 1,
125-
terms: 1,
126-
stripe_source: source.id,
127-
payment_request_type: paymentRequestType
94+
var paymentMethod = evt.paymentMethod;
95+
var email = paymentMethod.billing_details.email;
96+
var phone = paymentMethod.billing_details.phone;
97+
var billing = paymentMethod.billing_details.address;
98+
var name = paymentMethod.billing_details.name ?? evt.payerName;
99+
var shipping = evt.shippingAddress;
100+
var data = {
101+
_wpnonce: wc_stripe_payment_request_params.nonce.checkout,
102+
billing_first_name: name?.split( ' ' )?.slice( 0, 1 )?.join( ' ' ) ?? '',
103+
billing_last_name: name?.split( ' ' )?.slice( 1 )?.join( ' ' ) || '-',
104+
billing_company: '',
105+
billing_email: null !== email ? email : evt.payerEmail,
106+
billing_phone: null !== phone ? phone : evt.payerPhone && evt.payerPhone.replace( '/[() -]/g', '' ),
107+
billing_country: null !== billing ? billing.country : '',
108+
billing_address_1: null !== billing ? billing.line1 : '',
109+
billing_address_2: null !== billing ? billing.line2 : '',
110+
billing_city: null !== billing ? billing.city : '',
111+
billing_state: null !== billing ? billing.state : '',
112+
billing_postcode: null !== billing ? billing.postal_code : '',
113+
shipping_first_name: '',
114+
shipping_last_name: '',
115+
shipping_company: '',
116+
shipping_country: '',
117+
shipping_address_1: '',
118+
shipping_address_2: '',
119+
shipping_city: '',
120+
shipping_state: '',
121+
shipping_postcode: '',
122+
shipping_method: [ null === evt.shippingOption ? null : evt.shippingOption.id ],
123+
order_comments: '',
124+
payment_method: 'stripe',
125+
ship_to_different_address: 1,
126+
terms: 1,
127+
'wc-stripe-payment-method': paymentMethod.id,
128+
stripe_source: paymentMethod.id, // Needed to process the payment in legacy checkout mode.
129+
payment_request_type: paymentRequestType,
130+
'wc-stripe-is-deferred-intent': true,
128131
};
129132

130133
if ( shipping ) {
@@ -480,12 +483,12 @@ jQuery( function( $ ) {
480483
} );
481484
} );
482485

483-
paymentRequest.on( 'source', function( evt ) {
486+
paymentRequest.on( 'paymentmethod', function( evt ) {
484487
// Check if we allow prepaid cards.
485488
if ( 'no' === wc_stripe_payment_request_params.stripe.allow_prepaid_card && 'prepaid' === evt.source.card.funding ) {
486489
wc_stripe_payment_request.abortPayment( evt, wc_stripe_payment_request.getErrorMessageHTML( wc_stripe_payment_request_params.i18n.no_prepaid_card ) );
487490
} else {
488-
$.when( wc_stripe_payment_request.processSource( evt, paymentRequestType ) ).then( function( response ) {
491+
$.when( wc_stripe_payment_request.processPaymentMethod( evt, paymentRequestType ) ).then( function( response ) {
489492
if ( 'success' === response.result ) {
490493
wc_stripe_payment_request.completePayment( evt, response.redirect );
491494
} else {

changelog.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
*** Changelog ***
22

3+
= 8.8.0 - 2024-10-17 =
4+
* Fix - Update URL and path constants to support use of symlinked plugin.
5+
* Tweak - Disable ECE when cart has virtual products and tax is based on customer billing or shipping address.
6+
* Fix - Fix the usage of coupons and the total shipping amount when using the Express Checkout Element on the shortcode checkout.
7+
* Fix - Fixes some JS console errors when making a purchase with the Stripe Express Checkout Element on the shortcode checkout.
8+
* Fix - Updates the display logic for the OAuth re-connect promotional surface to follow the latest changes made to the connection settings object.
9+
* Fix - Remove unexpected HTML in error message for shortcode checkout.
10+
* Fix - Ensure ordering for Stripe payment methods is saved even when setting up from scratch.
11+
* Add - Implemented the "Update all subscriptions payment methods" checkbox on My Account → Payment methods for UPE payment methods.
12+
* Add - Add support for the new Stripe Express Checkout Element on the block cart and checkout page.
13+
* Add - Add support for the new Stripe Express Checkout Element on the shortcode checkout page.
14+
* Add - Add support for the new Stripe Express Checkout Element on the shortcode cart page.
15+
* Add - Add support for the new Stripe Express Checkout Element on the pay for order page.
16+
* Add - Add support for the new Stripe Checkout Element on the product page.
17+
* Dev - Introduces a new class with payment methods constants.
18+
* Dev - Introduces a new class with currency codes constants.
19+
* Dev - Improves the readability of the redirect URL generation code (UPE).
20+
* Fix - Fix mandate creation for subscriptions and saved payment methods.
21+
* Fix - Fix Google Pay address fields mapping for UAE addresses.
22+
* Tweak - Render the Klarna payment page in the store locale.
23+
* Tweak - Update the Apple Pay domain registration flow to use the new Stripe API endpoint.
24+
* Fix - Fix empty error message for Express Payments when order creation fails.
25+
* Fix - Fix multiple issues related to the reuse of Cash App Pay tokens (as a saved payment method) when subscribing.
26+
* Fix - Move charge related code to separate try-catch to prevent renewal failure.
27+
* Fix - Corrected translation text domain in UPE checkout integration.
28+
* Fix - Resolve an issue where Stripe Payment Method API calls passed the token's database ID instead of the Stripe ID.
29+
* Fix - Pre-orders set to pay upon release were remaining pending when attempting to pay using Stripe.
30+
* Fix - Ensure subscription renewal order statement descriptors include the order number suffix.
31+
* Fix - Resolved an issue which caused the WeChat Pay payment icon to not be displayed on shortcode checkout pages.
32+
* Fix - Set order payment method title to the customizable title setting rather than the default label.
33+
* Fix - Update Cash App payments to avoid confirming on creation, resolving issues with generic payment failures in live mode.
34+
* Fix - Switch Google Pay and Apple Pay PRB flow to create PaymentMethod (pm_) instead of Source (src_), utilizing deferred intent processing.
35+
* Tweak - Add order lock for redirect payments.
36+
* Fix - Missing Stripe Fee and Stripe Payout details on orders that were captured manually.
37+
* Fix - Allow legacy `src_` payment methods linked to a saved credit card to be displayed on the checkout and My Account pages when the new checkout experience is enabled.
38+
339
= 8.7.0 - 2024-09-16 =
440
* Add - Introduces a new promotional surface to encourage merchants with the legacy checkout experience and APMs enabled to use the new checkout experience.
541
* Fix - Prevent duplicate failed-order emails from being sent.

client/api/index.js

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* global Stripe */
22
import { __ } from '@wordpress/i18n';
33
import { isLinkEnabled } from 'wcstripe/stripe-utils';
4+
import {
5+
getExpressCheckoutData,
6+
getExpressCheckoutAjaxURL,
7+
getRequiredFieldDataFromCheckoutForm,
8+
} from 'wcstripe/express-checkout/utils';
49

510
/**
611
* Handles generic connections to the server and Stripe.
@@ -168,13 +173,15 @@ export default class WCStripeAPI {
168173
* Creates and confirms a setup intent.
169174
*
170175
* @param {Object} paymentMethod Payment method data.
176+
* @param {Object} additionalData Additional data to send with the request.
171177
*
172178
* @return {Promise} Promise containing the setup intent.
173179
*/
174-
setupIntent( paymentMethod ) {
180+
setupIntent( paymentMethod, additionalData = {} ) {
175181
return this.request(
176182
this.getAjaxUrl( 'create_and_confirm_setup_intent' ),
177183
{
184+
...additionalData,
178185
action: 'create_and_confirm_setup_intent',
179186
'wc-stripe-payment-method': paymentMethod.id,
180187
'wc-stripe-payment-type': paymentMethod.type,
@@ -467,4 +474,121 @@ export default class WCStripeAPI {
467474
}
468475
} );
469476
}
477+
478+
/**
479+
* Submits shipping address to get available shipping options
480+
* from Express Checkout ECE payment method.
481+
*
482+
* @param {Object} shippingAddress Shipping details.
483+
* @return {Promise} Promise for the request to the server.
484+
*/
485+
expressCheckoutECECalculateShippingOptions( shippingAddress ) {
486+
return this.request(
487+
getExpressCheckoutAjaxURL( 'get_shipping_options' ),
488+
{
489+
security: getExpressCheckoutData( 'nonce' )?.shipping,
490+
is_product_page: getExpressCheckoutData( 'is_product_page' ),
491+
...shippingAddress,
492+
}
493+
);
494+
}
495+
496+
/**
497+
* Updates cart with selected shipping option.
498+
*
499+
* @param {Object} shippingOption Shipping option.
500+
* @return {Promise} Promise for the request to the server.
501+
*/
502+
expressCheckoutUpdateShippingDetails( shippingOption ) {
503+
return this.request(
504+
getExpressCheckoutAjaxURL( 'update_shipping_method' ),
505+
{
506+
security: getExpressCheckoutData( 'nonce' )?.update_shipping,
507+
shipping_method: [ shippingOption.id ],
508+
is_product_page: getExpressCheckoutData( 'is_product_page' ),
509+
}
510+
);
511+
}
512+
513+
/**
514+
* Get cart items and total amount.
515+
*
516+
* @return {Promise} Promise for the request to the server.
517+
*/
518+
expressCheckoutGetCartDetails() {
519+
return this.request( getExpressCheckoutAjaxURL( 'get_cart_details' ), {
520+
security: getExpressCheckoutData( 'nonce' )?.get_cart_details,
521+
} );
522+
}
523+
524+
/**
525+
* Creates order based on Express Checkout ECE payment method.
526+
*
527+
* @param {Object} paymentData Order data.
528+
* @return {Promise} Promise for the request to the server.
529+
*/
530+
expressCheckoutECECreateOrder( paymentData ) {
531+
return this.request( getExpressCheckoutAjaxURL( 'create_order' ), {
532+
_wpnonce: getExpressCheckoutData( 'nonce' )?.checkout,
533+
...getRequiredFieldDataFromCheckoutForm( paymentData ),
534+
} );
535+
}
536+
537+
/**
538+
* Pays for an order based on the Express Checkout payment method.
539+
*
540+
* @param {number} order The order ID.
541+
* @param {Object} paymentData Order data.
542+
* @return {Promise} Promise for the request to the server.
543+
*/
544+
expressCheckoutECEPayForOrder( order, paymentData ) {
545+
return this.request( getExpressCheckoutAjaxURL( 'pay_for_order' ), {
546+
_wpnonce: getExpressCheckoutData( 'nonce' )?.pay_for_order,
547+
order,
548+
...paymentData,
549+
} );
550+
}
551+
552+
/**
553+
* Add product to cart from product page.
554+
*
555+
* @param {Object} productData Product data.
556+
* @return {Promise} Promise for the request to the server.
557+
*/
558+
expressCheckoutAddToCart( productData ) {
559+
return this.request( getExpressCheckoutAjaxURL( 'add_to_cart' ), {
560+
security: getExpressCheckoutData( 'nonce' )?.add_to_cart,
561+
...productData,
562+
} );
563+
}
564+
565+
/**
566+
* Get selected product data from variable product page.
567+
*
568+
* @param {Object} productData Product data.
569+
* @return {Promise} Promise for the request to the server.
570+
*/
571+
expressCheckoutGetSelectedProductData( productData ) {
572+
return this.request(
573+
getExpressCheckoutAjaxURL( 'get_selected_product_data' ),
574+
{
575+
security: getExpressCheckoutData( 'nonce' )
576+
?.get_selected_product_data,
577+
...productData,
578+
}
579+
);
580+
}
581+
582+
/**
583+
* Empty the cart.
584+
*
585+
* @param {number} bookingId Booking ID.
586+
* @return {Promise} Promise for the request to the server.
587+
*/
588+
expressCheckoutEmptyCart( bookingId ) {
589+
return this.request( getExpressCheckoutAjaxURL( 'clear_cart' ), {
590+
security: getExpressCheckoutData( 'nonce' )?.clear_cart,
591+
booking_id: bookingId,
592+
} );
593+
}
470594
}

client/blocks/express-checkout/apple-pay-preview.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const PAYMENT_METHOD_EXPRESS_CHECKOUT_ELEMENT =
2+
'express_checkout_element';

0 commit comments

Comments
 (0)