Skip to content

Commit c0423f3

Browse files
Merge pull request #11 from cashfree/feature/version_bump_2.0.0
Bug fix for get existing order
2 parents 7fc8e4d + 8acdf19 commit c0423f3

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

modules/gateways/cashfree.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ function cashfree_link($params)
9595

9696
function generatePaymentLink($cf_request, $params)
9797
{
98-
$apiEndpoint = ($params['testMode'] == 'on') ? 'https://sandbox.cashfree.com/pg/orders' : 'https://api.cashfree.com/pg/orders';
98+
$apiEndpoint = ($params['testMode'] == 'on') ? 'https://sandbox.cashfree.com/pg/orders' : 'https://api.cashfree.com/pg/orders';
99+
$getCashfreeOrderUrl = $apiEndpoint."/".$cf_request['orderId'];
100+
101+
$getOrder = getCfOrder($params, $getCashfreeOrderUrl);
102+
103+
if (null !== $getOrder && $getOrder->order_status == "ACTIVE" &&
104+
$getOrder->order_amount == $params['amount'] && $getOrder->order_currency == $params['currency']) {
105+
return $getOrder->payment_link;
106+
}
107+
99108
$request = array(
100109
"customer_details" => array(
101110
"customer_id" => "WhmcsCustomer",
@@ -129,7 +138,7 @@ function generatePaymentLink($cf_request, $params)
129138
CURLOPT_HTTPHEADER => [
130139
"Accept: application/json",
131140
"Content-Type: application/json",
132-
"x-api-version: 2021-05-21",
141+
"x-api-version: 2022-01-01",
133142
"x-client-id: ".$params['appId'],
134143
"x-client-secret: ".$params['secretKey'],
135144
"x-idempotency-key: ".$cf_request['orderId']
@@ -158,4 +167,37 @@ function generatePaymentLink($cf_request, $params)
158167
die("Unable to create your order. Please contact support.");
159168
}
160169
}
170+
}
171+
172+
function getCfOrder($params, $curlUrl) {
173+
$curl = curl_init();
174+
175+
curl_setopt_array($curl, [
176+
CURLOPT_URL => $curlUrl,
177+
CURLOPT_RETURNTRANSFER => true,
178+
CURLOPT_ENCODING => "",
179+
CURLOPT_MAXREDIRS => 10,
180+
CURLOPT_TIMEOUT => 30,
181+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
182+
CURLOPT_CUSTOMREQUEST => "GET",
183+
CURLOPT_HTTPHEADER => [
184+
"Accept: application/json",
185+
"Content-Type: application/json",
186+
"x-api-version: 2022-01-01",
187+
"x-client-id: ".$params['appId'],
188+
"x-client-secret: ".$params['secretKey']
189+
],
190+
]);
191+
192+
$getOrderResponse = curl_exec($curl);
193+
194+
$err = curl_error($curl);
195+
196+
curl_close($curl);
197+
198+
if ($err) {
199+
die("Unable to create your order. Please contact support.");
200+
}
201+
202+
return json_decode($getOrderResponse);
161203
}

0 commit comments

Comments
 (0)