Skip to content

Commit

Permalink
Merge pull request #90 from p-maguire/5.0.x
Browse files Browse the repository at this point in the history
SP-986: Plugin cleanup and whmcs.json changes
  • Loading branch information
p-maguire authored Jun 24, 2024
2 parents 90cb8af + 3351a4c commit 2a948d8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 48 deletions.
22 changes: 10 additions & 12 deletions modules/gateways/bitpaycheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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/
*
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
67 changes: 31 additions & 36 deletions modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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([
Expand All @@ -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([
Expand All @@ -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)
Expand All @@ -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([
Expand All @@ -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)
Expand All @@ -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([
Expand All @@ -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([
Expand Down
Binary file added modules/gateways/bitpaycheckout/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions modules/gateways/bitpaycheckout/whmcs.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"support_url": "https:\/\/www.bitpay.com\/request-help",
"docs_url": "https:\/\/developer.bitpay.com\/"
},
"authors": [
{
"name": "BitPay",
"homepage": "https:\/\/www.bitpay.com\/"
}
]
}

0 comments on commit 2a948d8

Please sign in to comment.