@@ -95,7 +95,16 @@ function cashfree_link($params)
95
95
96
96
function generatePaymentLink ($ cf_request , $ params )
97
97
{
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
+
99
108
$ request = array (
100
109
"customer_details " => array (
101
110
"customer_id " => "WhmcsCustomer " ,
@@ -129,7 +138,7 @@ function generatePaymentLink($cf_request, $params)
129
138
CURLOPT_HTTPHEADER => [
130
139
"Accept: application/json " ,
131
140
"Content-Type: application/json " ,
132
- "x-api-version: 2021-05-21 " ,
141
+ "x-api-version: 2022-01-01 " ,
133
142
"x-client-id: " .$ params ['appId ' ],
134
143
"x-client-secret: " .$ params ['secretKey ' ],
135
144
"x-idempotency-key: " .$ cf_request ['orderId ' ]
@@ -158,4 +167,37 @@ function generatePaymentLink($cf_request, $params)
158
167
die ("Unable to create your order. Please contact support. " );
159
168
}
160
169
}
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 );
161
203
}
0 commit comments