-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(EMI-2244): prototype stripe express checkout (#15123)
- Loading branch information
1 parent
60ba33c
commit 1a43767
Showing
6 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Apps/Order/Routes/Payment/ExpressCheckoutPrototype/ExpressCheckout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Spacer, Text } from "@artsy/palette" | ||
import { | ||
ExpressCheckoutElement, | ||
useElements, | ||
useStripe, | ||
} from "@stripe/react-stripe-js" | ||
|
||
export const ExpressCheckout = () => { | ||
const elements = useElements() | ||
const stripe = useStripe() | ||
const clientSecret = "client_secret_id" | ||
|
||
const onConfirm = async () => { | ||
if (!stripe || !elements) { | ||
return | ||
} | ||
|
||
const { error } = await stripe.confirmPayment({ | ||
elements: elements, | ||
clientSecret, | ||
confirmParams: { | ||
return_url: "https://artsy.net/", | ||
}, | ||
}) | ||
|
||
if (error) { | ||
console.error(error) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Text variant="lg-display">Express checkout</Text> | ||
<Spacer y={1} /> | ||
<ExpressCheckoutElement onConfirm={onConfirm} /> | ||
</> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Apps/Order/Routes/Payment/ExpressCheckoutPrototype/ExpressCheckoutProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Elements } from "@stripe/react-stripe-js" | ||
import { type StripeElementsOptions, loadStripe } from "@stripe/stripe-js" | ||
import { ExpressCheckout } from "Apps/Order/Routes/Payment/ExpressCheckoutPrototype/ExpressCheckout" | ||
import { getENV } from "Utils/getENV" | ||
|
||
export const ExpressCheckoutProvider = ({ order }) => { | ||
const { buyerTotalCents } = order | ||
|
||
const options: StripeElementsOptions = { | ||
mode: "payment", | ||
amount: buyerTotalCents, | ||
currency: "usd", | ||
} | ||
|
||
const stripePromise = loadStripe(getENV("STRIPE_PUBLISHABLE_KEY")) | ||
|
||
return ( | ||
<> | ||
<Elements stripe={stripePromise} options={options}> | ||
<ExpressCheckout /> | ||
</Elements> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters