");
}
/**
* Define Paystack gateway configuration options.
*
* @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(str_replace('/admin/', '/', $_SERVER['REQUEST_URI']), 0, strrpos($_SERVER['REQUEST_URI'], '/')) .
'/modules/gateways/callback/paystack.php';
return array(
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'Paystack (Debit/Credit Cards)'
),
'webhook' => array(
'FriendlyName' => 'Webhook URL',
'Type' => 'yesno',
'Description' => 'Copy and paste this URL on your Webhook URL settings ' . $callbackUrl . '
',
'Default' => "'" . $callbackUrl . "'",
),
'gatewayLogs' => array(
'FriendlyName' => 'Gateway logs',
'Type' => 'yesno',
'Description' => 'Tick to enable gateway logs',
'Default' => '0'
),
'testMode' => array(
'FriendlyName' => 'Test Mode',
'Type' => 'yesno',
'Description' => 'Tick to enable test mode',
'Default' => '0'
),
'liveSecretKey' => array(
'FriendlyName' => 'Live Secret Key',
'Type' => 'text',
'Size' => '32',
'Default' => 'sk_live_xxx'
),
'livePublicKey' => array(
'FriendlyName' => 'Live Public Key',
'Type' => 'text',
'Size' => '32',
'Default' => 'pk_live_xxx'
),
'testSecretKey' => array(
'FriendlyName' => 'Test Secrect Key',
'Type' => 'text',
'Size' => '32',
'Default' => 'sk_test_xxx'
),
'testPublicKey' => array(
'FriendlyName' => 'Test Public Key',
'Type' => 'text',
'Size' => '32',
'Default' => 'pk_test_xxx'
)
);
}
/**
* Payment link.
*
* @param array $params Payment Gateway Module Parameters
*
* @return string
*/
function paystack_link($params)
{
// Client
$email = $params['clientdetails']['email'];
$phone = $params['clientdetails']['phonenumber'];
$params['langpaynow']
= array_key_exists('langpaynow', $params) ?
$params['langpaynow'] : 'Pay with Paystack';
// Config Options
if ($params['testMode'] == 'on') {
$publicKey = $params['testPublicKey'];
$secretKey = $params['testSecretKey'];
} else {
$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));
// Invoice
$invoiceId = $params['invoiceid'];
$amountinkobo = round(floatval($params['amount']) * 100);
$currency = $params['currency'];
///Transaction_reference
$txnref = $invoiceId . '_' . time();
if (!in_array(strtoupper($currency), ['NGN', 'USD', 'GHS', 'ZAR', 'EGP', 'XOF', 'KES', 'RWF'])) {
return ("Sorry, this version of the Paystack WHMCS plugin only accepts NGN, USD, GHS, ZAR, EGP, XOF, KES, and RWF payments. $currency not yet supported.");
}
$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?' .
http_build_query(
array(
'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?' .
http_build_query(
array(
'invoiceid' => $invoiceId
)
);
$code = '