diff --git a/example/SampleProject/App.js b/example/SampleProject/App.js index 3b48cb97d..37b9809c6 100644 --- a/example/SampleProject/App.js +++ b/example/SampleProject/App.js @@ -6,64 +6,88 @@ * @flow */ - import React, { Component } from 'react'; - import { Button, StyleSheet, View, NativeModules, NativeEventEmitter } from 'react-native'; +import React, { Component } from 'react'; +import { Button, StyleSheet, View, NativeModules, NativeEventEmitter } from 'react-native'; import RazorpayCheckout from 'react-native-razorpay'; - +import base64 from 'react-native-base64' + +export default class ButtonBasics extends Component { - export default class ButtonBasics extends Component { _onPressButton() { -var options = { - description: 'Credits towards consultation', - image: 'https://i.imgur.com/3g7nmJC.png', - currency: 'INR', - key: 'Your razorpay key', - amount: '5000', - name: 'foo', - prefill: { - email: 'void@razorpay.com', - contact: '9191919191', - name: 'Razorpay Software' - }, - theme: {color: '#F37254'} - } - RazorpayCheckout.open(options).then((data) => { - // handle success - alert(`Success: ${data.razorpay_payment_id}`); - }).catch((error) => { - // handle failure - alert(`Error: ${error.code} | ${error.description}`); - }); + + fetch('https://api.razorpay.com/v1/orders', { + method: 'POST', + headers: new Headers({ + Accept: 'application/json', + 'Content-Type': 'application/json', + 'Authorization': `Basic ${base64.encode('rzp_test_1DP5mmOlF5G5ag:thisissupersecret')}` + }), + body: JSON.stringify({ + amount: 100, + currency: 'INR', + "receipt": "rcptid_11" + }) + }).then((res) => { + return res.json(); + }).then((payment) => { + console.log('PAYMENT :', payment.id); + var options = { + description: 'Credits towards consultation', + image: 'https://i.imgur.com/3g7nmJC.png', + currency: 'INR', + key: 'rzp_test_1DP5mmOlF5G5ag', + amount: '100', + name: 'foo', + prefill: { + email: 'void@razorpay.com', + contact: '9191919191', + name: 'Razorpay Software' + }, + order_id: payment.id, + theme: { color: '#F37254' } + } + console.log(options); + RazorpayCheckout.open(options).then().catch(); + }).catch() + /* RazorpayCheckout.open(options).then((data) => { + // handle success + alert(`Success: ${data.razorpay_payment_id}`); + console.log(data.razorpay_payment_id); + }).catch((error) => { + // handle failure + alert(`Error: ${error.code} | ${error.description}`); + console.log(error.description); + }); */ } render() { return ( - -