### Install dependencies with npm install Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/react-cra/README.md Run from the React client directory to install required dependencies before starting the app. ```sh npm install ``` -------------------------------- ### Install dependencies and run server (Stripe CLI) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/python/README.md Run these commands after creating the sample with `stripe samples create`. Installs Python dependencies and starts the Flask server on http://localhost:4242. ```bash pip install -r requirements.txt python server.py ``` -------------------------------- ### Start local server Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node-typescript/README.md Compile and run the TypeScript example. ```bash npm run start # Compiles and runs the TypeScript example. ``` -------------------------------- ### Install dependencies and start the server Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node/README.md Commands to install npm dependencies and start the Express server. ```bash npm install npm start ``` -------------------------------- ### Start the React app with npm start Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/react-cra/README.md Starts the React development server on localhost:3000. The backend servers run on localhost:4242, and API requests are proxied via the 'proxy' setting in package.json. ```sh npm start ``` -------------------------------- ### Start the HTML client with npx serve Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/html/README.md Run this command to start the HTML server on localhost:3000. This client runs independently of the backend server, but a backend server is required for the front-end to work. ```sh npx serve -p 3000 ``` -------------------------------- ### Install dependencies and start server (Stripe CLI) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/php/README.md Run these commands after creating the sample with the Stripe CLI to install dependencies and start the PHP server. ```bash composer install composer start ``` -------------------------------- ### Run Node server Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/README.md Navigate to the server/node folder, install dependencies, and start the server. The sample runs at localhost:4242 unless using the React client. ```sh cd server/node # there's a README in this folder with instructions npm install npm start ``` -------------------------------- ### Install dependencies with Composer Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/php/README.md Run composer install to set up project dependencies. ```bash composer install ``` -------------------------------- ### Start the app and open Expo dev tools Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/react-native-expo/README.md Run this command to start the React Native Expo Go client and open Expo development tools. ```sh yarn start ``` -------------------------------- ### Install dependencies and run server (Stripe CLI) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/ruby/README.md Run these commands after creating the sample with `stripe samples create` to install dependencies and start the Sinatra server. ```bash bundle install ruby server.rb ``` -------------------------------- ### Run the server locally with Composer Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/php/README.md Start the PHP server using Composer. ```bash composer start ``` -------------------------------- ### Setup development environment for custom-payment-flow with ruby and html Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Generates Docker Compose settings for a sample app with the specified server and client apps. Example uses ruby server and html client. ```bash ./sample-ci/setup_development_environment custom-payment-flow ruby ../../client/html ruby:3.1 ``` -------------------------------- ### Start the sample app Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Starts the sample app using Docker Compose with the frontend profile. After starting, open http://localhost:3000. ```bash docker compose --profile=frontend up ``` -------------------------------- ### Install dependencies with yarn Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/react-native-expo/README.md Run this command from the React Native (Expo) client directory to install required dependencies. ```sh yarn ``` -------------------------------- ### Run the Go server Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/go/README.md Starts the server from the server directory. After running, access the demo at localhost:4242 for the HTML client or localhost:3000 for React. ```sh go run server.go ``` -------------------------------- ### Run the .NET application Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/dotnet/README.md Command to start the .NET Core server. After running, access the demo at localhost:4242 if using the HTML client. ```bash dotnet run ``` -------------------------------- ### Run the packaged jar Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/java/README.md Starts the Java server using the built jar. The main class is com.stripe.sample.Server. ```bash java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server ``` -------------------------------- ### Install dependencies Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/README.md Install the required Python packages from requirements.txt. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Go dependencies with go mod tidy and vendor Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/go/README.md Run from the server directory containing server.go to fetch and vendor dependencies. ```sh go mod tidy go mod vendor ``` -------------------------------- ### Run the Node server Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Commands to install dependencies and start the Node server. The server runs at `localhost:4242` (or `localhost:3000` if using the React client). ```bash cd server/node # There's a README in this folder with instructions to run the server and how to enable Stripe Tax. npm install npm start ``` -------------------------------- ### Setup development environment for custom-payment-flow with node and react-cra Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Generates Docker Compose settings for a sample app with the specified server and client apps. Example uses node server and react-cra client. ```bash ./sample-ci/setup_development_environment custom-payment-flow node ../../client/react-cra node:lts ``` -------------------------------- ### Copy .env.example to server folder Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/README.md Copy the .env.example file into a .env file in the specific server language folder. Example shown for the Node server. ```sh cp .env.example custom-payment-flow/server/node/.env ``` -------------------------------- ### Start React dev server (cloned repo) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/node/README.md Run these commands from the client directory to start the React dev server. Requires DOMAIN=http://localhost:3000 in .env. ```bash cd ../../client/react-cra npm install npm start ``` -------------------------------- ### Clone the Repository Source: https://github.com/stripe-samples/accept-a-payment/blob/main/README.md Clone the accept-a-payment repository from GitHub to get started with the sample integrations. ```sh git clone https://github.com/stripe-samples/accept-a-payment ``` -------------------------------- ### Example .env file Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Environment variables required for the sample: Stripe keys, price ID, static directory, and domain. ```sh STRIPE_PUBLISHABLE_KEY= STRIPE_SECRET_KEY= PRICE= STATIC_DIR=../../client/html DOMAIN=http://localhost:4242 ``` -------------------------------- ### Install dependencies with bundle install Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/ruby/README.md Installs required Ruby dependencies for the Sinatra application. ```bash bundle install ``` -------------------------------- ### Run the server with ruby server.rb Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/ruby/README.md Starts the local Sinatra server. After running, access the application at http://localhost:4242. ```bash ruby server.rb ``` -------------------------------- ### Start React dev server (Stripe CLI) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/node/README.md Run these commands from the client directory to start the React dev server. Requires DOMAIN=http://localhost:3000 in .env. ```bash cd ../client npm install npm start ``` -------------------------------- ### Run the server locally with PHP built-in server Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/php/README.md Alternative way to start the server by running PHP's built-in web server from the public directory. ```bash cd public php -S 127.0.0.1:4242 ``` -------------------------------- ### Example .env file Source: https://github.com/stripe-samples/accept-a-payment/blob/main/payment-element/README.md Environment variables required for the sample. Replace the placeholders with your Stripe API keys. STATIC_DIR points to the client files and can be left as is unless you move the server. ```sh STRIPE_PUBLISHABLE_KEY= STRIPE_SECRET_KEY= STATIC_DIR=../../client/html ``` -------------------------------- ### Start ngrok Tunnel Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/VIDEOS.md Starts an ngrok tunnel to the local server on port 4242, providing a public HTTPS URL for testing Apple Pay. ```bash ngrok http 4242 ``` -------------------------------- ### Example .env file Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/README.md Environment variables required to run the sample. Replace the publishable and secret keys with your own from the Stripe dashboard. ```sh STRIPE_PUBLISHABLE_KEY= STRIPE_SECRET_KEY= STATIC_DIR=../../client/html DOMAIN=http://localhost:4242 ``` -------------------------------- ### Run Playwright tests Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Installs dependencies and runs a specific Playwright test file. The npm install is needed only the first time. ```bash docker compose exec playwright npm install # needed for the first time only docker compose exec playwright npm run test -- playwright/custom-payment-flow-e2e-react-cra.spec.ts ``` -------------------------------- ### Run the server locally Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/php/README.md Start the PHP built-in server from the public directory. The demo will be available at localhost:4242. ```sh cd public php -S localhost:4242 ``` -------------------------------- ### Run server with Maven (Stripe CLI) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/java/README.md Starts the Spark server after compiling. Used when the project was created via `stripe samples create`. ```bash mvn compile exec:java ``` -------------------------------- ### Run the server with dotnet run Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/dotnet/README.md Starts the ASP.NET Core server. Used after creating the sample with the Stripe CLI or after cloning the repo and setting up the .env file. ```bash dotnet run ``` -------------------------------- ### Export Environment Variables for Dev Containers Source: https://github.com/stripe-samples/accept-a-payment/blob/main/README.md After launching a Dev Container or Codespace, export the required Stripe API keys as environment variables before starting the server. ```sh export STRIPE_PUBLISHABLE_KEY=pk_test_... export STRIPE_SECRET_KEY=sk_test_... ``` -------------------------------- ### Run ngrok with host header rewrite Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/VIDEOS.md Starts an ngrok tunnel for local development, rewriting the host header to allow Apple Pay domain verification. Requires the React client on port 3000 and server on port 4242. ```bash ngrok http --host-header=rewrite 3000 ``` -------------------------------- ### Export COMPOSE_FILE environment variable Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Sets the Docker Compose file configuration for the sample app environment. Required before starting the sample app. ```bash export COMPOSE_FILE=docker-compose.yml:docker-compose.override.yml:docker-compose.playwright.yml ``` -------------------------------- ### Enable Stripe Tax in Server.java Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/java/README.md Uncomment this line in Server.java to enable automatic tax calculation during Checkout. Requires prior Stripe Tax setup and updated products/prices. ```java // .setAutomaticTax(SessionCreateParams.AutomaticTax.builder().setEnabled(true).build()) ``` -------------------------------- ### Enable Stripe Tax in server.py Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/python/README.md Uncomment this line in server.py to enable automatic tax calculation during checkout. Requires prior Stripe Tax setup and products/prices updated with tax behavior. ```python # automatic_tax={'enabled': True}, ``` -------------------------------- ### Enable Stripe Tax in server.go Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/go/README.md Uncomment this line in server.go to enable automatic sales tax calculation during checkout. Requires prior Stripe Tax setup and products/prices updated with tax behavior and optionally tax codes. ```go // AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)}, ``` -------------------------------- ### Example Price object from Stripe API Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Shows the JSON response from the Stripe API when creating a Price. Use the `id` field (e.g., `price_1Hh1ZeCZ6qsJgndJaX9fauRl`) to set the `PRICE` environment variable. ```json { "id": "price_1Hh1ZeCZ6qsJgndJaX9fauRl", "object": "price", "active": true, "billing_scheme": "per_unit", "created": 1603841250, "currency": "usd", "livemode": false, "lookup_key": null, "metadata": { }, "nickname": null, "product": "prod_IHalmba0p05ZKD", "recurring": null, "tiers_mode": null, "transform_quantity": null, "type": "one_time", "unit_amount": 500, "unit_amount_decimal": "500" } ``` -------------------------------- ### Enable Stripe Tax in create-checkout-session.php Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/php/README.md Uncomment this line in the `create-checkout-session.php` file to enable automatic tax calculation during checkout. Requires prior Stripe Tax setup. ```php // 'automatic_tax' => ['enabled' => true], ``` -------------------------------- ### Enable Stripe Tax in server.rb Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/ruby/README.md Commented-out line in server.rb. Uncomment to automatically calculate sales tax during checkout. Requires prior Stripe Tax setup and updated products/prices. ```ruby # automatic_tax: { enabled: true }, ``` -------------------------------- ### Enable Stripe Tax in server.js Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/node/README.md Commented-out code in server.js. Uncomment this line to automatically calculate sales tax during checkout. Requires prior Stripe Tax setup and products/prices updated with tax behavior. ```javascript // automatic_tax: { enabled: true } ``` -------------------------------- ### Copy .env.example to server folder Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Copy the .env.example file into the server folder of your chosen language, e.g., server/node. ```sh cp .env.example prebuilt-checkout-page/server/node/.env ``` -------------------------------- ### Copy .env.example and set Stripe API keys Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/php/README.md Copy the .env.example file from the root directory to .env and replace with your Stripe API keys. ```bash cp ../../.env.example .env ``` -------------------------------- ### Build the jar with Maven Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/java/README.md Compiles the Java project into a jar file. Run from the project directory. ```bash mvn package ``` -------------------------------- ### Create sample with Stripe CLI Source: https://github.com/stripe-samples/accept-a-payment/blob/main/payment-element/README.md Use the Stripe CLI to create a sample project. Run this command and then select 'payment-element' when prompted. ```sh stripe samples create accept-a-payment ``` ```sh payment-element ``` -------------------------------- ### Create sample with Stripe CLI Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Use the Stripe CLI to create the accept-a-payment sample. Then select the prebuilt-checkout-page option. ```sh stripe samples create accept-a-payment ``` ```sh prebuilt-checkout-page ``` -------------------------------- ### Stripe CLI: Login and Create Sample Source: https://github.com/stripe-samples/accept-a-payment/blob/main/README.md Use the Stripe CLI to authenticate and create the accept-a-payment sample. Run `stripe login` before `stripe samples create`; the CLI uses your login to configure API keys and file paths in `server/.env`. ```sh stripe login stripe samples create accept-a-payment ``` -------------------------------- ### Manual .env configuration Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/server/node/README.md Create .env manually if missing, with these keys. Required for the sample to work. ```bash STRIPE_PUBLISHABLE_KEY=pk_test_... STRIPE_SECRET_KEY=sk_test_... STATIC_DIR=../client ``` -------------------------------- ### Configure .env with Stripe keys and webhook secret Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/go/README.md Required environment configuration for the Go server. Includes Stripe API keys, webhook secret for signature verification, and paths for the front-end implementation. ```yaml # Stripe API keys - see https://stripe.com/docs/development/quickstart#api-keys STRIPE_PUBLISHABLE_KEY=pk_test... STRIPE_SECRET_KEY=sk_test... # Required to verify signatures in the webhook handler. # See README on how to use the Stripe CLI to test webhooks STRIPE_WEBHOOK_SECRET=whsec_... # Path to front-end implementation. Note: PHP has it's own front end implementation. STATIC_DIR=../../client/html DOMAIN=http://localhost:4242 ``` -------------------------------- ### Create and activate virtual environment (MacOS/Unix) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/README.md Commands to create a Python virtual environment and activate it on MacOS/Unix. ```bash python3 -m venv env source env/bin/activate ``` -------------------------------- ### Directory structure of the sample Source: https://github.com/stripe-samples/accept-a-payment/blob/main/elements-with-checkout-sessions/README.md Shows the layout of the project, including client (HTML and React) and server (Node, Python, Ruby, PHP, Java, Go, .NET) directories, plus testing and configuration files. ```text . ├── client │ ├── html # Vanilla HTML/JS client │ │ ├── index.html │ │ ├── index.css │ │ ├── index.js │ │ ├── complete.html │ │ ├── complete.css │ │ └── complete.js │ └── react-cra # React client (Vite dev server) │ └── ... ├── server │ ├── node │ ├── python │ ├── ruby │ ├── php │ ├── java │ ├── go │ └── dotnet ├── testing │ └── manual-test.sh # Run all 14 server×client combinations ├── .mise.toml # Tool versions (mise install) └── .env.example # Root env template ``` -------------------------------- ### Create and activate virtual environment (Windows PowerShell) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/README.md Commands to create a Python virtual environment and activate it on Windows PowerShell. ```powershell python3 -m venv env .\env\Scripts\activate.bat ``` -------------------------------- ### Create a Price with Stripe CLI Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Create a Price with a unit amount of 500 USD and product name 'demo'. ```sh stripe prices create --unit-amount 500 --currency usd -d "product_data[name]=demo" ``` -------------------------------- ### Export and run the application (MacOS/Unix) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/README.md Set the Flask app and run the server on port 4242 for MacOS/Unix. ```bash export FLASK_APP=server.py python3 -m flask run --port=4242 ``` -------------------------------- ### Create sample with Stripe CLI Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/README.md Use the Stripe CLI to create the accept-a-payment sample. Then select the custom-payment-flow option. ```sh stripe samples create accept-a-payment ``` ```sh custom-payment-flow ``` -------------------------------- ### Create .well-known directory and copy Apple Pay domain association file Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/VIDEOS.md Creates the .well-known directory in the React client's public folder and copies the downloaded Apple Pay domain association file into it. This file is required for Apple Pay domain verification. ```bash mkdir .well-known ``` ```bash cp ~/Downloads/apple-developer-merchantid-domain-association client/public/.well-known/ ``` -------------------------------- ### Create .env file for sample repository Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Defines environment variables needed for the sample app. DOMAIN should be http://web:4242 for HTML apps and http://frontend:3000 for React/Vue apps. STRIPE_WEBHOOK_SECRET can be obtained with the command docker compose run --rm stripe. ```bash // .env STRIPE_PUBLISHABLE_KEY STRIPE_SECRET_KEY STRIPE_WEBHOOK_SECRET # docker compose run --rm stripe will display an available webhook secret DOMAIN=http://frontend:3000 # or http://web:4242 for clients/html PRICE=price_xxxx # the price ID you have ``` -------------------------------- ### Create product with tax code Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Create a product with a tax code for Stripe Tax. Use txcd_10000000 for 'General - Electronically Supplied Services'. ```sh stripe products create \ --name="demo" \ --tax-code="txcd_10000000" ``` -------------------------------- ### Create PaymentIntent endpoint in server.py Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/TRANSCRIPTS.md Adds a POST route named 'create_Payment_Intent' that creates a PaymentIntent with hardcoded amount and currency, then returns the client secret as JSON. The amount is in the smallest currency denomination (e.g., cents). ```python @app.route('/create-payment-intent', methods=['POST']) def create_payment_intent(): intent = stripe.PaymentIntent.create( amount=1099, currency='usd', ) return jsonify({'clientSecret': intent['client_secret']}) ``` -------------------------------- ### Export and run the application (Windows PowerShell) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/README.md Set the Flask app and run the server on port 4242 for Windows PowerShell. ```powershell $env:FLASK_APP=“server.py" python3 -m flask run --port=4242 ``` -------------------------------- ### Enable Stripe Tax in appsettings.json Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/dotnet/README.md Optional configuration to enable Stripe Tax for calculating sales tax, VAT, and GST. Set CalculateTax to true in the Stripe section of appsettings.json. ```json "Stripe": { "CalculateTax": true } ``` -------------------------------- ### Enable Stripe Tax Source: https://github.com/stripe-samples/accept-a-payment/blob/main/payment-element/server/python/README.md Set calcuateTax to true in server.py to enable Stripe Tax calculation for transactions. ```python calcuateTax = False ``` -------------------------------- ### Clone sample-ci repo on playwright branch Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Clones the sample-ci repository and switches to the playwright branch. Needed for setting up the development environment. ```bash git clone --branch playwright ssh://git@github.com/stripe-samples/sample-ci ``` -------------------------------- ### Copy environment variables file Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node-typescript/README.md Copy the environment variables file from the root of the repository to the current directory. ```bash cp ../../../.env.example .env ``` -------------------------------- ### Run server (API) tests Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Runs RSpec tests for custom payment flow server using the runner service. ```bash docker compose exec runner bundle exec rspec spec/custom_payment_flow_server_spec.rb ``` -------------------------------- ### curl request to create PaymentIntent Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/TRANSCRIPTS.md Sends a POST request to the local server endpoint with an empty JSON body to test PaymentIntent creation. The response is well-formed JSON containing the client secret. ```bash curl -X POST http://localhost:4242/create-payment-intent \ -H 'Content-Type: application/json' \ -d '{}' ``` -------------------------------- ### Updated curl request with payment_method_types and currency Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/TRANSCRIPTS.md Sends a POST request with a JSON body containing 'payment_method_types' and 'currency' to test the refactored endpoint. ```bash curl -X POST http://localhost:4242/create-payment-intent \ -H 'Content-Type: application/json' \ -d '{"payment_method_types": ["card"], "currency": "usd"}' ``` -------------------------------- ### Webhook forwarding ready output Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node-typescript/README.md Output from the Stripe CLI indicating webhook forwarding is ready and showing the webhook signing secret. ```bash > Ready! Your webhook signing secret is whsec_xxx ``` -------------------------------- ### Set PRICE environment variable Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/dotnet/README.md Required configuration for the sample. The PRICE variable must be set to a valid Stripe Price ID; the placeholder price_12345 will not work. ```plaintext PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Run Capybara E2E tests Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Runs RSpec tests for custom payment flow E2E using the runner service. ```bash docker compose exec runner bundle exec rspec spec/custom_payment_flow_e2e_spec.rb ``` -------------------------------- ### Authenticate Stripe CLI Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node-typescript/README.md Authenticate the Stripe CLI with your Stripe account. ```bash stripe login ``` -------------------------------- ### Create Payment Request Button and Check Availability Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/VIDEOS.md Creates a payment request button using the payment request object and checks if the payment method is available via canMakePayment. If available, mounts the button; otherwise hides it. ```javascript const prButton = elements.create('paymentRequestButton', { paymentRequest: paymentRequest, }); paymentRequest.canMakePayment().then((result) => { if (result) { prButton.mount('#payment-request-button'); } else { document.getElementById('payment-request-button').style.display = 'none'; } }); ``` -------------------------------- ### Create Payment Intent Endpoint (server.js) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node/TRANSCRIPTS.md Adds a POST /create-payment-intent endpoint that creates a PaymentIntent with hardcoded amount and currency, returning JSON with only the client_secret. Amount is in the smallest currency unit (e.g., cents). ```javascript app.post('/create-payment-intent', async (req, res) => { // Create a PaymentIntent with the order amount and currency const paymentIntent = await stripe.paymentIntents.create({ amount: 1099, currency: 'usd', }); res.send({ clientSecret: paymentIntent.client_secret, }); }); ``` -------------------------------- ### Enable Stripe Tax calculation Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node/README.md Set calcuateTax to true in server.js to enable Stripe Tax for calculating sales tax, VAT, and GST. Default is false. ```javascript calcuateTax = false ``` -------------------------------- ### Set PRICE in .env Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/php/README.md The sample requires a Price ID in the `price` config variable. Replace `price_12345` with a valid Price ID from your Stripe account. ```plaintext PRICE=price_12345 ``` -------------------------------- ### Replace proxy destination in package.json for React/Vue apps Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Updates the proxy destination to http://web:4242 in the client app's package.json. Only needed for React/Vue apps. ```bash sed -i -E 's/("proxy":\s*)"http:\/\/localhost:4242"/\1"http:\/\/web:4242"/' custom-payment-flow/client/react-cra/package.json ``` -------------------------------- ### Refactored PaymentIntent endpoint with payment_method_types and currency Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/python/TRANSCRIPTS.md Updates the endpoint to deserialize JSON from the request body, extracting 'payment_method_types' and 'currency' to allow front-end customization. This supports various payment methods and currencies. ```python @app.route('/create-payment-intent', methods=['POST']) def create_payment_intent(): data = json.loads(request.data) intent = stripe.PaymentIntent.create( amount=1099, currency=data['currency'], payment_method_types=data['payment_method_types'], ) return jsonify({'clientSecret': intent['client_secret']}) ``` -------------------------------- ### Create price with tax behavior Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/README.md Create a price with exclusive tax behavior. Replace with the product ID from the previous step. ```sh stripe prices create \ --unit-amount=500 \ --currency=usd \ --tax-behavior=exclusive \ --product= ``` -------------------------------- ### Enable Stripe Tax in Program.cs Source: https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/dotnet/README.md Commented-out code in Program.cs. Uncomment this line to automatically calculate sales tax during checkout, after setting up Stripe Tax and updating products/prices. ```csharp // AutomaticTax = new SessionAutomaticTaxOptions { Enabled = true }, ``` -------------------------------- ### Refactored Create Payment Intent Endpoint with Request Body (server.js) Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node/TRANSCRIPTS.md Refactors the endpoint to deserialize the JSON request body, extracting paymentMethodType and currency to allow dynamic configuration. Some payment method types only work with specific currencies. ```javascript app.post('/create-payment-intent', async (req, res) => { const { paymentMethodType, currency } = req.body; // Create a PaymentIntent with the order amount and currency const paymentIntent = await stripe.paymentIntents.create({ amount: 1099, currency: currency, payment_method_types: [paymentMethodType], }); res.send({ clientSecret: paymentIntent.client_secret, }); }); ``` -------------------------------- ### Shut down the app Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Stops all running Docker Compose services. ```bash docker compose stop ``` -------------------------------- ### Run webhook locally with Stripe CLI Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/README.md Forward webhook events to your local server. The CLI prints a webhook secret key to set as STRIPE_WEBHOOK_SECRET in your .env file. ```sh stripe listen --forward-to localhost:4242/webhook ``` -------------------------------- ### Enable Stripe Tax calculation Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/node-typescript/README.md Set calculateTax to true in server.ts to enable Stripe Tax calculation for transactions. ```typescript const calculateTax = true; ``` -------------------------------- ### Listen for Payment Method Event Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/VIDEOS.md Adds an event listener for the 'paymentmethod' event on the payment request object. The event fires when a payment method is added through the payment flow, such as Apple Pay. ```javascript paymentRequest.on('paymentmethod', (event) => { console.log(event); }); ``` -------------------------------- ### Update Playwright snapshots with -g option Source: https://github.com/stripe-samples/accept-a-payment/blob/main/TESTING.md Updates existing snapshots used as expected images. The -g option filters tests by a part of the test title. ```bash docker compose exec playwright npm run test -- playwright/custom-payment-flow-e2e-react-cra.spec.ts --update-snapshots -g giropay ``` -------------------------------- ### Log Apple Pay Unavailability Source: https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/client/VIDEOS.md Logs a message when Apple Pay is not available, used for debugging during development. ```javascript console.log('Apple Pay is unavailable'); ```