5
5
if (!defined ("WHMCS " )) {
6
6
die ("This file cannot be accessed directly " );
7
7
}
8
+
8
9
/**
9
10
* Define module related meta data.
10
11
* @return array
@@ -13,11 +14,12 @@ function cashfree_MetaData()
13
14
{
14
15
return array (
15
16
'DisplayName ' => 'Cashfree ' ,
16
- 'APIVersion ' => '1.0 .2 ' ,
17
+ 'APIVersion ' => '2.1 .2 ' ,
17
18
'DisableLocalCredtCardInput ' => true ,
18
19
'TokenisedStorage ' => false ,
19
20
);
20
21
}
22
+
21
23
/**
22
24
* Define Cashfree gateway configuration options.
23
25
* @return array
@@ -61,6 +63,7 @@ function cashfree_config()
61
63
),
62
64
);
63
65
}
66
+
64
67
/**
65
68
* Payment link.
66
69
* Required by third party payment gateway modules only.
@@ -70,29 +73,27 @@ function cashfree_config()
70
73
* @return string
71
74
*/
72
75
function cashfree_link ($ params )
73
- {
76
+ {
74
77
// Invoice Parameters
75
- $ invoiceId = $ params ['invoiceid ' ];
78
+ $ invoiceId = $ params ['invoiceid ' ];
76
79
77
80
// System Parameters
78
- $ systemUrl = $ params ['systemurl ' ];
79
- $ moduleName = $ params ['paymentmethod ' ];
80
- $ result = mysql_fetch_assoc (select_query ('tblinvoices ' , '* ' , array ("id " => $ invoiceId )));
81
+ $ systemUrl = $ params ['systemurl ' ];
82
+ $ moduleName = $ params ['paymentmethod ' ];
83
+ $ result = mysql_fetch_assoc (select_query ('tblinvoices ' , '* ' , array ("id " => $ invoiceId )));
81
84
82
85
#check whether order is already paid or not, if paid then redirect to complete page
83
- if ($ result ['status ' ] === 'Paid ' )
84
- {
85
- header ("Location: " .$ params ['systemurl ' ]."/viewinvoice.php?id= " . $ invoiceId );
86
-
86
+ if ($ result ['status ' ] === 'Paid ' ) {
87
+ header ("Location: " . $ params ['systemurl ' ] . "/viewinvoice.php?id= " . $ invoiceId );
87
88
exit ;
88
- }
89
+ }
89
90
90
91
//Cashfree request parameters
91
- $ cf_request = array ();
92
- $ cf_request ['orderId ' ] = ' cashfreeWhmcs_ ' . $ invoiceId ;
93
- $ cf_request ['returnUrl ' ] = $ systemUrl . 'modules/gateways/callback/ ' . $ moduleName . '.php?order_id={order_id}&order_token={order_token} ' ;
94
- $ cf_request ['notifyUrl ' ] = $ systemUrl . 'modules/gateways/callback/ ' . $ moduleName . '_notify.php ' ;
95
- $ payment_link = generatePaymentLink ($ cf_request ,$ params );
92
+ $ cf_request = array ();
93
+ $ cf_request ['orderId ' ] = ' cf ' . time () . ' _ ' . $ invoiceId ;
94
+ $ cf_request ['returnUrl ' ] = $ systemUrl . 'modules/gateways/callback/ ' . $ moduleName . '.php?order_id={order_id}&order_token={order_token} ' ;
95
+ $ cf_request ['notifyUrl ' ] = $ systemUrl . 'modules/gateways/callback/ ' . $ moduleName . '_notify.php ' ;
96
+ $ payment_link = generatePaymentLink ($ cf_request , $ params );
96
97
97
98
$ langPayNow = $ params ['langpaynow ' ];
98
99
$ htmlOutput = '<form method="post" action=" ' . $ payment_link . '"> ' ;
@@ -105,107 +106,107 @@ function cashfree_link($params)
105
106
function generatePaymentLink ($ cf_request , $ params )
106
107
{
107
108
$ apiEndpoint = ($ params ['testMode ' ] == 'on ' ) ? 'https://sandbox.cashfree.com/pg/orders ' : 'https://api.cashfree.com/pg/orders ' ;
108
- $ getCashfreeOrderUrl = $ apiEndpoint. "/ " . $ cf_request ['orderId ' ];
109
-
109
+ $ getCashfreeOrderUrl = $ apiEndpoint . "/ " . $ cf_request ['orderId ' ];
110
+
110
111
$ getOrder = getCfOrder ($ params , $ getCashfreeOrderUrl );
111
112
112
113
if (null !== $ getOrder && $ getOrder ->order_status == "ACTIVE " &&
113
114
$ getOrder ->order_amount == $ params ['amount ' ] && $ getOrder ->order_currency == $ params ['currency ' ]) {
114
- return $ getOrder ->payment_link ;
115
+ return $ getOrder ->payment_link ;
115
116
}
116
117
117
118
$ request = array (
118
- "customer_details " => array (
119
- "customer_id " => "WhmcsCustomer " ,
120
- "customer_email " => $ params ['clientdetails ' ]['email ' ],
121
- "customer_name " => $ params ['clientdetails ' ]['firstname ' ].' ' .$ params ['clientdetails ' ]['lastname ' ],
122
- "customer_phone " => $ params ['clientdetails ' ]['phonenumber ' ]
119
+ "customer_details " => array (
120
+ "customer_id " => "WhmcsCustomer " ,
121
+ "customer_email " => $ params ['clientdetails ' ]['email ' ],
122
+ "customer_name " => $ params ['clientdetails ' ]['firstname ' ] . ' ' . $ params ['clientdetails ' ]['lastname ' ],
123
+ "customer_phone " => $ params ['clientdetails ' ]['phonenumber ' ],
124
+ ),
125
+ "order_id " => $ cf_request ['orderId ' ],
126
+ "order_amount " => $ params ['amount ' ],
127
+ "order_currency " => $ params ['currency ' ],
128
+ "order_note " => "WHMCS Order " ,
129
+ "order_meta " => array (
130
+ "return_url " => $ cf_request ['returnUrl ' ],
131
+ "notify_url " => $ cf_request ['notifyUrl ' ],
123
132
),
124
- "order_id " => $ cf_request ['orderId ' ],
125
- "order_amount " => $ params ['amount ' ],
126
- "order_currency " => $ params ['currency ' ],
127
- "order_note " => "WHMCS Order " ,
128
- "order_meta " => array (
129
- "return_url " => $ cf_request ['returnUrl ' ],
130
- "notify_url " => $ cf_request ['notifyUrl ' ]
131
- )
132
133
);
133
134
134
135
$ curlPostfield = json_encode ($ request );
135
136
136
137
$ curl = curl_init ();
137
138
138
139
curl_setopt_array ($ curl , [
139
- CURLOPT_URL => $ apiEndpoint ,
140
- CURLOPT_RETURNTRANSFER => true ,
141
- CURLOPT_ENCODING => "" ,
142
- CURLOPT_MAXREDIRS => 10 ,
143
- CURLOPT_TIMEOUT => 30 ,
144
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
145
- CURLOPT_CUSTOMREQUEST => "POST " ,
146
- CURLOPT_POSTFIELDS => $ curlPostfield ,
147
- CURLOPT_HTTPHEADER => [
148
- "Accept: application/json " ,
149
- "Content-Type: application/json " ,
150
- "x-api-version: 2022-01-01 " ,
151
- "x-client-id: " . $ params ['appId ' ],
152
- "x-client-secret: " . $ params ['secretKey ' ]
140
+ CURLOPT_URL => $ apiEndpoint ,
141
+ CURLOPT_RETURNTRANSFER => true ,
142
+ CURLOPT_ENCODING => "" ,
143
+ CURLOPT_MAXREDIRS => 10 ,
144
+ CURLOPT_TIMEOUT => 30 ,
145
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
146
+ CURLOPT_CUSTOMREQUEST => "POST " ,
147
+ CURLOPT_POSTFIELDS => $ curlPostfield ,
148
+ CURLOPT_HTTPHEADER => [
149
+ "Accept: application/json " ,
150
+ "Content-Type: application/json " ,
151
+ "x-api-version: 2022-01-01 " ,
152
+ "x-client-id: " . $ params ['appId ' ],
153
+ "x-client-secret: " . $ params ['secretKey ' ],
153
154
],
154
155
]);
155
156
156
157
$ response = curl_exec ($ curl );
157
-
158
+
158
159
$ err = curl_error ($ curl );
159
160
160
161
curl_close ($ curl );
161
162
162
163
if ($ err ) {
163
164
die ("Unable to create your order. Please contact support. " );
164
165
}
165
-
166
+
166
167
$ cfOrder = json_decode ($ response );
167
168
168
- if (null !== $ cfOrder && !empty ($ cfOrder ->order_token ))
169
- {
169
+ if (null !== $ cfOrder && !empty ($ cfOrder ->order_token )) {
170
170
return $ cfOrder ->payment_link ;
171
171
} else {
172
- if (!empty ($ cfOrder ->message )) {
172
+ if (!empty ($ cfOrder ->message )) {
173
173
die ($ cfOrder ->message );
174
174
} else {
175
175
die ("Unable to create your order. Please contact support. " );
176
176
}
177
177
}
178
178
}
179
179
180
- function getCfOrder ($ params , $ curlUrl ) {
180
+ function getCfOrder ($ params , $ curlUrl )
181
+ {
181
182
$ curl = curl_init ();
182
183
183
184
curl_setopt_array ($ curl , [
184
- CURLOPT_URL => $ curlUrl ,
185
- CURLOPT_RETURNTRANSFER => true ,
186
- CURLOPT_ENCODING => "" ,
187
- CURLOPT_MAXREDIRS => 10 ,
188
- CURLOPT_TIMEOUT => 30 ,
189
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
190
- CURLOPT_CUSTOMREQUEST => "GET " ,
191
- CURLOPT_HTTPHEADER => [
192
- "Accept: application/json " ,
193
- "Content-Type: application/json " ,
194
- "x-api-version: 2022-01-01 " ,
195
- "x-client-id: " . $ params ['appId ' ],
196
- "x-client-secret: " . $ params ['secretKey ' ]
185
+ CURLOPT_URL => $ curlUrl ,
186
+ CURLOPT_RETURNTRANSFER => true ,
187
+ CURLOPT_ENCODING => "" ,
188
+ CURLOPT_MAXREDIRS => 10 ,
189
+ CURLOPT_TIMEOUT => 30 ,
190
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
191
+ CURLOPT_CUSTOMREQUEST => "GET " ,
192
+ CURLOPT_HTTPHEADER => [
193
+ "Accept: application/json " ,
194
+ "Content-Type: application/json " ,
195
+ "x-api-version: 2022-01-01 " ,
196
+ "x-client-id: " . $ params ['appId ' ],
197
+ "x-client-secret: " . $ params ['secretKey ' ],
197
198
],
198
199
]);
199
200
200
201
$ getOrderResponse = curl_exec ($ curl );
201
-
202
+
202
203
$ err = curl_error ($ curl );
203
204
204
205
curl_close ($ curl );
205
206
206
207
if ($ err ) {
207
208
die ("Unable to create your order. Please contact support. " );
208
209
}
209
-
210
+
210
211
return json_decode ($ getOrderResponse );
211
212
}
0 commit comments