Skip to content

Commit

Permalink
WHMCS v7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter Poorthuis committed Apr 18, 2017
1 parent 9a88ef2 commit 9eeb00b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
Empty file modified modules/gateways/bit-pay/.htaccess
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions modules/gateways/bit-pay/bp_lib.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function bpCreateInvoice($orderId, $price, $posData, $options = array())
}

$post = json_encode($post);

$response = bpCurl($network, $options['apiKey'], $post);

return $response;
Expand Down
Empty file modified modules/gateways/bit-pay/bp_options.php
100644 → 100755
Empty file.
21 changes: 11 additions & 10 deletions modules/gateways/bit-pay/createinvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* THE SOFTWARE.
*/

use WHMCS\Database\Capsule;

include '../../../includes/functions.php';
include '../../../includes/gatewayfunctions.php';
include '../../../includes/invoicefunctions.php';
Expand All @@ -45,8 +47,8 @@
// get invoice
$invoiceId = (int) $_POST['invoiceId'];
$price = $currency = false;
$result = mysql_query("SELECT tblinvoices.total, tblinvoices.status, tblcurrencies.code FROM tblinvoices, tblclients, tblcurrencies where tblinvoices.userid = tblclients.id and tblclients.currency = tblcurrencies.id and tblinvoices.id=$invoiceId");
$data = mysql_fetch_assoc($result);
$result = Capsule::connection()->select("SELECT tblinvoices.total, tblinvoices.status, tblcurrencies.code FROM tblinvoices, tblclients, tblcurrencies where tblinvoices.userid = tblclients.id and tblclients.currency = tblcurrencies.id and tblinvoices.id=$invoiceId");
$data = (array)$result[0];

if (!$data) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: No invoice found for invoice id #' . $invoiceId);
Expand All @@ -65,8 +67,8 @@
// if convert-to option is set (gateway setting), then convert to requested currency
$convertTo = false;
$query = "SELECT value from tblpaymentgateways where `gateway` = '$gatewaymodule' and `setting` = 'convertto'";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);
$result = Capsule::connection()->select($query);
$data = (array)$result[0];

if ($data) {
$convertTo = $data['value'];
Expand All @@ -75,16 +77,16 @@
if ($convertTo) {
// fetch $currency and $convertTo currencies
$query = "SELECT rate FROM tblcurrencies where `code` = '$currency'";
$result = mysql_query($query);
$currentCurrency = mysql_fetch_assoc($result);
$result = Capsule::connection()->select($query);
$currentCurrency = (array)$result[0];

if (!$currentCurrency) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice currency of ' . $currency);
die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice currency of ' . $currency);
}

$result = mysql_query("SELECT code, rate FROM tblcurrencies where `id` = $convertTo");
$convertToCurrency = mysql_fetch_assoc($result);
$result = Capsule::connection()->select("SELECT code, rate FROM tblcurrencies where `id` = $convertTo");
$convertToCurrency = (array)$result[0];

if (!$convertToCurrency) {
bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo);
Expand All @@ -100,10 +102,9 @@

unset($options['invoiceId']);
unset($options['systemURL']);
unset($options['redirectURL']);

$options['notificationURL'] = $_POST['systemURL'].'/modules/gateways/callback/bitpay.php';
$options['redirectURL'] = isset($_POST['redirectURL']) ? $_POST['redirectURL'] : $_POST['systemURL'];
$options['redirectURL'] = $_POST['systemURL'];
$options['apiKey'] = $GATEWAY['apiKey'];
$options['transactionSpeed'] = $GATEWAY['transactionSpeed'];
$options['currency'] = $currency;
Expand Down
Empty file modified modules/gateways/bit-pay/index.php
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion modules/gateways/bitpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function bitpay_link($params)
'buyerEmail' => $email,
'buyerPhone' => $phone,
);

$form = '<form action="' . $systemurl . '/modules/gateways/bit-pay/createinvoice.php" method="POST">';

foreach ($post as $key => $value) {
Expand Down
9 changes: 9 additions & 0 deletions modules/gateways/callback/bitpay.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* THE SOFTWARE.
*/

use WHMCS\Database\Capsule;

// Required File Includes
include '../../../includes/functions.php';
include '../../../includes/gatewayfunctions.php';
Expand Down Expand Up @@ -60,6 +62,11 @@
$invoiceid = checkCbInvoiceID($invoiceid, $GATEWAY['name']);

$transid = $response['id'];


$invoice = Capsule::table('tblinvoices')->where('id', $invoiceid)->first();

$userid = $invoice->userid;

// Checks transaction number isn't already in the database and ends processing if it does
checkCbTransID($transid);
Expand All @@ -77,11 +84,13 @@
break;
case 'confirmed':
// Apply Payment to Invoice
Capsule::table('tblclients')->where('id', $userid)->update(array('defaultgateway' => $gatewaymodule));
addInvoicePayment($invoiceid, $transid, $amount, $fee, $gatewaymodule);
logTransaction($GATEWAY['name'], $response, 'The payment has been received, and the transaction has been confirmed on the bitcoin network. This will be updated when the transaction has been completed.');
break;
case 'complete':
// Apply Payment to Invoice
Capsule::table('tblclients')->where('id', $userid)->update(array('defaultgateway' => $gatewaymodule));
addInvoicePayment($invoiceid, $transid, $amount, $fee, $gatewaymodule);
logTransaction($GATEWAY['name'], $response, 'The transaction is now complete.');
break;
Expand Down

0 comments on commit 9eeb00b

Please sign in to comment.