0

I want to make cashfree payment gatway dynamic for that I want to change get method of cashfree to post method, as by get method I am unable to make dynamic filed of user and product .

I want to get current user and product and add it in payment method intead of static data.

Cashfree.XClientId = process.env.CASH_API_ID;
Cashfree.XClientSecret = process.env.CASH_SECRET;
Cashfree.XEnvironment = Cashfree.Environment.SANDBOX;

function generateOrderId() {
  const uniqueId = crypto.randomBytes(16).toString("hex");
  const hash = crypto.createHash("sha256");
  hash.update(uniqueId);
  const orderId = hash.digest("hex");
  return orderId.substr(0, 12);
}
export const paymentinitiate = async (req, res) => {
  try {
    console.log();
    var request = {
      order_amount: 1,
      order_currency: "INR",
      order_id: await generateOrderId(),
      customer_details: {
        customer_id: "walterwNrcMi",
        customer_phone: "9999999999",
      },
      order_meta: {
        return_url:
          "https://www.cashfree.com/devstudio/preview/pg/web/checkout?order_id={order_id}",
      },
    };

this is the code in server I am using for making payment. I want to make it dynamically.

I am unable to find its solution ???

I am using the same code as provided by cashfree payment gatway. in tha static data is showing but I want to change it dynamically but method is get ,, in get method cart cant be sent.

1
  • I want to send dynamic data in request of cashfree server side request in payment initiate, which is now static. Commented Jul 6 at 4:41

1 Answer 1

0

Cashfree lets you send dynamic data. This is how you would modify the above code. The key is to use order_tags. More about it here

import { Cashfree } from "cashfree-pg"; 

Cashfree.XClientId = process.env.CASH_API_ID;
Cashfree.XClientSecret = process.env.CASH_SECRET;
Cashfree.XEnvironment = Cashfree.Environment.SANDBOX;

var request = {
    "order_amount": 1.00,
    "order_currency": "INR",
    "order_id": "order_44594806",
    "customer_details": {
        "customer_id": "walterwNrcMi",
        "customer_phone": "8474090589"
    },
    "order_meta": {
        "return_url": "https://www.cashfree.com/devstudio/preview/pg/web/checkout?order_id={order_id}"
    },
    "order_tags": {
        "name": "Developer",
        "company": "Cashfree"
    }
};

Cashfree.PGCreateOrder("2023-08-01", request).then((response) => {
    console.log('Order created successfully:',response.data);
}).catch((error) => {
    console.error('Error:', error.response.data.message);
});
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.