Skip to content

Commit

Permalink
Merge pull request #5 from steveamaza/improve/checkout
Browse files Browse the repository at this point in the history
Improve/checkout
  • Loading branch information
ibrahimlawal authored May 4, 2018
2 parents 9baeb77 + 8a536a3 commit 1a0009d
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions modules/gateways/paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ function paystack_link($params)
$txnref = $invoiceId . '_' .time();


if (! (strtoupper($currency) == 'NGN')
|| (strtoupper($currency) == 'USD')
|| (strtoupper($currency) == 'GHS')
) {
if (!in_array(strtoupper($currency), [ 'NGN', 'USD', 'GHS' ])) {
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 and GHS payments. <i>$currency</i> not yet supported.</b>");
}

Expand Down Expand Up @@ -162,10 +159,15 @@ function paystack_link($params)
if (paymentMethod === \'paystack\') {
$(\'.payment-btn-container2\').hide();
var toAppend = \'<button type="button"'.
' onclick="payWithPaystack()"> '.addslashes($params['langpaynow']).'</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://paystack.com/assets/website/images/brand/badges/cards.png"/>\';
$(\'.payment-btn-container\').append(toAppend);
if($(\'.payment-btn-container\').length===0){
$(\'select[name="gateway"]\').after(toAppend);
if($(\'.payment-btn-container\').length===0){
$(\'select[name="gateway"]\').after(toAppend);
}
}
});
Expand All @@ -174,34 +176,45 @@ function paystack_link($params)
<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 * 100 .',
currency: \''.addslashes(trim($currency)).'\',
ref:\''.$txnref.'\',
callback: function(response){
window.location.href = \''.addslashes($callbackUrl).'&trxref=\' + response.trxref;
},
onClose: function(){
paystackIframeOpened = false;
}
key: \''.addslashes(trim($publicKey)).'\',
email: \''.addslashes(trim($email)).'\',
phone: \''.addslashes(trim($phone)).'\',
amount: '.$amountinkobo.',
currency: \''.addslashes(trim($currency)).'\',
ref:\''.$txnref.'\',
callback: function(response){
window.location.href = \''.addslashes($callbackUrl).'&trxref=\' + response.trxref;
},
onClose: function(){
paystackIframeOpened = false;
}
});
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).'\';
// 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...\');
$(\'.payment-btn-container2\').append(\'<button type="button"'.
' onclick="payWithPaystack()">'.addslashes($params['langpaynow']).'</button>\');
paystackHandler.openIframe();
paystackIframeOpened = true;
$(\'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://paystack.com/assets/website/images/brand/badges/cards.png"/>\');
}
}
' . ( $paynowload ? 'setTimeout("payWithPaystack()", 5100);' : '' ) . '
</script>';

Expand Down

0 comments on commit 1a0009d

Please sign in to comment.