Skip to content

Commit 388c701

Browse files
committed
feat: EP payments configured correctly
1 parent 2538fe5 commit 388c701

File tree

6 files changed

+397
-88
lines changed

6 files changed

+397
-88
lines changed

examples/spa-elastic-path-payments/README.md

Lines changed: 118 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,34 @@
22

33
This example showcases how to implement **Elastic Path payment gateway processing** with **Elastic Path Commerce Cloud** in a Single-Page Application (SPA) written in React. It builds on the `spa-guest-checkout` example, although omits a number of its features.
44

5-
> **Heads-up:** This project focuses **exclusively** on Elastic Path payment processing workflows. It creates minimal test orders solely to demonstrate payment handling—cart management, product catalogs, customer accounts, etc. are kept deliberately simple and are not the focus.
5+
> **Heads-up:** This project focuses **exclusively** on Elastic Path payment processing workflows using **Stripe**. It creates minimal test orders solely to demonstrate payment handling—cart management, product catalogs, customer accounts, etc. are kept deliberately simple and are not the focus.
66
77
Key capabilities demonstrated:
88

99
1. **Test Order Creation** – automatically creates incomplete orders with test products for payment processing demonstration.
10-
2. **Elastic Path Payment Gateway** – processes payments using Elastic Path's payment gateway for scenarios like:
10+
2. **Elastic Path Payment Gateway** – processes payments using Elastic Path's payment gateway powered by Stripe for scenarios like:
1111
• Credit card payments
12-
• Digital wallet payments
12+
• Digital wallet payments (Apple Pay, Google Pay)
1313
• Alternative payment methods
14-
Custom payment workflows
14+
Secure payment processing
1515
3. **Order State Management** – converts incomplete orders to complete orders after Elastic Path payment processing.
1616
4. **Payment Status Tracking** – displays real-time order and payment status updates with proper UI indicators.
17+
5. **Stripe Payment Element** – Uses Stripe's recommended Payment Element for secure payment collection.
1718

1819
> The example purposefully uses simplified order creation and minimal product selection to keep the focus on Elastic Path payment mechanics.
1920
2021
---
2122

23+
## Prerequisites
24+
25+
Before running this example, you'll need:
26+
27+
1. **Elastic Path Commerce Cloud Store** with Elastic Path Payments enabled
28+
2. **Stripe Account** - Elastic Path Payments is powered by Stripe
29+
3. **Stripe Publishable Key** - Get this from your Stripe Dashboard
30+
31+
---
32+
2233
## Project Structure
2334

2435
```
@@ -30,7 +41,7 @@ spa-elastic-path-payments/
3041
│ │ ├── AppHeader.tsx # Authentication status & cart ID display
3142
│ │ ├── StepIndicator.tsx # Multi-step progress indicator
3243
│ │ ├── OrderCreator.tsx # Creates test orders for payment demo
33-
│ │ ├── ElasticPathPayment.tsx # Elastic Path payment processing form
44+
│ │ ├── ElasticPathPayment.tsx # Elastic Path payment processing with Stripe
3445
│ │ ├── OrderStatus.tsx # Order & payment status display
3546
│ │ └── OrderCompleteView.tsx # Success screen with reset functionality
3647
│ ├── hooks/
@@ -61,23 +72,34 @@ This generates an incomplete order ready for Elastic Path payment processing.
6172

6273
### 2. Elastic Path Payment Processing
6374

64-
`ElasticPathPayment` captures payment details and processes them:
75+
`ElasticPathPayment` captures payment details and processes them using Stripe:
6576

6677
```tsx
67-
const paymentData = {
68-
gateway: "manual",
69-
method: "purchase",
70-
// if the user supplies a reference
71-
paymentmethod_meta: {
72-
custom_reference: paymentReference,
73-
name: "Elastic Path Payment",
78+
// 1. Initialize payment with Elastic Path
79+
const paymentResponse = await paymentSetup({
80+
path: { orderID: order.id },
81+
body: {
82+
data: {
83+
gateway: "elastic_path_payments_stripe",
84+
method: "purchase",
85+
payment: {
86+
currency: order.meta?.display_price?.with_tax?.currency,
87+
amount: order.meta?.display_price?.with_tax?.amount,
88+
},
89+
},
7490
},
75-
}
91+
})
7692

77-
await paymentSetup({
78-
path: { orderID: order.id },
79-
body: { data: paymentData },
93+
// 2. Confirm payment with Stripe
94+
const { error, paymentIntent } = await stripe.confirmPayment({
95+
elements,
96+
clientSecret,
97+
confirmParams: { return_url: window.location.origin },
98+
redirect: "if_required",
8099
})
100+
101+
// 3. Confirm with Elastic Path
102+
await confirmOrder({ path: { orderID: order.id } })
81103
```
82104

83105
### 3. Status Display
@@ -94,21 +116,94 @@ await paymentSetup({
94116
pnpm i # or npm install / yarn
95117
```
96118

97-
2. **Set environment variables** – create a `.env` file in `examples/spa-elastic-path-payments` (or export in your shell):
119+
2. **Set environment variables** – create a `.env` file in `examples/spa-elastic-path-payments`:
98120

99-
```
121+
```env
122+
# Elastic Path Commerce Cloud
100123
VITE_APP_EPCC_ENDPOINT_URL=https://YOUR_EP_DOMAIN.elasticpath.com
101124
VITE_APP_EPCC_CLIENT_ID=YOUR_CLIENT_ID
125+
126+
# Stripe (required for Elastic Path Payments)
127+
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_YOUR_STRIPE_PUBLISHABLE_KEY
102128
```
103129

104-
3. **Start Vite dev server**:
130+
**Important**: Make sure you're using your **Stripe publishable key** (starts with `pk_test_` for test mode or `pk_live_` for live mode).
131+
132+
3. **Configure Elastic Path Payments** in your Elastic Path store:
133+
134+
- Enable Elastic Path Payments in your store settings
135+
- Connect your Stripe account
136+
- Ensure the payment gateway is configured properly
137+
138+
4. **Start Vite dev server**:
105139

106140
```bash
107141
pnpm --filter spa-elastic-path-payments dev
108142
```
109143

144+
The app will be available at `http://localhost:5173`
145+
146+
---
147+
148+
## Environment Variables Reference
149+
150+
| Variable | Required | Description |
151+
| ----------------------------- | -------- | --------------------------------------------------- |
152+
| `VITE_APP_EPCC_ENDPOINT_URL` || Your Elastic Path Commerce Cloud store URL |
153+
| `VITE_APP_EPCC_CLIENT_ID` || Your Elastic Path store's client ID |
154+
| `VITE_STRIPE_PUBLISHABLE_KEY` || Your Stripe publishable key (from Stripe Dashboard) |
155+
156+
---
157+
158+
## Payment Flow
159+
160+
1. **Order Creation**: App creates a test order with sample products
161+
2. **Payment Initialization**: Call Elastic Path to setup payment with `elastic_path_payments_stripe` gateway
162+
3. **Stripe Elements**: Render Stripe Payment Element for secure payment collection
163+
4. **Payment Submission**: Submit payment form using Stripe Elements
164+
5. **Payment Confirmation**: Confirm payment with Stripe using client secret
165+
6. **Order Confirmation**: Confirm completed payment with Elastic Path
166+
7. **Success**: Display payment success and order completion
167+
168+
---
169+
170+
## Troubleshooting
171+
172+
### Common Issues
173+
174+
**"No client secret received"**
175+
176+
- Ensure Elastic Path Payments is enabled in your store
177+
- Verify your Stripe account is connected to Elastic Path
178+
- Check that the payment gateway configuration is correct
179+
180+
**"Payment system not ready"**
181+
182+
- Verify `VITE_STRIPE_PUBLISHABLE_KEY` is set correctly
183+
- Ensure you're using the publishable key (not secret key)
184+
- Check browser console for Stripe loading errors
185+
186+
**Payment fails**
187+
188+
- Check Stripe Dashboard for failed payment details
189+
- Verify test card numbers if using test mode
190+
- Ensure order amount and currency are valid
191+
192+
**404 Resource Not Found (Inventory/Products)**
193+
194+
- Ensure you have products in your Elastic Path Commerce Cloud store
195+
- Make sure products are published and not just in draft state
196+
- Check that your store has at least one simple product (not just base products with variants)
197+
- Verify your `VITE_APP_EPCC_ENDPOINT_URL` and `VITE_APP_EPCC_CLIENT_ID` are correct
198+
199+
**"No products available in your store"**
200+
201+
- Add at least one product to your Elastic Path Commerce Cloud store
202+
- Ensure the product is published and available
203+
- If you only have base products, create some child products or simple products
204+
110205
## Learn More
111206

112-
- [Elastic Path Payment Gateway Documentation](https://elasticpath.dev/docs/api/carts/cart-management)
113-
- [Order Management with Elastic Path](https://elasticpath.dev/docs/api/carts/cart-management)
114-
- [Payment Processing APIs](https://elasticpath.dev/docs/api/carts/cart-management)
207+
- [Elastic Path Payments Documentation](https://elasticpath.dev/docs/developer-tools/fundamentals/checkout/payments/elastic-path-payments/implement-payments)
208+
- [Stripe Payment Element Guide](https://stripe.com/docs/payments/payment-element)
209+
- [Elastic Path Commerce Cloud Docs](https://elasticpath.dev/docs)

examples/spa-elastic-path-payments/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
},
1212
"dependencies": {
1313
"@epcc-sdk/sdks-shopper": "workspace:*",
14+
"@stripe/react-stripe-js": "^2.4.0",
15+
"@stripe/stripe-js": "^2.2.2",
1416
"react": "^18.3.1",
1517
"react-dom": "^18.3.1"
1618
},

examples/spa-elastic-path-payments/pnpm-lock.yaml

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/spa-elastic-path-payments/src/App.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useState } from "react"
22
import { type OrderResponse } from "@epcc-sdk/sdks-shopper"
3+
import { Elements } from "@stripe/react-stripe-js"
4+
import { loadStripe } from "@stripe/stripe-js"
35
import { AppHeader } from "./components/AppHeader"
46
import { StepIndicator } from "./components/StepIndicator"
57
import { OrderCreator } from "./components/OrderCreator"
@@ -9,6 +11,14 @@ import { OrderCompleteView } from "./components/OrderCompleteView"
911
import { useAppInitialization } from "./hooks/useAppInitialization"
1012
import { useOrderCreation } from "./hooks/useOrderCreation"
1113

14+
// Initialize Stripe with account ID (like payments example)
15+
const stripePromise = loadStripe(
16+
import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY || "",
17+
{
18+
stripeAccount: import.meta.env.VITE_STRIPE_ACCOUNT_ID || "",
19+
},
20+
)
21+
1222
function App() {
1323
const [currentStep, setCurrentStep] = useState<
1424
"create" | "payment" | "complete"
@@ -61,11 +71,26 @@ function App() {
6171
{currentStep === "payment" && order && (
6272
<div className="space-y-6">
6373
<OrderStatus order={order} />
64-
<ElasticPathPayment
65-
order={order}
66-
onPaymentComplete={handlePaymentComplete}
67-
onError={clearError}
68-
/>
74+
<Elements
75+
stripe={stripePromise}
76+
options={{
77+
mode: "payment",
78+
currency:
79+
order.meta?.display_price?.with_tax?.currency?.toLowerCase() ||
80+
"usd",
81+
amount: order.meta?.display_price?.with_tax?.amount || 100,
82+
payment_method_types: ["card"],
83+
appearance: {
84+
theme: "stripe",
85+
},
86+
}}
87+
>
88+
<ElasticPathPayment
89+
order={order}
90+
onPaymentComplete={handlePaymentComplete}
91+
onError={clearError}
92+
/>
93+
</Elements>
6994
</div>
7095
)}
7196

0 commit comments

Comments
 (0)