Skip to content

Commit

Permalink
Merge pull request #19 from chrismadufor/v2-update
Browse files Browse the repository at this point in the history
Upgraded to inline v2 and added support for apple pay
  • Loading branch information
lukman-paystack authored Apr 25, 2024
2 parents b1d42ec + 5b3b656 commit 02a772e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 83 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.3.0 (April 25, 2024)

- Upgraded to Paystack inlinejs v2
- Added support for Apple pay
- Included fees in the payment data
- Added support for merchants who pass charges to customers
- Bug fixes

## 2.2.1 (November 13, 2020)

- Fix broken payment options image link
Expand Down
Binary file modified modules/.DS_Store
Binary file not shown.
6 changes: 4 additions & 2 deletions modules/gateways/callback/paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/ ********************************************************************* \
* *
* Paystack Payment Gateway *
* Version: 1.0.1 *
* Build Date: 18 May 2017 *
* Version: 2.3.0 *
* Build Date: April 25, 2024 *
* *
************************************************************************
* *
Expand Down Expand Up @@ -299,6 +299,8 @@ function paystackshutdownFunction(){
checkCbTransID($trxref);

$amount = floatval($txStatus->amount)/100;
$requested_amount = floatval($txStatus->requested_amount)/100;
if (isset($requested_amount) && $requested_amount > 0) $amount = $requested_amount
$fees = floatval($txStatus->fees)/100;
if ($gatewayParams['convertto']) {
$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");
Expand Down
155 changes: 74 additions & 81 deletions modules/gateways/paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* ****************************************************************** **\
* *
* Paystack Payment Gateway *
* Version: 1.0.1 *
* Build Date: 18 May 2017 *
* Version: 2.3.0 *
* Build Date: April 25, 2024 *
* *
* **********************************************************************
* *
Expand All @@ -24,13 +24,13 @@
* @return array
*/
function paystack_config()
{
{
$isSSL = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443);
$callbackUrl = 'http' . ($isSSL ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
//substr($_SERVER['SERVER_NAME'], 0, strrpos($_SERVER['SERVER_NAME'], '/')) . '/'
//substr($_SERVER['SERVER_NAME'], 0, strrpos($_SERVER['SERVER_NAME'], '/')) . '/'
substr(str_replace('/admin/', '/', $_SERVER['REQUEST_URI']), 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
'/modules/gateways/callback/paystack.php';

return array(
'FriendlyName' => array(
'Type' => 'System',
Expand All @@ -39,8 +39,8 @@ function paystack_config()
'webhook' => array(
'FriendlyName' => 'Webhook URL',
'Type' => 'yesno',
'Description' => 'Copy and paste this URL on your Webhook URL settings <code>'.$callbackUrl.'</code>',
'Default' => "'".$callbackUrl."'",
'Description' => 'Copy and paste this URL on your Webhook URL settings <code>' . $callbackUrl . '</code>',
'Default' => "'" . $callbackUrl . "'",
),
'gatewayLogs' => array(
'FriendlyName' => 'Gateway logs',
Expand Down Expand Up @@ -93,9 +93,9 @@ function paystack_link($params)
// Client
$email = $params['clientdetails']['email'];
$phone = $params['clientdetails']['phonenumber'];
$params['langpaynow']
= array_key_exists('langpaynow', $params) ?
$params['langpaynow'] : 'Pay with ATM' ;
$params['langpaynow']
= array_key_exists('langpaynow', $params) ?
$params['langpaynow'] : 'Pay with Paystack';

// Config Options
if ($params['testMode'] == 'on') {
Expand All @@ -105,65 +105,65 @@ function paystack_link($params)
$publicKey = $params['livePublicKey'];
$secretKey = $params['liveSecretKey'];
}

// check if there is an id in the GET meaning the invoice was loaded directly
$paynowload = ( !array_key_exists('id', $_GET) );
$paynowload = (!array_key_exists('id', $_GET));

// Invoice
$invoiceId = $params['invoiceid'];
$amountinkobo = round(floatval($params['amount'])*100);
$amountinkobo = round(floatval($params['amount']) * 100);
$currency = $params['currency'];
///Transaction_reference
$txnref = $invoiceId . '_' .time();
$txnref = $invoiceId . '_' . time();


if (!in_array(strtoupper($currency), [ 'NGN', 'USD', 'GHS', 'ZAR', 'EGP', 'XOF', 'KES', 'RWF' ])) {
if (!in_array(strtoupper($currency), ['NGN', 'USD', 'GHS', 'ZAR', 'EGP', 'XOF', 'KES', 'RWF'])) {
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>");
}

$isSSL = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443);
$fallbackUrl = 'http' . ($isSSL ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
'/modules/gateways/callback/paystack.php?' .
'/modules/gateways/callback/paystack.php?' .
http_build_query(
array(
'invoiceid' =>$invoiceId,
'email'=>$email,
'phone'=>$phone,
'reference' => $txnref,
'amountinkobo'=>$amountinkobo,
'go'=>'standard'
'invoiceid' => $invoiceId,
'email' => $email,
'phone' => $phone,
'reference' => $txnref,
'amountinkobo' => $amountinkobo,
'go' => 'standard'
)
);
$callbackUrl = 'http' . ($isSSL ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] .
substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
'/modules/gateways/callback/paystack.php?' .
'/modules/gateways/callback/paystack.php?' .
http_build_query(
array(
'invoiceid'=>$invoiceId
'invoiceid' => $invoiceId
)
);

$code = '
<form target="hiddenIFrame" action="about:blank">
<script src="https://js.paystack.co/v1/inline.js"></script>
<script src="https://js.paystack.co/v2/inline.js"></script>
<div class="payment-btn-container2"></div>
<script>
// load jQuery 1.12.3 if not loaded
(typeof $ === \'undefined\') && document.write("<scr" + "ipt type=\"text\/javascript\" '.
'src=\"https:\/\/code.jquery.com\/jquery-1.12.3.min.js\"><\/scr" + "ipt>");
(typeof $ === \'undefined\') && document.write("<scr" + "ipt type=\"text\/javascript\" ' .
'src=\"https:\/\/code.jquery.com\/jquery-1.12.3.min.js\"><\/scr" + "ipt>");
</script>
<script>
$(function() {
var paymentMethod = $(\'select[name="gateway"]\').val();
if (paymentMethod === \'paystack\') {
$(\'.payment-btn-container2\').hide();
var toAppend = \'<button type="button"'.
' onclick="payWithPaystack()"'.
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">'.
addslashes($params['langpaynow']).'</button>'.
'<img style="width: 150px; display: block; margin: 0 auto;"'.
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\';
var toAppend = \'<button type="button"' .
' onclick="payWithPaystack()"' .
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">' .
addslashes($params['langpaynow']) . '</button>' .
'<img style="width: 150px; display: block; margin: 0 auto;"' .
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\';
$(\'.payment-btn-container\').append(toAppend);
if($(\'.payment-btn-container\').length===0){
Expand All @@ -175,59 +175,52 @@ function paystack_link($params)
</form>
<div class="hidden" style="display:none"><iframe name="hiddenIFrame"></iframe></div>
<script>
var paystackIframeOpened = false;
var button_created = false;
var paystackHandler = PaystackPop.setup({
key: \''.addslashes(trim($publicKey)).'\',
email: \''.addslashes(trim($email)).'\',
phone: \''.addslashes(trim($phone)).'\',
amount: '.$amountinkobo.',
currency: \''.addslashes(trim($currency)).'\',
ref:\''.$txnref.'\',
metadata:{
"custom_fields":[
{
"display_name":"Plugin",
"variable_name":"plugin",
"value":"whmcs"
}
]
},
callback: function(response){
$(\'div.alert.alert-info.text-center\').hide();
$(\'.payment-btn-container2\').hide();
window.location.href = \''.addslashes($callbackUrl).'&trxref=\' + response.trxref;
},
onClose: function(){
paystackIframeOpened = false;
}
});
var paystackPop = new PaystackPop()
function payWithPaystack(){
if (paystackHandler.fallback || paystackIframeOpened) {
// Handle non-support of iframes or
// Being able to click PayWithPaystack even though iframe already open
window.location.href = \''.addslashes($fallbackUrl).'\';
} else {
paystackHandler.openIframe();
paystackIframeOpened = true;
$(\'img[alt="Loading"]\').hide();
$(\'div.alert.alert-info.text-center\').html(\'Click the button below to retry payment...\');
create_button();
}
}
paystackPop.checkout({
key: \'' . addslashes(trim($publicKey)) . '\',
email: \'' . addslashes(trim($email)) . '\',
phone: \'' . addslashes(trim($phone)) . '\',
amount: ' . $amountinkobo . ',
currency: \'' . addslashes(trim($currency)) . '\',
ref:\'' . $txnref . '\',
metadata:{
"custom_fields":[
{
"display_name":"Plugin",
"variable_name":"plugin",
"value":"whmcs"
}
]
},
onSuccess: function(response){
$(\'div.alert.alert-info.text-center\').hide();
$(\'.payment-btn-container2\').hide();
window.location.href = \'' . addslashes($callbackUrl) . '&trxref=\' + response.trxref;
},
onCancel: function(){
}
});
$(\'img[alt="Loading"]\').hide();
$(\'div.alert.alert-info.text-center\').html(\'Click the button below to retry payment...\');
create_button();
}
function create_button(){
if(!button_created){
button_created = true;
$(\'.payment-btn-container2\').append(\'<button type="button"'.
' onClick="window.location.reload()"'.
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">'.
addslashes($params['langpaynow']).'</button>'.
'<img style="width: 150px; display: block; margin: 0 auto;"'.
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\');
$(\'.payment-btn-container2\').append(\'<button type="button"' .
' onClick="window.location.reload()"' .
' style="padding: 10px 25px; margin: 10px;border-radius: 5px;background: #021C32; color:#fff">' .
addslashes($params['langpaynow']) . '</button>' .
'<img style="width: 150px; display: block; margin: 0 auto;"' .
' src="https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8yYVwvMTQxNzczXC9wcm9qZWN0c1wvMTc4NjE0XC9hc3NldHNcLzdmXC8yNzQ2ODcxXC83NDY5OGViODMzMzhlMWJiNjVhMDk4MTYwNjkzY2FlOC0xNTQwMDM5NjA0LnBuZyJ9:cloud:YYqwtVK3Tb8KMGeFiXCl_w9flKcsEY9D022GMOK9oFc"/>\');
}
}
' . ( $paynowload ? 'setTimeout("payWithPaystack()", 5100);' : '' ) . '
' . ($paynowload ? 'setTimeout("payWithPaystack()", 5100);' : '') . '
</script>';

return $code;
Expand Down

0 comments on commit 02a772e

Please sign in to comment.