Skip to content

Commit 02a772e

Browse files
Merge pull request #19 from chrismadufor/v2-update
Upgraded to inline v2 and added support for apple pay
2 parents b1d42ec + 5b3b656 commit 02a772e

File tree

5 files changed

+86
-83
lines changed

5 files changed

+86
-83
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.3.0 (April 25, 2024)
2+
3+
- Upgraded to Paystack inlinejs v2
4+
- Added support for Apple pay
5+
- Included fees in the payment data
6+
- Added support for merchants who pass charges to customers
7+
- Bug fixes
8+
19
## 2.2.1 (November 13, 2020)
210

311
- Fix broken payment options image link

modules/.DS_Store

0 Bytes
Binary file not shown.

modules/gateways/callback/paystack.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/ ********************************************************************* \
66
* *
77
* Paystack Payment Gateway *
8-
* Version: 1.0.1 *
9-
* Build Date: 18 May 2017 *
8+
* Version: 2.3.0 *
9+
* Build Date: April 25, 2024 *
1010
* *
1111
************************************************************************
1212
* *
@@ -299,6 +299,8 @@ function paystackshutdownFunction(){
299299
checkCbTransID($trxref);
300300

301301
$amount = floatval($txStatus->amount)/100;
302+
$requested_amount = floatval($txStatus->requested_amount)/100;
303+
if (isset($requested_amount) && $requested_amount > 0) $amount = $requested_amount
302304
$fees = floatval($txStatus->fees)/100;
303305
if ($gatewayParams['convertto']) {
304306
$result = select_query("tblclients", "tblinvoices.invoicenum,tblclients.currency,tblcurrencies.code", array("tblinvoices.id" => $invoiceId), "", "", "", "tblinvoices ON tblinvoices.userid=tblclients.id INNER JOIN tblcurrencies ON tblcurrencies.id=tblclients.currency");

modules/gateways/paystack.php

Lines changed: 74 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* ****************************************************************** **\
44
* *
55
* Paystack Payment Gateway *
6-
* Version: 1.0.1 *
7-
* Build Date: 18 May 2017 *
6+
* Version: 2.3.0 *
7+
* Build Date: April 25, 2024 *
88
* *
99
* **********************************************************************
1010
* *
@@ -24,13 +24,13 @@
2424
* @return array
2525
*/
2626
function paystack_config()
27-
{
27+
{
2828
$isSSL = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443);
2929
$callbackUrl = 'http' . ($isSSL ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
30-
//substr($_SERVER['SERVER_NAME'], 0, strrpos($_SERVER['SERVER_NAME'], '/')) . '/'
30+
//substr($_SERVER['SERVER_NAME'], 0, strrpos($_SERVER['SERVER_NAME'], '/')) . '/'
3131
substr(str_replace('/admin/', '/', $_SERVER['REQUEST_URI']), 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
3232
'/modules/gateways/callback/paystack.php';
33-
33+
3434
return array(
3535
'FriendlyName' => array(
3636
'Type' => 'System',
@@ -39,8 +39,8 @@ function paystack_config()
3939
'webhook' => array(
4040
'FriendlyName' => 'Webhook URL',
4141
'Type' => 'yesno',
42-
'Description' => 'Copy and paste this URL on your Webhook URL settings <code>'.$callbackUrl.'</code>',
43-
'Default' => "'".$callbackUrl."'",
42+
'Description' => 'Copy and paste this URL on your Webhook URL settings <code>' . $callbackUrl . '</code>',
43+
'Default' => "'" . $callbackUrl . "'",
4444
),
4545
'gatewayLogs' => array(
4646
'FriendlyName' => 'Gateway logs',
@@ -93,9 +93,9 @@ function paystack_link($params)
9393
// Client
9494
$email = $params['clientdetails']['email'];
9595
$phone = $params['clientdetails']['phonenumber'];
96-
$params['langpaynow']
97-
= array_key_exists('langpaynow', $params) ?
98-
$params['langpaynow'] : 'Pay with ATM' ;
96+
$params['langpaynow']
97+
= array_key_exists('langpaynow', $params) ?
98+
$params['langpaynow'] : 'Pay with Paystack';
9999

100100
// Config Options
101101
if ($params['testMode'] == 'on') {
@@ -105,65 +105,65 @@ function paystack_link($params)
105105
$publicKey = $params['livePublicKey'];
106106
$secretKey = $params['liveSecretKey'];
107107
}
108-
108+
109109
// check if there is an id in the GET meaning the invoice was loaded directly
110-
$paynowload = ( !array_key_exists('id', $_GET) );
111-
110+
$paynowload = (!array_key_exists('id', $_GET));
111+
112112
// Invoice
113113
$invoiceId = $params['invoiceid'];
114-
$amountinkobo = round(floatval($params['amount'])*100);
114+
$amountinkobo = round(floatval($params['amount']) * 100);
115115
$currency = $params['currency'];
116116
///Transaction_reference
117-
$txnref = $invoiceId . '_' .time();
117+
$txnref = $invoiceId . '_' . time();
118118

119119

120-
if (!in_array(strtoupper($currency), [ 'NGN', 'USD', 'GHS', 'ZAR', 'EGP', 'XOF', 'KES', 'RWF' ])) {
120+
if (!in_array(strtoupper($currency), ['NGN', 'USD', 'GHS', 'ZAR', 'EGP', 'XOF', 'KES', 'RWF'])) {
121121
return ("<b style='color:red;margin:2px;padding:2px;border:1px dotted;display: block;border-radius: 10px;font-size: 13px;'>Sorry, this version of the Paystack WHMCS plugin only accepts NGN, USD, GHS, ZAR, EGP, XOF, KES, and RWF payments. <i>$currency</i> not yet supported.</b>");
122122
}
123-
123+
124124
$isSSL = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443);
125125
$fallbackUrl = 'http' . ($isSSL ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
126126
substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
127-
'/modules/gateways/callback/paystack.php?' .
127+
'/modules/gateways/callback/paystack.php?' .
128128
http_build_query(
129129
array(
130-
'invoiceid' =>$invoiceId,
131-
'email'=>$email,
132-
'phone'=>$phone,
133-
'reference' => $txnref,
134-
'amountinkobo'=>$amountinkobo,
135-
'go'=>'standard'
130+
'invoiceid' => $invoiceId,
131+
'email' => $email,
132+
'phone' => $phone,
133+
'reference' => $txnref,
134+
'amountinkobo' => $amountinkobo,
135+
'go' => 'standard'
136136
)
137137
);
138138
$callbackUrl = 'http' . ($isSSL ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
139139
substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
140-
'/modules/gateways/callback/paystack.php?' .
140+
'/modules/gateways/callback/paystack.php?' .
141141
http_build_query(
142142
array(
143-
'invoiceid'=>$invoiceId
143+
'invoiceid' => $invoiceId
144144
)
145145
);
146146

147147
$code = '
148148
<form target="hiddenIFrame" action="about:blank">
149-
<script src="https://js.paystack.co/v1/inline.js"></script>
149+
<script src="https://js.paystack.co/v2/inline.js"></script>
150150
<div class="payment-btn-container2"></div>
151151
<script>
152152
// load jQuery 1.12.3 if not loaded
153-
(typeof $ === \'undefined\') && document.write("<scr" + "ipt type=\"text\/javascript\" '.
154-
'src=\"https:\/\/code.jquery.com\/jquery-1.12.3.min.js\"><\/scr" + "ipt>");
153+
(typeof $ === \'undefined\') && document.write("<scr" + "ipt type=\"text\/javascript\" ' .
154+
'src=\"https:\/\/code.jquery.com\/jquery-1.12.3.min.js\"><\/scr" + "ipt>");
155155
</script>
156156
<script>
157157
$(function() {
158158
var paymentMethod = $(\'select[name="gateway"]\').val();
159159
if (paymentMethod === \'paystack\') {
160160
$(\'.payment-btn-container2\').hide();
161-
var toAppend = \'<button type="button"'.
162-
' onclick="payWithPaystack()"'.
163-
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">'.
164-
addslashes($params['langpaynow']).'</button>'.
165-
'<img style="width: 150px; display: block; margin: 0 auto;"'.
166-
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\';
161+
var toAppend = \'<button type="button"' .
162+
' onclick="payWithPaystack()"' .
163+
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">' .
164+
addslashes($params['langpaynow']) . '</button>' .
165+
'<img style="width: 150px; display: block; margin: 0 auto;"' .
166+
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\';
167167
168168
$(\'.payment-btn-container\').append(toAppend);
169169
if($(\'.payment-btn-container\').length===0){
@@ -175,59 +175,52 @@ function paystack_link($params)
175175
</form>
176176
<div class="hidden" style="display:none"><iframe name="hiddenIFrame"></iframe></div>
177177
<script>
178-
var paystackIframeOpened = false;
179178
var button_created = false;
180-
var paystackHandler = PaystackPop.setup({
181-
key: \''.addslashes(trim($publicKey)).'\',
182-
email: \''.addslashes(trim($email)).'\',
183-
phone: \''.addslashes(trim($phone)).'\',
184-
amount: '.$amountinkobo.',
185-
currency: \''.addslashes(trim($currency)).'\',
186-
ref:\''.$txnref.'\',
187-
metadata:{
188-
"custom_fields":[
189-
{
190-
"display_name":"Plugin",
191-
"variable_name":"plugin",
192-
"value":"whmcs"
193-
}
194-
]
195-
},
196-
callback: function(response){
197-
$(\'div.alert.alert-info.text-center\').hide();
198-
$(\'.payment-btn-container2\').hide();
199-
200-
window.location.href = \''.addslashes($callbackUrl).'&trxref=\' + response.trxref;
201-
},
202-
onClose: function(){
203-
paystackIframeOpened = false;
204-
}
205-
});
179+
var paystackPop = new PaystackPop()
180+
206181
function payWithPaystack(){
207-
if (paystackHandler.fallback || paystackIframeOpened) {
208-
// Handle non-support of iframes or
209-
// Being able to click PayWithPaystack even though iframe already open
210-
window.location.href = \''.addslashes($fallbackUrl).'\';
211-
} else {
212-
paystackHandler.openIframe();
213-
paystackIframeOpened = true;
214-
$(\'img[alt="Loading"]\').hide();
215-
$(\'div.alert.alert-info.text-center\').html(\'Click the button below to retry payment...\');
216-
create_button();
217-
}
218-
}
182+
paystackPop.checkout({
183+
key: \'' . addslashes(trim($publicKey)) . '\',
184+
email: \'' . addslashes(trim($email)) . '\',
185+
phone: \'' . addslashes(trim($phone)) . '\',
186+
amount: ' . $amountinkobo . ',
187+
currency: \'' . addslashes(trim($currency)) . '\',
188+
ref:\'' . $txnref . '\',
189+
metadata:{
190+
"custom_fields":[
191+
{
192+
"display_name":"Plugin",
193+
"variable_name":"plugin",
194+
"value":"whmcs"
195+
}
196+
]
197+
},
198+
onSuccess: function(response){
199+
$(\'div.alert.alert-info.text-center\').hide();
200+
$(\'.payment-btn-container2\').hide();
201+
202+
window.location.href = \'' . addslashes($callbackUrl) . '&trxref=\' + response.trxref;
203+
},
204+
onCancel: function(){
205+
}
206+
});
207+
$(\'img[alt="Loading"]\').hide();
208+
$(\'div.alert.alert-info.text-center\').html(\'Click the button below to retry payment...\');
209+
create_button();
210+
}
211+
219212
function create_button(){
220213
if(!button_created){
221214
button_created = true;
222-
$(\'.payment-btn-container2\').append(\'<button type="button"'.
223-
' onClick="window.location.reload()"'.
224-
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">'.
225-
addslashes($params['langpaynow']).'</button>'.
226-
'<img style="width: 150px; display: block; margin: 0 auto;"'.
227-
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\');
215+
$(\'.payment-btn-container2\').append(\'<button type="button"' .
216+
' onClick="window.location.reload()"' .
217+
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">' .
218+
addslashes($params['langpaynow']) . '</button>' .
219+
'<img style="width: 150px; display: block; margin: 0 auto;"' .
220+
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\');
228221
}
229222
}
230-
' . ( $paynowload ? 'setTimeout("payWithPaystack()", 5100);' : '' ) . '
223+
' . ($paynowload ? 'setTimeout("payWithPaystack()", 5100);' : '') . '
231224
</script>';
232225

233226
return $code;

0 commit comments

Comments
 (0)