### Starting the Server and Installing Dependencies for Stripe Sample Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md These commands install the necessary Node.js dependencies for the Stripe sample project and then start the local development server. The server will typically run on `localhost:4242` or the React client on `localhost:3000`. ```Shell npm install npm start ``` -------------------------------- ### Cloning Stripe Checkout Sample using Stripe CLI Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This command uses the Stripe CLI to quickly clone and configure the `checkout-one-time-payments` sample. It automates the setup of server and client languages and populates the `.env` file with API keys, streamlining the initial setup process. ```Shell stripe samples create checkout-one-time-payments ``` -------------------------------- ### Manually Cloning Stripe Checkout Sample with Git Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This Git command allows manual cloning of the `checkout-one-time-payments` sample repository directly from GitHub, providing an alternative to the Stripe CLI for users who prefer a manual setup process. ```Shell git clone https://github.com/stripe-samples/checkout-one-time-payments ``` -------------------------------- ### Example JSON Response for Stripe Price Creation Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This JSON object illustrates the typical response received after successfully creating a Stripe Price. It contains key details such as the unique `id` of the price, currency, unit amount, and associated product ID, which is then used to configure the `.env` file. ```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" } ``` -------------------------------- ### Running a Local Webhook with Stripe CLI Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This command uses the Stripe CLI to listen for webhook events and forward them to a local endpoint. It's essential for testing webhook functionality during development and requires prior installation and linking of the Stripe CLI to your account. ```Shell stripe listen --forward-to localhost:4242/webhook ``` -------------------------------- ### Starting React Client Application (Bash) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/client/react-cra/README.md This command initiates the React development server, making the client application accessible, typically at `http://localhost:3000`. It assumes all project dependencies have been successfully installed beforehand. ```Bash npm start ``` -------------------------------- ### Navigating to Node.js Server Directory Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This command changes the current directory to the `server/node` folder. This is the initial step required to run the Node.js server implementation of the Stripe Checkout sample locally, allowing execution of server-side scripts. ```Shell cd server/node ``` -------------------------------- ### Copying .env Configuration File for Node.js Server Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This command copies the `.env.example` template to a `.env` file within the `server/node` directory. This step is necessary for configuring environment variables specific to the Node.js server implementation, allowing the application to access Stripe API keys and other settings. ```Shell cp .env.example server/node/.env ``` -------------------------------- ### Starting PHP Local Development Server (Shell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/php/README.md These shell commands first change the directory to `public` and then start a PHP built-in web server on `localhost:4242`. This allows the application to be accessed and tested locally via a web browser. ```Shell cd public php -S localhost:4242 ``` -------------------------------- ### Copying .env Example File (Shell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/php/README.md This command copies the `.env.example` file to `.env`, which is the first step in configuring environment variables for the application. Users must then replace placeholder values with their actual Stripe API keys and Price ID. ```Shell cp ../../.env.example .env ``` -------------------------------- ### Installing PHP Dependencies with Composer (Shell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/php/README.md This command runs Composer to install all required PHP dependencies for the project. It ensures that all necessary libraries and packages are available for the application to run correctly. ```Shell composer install ``` -------------------------------- ### Running the Go Application Server - Shell Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/go/README.md This shell command compiles and runs the `server.go` application. It starts the local server, making the demo accessible via a web browser at the specified local host address (e.g., `localhost:4242` for HTML client or `localhost:3000` for React). ```Shell go run server.go ``` -------------------------------- ### Installing Node.js Dependencies Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/node/README.md This command installs all required Node.js packages listed in the `package.json` file. It is a standard step to prepare the project for execution after cloning or updating. ```Shell npm install ``` -------------------------------- ### Installing Dependencies for React Client (Bash) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/client/react-cra/README.md This command installs all necessary Node.js dependencies for the React client application, as defined in the `package.json` file. It is a prerequisite for running the client and ensures all required packages are available. ```Bash npm install ``` -------------------------------- ### Configuring Stripe API Keys in .env File Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md These lines represent the essential environment variables for authenticating with the Stripe API. `STRIPE_PUBLISHABLE_KEY` is used on the client-side for public operations, while `STRIPE_SECRET_KEY` is used on the server-side for secure API calls and should be kept confidential. ```Shell STRIPE_PUBLISHABLE_KEY= STRIPE_SECRET_KEY= ``` -------------------------------- ### Running Packaged Java Application Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/java/README.md This command executes the compiled Java application from its JAR file, specifying the classpath and the main server class. It starts the local server, making the demo accessible via a web browser. ```Shell java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server ``` -------------------------------- ### Creating a Product with Tax Code using Stripe CLI Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This command creates a new Stripe Product named 'demo' and assigns it a specific tax code (`txcd_10000000`) for 'General - Electronically Supplied Services'. This is crucial for accurate tax calculation when Stripe Tax is enabled, ensuring the correct tax rates are applied. ```Shell stripe products create \\ --name="demo" \\ --tax-code="txcd_10000000" ``` -------------------------------- ### Configuring Stripe Price ID in .env File Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This environment variable sets the `PRICE` ID in the `.env` file, linking the application to a specific Stripe Price object. This ID is crucial for the Checkout session to know which product and amount to charge, ensuring the correct item is processed. ```Shell PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Installing Ruby Dependencies (Shell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/ruby/README.md This command installs all necessary Ruby gem dependencies for the project, as specified in the Gemfile. It ensures that all required libraries are available before running the application. ```Shell bundle install ``` -------------------------------- ### Creating a One-Time Price using Stripe CLI Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This Stripe CLI command creates a new one-time Price object with a unit amount of 500 cents (5 USD) and associates it with a product named 'demo'. This generated Price ID is a prerequisite for the Checkout sample to function correctly. ```Shell stripe prices create --unit-amount 500 --currency usd -d "product_data[name]=demo" ``` -------------------------------- ### Running the Node.js Application Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/node/README.md This command starts the Node.js Express server application. It typically executes a script defined in `package.json` (e.g., `node server.js`) to launch the web server. ```Shell npm start ``` -------------------------------- ### Running Sinatra Application (Shell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/ruby/README.md This command starts the Sinatra web application. Once executed, the application will be accessible via a web browser, typically at 'localhost:4242' for the HTML client or 'localhost:3000' for the React client. ```Shell ruby server.rb ``` -------------------------------- ### Installing Python Dependencies Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md This command installs all necessary Python packages listed in the `requirements.txt` file into the currently active virtual environment. This step is crucial to ensure that all required libraries for the application are available and correctly configured. ```Shell pip install -r requirements.txt ``` -------------------------------- ### Creating a Price with Exclusive Tax Behavior using Stripe CLI Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/README.md This command creates a new Stripe Price with a unit amount of 500 USD, specifying an `exclusive` tax behavior. It links the price to a previously created product using its ID, enabling Stripe Tax to calculate taxes separately from the base price. ```Shell stripe prices create \\ --unit-amount=500 \\ --currency=usd \\ --tax-behavior=exclusive \\ --product= ``` -------------------------------- ### Installing Go Module Dependencies - Shell Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/go/README.md This shell command is used to add any missing module requirements to `go.mod` and remove unused ones. It ensures that the project's dependency graph is clean and up-to-date before building or running the application. ```Shell go mod tidy ``` -------------------------------- ### Running Flask Application (MacOS/Unix) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md These commands set the `FLASK_APP` environment variable to `server.py` and then initiate the Flask development server on port 4242 for MacOS/Unix systems. This action starts the backend server, making the Stripe sample application accessible. ```Shell export FLASK_APP=server.py python3 -m flask run --port=4242 ``` -------------------------------- ### Running .NET Core Application Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/dotnet/README.md This command is used to compile and run the .NET Core application. Executing `dotnet run` starts the web server, making the application accessible locally, typically on port 4242 or 3000 depending on the client. ```Shell dotnet run ``` -------------------------------- ### Setting Stripe Price ID in .env (YAML) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/php/README.md This snippet shows an example of how the `PRICE` environment variable should be set in the `.env` file. It requires a valid Stripe Price ID, which is crucial for the sample to function correctly during checkout. ```YAML PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Configuring Stripe Price ID in .env Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/node/README.md This snippet shows an example of how to set the `PRICE` environment variable in the `.env` file. This variable must contain a valid Stripe Price ID, which is crucial for the checkout process to function correctly. ```Shell PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Creating and Activating Python Virtual Environment (MacOS/Unix) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md These commands create a new Python virtual environment named 'env' and subsequently activate it on MacOS or Unix systems. Utilizing a virtual environment helps isolate project dependencies, preventing potential conflicts with globally installed Python packages. ```Shell python3 -m venv env source env/bin/activate ``` -------------------------------- ### Configuring Stripe Price ID in .env - Shell Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/go/README.md This snippet shows an example of how to set the `PRICE` environment variable in the `.env` file. This variable must contain a valid Stripe Price ID for the sample to function correctly, replacing the placeholder `price_12345` with an actual ID from your Stripe account. ```Shell PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Enabling Automatic Tax Calculation in Stripe Checkout Session (Java) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/java/README.md This Java snippet, found in `Server.java`, demonstrates how to enable automatic tax calculation for a Stripe Checkout Session by uncommenting the `setAutomaticTax` line. This requires prior setup of Stripe Tax and updated product/price configurations. ```Java // .setAutomaticTax(SessionCreateParams.AutomaticTax.builder().setEnabled(true).build()) ``` -------------------------------- ### Enabling Automatic Tax Calculation in Stripe Checkout (Python) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md This Python code snippet, located in the `server.py` file, enables automatic tax calculation for Stripe Checkout sessions when uncommented. Proper setup of Stripe Tax and updated product/price configurations in the Stripe dashboard are prerequisites for this feature. ```Python # automatic_tax={'enabled': True}, ``` -------------------------------- ### Running Flask Application (Windows PowerShell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md These commands set the `FLASK_APP` environment variable to `server.py` and then launch the Flask development server on port 4242 for Windows using PowerShell. This process initializes the backend server, making the Stripe sample application operational. ```PowerShell $env:FLASK_APP=“server.py" python3 -m flask run --port=4242 ``` -------------------------------- ### Building Java Project with Maven Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/java/README.md This command uses Maven to compile the Java source code and package it into an executable JAR file. It's a prerequisite step before running the application, ensuring all dependencies are resolved and the project is built. ```Shell mvn package ``` -------------------------------- ### Creating and Activating Python Virtual Environment (Windows PowerShell) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md These commands create a new Python virtual environment named 'env' and then activate it specifically for Windows using PowerShell. Activating the virtual environment ensures that all project-specific dependencies are correctly utilized. ```PowerShell python3 -m venv env .\env\Scripts\activate.bat ``` -------------------------------- ### Vendoring Go Module Dependencies - Shell Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/go/README.md This shell command copies all necessary Go module dependencies into a local `vendor` directory. Vendoring allows the application to be built and run without an internet connection, ensuring consistent builds across different environments. ```Shell go mod vendor ``` -------------------------------- ### Enabling Automatic Tax in Stripe Checkout Session - Go Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/go/README.md This Go snippet, found in `server.go`, demonstrates how to enable automatic tax calculation for a Stripe Checkout Session. Uncommenting this line activates Stripe Tax, provided that Stripe Tax has been set up and products/prices are configured with tax behavior and codes. ```Go // AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)}, ``` -------------------------------- ### Configuring Stripe Price ID in .env (Plain Text) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/ruby/README.md This snippet shows how to set the 'PRICE' environment variable in the .env file. This variable must contain a valid Stripe Price ID for the sample to function correctly, as 'price_12345' is a placeholder. ```Plain Text PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Configuring Stripe Price ID in .env Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/java/README.md This snippet shows how to set the `PRICE` environment variable in the `.env` file. This variable is crucial for specifying the Stripe Price ID used in the Checkout session, ensuring the sample works correctly with a valid product price. ```Shell PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Enabling Automatic Tax Calculation in C# Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/dotnet/README.md This C# snippet from `Program.cs` demonstrates how to enable automatic tax calculation for Stripe Checkout sessions. Uncommenting this line activates Stripe Tax, provided that Stripe Tax is set up and product/price tax behaviors are configured. ```C# // AutomaticTax = new SessionAutomaticTaxOptions { Enabled = true }, ``` -------------------------------- ### Configuring Price ID in .env file Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/dotnet/README.md This snippet shows how to configure the Stripe Price ID in the .env file, which is required for the sample application to function correctly. The PRICE variable should be set to a valid Price ID from your Stripe account. ```dotenv PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Enabling Automatic Tax Calculation in Stripe Checkout (Ruby) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/ruby/README.md This Ruby snippet demonstrates how to enable automatic tax calculation for Stripe Checkout sessions. Uncommenting this line in 'server.rb' will activate the feature, provided Stripe Tax has been previously set up and products/prices are configured with tax behavior. ```Ruby # automatic_tax: { enabled: true }, ``` -------------------------------- ### Enabling Automatic Tax in PHP Checkout Session (PHP) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/php/README.md This PHP code snippet, found in `create-checkout-session.php`, is initially commented out. Uncommenting this line enables automatic tax calculation for the Stripe Checkout session, provided Stripe Tax has been set up and products/prices are configured with tax behavior. ```PHP // 'automatic_tax' => ['enabled' => true], ``` -------------------------------- ### Configuring Stripe Price ID in .env Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/python/README.md This snippet illustrates the required format for setting the Stripe Price ID within the `.env` configuration file. A valid Price ID from your Stripe account must be assigned to the `PRICE` environment variable for the sample application to function correctly. ```dotenv PRICE=price_1Hh1ZeCZ6qsJgndJaX9fauRl ``` -------------------------------- ### Enabling Automatic Tax Calculation in Stripe Checkout (JavaScript) Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/node/README.md This JavaScript snippet, found in `server.js`, demonstrates how to enable automatic tax calculation for Stripe Checkout sessions. Uncommenting this line activates Stripe Tax, provided that Stripe Tax is already set up and products/prices are configured with tax behavior. ```JavaScript // automatic_tax: {enabled: true}, ``` -------------------------------- ### Fetching and Displaying Stripe Checkout Session in JavaScript Source: https://github.com/stripe-samples/checkout-one-time-payments/blob/main/server/php/public/success.html This JavaScript snippet retrieves the 'session_id' from the URL query parameters. It then makes an asynchronous request to a backend endpoint ('/get-checkout-session.php') to fetch the full Stripe Checkout Session object, formats the JSON response, and displays it within a 'pre' HTML element. It includes error handling for the fetch operation. ```JavaScript var urlParams = new URLSearchParams(window.location.search); var sessionId = urlParams.get("session_id") if (sessionId) { fetch("/get-checkout-session.php?sessionId=" + sessionId).then(function(result){ return result.json() }).then(function(session){ var sessionJSON = JSON.stringify(session, null, 2); document.querySelector("pre").textContent = sessionJSON; }).catch(function(err){ console.log('Error when fetching Checkout session', err); }); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.