Skip to content

Commit ff9e954

Browse files
committed
Merge remote-tracking branch 'origin/release/9.0.0' into trunk
2 parents b8c5f58 + 35bc7f6 commit ff9e954

File tree

86 files changed

+884
-579
lines changed

Some content is hidden

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

86 files changed

+884
-579
lines changed

assets/js/stripe-payment-request.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jQuery( function( $ ) {
144144

145145
data = wc_stripe_payment_request.getRequiredFieldDataFromCheckoutForm( data );
146146

147-
return data;
147+
return { ...data, ...wc_stripe_payment_request.extractOrderAttributionData() };
148148
},
149149

150150
/**
@@ -173,7 +173,7 @@ jQuery( function( $ ) {
173173
if ( ! data[ name ] ) {
174174
data[ name ] = value;
175175
}
176-
176+
177177
// if shipping same as billing is selected, copy the billing field to shipping field.
178178
const shipToDiffAddress = $( '#ship-to-different-address' ).find( 'input' ).is( ':checked' );
179179
if ( ! shipToDiffAddress ) {
@@ -833,6 +833,24 @@ jQuery( function( $ ) {
833833
} );
834834
},
835835

836+
/**
837+
* Get order attribution data from the hidden inputs.
838+
*
839+
* @return {Object} Order attribution data.
840+
*/
841+
extractOrderAttributionData: function() {
842+
const $orderAttributionWrapper = $( 'wc-order-attribution-inputs' );
843+
if ( ! $orderAttributionWrapper.length ) {
844+
return {};
845+
}
846+
847+
const orderAttributionData = {};
848+
$orderAttributionWrapper.children( 'input' ).each( function () {
849+
orderAttributionData[ $(this).attr( 'name' ) ] = $(this).val();
850+
});
851+
return orderAttributionData;
852+
},
853+
836854
showPaymentRequestButton: function( prButton ) {
837855
if ( wc_stripe_payment_request.isCustomPaymentRequestButton( prButton ) ) {
838856
prButton.addClass( 'is-active' );

changelog.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
*** Changelog ***
22

3+
= 9.0.0 - 2024-12-12 =
4+
* Fix - Fix 404 that happens when using ECE and 3D Secure auth is triggered.
5+
* Fix - Set correct payment method when using Link and a card that is 3D Secure authenticated.
6+
* Fix - Fix total calculation for custom product types when using the Payment Request Button.
7+
* Fix - Fix order attribution metadata not included in PRBs or Express Checkout Element.
8+
* Add - Pre-fill user email and phone number for Link in the Payment Element.
9+
* Remove - Remove Link autofill modal feature.
10+
* Update - Improve accuracy of webhook status information displayed in settings page.
11+
* Tweak - Standardize ECE Express payment buttons on Pay for Order page to match cart and checkout itemization behavior.
12+
* Tweak - Remove duplicate notice about the new checkout experience.
13+
* Tweak - Include page URL information in the SSL-required log for the Stripe Express Checkout Element.
14+
* Fix - Fix ECE modal not loading on pay for order page when coupon is applied.
15+
* Fix - Do not load express payment buttons on switch subscription page.
16+
* Fix - Resolve a fatal error by casting product price and subscription sign up fee to 'float' while adding them.
17+
* Fix - Return 'is_live' as true in account summary response when test mode is disabled in gateway settings and charge is enabled in Stripe account.
18+
* Fix - Prevents notices being displayed on WordPress 6.7 due to loading translations too early (only shown on stores with WP_DEBUG enabled).
19+
* Fix - Prevent showing the shipping options on express checkout modal for virtual product variations.
20+
* Fix - Do not assume payment is using a saved card when retrying a failed payment.
21+
* Tweak - Update links to plugin documentation and Stripe documentation.
22+
323
= 8.9.0 - 2024-11-14 =
424
* Update - Enhance webhook processing to enable retrieving orders using payment_intent metadata.
525
* Dev - Minor updates to the webhook handler class related to payment method names constants.
@@ -1347,7 +1367,7 @@
13471367
* Add support for changing a subscription's recurring amount
13481368

13491369
= 1.5.0 - 2013-01-18 =
1350-
* Supports Stripe Checkout https://stripe.com/docs/checkout
1370+
* Supports Stripe Checkout https://docs.stripe.com/payments/checkout
13511371

13521372
= 1.4.0 - 2013-01-18 =
13531373
* WC 2.0 Compat

client/api/index.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* global Stripe */
22
import { __ } from '@wordpress/i18n';
3-
import { isLinkEnabled } from 'wcstripe/stripe-utils';
43
import {
54
getExpressCheckoutData,
65
getExpressCheckoutAjaxURL,
@@ -64,20 +63,9 @@ export default class WCStripeAPI {
6463
* @return {Object} The Stripe Object.
6564
*/
6665
getStripe() {
67-
const {
68-
key,
69-
locale,
70-
isUPEEnabled,
71-
paymentMethodsConfig,
72-
} = this.options;
66+
const { key, locale } = this.options;
7367
if ( ! this.stripe ) {
74-
if ( isUPEEnabled && isLinkEnabled( paymentMethodsConfig ) ) {
75-
this.stripe = this.createStripe( key, locale, [
76-
'link_autofill_modal_beta_1',
77-
] );
78-
} else {
79-
this.stripe = this.createStripe( key, locale );
80-
}
68+
this.stripe = this.createStripe( key, locale );
8169
}
8270
return this.stripe;
8371
}
@@ -302,7 +290,8 @@ export default class WCStripeAPI {
302290
*
303291
* @param {string} redirectUrl The redirect URL, returned from the server.
304292
* @param {string} paymentMethodToSave The ID of a Payment Method if it should be saved (optional).
305-
* @return {string|true} A redirect URL on success, or `true` if no confirmation is needed.
293+
* @return {Object|true} An object containing the redirect URL on success and a flag indicating
294+
* if the page is the Pay for order page, or `true` if no confirmation is needed.
306295
*/
307296
confirmIntent( redirectUrl, paymentMethodToSave ) {
308297
const partials = redirectUrl.match(

client/blocks/__tests__/utils.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { render } from '@testing-library/react';
2+
import {
3+
extractOrderAttributionData,
4+
populateOrderAttributionInputs,
5+
} from 'wcstripe/blocks/utils';
6+
7+
describe( 'Blocks Utils', () => {
8+
describe( 'extractOrderAttributionData', () => {
9+
it( 'order attribution wrapper not found', () => {
10+
const data = extractOrderAttributionData();
11+
expect( data ).toStrictEqual( {} );
12+
} );
13+
14+
it( 'order attribution wrapper exists', () => {
15+
render(
16+
<wc-order-attribution-inputs>
17+
<input name="foo" defaultValue="bar" />
18+
<input name="baz" defaultValue="qux" />
19+
</wc-order-attribution-inputs>
20+
);
21+
22+
const data = extractOrderAttributionData();
23+
expect( data ).toStrictEqual( {
24+
foo: 'bar',
25+
baz: 'qux',
26+
} );
27+
} );
28+
} );
29+
30+
describe( 'populateOrderAttributionInputs', () => {
31+
test( 'order attribution global present', () => {
32+
global.wc_order_attribution = {
33+
params: {
34+
allowTracking: true,
35+
},
36+
setOrderTracking: jest.fn(),
37+
};
38+
39+
populateOrderAttributionInputs();
40+
41+
expect(
42+
global.wc_order_attribution.setOrderTracking
43+
).toHaveBeenCalledWith( true );
44+
} );
45+
} );
46+
} );

client/blocks/normalize.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
* @typedef {import('@woocommerce/type-defs/billing').BillingData} CartBillingAddress
1010
*/
1111

12-
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';
12+
import {
13+
extractOrderAttributionData,
14+
getBlocksConfiguration,
15+
} from 'wcstripe/blocks/utils';
1316

1417
/**
1518
* Normalizes order data received upon creating an order using the store's AJAX API.
@@ -79,7 +82,7 @@ const normalizeOrderData = ( paymentMethodEvent, paymentRequestType ) => {
7982
data.shipping_postcode = shipping?.postalCode;
8083
}
8184

82-
return data;
85+
return { ...data, ...extractOrderAttributionData() };
8386
};
8487

8588
/**

client/blocks/payment-request/payment-request-express.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { __ } from '@wordpress/i18n';
2+
import { useEffect } from '@wordpress/element';
23
import {
34
Elements,
45
PaymentRequestButtonElement,
@@ -70,6 +71,17 @@ const PaymentRequestExpressComponent = ( {
7071
);
7172
useCancelHandler( paymentRequest, onClose );
7273

74+
useEffect( () => {
75+
if ( paymentRequest ) {
76+
const orderAttribution = window?.wc_order_attribution;
77+
if ( orderAttribution ) {
78+
orderAttribution.setOrderTracking(
79+
orderAttribution.params.allowTracking
80+
);
81+
}
82+
}
83+
}, [ paymentRequest ] );
84+
7385
// locale is not a valid value for the paymentRequestButton style.
7486
// Make sure `theme` defaults to 'dark' if it's not found in the server provided configuration.
7587
let {
@@ -173,6 +185,7 @@ export const PaymentRequestExpress = ( props ) => {
173185
return (
174186
<Elements stripe={ stripe }>
175187
<PaymentRequestExpressComponent { ...props } />
188+
<wc-order-attribution-inputs id="wc-stripe-express-checkout__order-attribution-inputs" />
176189
</Elements>
177190
);
178191
};

client/blocks/upe/hooks.js

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { useEffect } from '@wordpress/element';
22
import { useSelect, useDispatch } from '@wordpress/data';
33
import confirmCardPayment from './confirm-card-payment.js';
4-
import enableStripeLinkPaymentMethod from 'wcstripe/stripe-link';
54
import { WC_STORE_CART } from 'wcstripe/blocks/credit-card/constants';
6-
import { isLinkEnabled } from 'wcstripe/stripe-utils';
75

86
/**
97
* Handles the Block Checkout onCheckoutSuccess event.
@@ -80,103 +78,6 @@ export const usePaymentFailHandler = (
8078
);
8179
};
8280

83-
/**
84-
* Handles rendering the Block Checkout Stripe Link payment method.
85-
*
86-
* @param {*} api The api object.
87-
* @param {*} elements The Stripe elements object.
88-
* @param {*} paymentMethodsConfig The payment methods config object. Used to determine if Stripe Link is enabled.
89-
*/
90-
export const useStripeLink = ( api, elements, paymentMethodsConfig ) => {
91-
const customerData = useCustomerData();
92-
useEffect( () => {
93-
if ( isLinkEnabled( paymentMethodsConfig ) ) {
94-
const shippingAddressFields = {
95-
line1: 'shipping-address_1',
96-
line2: 'shipping-address_2',
97-
city: 'shipping-city',
98-
state: 'components-form-token-input-1',
99-
postal_code: 'shipping-postcode',
100-
country: 'components-form-token-input-0',
101-
first_name: 'shipping-first_name',
102-
last_name: 'shipping-last_name',
103-
};
104-
const billingAddressFields = {
105-
line1: 'billing-address_1',
106-
line2: 'billing-address_2',
107-
city: 'billing-city',
108-
state: 'components-form-token-input-3',
109-
postal_code: 'billing-postcode',
110-
country: 'components-form-token-input-2',
111-
first_name: 'billing-first_name',
112-
last_name: 'billing-last_name',
113-
};
114-
115-
enableStripeLinkPaymentMethod( {
116-
api,
117-
elements,
118-
emailId: 'email',
119-
fill_field_method: ( address, nodeId, key ) => {
120-
const setAddress =
121-
shippingAddressFields[ key ] === nodeId
122-
? customerData.setShippingAddress
123-
: customerData.setBillingAddress;
124-
const customerAddress =
125-
shippingAddressFields[ key ] === nodeId
126-
? customerData.shippingAddress
127-
: customerData.billingAddress;
128-
129-
if ( undefined === customerAddress ) {
130-
return;
131-
}
132-
133-
if ( address.address[ key ] === null ) {
134-
address.address[ key ] = '';
135-
}
136-
137-
if ( key === 'line1' ) {
138-
customerAddress.address_1 = address.address[ key ];
139-
} else if ( key === 'line2' ) {
140-
customerAddress.address_2 = address.address[ key ];
141-
} else if ( key === 'postal_code' ) {
142-
customerAddress.postcode = address.address[ key ];
143-
} else {
144-
customerAddress[ key ] = address.address[ key ];
145-
}
146-
147-
if ( undefined !== customerData.billingAddress ) {
148-
customerAddress.email = getEmail();
149-
}
150-
151-
setAddress( customerAddress );
152-
153-
function getEmail() {
154-
return document.getElementById( 'email' ).value;
155-
}
156-
157-
customerData.billingAddress.email = getEmail();
158-
customerData.setBillingAddress(
159-
customerData.billingAddress
160-
);
161-
},
162-
complete_shipping: () => {
163-
return (
164-
document.getElementById( 'shipping-address_1' ) !== null
165-
);
166-
},
167-
shipping_fields: shippingAddressFields,
168-
billing_fields: billingAddressFields,
169-
complete_billing: () => {
170-
return (
171-
document.getElementById( 'billing-address_1' ) !== null
172-
);
173-
},
174-
} );
175-
}
176-
// eslint-disable-next-line react-hooks/exhaustive-deps
177-
}, [ elements ] );
178-
};
179-
18081
/**
18182
* Returns the customer data and setters for the customer data.
18283
*

client/blocks/upe/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
expressCheckoutElementsStripeLink,
1515
} from 'wcstripe/blocks/express-checkout';
1616
import WCStripeAPI from 'wcstripe/api';
17-
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';
17+
import {
18+
addOrderAttributionInputsIfNotExists,
19+
getBlocksConfiguration,
20+
populateOrderAttributionInputs,
21+
} from 'wcstripe/blocks/utils';
1822
import './styles.scss';
1923

2024
const api = new WCStripeAPI(
@@ -106,3 +110,9 @@ if ( getBlocksConfiguration()?.isECEEnabled ) {
106110

107111
// Update token labels when the checkout form is loaded.
108112
updateTokenLabelsWhenLoaded();
113+
114+
// Add order attribution inputs to the page.
115+
addOrderAttributionInputsIfNotExists();
116+
117+
// Populate order attribution inputs with order tracking data.
118+
populateOrderAttributionInputs();

0 commit comments

Comments
 (0)