Skip to content

Commit f4e9308

Browse files
authored
v2.0.0 (#76)
* [iOS] Upgrade to v2 * Update snapshot * Bump version (major) + add changelog entry * Update Ci to add lint/test dependency to platform test actions * Update iOS tests * [Module] Add tests for completed event handling * [Android] Add test for completed event * Reset checkout title * Update README * Update Android implementation * Remove redundant swift comment * Remove redundant Android dependency * Make pixel event data required * Minor TS improvements * Map CheckoutEvent names to callbacks to remove casting * Upgrade typescript, revert to casting * Remove L from color hex * De-duplicate handleWebPixelEvent and handleCompletedEvent private methods * Prevent prettier destroying blockquotes in readme * Improve types
1 parent ae9d84d commit f4e9308

File tree

33 files changed

+813
-303
lines changed

33 files changed

+813
-303
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ jobs:
3939

4040
- run: ./scripts/compare_snapshot
4141

42+
lint:
43+
name: Lint module + sample
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v3
47+
48+
- name: Setup
49+
uses: ./.github/actions/setup
50+
51+
- run: |
52+
yarn module lint
53+
yarn sample lint
54+
4255
test:
4356
name: Run jest tests
4457
runs-on: ubuntu-latest
@@ -53,6 +66,7 @@ jobs:
5366
test-android:
5467
name: Run Android Tests
5568
runs-on: ubuntu-latest
69+
needs: [lint, test]
5670
steps:
5771
- name: Checkout
5872
uses: actions/checkout@v3
@@ -75,6 +89,7 @@ jobs:
7589
test-ios:
7690
name: Run iOS Tests
7791
runs-on: macos-13
92+
needs: [lint, lint-swift, test]
7893
steps:
7994
- name: Checkout
8095
uses: actions/checkout@v3

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
# Changelog
22

3+
## 2.0.0 - March 21, 2024
4+
5+
### Updated dependencies
6+
7+
- [`[email protected]`](https://github.com/Shopify/checkout-sheet-kit-swift/releases)
8+
- [`[email protected]`](https://github.com/Shopify/checkout-sheet-kit-android/releases)
9+
10+
### New features
11+
12+
1. The loading spinner has been replaced by a progress bar. This will result in
13+
a faster perceived load time since the SDK will now no longer wait for full
14+
page load to show the DOM content.
15+
2. The "title" of the webview is now configurable via a `Localizable.xcstrings`
16+
file on iOS, a `res/values/strings.xml` on Android or using the `title`
17+
attribute on the ShopifyCheckoutSheetKit configuration.
18+
19+
> [!IMPORTANT]
20+
> The `title` attribute on the configuration will configure iOS _only_.
21+
22+
```diff
23+
ShopifyCheckoutSheetKit.setConfig({
24+
+ title: "Localized value"
25+
})
26+
```
27+
28+
1. The `completed` event now returns details about the order, including the
29+
order ID:
30+
31+
```diff
32+
- const checkoutCompletedSubscription = shopify.addEventListener('completed', () => {
33+
+ const checkoutCompletedSubscription = shopify.addEventListener('completed', event => {
34+
+ console.log('[CheckoutCompletedEvent]', event.orderDetails.id);
35+
});
36+
```
37+
38+
### Breaking changes
39+
40+
1. `spinnerColor` has been replaced by `tintColor` for iOS and
41+
`progressIndicator` for android.
42+
343
## 1.0.5 - March 5, 2024
444

545
- Updates the underlying swift SDK from `1.0.1` to `1.0.2` to include

README.md

Lines changed: 123 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ function App() {
110110
```
111111

112112
See [Usage with the Storefront API](#usage-with-the-storefront-api) below on how
113-
to get a checkoutUrl to pass to the SDK.
113+
to get a checkout URL to pass to the kit.
114+
115+
<!-- prettier-ignore-start -->
114116

115117
> [!NOTE]
116118
> The recommended usage of the library is through a
117119
> `ShopifyCheckoutSheetProvider` Context provider, but see
118120
> [Programmatic usage](#programamatic-usage) below for details on how to use the
119121
> library without React context.
120122
123+
<!-- prettier-ignore-end -->
124+
121125
### Programmatic Usage
122126

123127
To use the library without React context, import the `ShopifyCheckoutSheet`
@@ -264,11 +268,15 @@ function App() {
264268
}
265269
```
266270

271+
<!-- prettier-ignore-start -->
272+
267273
> [!TIP]
268-
> To help optimize and deliver the best experience the SDK also provides a
269-
> [preloading API](#preloading) that can be used to initialize the checkout
274+
> To help optimize and deliver the best experience the SDK also provides
275+
> a [preloading API](#preloading) that can be used to initialize the checkout
270276
> session in the background and ahead of time.
271277

278+
<!-- prettier-ignore-end -->
279+
272280
### Configuration
273281

274282
The SDK provides a way to customize the presented checkout experience through a
@@ -296,11 +304,11 @@ const config: Configuration = {
296304
colors: {
297305
ios: {
298306
backgroundColor: '#f0f0e8',
299-
spinnerColor: '#2d2a38',
307+
tintColor: '#2d2a38',
300308
},
301309
android: {
302310
backgroundColor: '#f0f0e8',
303-
spinnerColor: '#2d2a38',
311+
progressIndicator: '#2d2a38',
304312
headerBackgroundColor: '#f0f0e8',
305313
headerTextColor: '#2d2a38',
306314
},
@@ -344,11 +352,11 @@ const config: Configuration = {
344352
colors: {
345353
ios: {
346354
backgroundColor: '#ffffff',
347-
spinnerColor: '#000000',
355+
tintColor: '#000000',
348356
},
349357
android: {
350358
backgroundColor: '#ffffff',
351-
spinnerColor: '#2d2a38',
359+
progressIndicator: '#2d2a38',
352360
headerBackgroundColor: '#ffffff',
353361
headerTextColor: '#000000',
354362
},
@@ -374,13 +382,13 @@ const config: Configuration = {
374382
android: {
375383
light: {
376384
backgroundColor: '#ffffff',
377-
spinnerColor: '#2d2a38',
385+
progressIndicator: '#2d2a38',
378386
headerBackgroundColor: '#ffffff',
379387
headerTextColor: '#000000',
380388
},
381389
dark: {
382390
backgroundColor: '#000000',
383-
spinnerColor: '#0087ff',
391+
progressIndicator: '#0087ff',
384392
headerBackgroundColor: '#000000',
385393
headerTextColor: '#ffffff',
386394
},
@@ -397,6 +405,88 @@ function AppWithContext() {
397405
}
398406
```
399407

408+
### Localization
409+
410+
#### Checkout Sheet title
411+
412+
There are several ways to change the title of the Checkout Sheet.
413+
414+
##### iOS
415+
416+
On iOS, you can set a localized value on the `title` attribute of the
417+
configuration.
418+
419+
Alternatively, use a Localizable.xcstrings file in your app by doing the
420+
following:
421+
422+
1. Create a `Localizable.xcstrings` file under "ios/{YourApplicationName}"
423+
2. Add an entry for the key `"shopify_checkout_sheet_title"`
424+
425+
##### Android
426+
427+
On Android, you can add a string entry for the key `"checkout_web_view_title"`
428+
to the "android/app/src/res/values/strings.xml" file for your application.
429+
430+
```diff
431+
<resources>
432+
<string name="app_name">Your App Name</string>
433+
+ <string name="checkout_web_view_title">Checkout</string>
434+
</resources>
435+
```
436+
437+
<!-- prettier-ignore-start -->
438+
439+
> [!IMPORTANT]
440+
> The `title` configuration attribute will only affect iOS. For Android you **must** use
441+
> `res/values/strings.xml`.
442+
443+
<!-- prettier-ignore-end -->
444+
445+
#### Currency
446+
447+
To set an appropriate currency for a given cart, the Storefront API offers an
448+
`@inContext(country)` directive which will ensure the correct currency is
449+
presented.
450+
451+
```tsx
452+
const CREATE_CART_MUTATION = gql`
453+
mutation CreateCart($input: CartInput, $country: CountryCode = CA)
454+
@inContext(country: $country) {
455+
cartCreate(input: $input) {
456+
cart {
457+
id
458+
checkoutUrl
459+
}
460+
}
461+
}
462+
`;
463+
```
464+
465+
See [Storefront Directives](https://shopify.dev/docs/api/storefront#directives)
466+
for more information.
467+
468+
#### Language
469+
470+
Similarly to currency, you can use an `@inContext(language)` directive to set
471+
the language for your checkout.
472+
473+
```tsx
474+
const CREATE_CART_MUTATION = gql`
475+
mutation CreateCart($input: CartInput, $language: Language = EN)
476+
@inContext(language: $language) {
477+
cartCreate(input: $input) {
478+
cart {
479+
id
480+
checkoutUrl
481+
}
482+
}
483+
}
484+
`;
485+
```
486+
487+
See [Storefront Directives](https://shopify.dev/docs/api/storefront#directives)
488+
for more information.
489+
400490
### Preloading
401491

402492
Initializing a checkout session requires communicating with Shopify servers,
@@ -444,12 +534,12 @@ There are currently 3 checkout events exposed through the Native Module. You can
444534
subscribe to these events using `addEventListener` and `removeEventListeners`
445535
methods - available on both the context provider as well as the class instance.
446536

447-
| Name | Callback | Description |
448-
| ----------- | ------------------------------------ | ------------------------------------------------------------ |
449-
| `close` | `() => void` | Fired when the checkout has been closed. |
450-
| `completed` | `() => void` | Fired when the checkout has been successfully completed. |
451-
| `error` | `(error: {message: string}) => void` | Fired when a checkout exception has been raised. |
452-
| `pixel` | `(event: PixelEvent) => void` | Fired when a Web Pixel event has been relayed from checkout. |
537+
| Name | Callback | Description |
538+
| ----------- | ----------------------------------------- | ------------------------------------------------------------ |
539+
| `close` | `() => void` | Fired when the checkout has been closed. |
540+
| `completed` | `(event: CheckoutCompletedEvent) => void` | Fired when the checkout has been successfully completed. |
541+
| `error` | `(error: {message: string}) => void` | Fired when a checkout exception has been raised. |
542+
| `pixel` | `(event: PixelEvent) => void` | Fired when a Web Pixel event has been relayed from checkout. |
453543

454544
#### `addEventListener(eventName, callback)`
455545

@@ -466,9 +556,13 @@ useEffect(() => {
466556
// Do something on checkout close
467557
});
468558

469-
const completed = shopifyCheckout.addEventListener('completed', () => {
470-
// Do something on checkout completion
471-
});
559+
const completed = shopifyCheckout.addEventListener(
560+
'completed',
561+
(event: CheckoutCompletedEvent) => {
562+
// Lookup order on checkout completion
563+
const orderId = event.orderDetails.id;
564+
},
565+
);
472566

473567
const error = shopifyCheckout.addEventListener(
474568
'error',
@@ -565,10 +659,14 @@ external identity system and initialize a buyer-aware checkout session.
565659
`checkoutUrl`
566660
2. Provide the Multipass URL to `present(checkoutUrl)`
567661

662+
<!-- prettier-ignore-start -->
663+
568664
> [!IMPORTANT]
569-
> The above JSON omits useful customer attributes that should be provided
570-
> where possible and encryption and signing should be done server-side to ensure
571-
> Multipass keys are kept secret._
665+
> The above JSON omits useful customer attributes that should be
666+
> provided where possible and encryption and signing should be done server-side
667+
> to ensure Multipass keys are kept secret.
668+
669+
<!-- prettier-ignore-end -->
572670

573671
#### Shop Pay
574672

@@ -595,7 +693,8 @@ see [guidelines and instructions](.github/CONTRIBUTING.md). See
595693

596694
#### Running the sample app
597695

598-
To run the sample app in this repo, first clone the repo and run the following commands at the root of the project directory.
696+
To run the sample app in this repo, first clone the repo and run the following
697+
commands at the root of the project directory.
599698

600699
#### Install NPM dependencies
601700

@@ -617,7 +716,8 @@ yarn module build
617716

618717
#### Update the dotenv file
619718

620-
Replace the details in the `sample/.env.example` file and rename it to `sample/.env`
719+
Replace the details in the `sample/.env.example` file and rename it to
720+
`sample/.env`
621721

622722
```
623723
# Storefront Details

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

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

2222
s.dependency "React-Core"
23-
s.dependency "ShopifyCheckoutSheetKit", "~> 1.0.2"
23+
s.dependency "ShopifyCheckoutSheetKit", "~> 2.0.1"
2424

2525
if fabric_enabled
2626
install_modules_dependencies(s)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ dependencies {
9090
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
9191
//noinspection GradleDynamicVersion
9292
implementation "com.facebook.react:react-native:+"
93-
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
93+
// Uncomment to install dependencies for local development
94+
// implementation("com.facebook.react:react-android:+")
95+
9496
implementation("com.shopify:checkout-sheet-kit:${SHOPIFY_CHECKOUT_SDK_VERSION}")
9597
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.5")
9698
debugImplementation("com.shopify:checkout-sheet-kit:${SHOPIFY_CHECKOUT_SDK_VERSION}")

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 = "33.0.0"
66

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

0 commit comments

Comments
 (0)