Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from 'react';
- import {
- StyleSheet,
- Button,
- Text,
- } from 'react-native';
- import {
- useStripe,
- } from '@stripe/stripe-react-native';
- const SetupIntentComponent = (props) => {
- const { initPaymentSheet, presentPaymentSheet } = useStripe();
- async function createPaymentSheet() {
- const response = await fetch(
- "MY_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,
- customFlow: false,
- merchantDisplayName: "DineDen",
- style: "alwaysDark",
- });
- console.log(error);
- if (!error) {
- const { paymentError } = await presentPaymentSheet({
- clientSecret: paymentIntent,
- });
- if (paymentError) {
- console.log("Payment Error");
- console.log(paymentError);
- }
- else {
- console.log("Successful payment")
- }
- }
- }
- return (
- <>
- <Button
- title="PaymentSheet!!"
- onPress={() => {
- createPaymentSheet();
- }}
- />
- </>
- )
- }
- const SetupIntentComponentStyle = StyleSheet.create({
- cardField: {
- height: 50,
- marginLeft: 15,
- marginRight: 15,
- marginVertical: 30,
- },
- });
- export default SetupIntentComponent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement