payu-intrepos / payu-non-seamless-react

Non-Seamless SDK for React Native
6 stars 11 forks source link

payment_related_details_for_mobile_sdk is not hitting ...its just loading in static hashes #10

Open shrutiraoniit25 opened 3 years ago

shrutiraoniit25 commented 3 years ago

so I wanted to use the static generation of hash, where I calculated the hash values and trying to hit the pay biz but it's stuck at please wait and my hash values are correct. down here is my code: `const paymentHash = calculateHash(key + '|' + txnid + '|' + amount + '|' + productInfo + '|' + firstName + '|' + email + '|' + udf1 + '|' + udf2 + '|' + udf3 + '|' +udf4 + '|' + udf5 + '||||||' + merchantSalt); const vasHash = calculateHash(key + '|vas_for_mobile_sdk|' + amount + '|' + merchantSalt); const paymentDetailsHash = calculateHash ( key + '|payment_related_details_for_mobile_sdk|' + 'umang:arya' + '|' + merchantSalt);

var payUPaymentParams = { key: '3TnMpV', amount: "10", transactionId: txnid, productInfo: 'product_info', firstName: 'firstname', email: 'test@gmail.com', phone: '9999999999', ios_surl: 'https://payu.herokuapp.com/ios_success', ios_furl: 'https://payu.herokuapp.com/ios_failure', android_surl: 'https://payu.herokuapp.com/success', android_furl: 'https://payu.herokuapp.com/failure', environment: 0 + "", merchantSalt: 'g0nGFe03', userCredential: 'umang:arya', additionalParam:{ udf1: 'udf1', udf2: 'udf2', udf3: 'udf3', udf4: 'udf4', udf5: 'udf5', payment: paymentHash, payment_related_details_for_mobile_sdk: paymentDetailsHash, vas_for_mobile_sdk: vasHash

},

}

var payUCheckoutProConfig = { merchantName: "Rashan vala", merchantLogo: "Jio", showExitConfirmationOnCheckoutScreen: true, showExitConfirmationOnPaymentScreen: true, cartDetails: [{ 'Order': 'Value' }, { 'Key Name': 'Value1' }], paymentModesOrder: [{ 'UPI': 'TEZ' }, { 'Cards': 'PAYTM' },{ 'EMI': '' }], surePayCount: 1, merchantResponseTimeout: 10000, }

