![[Pasted image 20240701172445.png]]
This application provides a basic e-commerce site integrated with commercetools Payment Connector and Stripe Web Elements. It retrieves a product catalog directly from commercetools and uses commercetools' cart API when a user adds a new item to the cart. The Stripe Payment Element and Express Checkout are embedded through the Payment Connector.
The following Stripe Web Elements are used directly from Stripe:
Additionally, the Stripe Payment Element and Express Checkout Element are embedded through the Payment Connector Integration found in the Stripe commercetools Connect App GitHub repository.
When a user chooses to checkout, the e-commerce platform will:
- Create the Link Authentication Element and Address Element to collect complete billing and shipping addresses.
- Add the shipping information to the cart in commercetools.
- Utilize the Payment Connector integration for payment components, namely the Stripe Payment Element and Express Checkout Element.
After the user submits the payment:
- The embedded components will call the Payment Connector processor responsible of creating the payment intent on Stripe.
- The payment intent will contain metadata including the cart ID, commercetools project ID, and payment ID created in commercetools.
- The payment created in commercetools will have the payment intent ID from Stripe in the
interfaceId
field.
All Stripe webhooks will be sent to the Payment Connector backend. The Payment Connector will then:
- Process the events.
- Update the commercetools status accordingly.
- Link Authentication Element (e-commerce site integrated)
- Address Element (e-commerce site integrated)
- Stripe Payment Element (from Payment Connector integration)
- Express Checkout Element (from Payment Connector integration)
To enable the Apple Pay button in the payment element component, your website must have the correct domain association file hosted. This file is crucial for Apple to verify that you control the domain where Apple Pay will be used.
- Domain Association File: Stripe generates a domain association file named
apple-developer-merchantid-domain-association
. You need to host this file at the following URL on your website:https://yourwebsite.com/.well-known/apple-developer-merchantid-domain-association
- Replace
https://yourwebsite.com
with your actual domain.
- Verification Process: Once the file is correctly hosted, Stripe will automatically attempt to verify your domain with Apple. This verification is necessary for Apple Pay to function correctly on your site.
- Updating the File: Keep in mind that this file has an expiration date. If you receive an error about an outdated file, you'll need to download the latest version from Stripe and replace the old file on your server. These steps ensure that the Apple Pay button is displayed and functional when using the payment element on your site.
For a comprehensive step-by-step guide on installing both the Payment Connector and the example e-commerce site, please refer to the PDF guide linked below. This guide includes detailed instructions, screenshots, and troubleshooting tips to ensure a smooth setup process.
Download Installation Guide PDF
To install the necessary packages, run:
npm install
Note: Please make sure to have the Payment Connector from the commercetools marketplace and deploy the Payment Connector URL. To install it, you will need to run the example site and the Payment Connector project locally or add the Payment Connector from the commercetools marketplace. Further information on how to run the Payment Connector can be found in the Payment Connector documentation.
To start the app server, run the following command from the root directory:
npm start
To run the app, navigate to the client directory and start it:
cd client
npm start
When running locally, copy /.env-sample to /.env and update it with your details:
cp .env-sample .env
Variable | Description | Example |
---|---|---|
REACT_APP_SK | Stripe Private Key | sktest**** |
REACT_APP_ADMIN | Stripe Account ID | actt_**** |
REACT_APP_PORT | Port to run the server | 8081 |
REACT_APP_BASE_URL | Base URL of the server | http://localhost:8081 |
REACT_APP_CT_PROJECT_KEY | commercetools Project Key | * |
REACT_APP_CT_CLIENT_ID | commercetools Client ID | * |
REACT_APP_CT_SECRET | commercetools Secret Key | * |
REACT_APP_CT_API_URL | commercetools API URL | https://api.europe-west1.gcp.commercetools.com |
REACT_APP_CT_AUTH_URL | commercetools Auth URL | https://auth.europe-west1.gcp.commercetools.com |
Similarly, copy /client/.env-sample to /client/.env and update it with your details:
cp client/.env-sample client/.env
Variable | Description | Example |
---|---|---|
REACT_APP_PK | Stripe Publishable Key | pktest**** |
REACT_APP_BASE_URL | Base URL of the server example site | http://localhost:8081 |
REACT_APP_PROJECT_KEY | commercetools Project Key | * |
REACT_APP_CTP_CLIENT_ID | commercetools Client ID | * |
REACT_APP_CLIENT_SECRET | commercetools Secret Key | * |
REACT_APP_SESSION_URL | commercetools API session url | https://session.us-central1.gcp.commercetools.com |
REACT_APP_AUTH_URL | commercetools Auth URL | https://auth.europe-west1.gcp.commercetools.com |
REACT_APP_ENABLER_BUILD_URL | URL of the Connector enabler deployed in commercetools | https://assets-307a12410-95f0-4c70-8d69-75ca21sd28ad4c.assets.us-central1.gcp.preview.commercetools.app/connector-enabler.es.js |
REACT_APP_PROCESOR_URL | URL of the Connector Processor deployed in commercetools | https://service-1d71326-3fd2-4bd5-b7c4-a12134.us-central1.gcp.preview.commercetools.app |
Below is a detailed sequence diagram of the calls used inside the checkout example:
When creating a new API client you will need to set the following Scopes:
- Customers
- Orders
- Payments
- Products
- Categories
- Customers
- Orders
- Payments
- Products (all)
- Products (published)
- Orders
- Payments
- Profile
- Shopping Lists
- Create Anonymous Token