From d19f5a280bcdfccb9eafb060886219fbef717337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktoras=20Laukevi=C4=8Dius?= Date: Mon, 5 Apr 2021 12:39:20 +0300 Subject: [PATCH] Introduce demo server with payment handling --- .gitignore | 1 + demo/App.js | 36 +++++++++++++++++++++++++++++++----- demo/package.json | 4 +++- demo/secrets.js_example | 4 ++++ demo/server.js | 26 ++++++++++++++++++++++++++ demo/yarn.lock | 12 ++++++++++-- 6 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 demo/secrets.js_example create mode 100644 demo/server.js diff --git a/.gitignore b/.gitignore index 2be18c5..4681f84 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ buck-out/ *.keystore demo/ios/Pods/** +demo/secrets.js diff --git a/demo/App.js b/demo/App.js index b673160..7cdd6ca 100644 --- a/demo/App.js +++ b/demo/App.js @@ -1,20 +1,46 @@ import { StatusBar } from 'expo-status-bar'; import React from 'react'; -import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; +import { StyleSheet, View, Button } from 'react-native'; export default function App() { initStripe = async () => { + const { STRIPE_PAYMENTS_APP_KEY } = require('./secrets'); const { default: stripe } = await import('react-native-stripe-payments'); - stripe.setOptions({ publishingKey: 'STRIPE_PUBLISHING_KEY' }); + stripe.setOptions({ publishingKey: STRIPE_PAYMENTS_APP_KEY }); } + makePayment = async (isCardNeedConfirm) => { + const { default: stripe } = await import('react-native-stripe-payments'); + + const response = await fetch("http://localhost:8000/pay", { method: 'get' }) + let res = await response.json(); + console.log(res); + + const cardDetails = { + number: isCardNeedConfirm ? '4000002500003155' : '4242424242424242', + expMonth: 12, + expYear: 25, + cvc: '888', + }; + let result = await stripe.confirmPayment(res.client_secret, cardDetails); + console.log(result); + } + + this.initStripe(); return ( - this.initStripe()}> - Init Stripe - +