1
1
<?php
2
- define ('CASHFREE_PLUGIN_VERSION ' , '2.3 .0 ' , true );
2
+ define ('CASHFREE_PLUGIN_VERSION ' , '2.4 .0 ' , true );
3
3
define ('API_VERSION ' , '2022-09-01 ' );
4
4
5
5
/**
@@ -62,6 +62,11 @@ function cashfree_config()
62
62
'Type ' => 'yesno ' ,
63
63
'Description ' => 'Tick to enable test mode ' ,
64
64
),
65
+ 'checkoutPopUp ' => array (
66
+ 'FriendlyName ' => 'Enable Popup Checkout ' ,
67
+ 'Type ' => 'yesno ' ,
68
+ 'Description ' => 'Tick to enable popup checkout ' ,
69
+ ),
65
70
);
66
71
}
67
72
/**
@@ -73,55 +78,60 @@ function cashfree_config()
73
78
* @return string
74
79
*/
75
80
function cashfree_link ($ params )
76
- {
81
+ {
77
82
// Invoice Parameters
78
- $ invoice_id = $ params ['invoiceid ' ];
83
+ $ invoice_id = $ params ['invoiceid ' ];
79
84
80
85
// System Parameters
81
- $ system_url = $ params ['systemurl ' ];
82
- $ module_name = $ params ['paymentmethod ' ];
86
+ $ system_url = $ params ['systemurl ' ];
87
+ $ module_name = $ params ['paymentmethod ' ];
83
88
$ invoice_details = mysql_fetch_assoc (select_query ('tblinvoices ' , '* ' , array ("id " => $ invoice_id )));
84
89
85
- #check whether order is already paid or not, if paid then redirect to complete page
86
- if ($ invoice_details ['status ' ] === 'Paid ' )
87
- {
88
- header ("Location: " .$ system_url ."/viewinvoice.php?id= " . $ invoice_id );
89
-
90
+ // Check if the order is already paid
91
+ if ($ invoice_details ['status ' ] === 'Paid ' ) {
92
+ header ("Location: " . $ system_url . "/viewinvoice.php?id= " . $ invoice_id );
90
93
exit ;
91
- }
92
-
93
- //Cashfree request parameters
94
- $ cf_request = array ();
95
- $ cf_request ['orderId ' ] = 'cf ' .time ().'_ ' .$ invoice_id ;
96
- $ cf_request ['returnUrl ' ] = $ system_url . 'modules/gateways/cashfree/ ' . $ module_name . '.php?order_id={order_id} ' ;
97
- $ cf_request ['notifyUrl ' ] = $ system_url . 'modules/gateways/cashfree/ ' . $ module_name . '_notify.php ' ;
98
- $ mode = $ cf_request ['mode ' ] = ($ params ['testMode ' ] == 'on ' ) ? 'sandbox ' : 'production ' ;
99
- $ payment_session_id = generatePaymentSession ($ cf_request ,$ params );
94
+ }
100
95
96
+ // Cashfree request parameters
97
+ $ cf_request = array (
98
+ 'orderId ' => 'cf ' . time () . '_ ' . $ invoice_id ,
99
+ 'returnUrl ' => $ system_url . 'modules/gateways/cashfree/ ' . $ module_name . '.php?order_id={order_id} ' ,
100
+ 'notifyUrl ' => $ system_url . 'modules/gateways/cashfree/ ' . $ module_name . '_notify.php ' ,
101
+ 'mode ' => ($ params ['testMode ' ] == 'on ' ) ? 'sandbox ' : 'production '
102
+ );
103
+ $ callback_url = $ system_url . 'modules/gateways/cashfree/ ' . $ module_name . '.php?order_id= ' . $ cf_request ['orderId ' ];
104
+ $ payment_session_id = generatePaymentSession ($ cf_request , $ params );
105
+ // HTML Output
106
+ $ checkout_function = $ params ['checkoutPopUp ' ] == 'on ' ? "openCheckout() " : "cashfree.checkout({paymentSessionId: ' $ payment_session_id', platformName: 'wh'}) " ;
101
107
$ html_output = <<<EOT
102
108
<!DOCTYPE html>
103
109
<html lang="en">
104
110
<head>
105
111
<script src="https://sdk.cashfree.com/js/v3/cashfree.js"></script>
106
112
</head>
107
113
<body>
108
- <button type="button" id="renderBtn">
109
- Pay Now
110
- </button>
114
+ <form action="javascript:void(0);"></form>
115
+ <button type="button" id="renderBtn">Pay Now</button>
111
116
</body>
112
117
<script>
113
- const cashfree = Cashfree({
114
- mode: " $ mode"
115
- });
116
- document.getElementById("renderBtn").addEventListener("click", () => {
118
+ const cashfree = Cashfree({mode: " {$ cf_request ['mode ' ]}"});
119
+ function openCheckout(){
117
120
cashfree.checkout({
118
- paymentSessionId: " $ payment_session_id",
119
- platformName: "wh"
121
+ paymentSessionId: " $ payment_session_id",
122
+ redirectTarget: "_modal",
123
+ platformName: "wh"
124
+ }).then((result) => {
125
+ window.location.href = " $ callback_url";
120
126
});
127
+ }
128
+ document.getElementById("renderBtn").addEventListener("click", () => {
129
+ $ checkout_function;
121
130
});
122
131
</script>
123
132
</html>
124
- EOT ;
133
+ EOT ;
134
+
125
135
return $ html_output ;
126
136
}
127
137
@@ -223,15 +233,15 @@ function createCashfreeOrder($cf_request, $params, $api_endpoint) {
223
233
]);
224
234
225
235
$ response = curl_exec ($ curl );
226
-
227
- $ err = curl_error ($ curl );
228
-
236
+ $ httpcode = curl_getinfo ($ curl , CURLINFO_HTTP_CODE );
229
237
curl_close ($ curl );
230
-
231
- if ($ err ) {
238
+ if ($ httpcode != 200 ) {
239
+ $ errArray = json_decode ($ response , true );
240
+ if (isset ($ errArray ['message ' ])) {
241
+ die ($ errArray ['message ' ]);
242
+ }
232
243
die ("Unable to create your order. Please contact support. " );
233
244
}
234
-
235
245
$ cf_order = json_decode ($ response );
236
246
237
247
if ($ cf_order && !empty ($ cf_order ->payment_session_id )) {
0 commit comments