Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Adds two key steps on building ecommerce sites with Stripe tutorial #18669

Merged
merged 22 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bfd37fc
resolves #14598
Sep 21, 2019
f6d376e
Fixed typos and added related content
Sep 21, 2019
5f6066c
Fixed additional typos
Sep 21, 2019
e90b62b
Fixed additional typos, one with the name of the file, added links fo…
urielhdz Sep 23, 2019
18bb470
Updated title based on @marcysutton suggestions
Sep 24, 2019
552e796
Solves suggested changes such as modifying links for relative urls, r…
urielhdz Sep 24, 2019
2db5d7f
Merge branch 'master' of https://github.com/urielhdz/gatsby
urielhdz Sep 24, 2019
91e686a
Apply additional suggestions
Sep 25, 2019
c0b0231
Merge branch 'master' of https://github.com/gatsbyjs/gatsby
urielhdz Oct 4, 2019
98e6281
Little typo with the npm-force-resolutions package name is fixed
urielhdz Oct 4, 2019
f75c6e7
Merge remote-tracking branch 'upstream/master' into fixing-typo-in-up…
urielhdz Oct 14, 2019
76353b9
Added two additional steps for the tutorial on how to build ecommer s…
urielhdz Oct 14, 2019
9d965f5
Added missing screenshot files
urielhdz Oct 14, 2019
908cb8d
Removed intstructions from the old Stripe UI
urielhdz Oct 15, 2019
3a6632a
Removes the now unused images and integrates suggestions from gatsby …
urielhdz Oct 15, 2019
dedd148
Changed integration to function when referring to the `redirectToChec…
urielhdz Oct 16, 2019
130c827
Rewrote the requirements to use this integration, changed pronouns, f…
urielhdz Oct 16, 2019
ab10eeb
Added missing screenshot file
urielhdz Oct 16, 2019
24c4d15
Apply suggestions from code review
urielhdz Oct 29, 2019
57cb601
Apply suggestions from code review
urielhdz Oct 29, 2019
ac57380
Merge branch 'master' into UpdateEcommerceTutorial
laurieontech Nov 14, 2019
04ebfe8
Merge remote-tracking branch 'upstream/master' into UpdateEcommerceTu…
Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions docs/tutorial/ecommerce-tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ You have 2 keys in both test mode and production mode:

While testing, you must use the key(s) that include _test_. For production code, you will need to use the live keys. As the names imply, your publishable key may be included in code that you share publicly (for example, on the frontend, and in GitHub), whereas your secret key should not be shared with anyone or committed to any public repo. It’s important to restrict access to this secret key because anyone who has it could potentially read or send requests from your Stripe account and see information about charges or purchases or even refund customers.

### Enabling the "Checkout client-only integration" for your Stripe account

Through this tutorial you will be using the "Checkout client-only integration" from Stripe. To use this integration you need to activate it on the corresponding [Checkout settings](https://dashboard.stripe.com/account/checkout/settings) from your Stripe Dashboard.

![Stripe control to enable the Checkout client-side only integration highlighted](stripe-checkout-clientside-functionality.png)

> 💡 This change will also modify the interface that Stripe provides to administrate your products, keep this in mind in case you have previously used this tool. If you have never used the product administrator, you don't need to worry.
urielhdz marked this conversation as resolved.
Show resolved Hide resolved

Lastly, you need to set a name for your Stripe account on your [Account settings](https://dashboard.stripe.com/account) to use this integration.
urielhdz marked this conversation as resolved.
Show resolved Hide resolved

To learn more about this integration you may use the [Stripe docs](https://stripe.com/docs/payments/checkout#configure).

## Examples

You can find an implementation of these examples [on GitHub](https://github.com/thorsten-stripe/ecommerce-gatsby-tutorial).
Expand All @@ -112,9 +124,9 @@ If you're selling a simple product, like an eBook for example, you can create a

#### Create a product and SKU

For Stripe Checkout to work without any backend component, you need to create a product listing in the Stripe Dashboard. This is required for Stripe to validate that the request coming from the frontend is legitimate and to charge the right amount for the selected product/SKU. To set this up, simply follow the steps in the [Stripe docs](https://stripe.com/docs/payments/checkout#configure).
To sell your products, first you need to create them on Stripe using the [Stripe Dashboard](https://dashboard.stripe.com/products) or the [Stripe API](https://stripe.com/docs/api/products/create). This is required for Stripe to validate that the request coming from the frontend is legitimate and to charge the right amount for the selected product/SKU. Stripe requires every SKU used with Stripe Checkout to have a name, be sure to add one to all of your SKUs.
urielhdz marked this conversation as resolved.
Show resolved Hide resolved

Note: You will need to create both test and live product SKUs in the Stripe admin. Make sure you toggle to 'Viewing test data' and then create your products for local development.
You will need to create both test and live product SKUs in the Stripe Dashboard. Make sure you toggle to "Viewing test data" and then create your products for local development.

#### Create a checkout component that loads StripeJS and redirects to the checkout

Expand Down Expand Up @@ -282,7 +294,7 @@ module.exports = {
}
```

To retrieve your SKUs from your Stripe account you will need to provide your secret API key. This key needs to kept secret and must never be shared on the frontend or on GitHub. Therefore we need to set an environment variable to store the secret key. You can read more about the usage of env variables in Gatsby [here](https://www.gatsbyjs.org/docs/environment-variables/).
To retrieve your SKUs from your Stripe account you will need to provide your secret API key. This key needs to kept secret and must never be shared on the frontend or on GitHub. Therefore you need to set an environment variable to store the secret key. You can read more about the usage of env variables in Gatsby [here](https://www.gatsbyjs.org/docs/environment-variables/).
urielhdz marked this conversation as resolved.
Show resolved Hide resolved

In the root directory of your project add a `.env.development` file:

Expand Down Expand Up @@ -448,7 +460,7 @@ export default SkuCard

This component renders a neat card for each individual SKU, with the SKU name, nicely formatted pricing, and a "BUY ME" button. The button triggers the `redirectToCheckout()` function with the corresponding SKU ID.

Lastly, we need to refactor our `Skus` component to initialize the Stripe.js client, and render `SkuCards` while handing down the Stripe.js client in the `props`:
Lastly, you need to refactor your `Skus` component to initialize the Stripe.js client, and render `SkuCards` while handing down the Stripe.js client in the `props`:

```jsx:title=src/components/Products/Skus.js
import React, { Component } from 'react'
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.