Suraj-Tiwari / react-native-payumoney

React Native Payumoney (Android/IOS)
MIT License
18 stars 9 forks source link

Getting Error Toast Some error occured, success: false #7

Closed naveenvignesh5 closed 6 years ago

naveenvignesh5 commented 6 years ago

My PHP Code

<?php
    header('Access-Control-Allow-Origin:*');
    header('Content-Type: application/json');
    //Make sure that it is a POST request.
    $res = new \stdClass();
    if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
        $res -> err = 'Request method must be POST!';
        throw new Exception(json_encode($res));
    }

    //Make sure that the content type of the POST request has been set to application/json
    // $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
    // if(strcasecmp($contentType, 'application/json') != 0){
    //     $res -> err = 'Content type must be: application/json';
    //     throw new Exception(json_encode($res));
    // }

    //Receive the RAW post data.
    $content = trim(file_get_contents("php://input"));

    //Attempt to decode the incoming RAW post data from JSON.
    $input = json_decode($content, true);

    //If json_decode failed, the JSON is invalid.
    if(!is_array($input)){
        throw new Exception('Received content contained invalid JSON!');
    }

    //Process the JSON.

    function makeHash($key, $txnid, $amount, $productinfo, $firstname, $email){
        $salt = "WDbzI4n2qU"; //Please change the value with the live salt for production environment

        $payhash_str = $key . '|' . checkNull($txnid) . '|' . checkNull($amount) . '|' . checkNull($productinfo) . '|' . checkNull($firstname) . '|' . checkNull($email) . '|||||||||||' . $salt;

        $hash = strtolower(hash('sha512', $payhash_str));
        return $hash;
    }

    function checkNull($value)
    {
        if ($value == null) {
            return '';
        } else {
            return $value;
        }
    }

    $key = $input['key'];
    $txnid = $input['txnid'];
    $amount = $input['amount'];
    $productinfo = $input['productinfo'];
    $firstname = $input['firstname'];
    $email = $input['email'];

    $res -> hash = makeHash($key, $txnid, $amount, $productinfo, $firstname, $email);
    $res -> data = $input;
    echo json_encode($res); 

?>

React Native Module

export const pay = data => new Promise(async (reject, resolve) => {
  try {
    const isConnected = await Network.isConnected();

    if (!isConnected) reject(NetworkError());

    // const user = await GetCurrentUser();

    // const { amount, productinfo } = data;
    // const { name, email } = user;

    const txid = '12345';

    const hashReqBody = {
      key: 'tdDbpjSr',
      txnid: txid,
      amount: 99.99,
      productinfo: 'test',
      firstname: 'test',
      email: 'test@gmail.com',
    };

    const hashRes = await POST('https://pancratic-winch.000webhostapp.com/hash.php', hashReqBody);

    const options = {
      amount: 99.99,
      productId: 'test',
      txid,
      name: 'test',
      email: 'test@gmail.com',
      phone: '9444772154',
      id: '6469569',
      key: 'tdDbpjSr',
      surl: 'https://www.payumoney.com/mobileapp/payumoney/success.php',
      furl: 'https://www.payumoney.com/mobileapp/payumoney/failure.php',
      sandbox: true,
      hash: hashRes.hash, // 85c0452ac17d651aca2d2b8a3fad9b9bfd0f2a956cab72c7281ee9ab3a0b4ac3f61691da24133835e8ff78d0f8c63906e2f594e4fae0a76e515ce8c22a2b0b55
    };

    const payres = await PayuMoney.pay(options);
    resolve(payres);
  } catch (err) {
    reject(err);
  }
});
vijay2330 commented 6 years ago

I am also facing this error? Is any thing need to be updated ?

vijay2330 commented 6 years ago

@naveenvignesh5 bro did u find the solution for this?

Suraj-Tiwari commented 6 years ago

Do you have test credentials? or using one provided from payumoney dashboard.

Suraj-Tiwari commented 6 years ago

please try with there credentials https://github.com/Suraj-Tiwari/react-native-payumoney/issues/2#issuecomment-409661804

Suraj-Tiwari commented 6 years ago

// are you sure about this? this snippet in your comment looks invalid.

const options = {
      amount: 99.99,
      productId: 'test',
      **txid : txid,**      **//<- here it should be like this**
      name: 'test',
      email: 'test@gmail.com',
      phone: '9444772154',
      id: '6469569',
      key: 'tdDbpjSr',
      surl: 'https://www.payumoney.com/mobileapp/payumoney/success.php',
      furl: 'https://www.payumoney.com/mobileapp/payumoney/failure.php',
      sandbox: true,
      hash: hashRes.hash, // 85c0452ac17d651aca2d2b8a3fad9b9bfd0f2a956cab72c7281ee9ab3a0b4ac3f61691da24133835e8ff78d0f8c63906e2f594e4fae0a76e515ce8c22a2b0b55
    };
naveenvignesh5 commented 6 years ago

That is es6 notation. I wrote it like that to avoid lint. I tried with the way you told me. Still I am getting this error.

@Suraj-Tiwari your custom options seems to be working where hardcoded hash is present but not my sandbox credentials.

@vijay2330 No I was not able to find a solution.

vijay2330 commented 6 years ago

@Suraj-Tiwari i tried ur options code... it is working now.... let me confirm once by adding my own credentials from dashboard

vijay2330 commented 6 years ago

@Suraj-Tiwari Using my own credentials is not working.... But using the test credentials... app works perfectly.I got the credentials from dashboard

@naveenvignesh5 own credentials is not working as u mentioned

Suraj-Tiwari commented 6 years ago

Because those credentials are for web testing. For android you have to ask them.

set Sandbox:false to test out with your credentials in production.

vijay2330 commented 6 years ago

I asked payumoney about this..... They replied as below...

Please change the dependency to the below as: compile 'com.payumoney.sdkui:plug-n-play:1.4.4’

Will it work for the linked react-native module

vijay2330 commented 6 years ago

By adding compile 'com.payumoney.sdkui:plug-n-play:1.4.4’ ... Clicking on Make payment button closes the app

Suraj-Tiwari commented 6 years ago

You don't have to change dependency. If You can simply proceed with my test credentials set Sandbox to false and check it for production.

vijay2330 commented 6 years ago

@Suraj-Tiwari its not working..... Changing sandbox to false throws same error....

Suraj-Tiwari commented 6 years ago

@vijay2330 @naveenvignesh5 confirm if you have approval.

[
            "amount" => $amount,
            "txid" => $txnid,
            "productId" => $productinfo,
            "name" => $name,
            "email" => $email,
            "phone" => $r->mobile,
            "id" => $id,
            "key" => $key,
            "surl" => "", //url
            "furl" => "", //url
            "sandbox" => false,
            "hash" => $hash
]

this is the data (in json format) i'm passing to sdk in app generated on server. (Production app)

vijay2330 commented 6 years ago

@Suraj-Tiwari can u please explain about surl and furl and what url need to point this.

Suraj-Tiwari commented 6 years ago

in my Case both of them are pointing to hash generating link

vijay2330 commented 6 years ago

@Suraj-Tiwari My backend php file url is http://192.168.1.72/sanjai_nidhi_backend/api.php... In this endpoint only the hash making process is executing...... I tried to give this url in both surl and furl but same error is throwing

Suraj-Tiwari commented 6 years ago

try checking logs in logcat.

Suraj-Tiwari commented 6 years ago

closing due to inactivity