Every attempt to integrate the Cashfree payment gateway into my Laravel application results in the same error.
[2024-03-26 17:19:44] local.DEBUG: Input data for payment initiation: {"orderId":"inv004","orderAmount":"0963462492","customerName":"Manuel Portillo","customerEmail":"[email protected]","customerPhone":"7365435505","returnUrl":"https://payment.remwhacktechnologies.com/payment/callback","version":"2021-05-21"} [2024-03-26 17:19:45] local.ERROR: Error initiating payment: 400 - {"message":"version value should be 2021-05-21 or 2022-01-01 or 2022-09-01 or 2023-08-01","code":"request_failed","type":"invalid_request_error"}
I have changed the version year and tried all possibilities, but I consistently receive the same error. The code below is from my controller, where I am initiating my payment
public function initiatePayment(Request $request)
{
try {
// Perform validation on $request->input() if necessary
$clientId = 'TEST10152050eee78259b07eef2a86fc05025101'; // Your Cashfree client ID
$clientSecret = 'cfsk_ma_test_303cb4db3e6ad084b222959b7014db1a_0161753d'; // Your Cashfree client secret
$orderId = 'inv004'; // Generate a unique order ID
$orderAmount = $request->input('amount');
$customerName = $request->input('name');
$customerEmail = $request->input('email');
$customerPhone = $request->input('phone');
$returnUrl = 'https://payment.remwhacktechnologies.com/payment/callback'; // Ensure the return URL is correct
$version = '2021-05-21'; // Set the correct version parameter
// Log input data for debugging
Log::debug('Input data for payment initiation:', [
'orderId' => $orderId,
'orderAmount' => $orderAmount,
'customerName' => $customerName,
'customerEmail' => $customerEmail,
'customerPhone' => $customerPhone,
'returnUrl' => $returnUrl,
'version' => $version,
]);
$response = Http::withHeaders([
'X-Client-Id' => $clientId,
'X-Client-Secret' => $clientSecret,
'Content-Type' => 'application/json',
'Accept' => 'application/json',
])->post('https://sandbox.cashfree.com/pg/orders', [
'orderId' => $orderId,
'orderAmount' => $orderAmount,
'customerName' => $customerName,
'customerEmail' => $customerEmail,
'customerPhone' => $customerPhone,
'returnUrl' => $returnUrl,
'version' => $version, // Include the version parameter
]);
if ($response->successful()) {
// Redirect user to payment gateway
return redirect($response['paymentLink']);
} else {
// Log error response
Log::error('Error initiating payment: '.$response->status().' - '.$response->body());
// Handle unsuccessful response
return response()->json(['error' => 'Error initiating payment']);
}
} catch (RequestException $e) {
// Log exception
Log::error('Error initiating payment: '.$e->getCode().' - '.$e->getMessage());
// Handle request exception
return response()->json(['error' => 'Error initiating payment']);
}
}
I have attempted to use all available versions, including 2021-05-21, 2022-01-01, 2022-09-01, and 2023-08-01, but the error persists. As a newcomer to PHP and Laravel, I would greatly appreciate any help you can give me.
This is deprecated method. Instead of this try cashfree latest php sdk i.e. https://github.com/cashfree/cashfree-pg-sdk-php
Install using composer
For your use case sample code is
Make sure you have imported all necessary dependency