Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { StripeProvider, useStripe } from '@stripe/stripe-react-native';
- import type {Node} from 'react';
- import {
- SafeAreaView,
- StatusBar,
- Button,
- } from 'react-native';
- const App: () => Node = () => {
- const { initPaymentSheet, presentPaymentSheet } = useStripe();
- async function createPaymentSheet() {
- const response = await fetch(
- "https://my-redacted-backend-url/payment-sheet",
- {
- method: 'POST',
- headers: {
- Accept: 'application/json',
- 'Content-Type': 'application/json'
- },
- }
- );
- const responseJson = await response.json()
- console.log(responseJson);
- const {
- paymentIntent,
- ephemeralKey,
- customer
- } = responseJson;
- const { error } = await initPaymentSheet({
- customerId: customer,
- customerEphemeralKeySecret: ephemeralKey,
- paymentIntentClientSecret: paymentIntent,
- googlePay: true,
- merchantCountryCode: "US",
- testEnv: true,
- });
- if (!error) {
- const { paymentError } = await presentPaymentSheet({
- clientSecret: paymentIntent,
- });
- if (paymentError) {
- console.log("Payment Error");
- console.log(paymentError);
- }
- else {
- console.log("Successful payment")
- }
- }
- }
- return (
- <StripeProvider
- publishableKey="pk_test_mypublishablekey"
- merchantIdentifier="merchant.identifier">
- <SafeAreaView>
- <StatusBar />
- <Button
- title="Set up and present PaymentSheet"
- onPress={ () => {
- createPaymentSheet();
- }} />
- </SafeAreaView>
- </StripeProvider>
- );
- };
- export default App;
Add Comment
Please, Sign In to add comment