Skip to content

Commit 44e6880

Browse files
committed
Centralize sample storefront configuration
1 parent f61a6a0 commit 44e6880

28 files changed

Lines changed: 1262 additions & 247 deletions

.env.example

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Checkout Kit sample storefront configuration.
2+
# Copy this file to .env, fill in local values, then run:
3+
# scripts/setup_storefront_env
4+
# Optional Apple Pay and Customer Account API values can stay blank.
5+
#
6+
# Do not commit real values from .env or generated platform config files.
7+
8+
# Storefront details
9+
STOREFRONT_DOMAIN=your-store.myshopify.com
10+
STOREFRONT_ACCESS_TOKEN=your-public-storefront-access-token
11+
# Optional Apple Pay merchant identifier used by accelerated checkout flows.
12+
STOREFRONT_MERCHANT_IDENTIFIER=
13+
14+
# Storefront API version
15+
API_VERSION=2026-04
16+
17+
# Customer Account API (optional)
18+
CUSTOMER_ACCOUNT_API_CLIENT_ID=
19+
CUSTOMER_ACCOUNT_API_SHOP_ID=
20+
CUSTOMER_ACCOUNT_API_VERSION=2026-04
21+
22+
# Buyer identity defaults used by sample apps
23+
EMAIL=checkout-kit@example.com
24+
ADDRESS_1=650 King Street
25+
ADDRESS_2=Shopify HQ
26+
CITY=Toronto
27+
COMPANY=Shopify
28+
COUNTRY=CA
29+
FIRST_NAME=Evelyn
30+
LAST_NAME=Hartley
31+
PROVINCE=ON
32+
ZIP=M5V 1M7
33+
PHONE=+14165550100

.github/CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ dev check
5050

5151
Platform-scoped commands are available as `dev android <command>`, `dev swift <command>`, and `dev react-native <command>` (or `dev rn`). Protocol schema/model commands are available as `dev protocol <command>`. For cross-platform changes, use `dev lint`, `dev test`, `dev check`, `dev format`, and `dev build`.
5252

53+
Sample app storefront configuration is generated from the repo-root `.env`.
54+
Shopify employees get this through `dev up`. External contributors can copy
55+
`.env.example` to `.env`, fill in local storefront values, then run
56+
`scripts/setup_storefront_env` from the repo root.
57+
5358
---
5459

5560
## Swift (`platforms/swift/`)

.github/workflows/android-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ jobs:
4747
cache: 'gradle'
4848

4949
- name: Setup sample app environment
50-
run: cp .env.example .env
51-
working-directory: platforms/android/samples/MobileBuyIntegration
50+
run: ${{ github.workspace }}/scripts/setup_storefront_env --skip-optional-prompts
51+
env:
52+
STOREFRONT_DOMAIN: example.myshopify.com
53+
STOREFRONT_ACCESS_TOKEN: test-token
5254

5355
- name: Build Sample App
5456
run: ./gradlew assembleDebug

.github/workflows/rn-test-android.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ jobs:
5454
env:
5555
GRADLE_OPTS: -Xmx4g -XX:MaxMetaspaceSize=768m
5656
JAVA_HOME: ${{ steps.setup-java.outputs.path }}
57+
STOREFRONT_DOMAIN: example.myshopify.com
58+
STOREFRONT_ACCESS_TOKEN: test-token
5759
run: |
5860
echo "JAVA_HOME: $JAVA_HOME"
5961
java -version
6062
javac -version
61-
echo "STOREFRONT_DOMAIN=myshopify.com" > sample/.env
63+
${{ github.workspace }}/scripts/setup_storefront_env --skip-optional-prompts
6264
pnpm module build
6365
pnpm sample test:android --no-daemon

.github/workflows/swift-build-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ jobs:
1313
with:
1414
test-path: ./Scripts/build_samples
1515
job-name: Build Sample Apps
16+
setup-storefront-env: true

.github/workflows/swift-test-workflow.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
required: false
99
type: string
1010
default: Run
11+
setup-storefront-env:
12+
required: false
13+
type: boolean
14+
default: false
1115

1216
permissions:
1317
contents: read
@@ -68,5 +72,12 @@ jobs:
6872
echo "CURRENT_SIMULATOR_UUID=$CURRENT_SIMULATOR_UUID" >> $GITHUB_ENV
6973
echo ""
7074
75+
- name: Setup sample app storefront configuration
76+
if: ${{ inputs.setup-storefront-env }}
77+
env:
78+
STOREFRONT_DOMAIN: example.myshopify.com
79+
STOREFRONT_ACCESS_TOKEN: test-token
80+
run: ${{ github.workspace }}/scripts/setup_storefront_env --skip-optional-prompts
81+
7182
- name: Run Tests
7283
run: ${{ inputs.test-path }}

platforms/android/samples/MobileBuyIntegration/.env.example

Lines changed: 0 additions & 14 deletions
This file was deleted.

platforms/android/samples/MobileBuyIntegration/README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ Do not edit files in `app/build/generated/source/apollo/` by hand. Update `.grap
6666

6767
## Setup
6868

69-
From this directory:
69+
From the repo root:
7070

7171
```sh
7272
cp .env.example .env
73+
scripts/setup_storefront_env
7374
```
7475

75-
Edit `.env`:
76+
Edit the repo-root `.env`:
7677

7778
```text
7879
STOREFRONT_DOMAIN=your-store.myshopify.com
@@ -84,19 +85,21 @@ Optional values enable Customer Account API and buyer identity demo flows:
8485

