Skip to content

Commit

Permalink
set up success url
Browse files Browse the repository at this point in the history
  • Loading branch information
dayhaysoos committed Feb 12, 2020
1 parent dec44a1 commit 7537e83
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/non-profit-site/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
resolve: 'gatsby-theme-stripe-non-profit',
options: {
stripePublicKey: process.env.STRIPE_API_PUBLIC,
successUrl: 'https://gatsbyjs.com',
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-theme-stripe-non-profit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-theme-stripe-non-profit",
"version": "0.1.1",
"version": "0.1.3",
"author": {
"name": "Nick DeJesus",
"url": "https://www.twitter.com/dayhaysoos",
Expand Down
11 changes: 5 additions & 6 deletions packages/gatsby-theme-stripe-non-profit/src/context/donate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ const reducer = (donate, action) => {

const DonateContext = createContext()

export const DonateProvider = ({ children, stripe }) => (
export const DonateProvider = ({ children, stripe, successUrl }) => (
<DonateContext.Provider
value={useReducer(reducer, {
lastClicked: {},
isPaying: false,
stripe,
successUrl,
})}
>
{children}
Expand All @@ -40,22 +41,20 @@ export const DonateProvider = ({ children, stripe }) => (

export const useDonate = () => {
const [donate, dispatch] = useContext(DonateContext)
const { stripe } = donate

const { lastClicked, isPaying } = donate
const { stripe, lastClicked, isPaying, successUrl } = donate

const redirectToPlanCheckout = async () => {
const { error } = await stripe.redirectToCheckout({
items: [{ plan: lastClicked.lastClickedItem, quantity: 1 }],
successUrl: `http://localhost:8000/`,
successUrl: successUrl,
cancelUrl: `http://localhost:8000/`,
})
}

const redirectToSkuCheckout = async sku => {
const { error } = await stripe.redirectToCheckout({
items: [{ sku: sku.lastClickedItem, quantity: 1 }],
successUrl: `http://localhost:8000/`,
successUrl: successUrl,
cancelUrl: `http://localhost:8000/`,
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @jsx jsx */
import { jsx } from 'theme-ui'

const ThankYou = () => <h1>Thank you</h1>

export default ThankYou

0 comments on commit 7537e83

Please sign in to comment.