var paymentObject = { payUPaymentParams: payUPaymentParams, // payUCheckoutProConfig is optional // Detail can be found in latter section payUCheckoutProConfig: payUCheckoutProConfig }

// --------------------------------handle payment --------------------------

const paymenthandle = () => { const eventEmitter = new NativeEventEmitter(PayUBizSdk); var paymentSuccess = eventEmitter.addListener('onPaymentSuccess', onPaymentSuccess); var paymentFailure = eventEmitter.addListener('onPaymentFailure', onPaymentFailure); var paymentCancel = eventEmitter.addListener('onPaymentCancel', onPaymentCancel); var error = eventEmitter.addListener('onError', onError); // var GenerateHash = eventEmitter.addListener('generateHash', generateHash); } const onPaymentSuccess = (e) => { console.log(e.merchantResponse); console.log(e.payuResponse); } const onPaymentFailure = (e) => { console.log('onPayment failure -' + e.merchantResponse); console.log('payuResponsefailure -' + e.payuResponse); } const onPaymentCancel = (e) => { console.log('onPaymentCancel isTxnInitiated -' + e); } const onError = (e) => { console.log('error'+ JSON.stringify(e)); } // const generateHash = (e) => { // console.log(e.hashName); // console.log(e.hashString); // sendBackHash(e.hashName, e.hashString + merchantSalt); // }

// const sendBackHash = (hashName, hashData) => { // console.log(hashName); // var hashValue = calculateHash(hashData); // var result = { [hashName]: hashValue }; // console.log(result); // PayUBizSdk.hashGenerated(result); // }

function calculateHash (data) {

console.log(data);
var result = sha512(data);
console.log(result);
return result;

} //const generateHash = (e) => { // console.log('hash name'+ ' ' + e.hashName); // console.log(e.hashString); // var hashStringWithoutSalt = e.hashString; // var hashName = e.hashName; // Pass hashStringWithoutSalt to server // Server will append salt at the end and generate sha512 hash over it // var hashValue = data.hash; //var result = { [hashName]: hashValue }; //PayUBizSdk.hashGenerated(hashValue); //} const LaunchPayu = () => { PayUBizSdk.openCheckoutScreen(paymentObject);`

PFA of the screen shot. Screenshot (130) Screenshot (131)

mptechjolly commented 2 years ago

Hello @shrutiraoniit25

I m also facing same issue my screen getting stuck, you found any solution for same? please let me know if you got any answer.

Screenshot 2022-07-05 at 10 13 11 PM

saumyabhatnagar1 commented 1 year ago

Facing the same issue, any updates ?

rahulTPatil commented 1 year ago

I've also struggled a lot with this issue. Gladly, a developer friend of mine helped me to resolve it. Posting the resolution which worked for me.

Tested on Latest version of React Native

Steps:

  1. Install the necessary package js-sha512 npm i js-sha512

  2. Use the below code. Make the necessary changes for the Merchant Name and Hash String.

    
    import {View, Button, NativeEventEmitter} from 'react-native';
    import PayUBizSdk from 'payu-non-seam-less-react';
    import {sha512} from 'js-sha512';
    import {useEffect} from 'react';

export default function App() { useEffect(() => { const eventEmitter = new NativeEventEmitter(); const paymentSuccess = eventEmitter.addListener('onPaymentSuccess', e => { console.log(e.merchantResponse); console.log(e.payuResponse); }); const paymentFailure = eventEmitter.addListener('onPaymentFailure', e => { console.log(e.merchantResponse); console.log(e.payuResponse); }); const paymentCancel = eventEmitter.addListener('onPaymentCancel', e => { console.log('onPaymentCancel isTxnInitiated -' + e); }); const error = eventEmitter.addListener('onError', e => { console.log(e); }); const generateHash = eventEmitter.addListener( 'generateHash', ongenerateHash, ); return () => { eventEmitter.removeAllListeners('paymentSuccess'); }; }, []);

var payUPaymentParams = { key: 'merchantKey', transactionId: new Date().getTime().toString(), amount: '1.0', productInfo: 'productInfo', firstName: 'firstName', email: 'test@gmail.com', phone: '7788996655', ios_surl: 'https://payu.herokuapp.com/ios_success', ios_furl: 'https://payu.herokuapp.com/ios_failure', android_surl: 'https://payu.herokuapp.com/ios_success', android_furl: 'https://payu.herokuapp.com/ios_failure', environment: '1', //<0 for Production/1 for Staging> userCredential: 'merchantKey:test@gmail.com', };

const ongenerateHash = (e:any) => { console.log(e.hashName); console.log(e.hashString); sendBackHash( e.hashName, e.hashString + '', ); };

const sendBackHash = (hashName: any, hashData: any) => { console.log(hashName); var hashValue = calculateHash(hashData); var result = {[hashName]: hashValue}; console.log(result); PayUBizSdk.hashGenerated(result); };

const calculateHash = (data: any) => { console.log(data); var result = sha512(data); console.log(result); return result; };

var payUCheckoutProConfig = { merchantResponseTimeout: 1000, paymentModesOrder: [{UPI: 'TEZ'},{Wallets: 'PHONEPE'}], showExitConfirmationOnCheckoutScreen: true, showExitConfirmationOnPaymentScreen: true, surePayCount: 1, merchantName: 'merchantName', };

const handlePayment = () => { console.log('Clicked on Payment'); var paymentObject = { payUPaymentParams: payUPaymentParams, // payUCheckoutProConfig is optional // Detail can be found in latter section payUCheckoutProConfig: payUCheckoutProConfig, }; PayUBizSdk.openCheckoutScreen(paymentObject); console.log('PAYMENT SCREEN OPENED'); };

return ( <View style={{flex: 1, margin: 20, justifyContent: 'center'}}> <Button title="Test Payment" onPress={() => handlePayment()} /> ); }