Skip to content

Commit 470eeb3

Browse files
authored
Add support for supportedShippingCountries (#345)
* Add support for supportedShippingCountries * Update swift tests * Update runner to macos-26-xlarge * ci: do not switch to xcode 16.4
1 parent aedc999 commit 470eeb3

15 files changed

+148
-38
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,13 @@ jobs:
116116
117117
test-ios:
118118
name: Run Swift Tests
119-
runs-on: macos-15-xlarge
119+
runs-on: macos-26-xlarge
120120
timeout-minutes: 20
121121
needs: [lint, test]
122122
steps:
123123
- name: Checkout
124124
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
125125

126-
- name: Switch to Xcode 16.4
127-
run: |
128-
sudo xcode-select --switch /Applications/Xcode_16.4.app
129-
130126
- name: Display Current Xcode Information
131127
run: |
132128
echo "Xcode Path: $(xcode-select -p)"

modules/@shopify/checkout-sheet-kit/RNShopifyCheckoutSheetKit.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Pod::Spec.new do |s|
2020
s.source_files = "ios/*.{h,m,mm,swift}"
2121

2222
s.dependency "React-Core"
23-
s.dependency "ShopifyCheckoutSheetKit", "~> 3.4.0-rc.8"
24-
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.4.0-rc.8"
23+
s.dependency "ShopifyCheckoutSheetKit", "~> 3.4.0-rc.9"
24+
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.4.0-rc.9"
2525

2626
if fabric_enabled
2727
# Use React Native's helper if available, otherwise add dependencies directly

modules/@shopify/checkout-sheet-kit/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ ndkVersion=23.1.7779620
55
buildToolsVersion = "35.0.0"
66

77
# Version of Shopify Checkout SDK to use with React Native
8-
SHOPIFY_CHECKOUT_SDK_VERSION=3.5.1
8+
SHOPIFY_CHECKOUT_SDK_VERSION=3.5.2

modules/@shopify/checkout-sheet-kit/ios/AcceleratedCheckoutButtons+Extensions.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@ import SwiftUI
3131
@available(iOS 16.0, *)
3232
extension PayWithApplePayButtonLabel {
3333
static func from(_ string: String?, fallback: PayWithApplePayButtonLabel = .plain) -> PayWithApplePayButtonLabel {
34-
guard let string else {
34+
guard let string, let value = map[string] else {
3535
return fallback
3636
}
37-
return map[string] ?? .plain
38-
}
3937

40-
public static func == (lhs: PayWithApplePayButtonLabel, rhs: PayWithApplePayButtonLabel) -> Bool {
41-
return String(describing: lhs) == String(describing: rhs)
38+
return value
4239
}
4340

4441
private static let map: [String: PayWithApplePayButtonLabel] = [

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ @interface RCT_EXTERN_MODULE (RCTShopifyCheckoutSheetKit, NSObject)
6363
RCT_EXTERN_METHOD(configureAcceleratedCheckouts : (NSString*)storefrontDomain storefrontAccessToken : (
6464
NSString*)storefrontAccessToken customerEmail : (NSString*)customerEmail customerPhoneNumber : (NSString*)
6565
customerPhoneNumber customerAccessToken : (NSString*)customerAccessToken applePayMerchantIdentifier : (NSString*)
66-
applePayMerchantIdentifier applyPayContactFields : (NSArray*)applyPayContactFields resolve : (
66+
applePayMerchantIdentifier applyPayContactFields : (NSArray*)applyPayContactFields supportedShippingCountries : (NSArray*)supportedShippingCountries resolve : (
6767
RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);
6868

6969
/**

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
221221
customerAccessToken: String?,
222222
applePayMerchantIdentifier: String?,
223223
applyPayContactFields: [String]?,
224+
supportedShippingCountries: [String]?,
224225
resolve: @escaping RCTPromiseResolveBlock,
225226
reject _: @escaping RCTPromiseRejectBlock
226227
) {
@@ -247,7 +248,8 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
247248

248249
acceleratedCheckoutsApplePayConfiguration = ShopifyAcceleratedCheckouts.ApplePayConfiguration(
249250
merchantIdentifier: merchantIdentifier,
250-
contactFields: fields
251+
contactFields: fields,
252+
supportedShippingCountries: Set(supportedShippingCountries ?? [])
251253
)
252254

253255
AcceleratedCheckoutConfiguration.shared.applePayConfiguration = acceleratedCheckoutsApplePayConfiguration as? ShopifyAcceleratedCheckouts.ApplePayConfiguration

modules/@shopify/checkout-sheet-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@shopify/checkout-sheet-kit",
33
"license": "MIT",
4-
"version": "3.4.0-rc.2",
4+
"version": "3.4.0-rc.3",
55
"main": "lib/commonjs/index.js",
66
"types": "src/index.ts",
77
"source": "src/index.ts",

modules/@shopify/checkout-sheet-kit/src/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ export interface AcceleratedCheckoutConfiguration {
233233
* Example: 'merchant.com.yourcompany'
234234
*/
235235
merchantIdentifier: string;
236+
/**
237+
* Restrict the countries available for shipping during the Apple Pay flow.
238+
* Expects ISO 3166-1 alpha-2 country codes (e.g., "US", "CA", "GB").
239+
* @default null (all countries supported, as per Shop configuration)
240+
*/
241+
supportedShippingCountries?: string[];
236242
};
237243
};
238244
}

modules/@shopify/checkout-sheet-kit/src/index.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
238238
config.customer?.accessToken || null,
239239
config.wallets?.applePay?.merchantIdentifier || null,
240240
config.wallets?.applePay?.contactFields || [],
241+
config.wallets?.applePay?.supportedShippingCountries || [],
241242
);
242243
return configured;
243244
} catch (error) {
@@ -289,28 +290,38 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
289290
private validateAcceleratedCheckoutsConfiguration(
290291
acceleratedCheckouts: Configuration['acceleratedCheckouts'],
291292
) {
293+
if (!acceleratedCheckouts) {
294+
return;
295+
}
296+
297+
const {storefrontDomain, storefrontAccessToken, wallets} =
298+
acceleratedCheckouts;
299+
292300
/**
293301
* Required Accelerated Checkouts configuration properties
294302
*/
295-
if (!acceleratedCheckouts?.storefrontDomain) {
303+
if (!storefrontDomain) {
296304
throw new Error('`storefrontDomain` is required');
297305
}
298-
if (!acceleratedCheckouts.storefrontAccessToken) {
306+
if (!storefrontAccessToken) {
299307
throw new Error('`storefrontAccessToken` is required');
300308
}
301309

302310
/**
303311
* Validate Apple Pay config if available
304312
*/
305-
if (acceleratedCheckouts.wallets?.applePay) {
306-
if (!acceleratedCheckouts.wallets.applePay.merchantIdentifier) {
313+
if (wallets?.applePay) {
314+
const {merchantIdentifier, contactFields, supportedShippingCountries} =
315+
wallets.applePay;
316+
317+
if (!merchantIdentifier) {
307318
throw new Error('`wallets.applePay.merchantIdentifier` is required');
308319
}
309320

310321
const expectedContactFields = Object.values(ApplePayContactField);
311322
const hasInvalidContactFields =
312-
Array.isArray(acceleratedCheckouts.wallets.applePay.contactFields) &&
313-
acceleratedCheckouts.wallets.applePay.contactFields.some(
323+
Array.isArray(contactFields) &&
324+
contactFields.some(
314325
value =>
315326
!expectedContactFields.includes(
316327
value.toLowerCase() as ApplePayContactField,
@@ -319,7 +330,16 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
319330

320331
if (hasInvalidContactFields) {
321332
throw new Error(
322-
`'wallets.applePay.contactFields' contains unexpected values. Expected "${expectedContactFields.join(', ')}", received "${acceleratedCheckouts.wallets.applePay.contactFields}"`,
333+
`'wallets.applePay.contactFields' contains unexpected values. Expected "${expectedContactFields.join(', ')}", received "${contactFields}"`,
334+
);
335+
}
336+
337+
if (
338+
Array.isArray(supportedShippingCountries) &&
339+
supportedShippingCountries?.some(country => typeof country !== 'string')
340+
) {
341+
throw new Error(
342+
`'wallets.applePay.supportedShippingCountries' contains unexpected values. Expects ISO 3166-1 alpha-2 country codes (e.g., "US", "CA", "GB").`,
323343
);
324344
}
325345
}

modules/@shopify/checkout-sheet-kit/tests/context.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe('ShopifyCheckoutSheetProvider', () => {
120120
'customer-access-token',
121121
'merchant.test',
122122
['email'],
123+
[],
123124
);
124125
});
125126

@@ -391,11 +392,13 @@ describe('useShopifyCheckoutSheet', () => {
391392
describe('ShopifyCheckoutSheetContext without provider', () => {
392393
it('throws error when hook is used without provider', () => {
393394
const errorSpy = jest.spyOn(console, 'error').mockImplementation();
394-
395+
395396
expect(() => {
396397
render(<HookTestComponent onHookValue={() => {}} />);
397-
}).toThrow('useShopifyCheckoutSheet must be used from within a ShopifyCheckoutSheetContext');
398-
398+
}).toThrow(
399+
'useShopifyCheckoutSheet must be used from within a ShopifyCheckoutSheetContext',
400+
);
401+
399402
errorSpy.mockRestore();
400403
});
401404
});

0 commit comments

Comments
 (0)