Last active
January 28, 2021 12:54
-
-
Save aabhasr1/ba9805a94ba44a342dc94820740cd9b0 to your computer and use it in GitHub Desktop.
Sample Code
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
import React, {Component} from 'react'; | |
import {Platform, StyleSheet, Button, View} from 'react-native'; | |
import {NativeModules} from 'react-native'; | |
import RNPgReactNativeSDK from 'react-native-pg-react-native-sdk' | |
import axios from 'axios'; | |
axios.defaults.timeout = 5000; | |
var testUrl = "https://test.cashfree.com/api/v2/cftoken/order"; | |
var prodUrl = "https://api.cashfree.com/api/v2/cftoken/order"; | |
export default class App extends Component { | |
_startProcess() { | |
var orderId; | |
const apiKey = "--appIdhere--"; | |
const apiSecret = "--secrethere--"; | |
const env = "TEST"; | |
orderId = "Order" + parseInt((100000000 * Math.random())); | |
let orderApiMap = { | |
"orderId": orderId, | |
"orderAmount": "1", | |
"orderCurrency": "INR" | |
} | |
const postParams = { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
'x-client-id': apiKey, | |
'x-client-secret': apiSecret | |
}, | |
body: JSON.stringify(orderApiMap) | |
} | |
var cfToken; | |
fetch(testUrl, postParams).then(response => { | |
// console.log("data" + response.json()); | |
return response.json() | |
}) | |
.then(data => { | |
cfToken = data.cftoken | |
console.log("Token : " + data.cftoken); | |
startPayment(cfToken) | |
}) | |
function startPayment(cfToken) { | |
var map = { | |
"orderId": orderId, | |
"orderAmount": "1", | |
"appId": apiKey, | |
"tokenData": cfToken, | |
"orderCurrency": "INR", | |
"orderNote": "asdasdasd", | |
"notifyUrl": "https://test.gocashfree.com/notify", | |
"customerName": "Cashfree User", | |
"verifyExpiry": "100", | |
"customerPhone": "9999999999", | |
"customerEmail": "[email protected]" | |
} | |
RNPgReactNativeSDK.startPaymentWEB(map,env,(result) => { | |
console.log(result); | |
var obj = JSON.parse(result, function (key, value) { | |
console.log(key + "::" + value); | |
// Do something with the result | |
}) | |
}); | |
} | |
} | |
render() { | |
return ( | |
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}> | |
<Button onPress={()=>this._startProcess()} title="WEB" /> | |
</View> | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment