diff --git a/modules/gateways/bitpaycheckout.php b/modules/gateways/bitpaycheckout.php index 87adab0..87f09ef 100644 --- a/modules/gateways/bitpaycheckout.php +++ b/modules/gateways/bitpaycheckout.php @@ -15,11 +15,11 @@ * @license http://www.whmcs.com/license/ WHMCS Eula */ -if (!defined("WHMCS")) { - die("This file cannot be accessed directly"); +if (!defined('WHMCS')) { + die('This file cannot be accessed directly'); } -include_once(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout' +require(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'); @@ -75,8 +75,6 @@ function ($table) { * * radio * * textarea * - * Examples of each field type and their possible configuration parameters are - * provided in the sample function below. * * @see https://developers.whmcs.com/payment-gateways/configuration/ * @@ -140,7 +138,7 @@ function bitpaycheckout_link($config_params) } $bitpay_checkout_mode = $config_params['bitpay_checkout_mode']; - $curpage = basename($_SERVER["SCRIPT_FILENAME"]); + $curpage = basename($_SERVER['SCRIPT_FILENAME']); $curpage = str_replace("/", "", $curpage); if ($curpage != 'viewinvoice.php') { @@ -196,13 +194,13 @@ function bitpaycheckout_link($config_params) $params->orderId = trim($invoiceId); // @phpcs:ignore Generic.Files.LineLength.TooLong + $protocol = 'https://'; + // @phpcs:ignore Generic.Files.LineLength.TooLong $params->notificationURL = $protocol . $_SERVER['SERVER_NAME']. $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php'; // @phpcs:ignore Generic.Files.LineLength.TooLong $params->redirectURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $params->fullNotifications = true; - $protocol = 'https://'; - // @phpcs:ignore Generic.Files.LineLength.TooLong $notificationURL = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php'; // @phpcs:ignore Generic.Files.LineLength.TooLong @@ -232,11 +230,11 @@ function bitpaycheckout_link($config_params) $invoice->setBuyer($buyer); $basicInvoice = $client->createInvoice($invoice, Facade::POS, false); - error_log("=======USER LOADED BITPAY CHECKOUT INVOICE====="); + error_log('=======USER LOADED BITPAY CHECKOUT INVOICE====='); error_log(date('d.m.Y H:i:s')); - error_log("=======END OF INVOICE=========================="); + error_log('=======END OF INVOICE=========================='); - #insert into the database + // Insert into the database $pdo = Capsule::connection()->getPdo(); $pdo->beginTransaction(); @@ -277,7 +275,7 @@ function redirectURL($url){ var payment_status = null; var is_paid = false; - window.addEventListener("message", function(event) { + window.addEventListener('message', function(event) { payment_status = event.data.status; if(payment_status == 'paid' || payment_status == 'confirmed' || payment_status == 'complete'){ is_paid = true; diff --git a/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php b/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php index 405f1dd..eac9ec4 100644 --- a/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php +++ b/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php @@ -3,14 +3,9 @@ /** * BitPay Checkout IPN 5.0.0 * - * This file demonstrates how a payment gateway callback should be - * handled within WHMCS. - * - * It demonstrates verifying that the payment gateway module is active, - * validating an Invoice ID, checking for the existence of a Transaction ID, - * Logging the Transaction for debugging and Adding Payment to an Invoice. - * - * For more information, please refer to the online documentation. + * This file verifies that the payment gateway module is active, + * validates an Invoice ID, checks for the existence of a Transaction ID, + * and adds Payment to an Invoice. * * @see https://developers.whmcs.com/payment-gateways/callbacks/ * @@ -30,8 +25,8 @@ // Fetch gateway configuration parameters. $gatewayParams = getGatewayVariables($gatewayModuleName); -define("TEST_URL", 'https://test.bitpay.com/invoices/'); -define("PROD_URL", 'https://bitpay.com/invoices/'); +define('TEST_URL', 'https://test.bitpay.com/invoices/'); +define('PROD_URL', 'https://bitpay.com/invoices/'); function checkInvoiceStatus($url) { @@ -48,17 +43,17 @@ function checkInvoiceStatus($url) $data = $response['data']; $file = 'bitpay.txt'; -$err = "bitpay_err.txt"; +$err = 'bitpay_err.txt'; -file_put_contents($file, "===========INCOMING IPN=========================", FILE_APPEND); +file_put_contents($file, '===========INCOMING IPN=========================', FILE_APPEND); file_put_contents($file, date('d.m.Y H:i:s'), FILE_APPEND); file_put_contents($file, print_r($response, true), FILE_APPEND); -file_put_contents($file, "===========END OF IPN===========================", FILE_APPEND); +file_put_contents($file, '===========END OF IPN===========================', FILE_APPEND); $order_status = $data['status']; $order_invoice = $data['id']; $endpoint = $gatewayParams['bitpay_checkout_endpoint']; -if ($endpoint == "Test") { +if ($endpoint == 'Test') { $url_check = TEST_URL . $order_invoice; } else { $url_check = PROD_URL . $order_invoice; @@ -67,7 +62,7 @@ function checkInvoiceStatus($url) $orderid = checkCbInvoiceID($invoiceStatus->data->orderId, 'bitpaycheckout'); $price = $invoiceStatus->data->price; -#first see if the ipn matches +// First see if the ipn matches $trans_data = Capsule::table('_bitpay_checkout_transactions') ->select('order_id', 'transaction_id', 'transaction_status') ->where([ @@ -81,15 +76,15 @@ function checkInvoiceStatus($url) if ($btn_id) { switch ($data['status']) { - #complete, update invoice table to Paid + // Complete, update invoice table to Paid case 'complete': if ($transaction_status == $data['status']) { exit(); } - #update the bitpay_invoice table - $table = "_bitpay_checkout_transactions"; - $update = array("transaction_status" => "complete", "updated_at" => date('Y-m-d H:i:s')); + // Update the bitpay_invoice table + $table = '_bitpay_checkout_transactions'; + $update = array('transaction_status' => 'complete', 'updated_at' => date('Y-m-d H:i:s')); try { Capsule::table($table) ->where([ @@ -110,10 +105,10 @@ function checkInvoiceStatus($url) ); break; - #processing - put in Payment Pending + // Processing - put in Payment Pending case 'paid': - #update the invoices table - $table = "tblinvoices"; + // Update the invoices table + $table = 'tblinvoices'; $update = array("status" => 'Payment Pending','datepaid' => date('Y-m-d H:i:s')); try { Capsule::table($table) @@ -126,9 +121,9 @@ function checkInvoiceStatus($url) file_put_contents($file, $e, FILE_APPEND); } - #update the bitpay_invoice table - $table = "_bitpay_checkout_transactions"; - $update = array("transaction_status" => 'paid', "updated_at" => date('Y-m-d H:i:s')); + // Update the bitpay_invoice table + $table = '_bitpay_checkout_transactions'; + $update = array('transaction_status' => 'paid', 'updated_at' => date('Y-m-d H:i:s')); try { Capsule::table($table) ->where([ @@ -141,10 +136,10 @@ function checkInvoiceStatus($url) } break; - #expired, remove from transaction table, wont be in invoice table + // Expired, remove from transaction table, wont be in invoice table case 'expired': - #delete any orphans - $table = "_bitpay_checkout_transactions"; + // Delete any orphans + $table = '_bitpay_checkout_transactions'; try { Capsule::table($table) ->where('transaction_id', '=', $order_invoice) @@ -154,12 +149,12 @@ function checkInvoiceStatus($url) } break; - #refunded, set invoice and bitpay transaction to refunded status + // Refunded, set invoice and bitpay transaction to refunded status case 'pending': - if ($event['name'] == "refund_pending") { - #update the invoices table - $table = "tblinvoices"; - $update = array("status" => 'Refunded','datepaid' => date('Y-m-d H:i:s')); + if ($event['name'] == 'refund_pending') { + //update the invoices table + $table = 'tblinvoices'; + $update = array('status' => 'Refunded','datepaid' => date('Y-m-d H:i:s')); try { Capsule::table($table) ->where([ @@ -171,9 +166,9 @@ function checkInvoiceStatus($url) file_put_contents($file, $e, FILE_APPEND); } - #update the bitpay invoice table - $table = "_bitpay_checkout_transactions"; - $update = array("transaction_status" => 'refunded', "updated_at" => date('Y-m-d H:i:s')); + // Update the bitpay invoice table + $table = '_bitpay_checkout_transactions'; + $update = array('transaction_status' => 'refunded', 'updated_at' => date('Y-m-d H:i:s')); try { Capsule::table($table) ->where([ diff --git a/modules/gateways/bitpaycheckout/icon-256x256.png b/modules/gateways/bitpaycheckout/icon-256x256.png new file mode 100644 index 0000000..0f78df9 Binary files /dev/null and b/modules/gateways/bitpaycheckout/icon-256x256.png differ diff --git a/modules/gateways/bitpaycheckout/whmcs.json b/modules/gateways/bitpaycheckout/whmcs.json new file mode 100644 index 0000000..db8359b --- /dev/null +++ b/modules/gateways/bitpaycheckout/whmcs.json @@ -0,0 +1,35 @@ +{ + "schema": "1.0", + "type": "whmcs-gateways", + "name": "BitPayCheckout", + "license": "MIT", + "category": "payments", + "description": { + "name": "BitPay Checkout", + "tagline": "Accept payments via crypto currency using BitPay", + "features": [ + "Accept bitcoin and bitcoin cash payments from payment protocol compatible wallets", + "Price in your local currency", + "Get settled via Bank transfer (EUR, USD, GBP or any of the supported fiat currencies), BTC, BCH, ETH, WBTC, LTC, DOGE, XRP or stable coins (USDC, GUSD, PAXOS, BUSD and DAI)", + "By design, chargebacks are not possible with cryptocurrency payments", + "Have an overview of all your bitcoin and bitcoin cash payments in your BitPay merchant account at https://bitpay.com/dashboard", + "Refund your customers in bitcoin or bitcoin cash in your BitPay merchant dashboard at https://bitpay.com/dashboard/payments" + ] + }, + "logo": { + "filename": "icon-256x256.png" + }, + "support": { + "homepage": "https:\/\/www.bitpay.com\/", + "learn_more": "https:\/\/www.bitpay.com\/online-payments", + "email": "support@bitpay.com", + "support_url": "https:\/\/www.bitpay.com\/request-help", + "docs_url": "https:\/\/developer.bitpay.com\/" + }, + "authors": [ + { + "name": "BitPay", + "homepage": "https:\/\/www.bitpay.com\/" + } + ] +}