8586
```text
8687
CUSTOMER_ACCOUNT_API_CLIENT_ID=your-client-id
87-
CUSTOMER_ACCOUNT_API_REDIRECT_URI=shop.<shop id>.app://callback
88-
CUSTOMER_ACCOUNT_API_GRAPHQL_BASE_URL=https://shopify.com/<shop id>/account/customer/api/<api version>/graphql
89-
CUSTOMER_ACCOUNT_API_AUTH_BASE_URL=https://shopify.com/authentication/<shop id>
90-
PREFILL_EMAIL=test.buyer@example.com
91-
PREFILL_PHONE=+16135550123
88+
CUSTOMER_ACCOUNT_API_SHOP_ID=your-shop-id
89+
CUSTOMER_ACCOUNT_API_VERSION=2026-04
90+
EMAIL=test.buyer@example.com
91+
PHONE=+16135550123
9292
```
9393

94+
The setup script generates this sample's local `.env`.
95+
9496
Open the project in Android Studio, sync Gradle, then build and run.
9597

9698
## Updating the Storefront API version
9799

98-
1. Update `API_VERSION` in `.env`.
99-
2. Download the schema with Rover. This introspects your store's Storefront API and writes `schema.graphqls` into `app/src/main/graphql/`.
100+
1. Update `API_VERSION` in the repo-root `.env`.
101+
2. Run `scripts/setup_storefront_env` from the repo root.
102+
3. Download the schema with Rover. This introspects your store's Storefront API and writes `schema.graphqls` into `app/src/main/graphql/`.
100103

101104
```sh
102105
rover graph introspect \
@@ -105,7 +108,7 @@ Open the project in Android Studio, sync Gradle, then build and run.
105108
--output "app/src/main/graphql/schema.graphqls"
106109
```
107110

108-
3. Update GraphQL operations in `app/src/main/graphql/` if the schema changed. For example, add a product field to `FetchProducts.graphql` before regenerating types:
111+
4. Update GraphQL operations in `app/src/main/graphql/` if the schema changed. For example, add a product field to `FetchProducts.graphql` before regenerating types:
109112

110113
```graphql
111114
query FetchProducts(...) {

platforms/android/samples/MobileBuyIntegration/app/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,40 @@ def loadProperties() {
2020

2121
def properties = loadProperties()
2222

23+
def propertyOrDefault = { String key, String defaultValue ->
24+
def value = properties.getProperty(key)
25+
return value?.trim() ? value.trim() : defaultValue
26+
}
27+
2328
// Storefront API
2429
def storefrontDomain = properties.getProperty("STOREFRONT_DOMAIN")
2530
def accessToken = properties.getProperty("STOREFRONT_ACCESS_TOKEN")
2631
def apiVersion = properties.getProperty("API_VERSION", "2026-04")
2732

2833
// Customer Account API
2934
def customerAccountApiClientId = properties.getProperty("CUSTOMER_ACCOUNT_API_CLIENT_ID")
35+
def customerAccountApiShopId = properties.getProperty("CUSTOMER_ACCOUNT_API_SHOP_ID")
36+
def customerAccountApiVersion = propertyOrDefault("CUSTOMER_ACCOUNT_API_VERSION", "unstable")
3037
def customerAccountApiRedirectUri = properties.getProperty("CUSTOMER_ACCOUNT_API_REDIRECT_URI")
3138

3239
def customerAccountApiGraphQLBaseUrl = properties.getProperty("CUSTOMER_ACCOUNT_API_GRAPHQL_BASE_URL")
3340
def customerAccountApiAuthBaseUrl = properties.getProperty("CUSTOMER_ACCOUNT_API_AUTH_BASE_URL")
3441

42+
if (!customerAccountApiRedirectUri && customerAccountApiShopId) {
43+
customerAccountApiRedirectUri = "shop.${customerAccountApiShopId}.app://callback"
44+
}
45+
46+
if (!customerAccountApiGraphQLBaseUrl && customerAccountApiShopId) {
47+
customerAccountApiGraphQLBaseUrl = "https://shopify.com/${customerAccountApiShopId}/account/customer/api/${customerAccountApiVersion}/graphql"
48+
}
49+
50+
if (!customerAccountApiAuthBaseUrl && customerAccountApiShopId) {
51+
customerAccountApiAuthBaseUrl = "https://shopify.com/authentication/${customerAccountApiShopId}"
52+
}
53+
3554
// Demo buyer identity (prefill toggle in Settings)
36-
def prefillEmail = properties.getProperty("PREFILL_EMAIL", "test.buyer@example.com")
37-
def prefillPhone = properties.getProperty("PREFILL_PHONE", "+16135550123")
55+
def prefillEmail = properties.getProperty("EMAIL", properties.getProperty("PREFILL_EMAIL", "test.buyer@example.com"))
56+
def prefillPhone = properties.getProperty("PHONE", properties.getProperty("PREFILL_PHONE", "+14165550100"))
3857

3958
if (!storefrontDomain || !accessToken) {
4059
println("**** Please add a .env file with STOREFRONT_DOMAIN and STOREFRONT_ACCESS_TOKEN set *****")

platforms/android/samples/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ This directory contains Android sample apps for Checkout Kit.
88

99
## Setup
1010

11-
From `platforms/android/samples/MobileBuyIntegration`:
11+
From the repo root:
1212

1313
```sh
1414
cp .env.example .env
15+
scripts/setup_storefront_env
1516
```
1617

17-
Fill in:
18+
Fill `.env` with:
1819

1920
- `STOREFRONT_DOMAIN`
2021
- `STOREFRONT_ACCESS_TOKEN`
2122
- `API_VERSION`
2223
- Optional Customer Account API values
2324
- Optional demo buyer identity values
2425

26+
The setup script generates `platforms/android/samples/MobileBuyIntegration/.env`.
27+
2528
Open `MobileBuyIntegration` in Android Studio, sync Gradle, then build and run the `app` target.

0 commit comments

Comments
 (0)