cashfree payment gateway intergration in reactjs

1.9k views Asked by At

I am using cashfree payment gateway in my website , its working fine but i don't know that how to get the response of cashfree transaction and i use the redirect link is https://payments-test.cashfree.com/order/orderToken to open the cashfree UI,so help me and my code is here...


import React from 'react';
import { useState, useEffect } from 'react';
import { connect } from "react-redux";
import { cash_data } from "../../../../store/Action/UserFatchData";
import { dropinComponents } from "./dropinComponents.js";

const Cashfree1 = ({ dispatch, res }) => {
  const [orderToken, setOrderToken] = useState("3D3S3KLoiTRp9lVwzUvo");
  const [components, setComponents] = useState([]);

  const [payment, setpayment] = useState({
    order_id: "4158",
    order_amount: 15.00,
    order_currency: "INR",
    order_note: "Additional order info",
    customer_details: {
      customer_id: "12345",
      customer_email: "[email protected]",
      customer_phone: "9816512345"
    }
  })


  useEffect(() => {
    let comp = []
    dropinComponents.map((name, index) => {
      return (
        comp.push(name.id)
      )
    })
    setComponents(comp)
    // dispatch(cash_data(payment))
    window.location.href = "https://payments-test.cashfree.com/order/#3D3S3KLoiTRp9lVwzUvo"
  }, [])
  return (
    <>

    </>
  )
}

const mapStateToProps = (state) => ({
  res: state.Cash,
});

export default connect(mapStateToProps)(Cashfree1);
1

There are 1 answers

0
Raj Nandan Sharma On

to get the response first you will have to add a return url like this

{
    order_id: "4158",
    order_amount: 15.00,
    order_currency: "INR",
    order_note: "Additional order info",
    customer_details: {
      customer_id: "12345",
      customer_email: "[email protected]",
      customer_phone: "9816512345"
    },
    order_meta: {
       return_url: "https://merchant.in/pg/process_return?cf_id={order_id}&cf_token={order_token}"
    }
  }

Once you have done that, Cashfree will redirect the user to the above with order_id and order_token as part of the URL. You should then call the https://sandbox.cashfree.com/pg/orders/order_token to fetch the transaction and order status.

You can read more here