Skip to content

Commit 2a948d8

Browse files
authored
Merge pull request #90 from p-maguire/5.0.x
SP-986: Plugin cleanup and whmcs.json changes
2 parents 90cb8af + 3351a4c commit 2a948d8

File tree

4 files changed

+76
-48
lines changed

4 files changed

+76
-48
lines changed

modules/gateways/bitpaycheckout.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
* @license http://www.whmcs.com/license/ WHMCS Eula
1616
*/
1717

18-
if (!defined("WHMCS")) {
19-
die("This file cannot be accessed directly");
18+
if (!defined('WHMCS')) {
19+
die('This file cannot be accessed directly');
2020
}
2121

22-
include_once(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout'
22+
require(__DIR__ . DIRECTORY_SEPARATOR . 'bitpaycheckout'
2323
. DIRECTORY_SEPARATOR . 'vendor'
2424
. DIRECTORY_SEPARATOR . 'autoload.php');
2525

@@ -75,8 +75,6 @@ function ($table) {
7575
* * radio
7676
* * textarea
7777
*
78-
* Examples of each field type and their possible configuration parameters are
79-
* provided in the sample function below.
8078
*
8179
* @see https://developers.whmcs.com/payment-gateways/configuration/
8280
*
@@ -140,7 +138,7 @@ function bitpaycheckout_link($config_params)
140138
}
141139
$bitpay_checkout_mode = $config_params['bitpay_checkout_mode'];
142140

143-
$curpage = basename($_SERVER["SCRIPT_FILENAME"]);
141+
$curpage = basename($_SERVER['SCRIPT_FILENAME']);
144142

145143
$curpage = str_replace("/", "", $curpage);
146144
if ($curpage != 'viewinvoice.php') {
@@ -196,13 +194,13 @@ function bitpaycheckout_link($config_params)
196194

197195
$params->orderId = trim($invoiceId);
198196
// @phpcs:ignore Generic.Files.LineLength.TooLong
197+
$protocol = 'https://';
198+
// @phpcs:ignore Generic.Files.LineLength.TooLong
199199
$params->notificationURL = $protocol . $_SERVER['SERVER_NAME']. $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php';
200200
// @phpcs:ignore Generic.Files.LineLength.TooLong
201201
$params->redirectURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
202202
$params->fullNotifications = true;
203203

204-
$protocol = 'https://';
205-
206204
// @phpcs:ignore Generic.Files.LineLength.TooLong
207205
$notificationURL = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php';
208206
// @phpcs:ignore Generic.Files.LineLength.TooLong
@@ -232,11 +230,11 @@ function bitpaycheckout_link($config_params)
232230
$invoice->setBuyer($buyer);
233231
$basicInvoice = $client->createInvoice($invoice, Facade::POS, false);
234232

235-
error_log("=======USER LOADED BITPAY CHECKOUT INVOICE=====");
233+
error_log('=======USER LOADED BITPAY CHECKOUT INVOICE=====');
236234
error_log(date('d.m.Y H:i:s'));
237-
error_log("=======END OF INVOICE==========================");
235+
error_log('=======END OF INVOICE==========================');
238236

239-
#insert into the database
237+
// Insert into the database
240238
$pdo = Capsule::connection()->getPdo();
241239
$pdo->beginTransaction();
242240

@@ -277,7 +275,7 @@ function redirectURL($url){
277275

278276
var payment_status = null;
279277
var is_paid = false;
280-
window.addEventListener("message", function(event) {
278+
window.addEventListener('message', function(event) {
281279
payment_status = event.data.status;
282280
if(payment_status == 'paid' || payment_status == 'confirmed' || payment_status == 'complete'){
283281
is_paid = true;

modules/gateways/bitpaycheckout/callback/bitpaycheckout_ipn.php

+31-36
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
/**
44
* BitPay Checkout IPN 5.0.0
55
*
6-
* This file demonstrates how a payment gateway callback should be
7-
* handled within WHMCS.
8-
*
9-
* It demonstrates verifying that the payment gateway module is active,
10-
* validating an Invoice ID, checking for the existence of a Transaction ID,
11-
* Logging the Transaction for debugging and Adding Payment to an Invoice.
12-
*
13-
* For more information, please refer to the online documentation.
6+
* This file verifies that the payment gateway module is active,
7+
* validates an Invoice ID, checks for the existence of a Transaction ID,
8+
* and adds Payment to an Invoice.
149
*
1510
* @see https://developers.whmcs.com/payment-gateways/callbacks/
1611
*
@@ -30,8 +25,8 @@
3025

3126
// Fetch gateway configuration parameters.
3227
$gatewayParams = getGatewayVariables($gatewayModuleName);
33-
define("TEST_URL", 'https://test.bitpay.com/invoices/');
34-
define("PROD_URL", 'https://bitpay.com/invoices/');
28+
define('TEST_URL', 'https://test.bitpay.com/invoices/');
29+
define('PROD_URL', 'https://bitpay.com/invoices/');
3530

3631
function checkInvoiceStatus($url)
3732
{
@@ -48,17 +43,17 @@ function checkInvoiceStatus($url)
4843
$data = $response['data'];
4944

5045
$file = 'bitpay.txt';
51-
$err = "bitpay_err.txt";
46+
$err = 'bitpay_err.txt';
5247

53-
file_put_contents($file, "===========INCOMING IPN=========================", FILE_APPEND);
48+
file_put_contents($file, '===========INCOMING IPN=========================', FILE_APPEND);
5449
file_put_contents($file, date('d.m.Y H:i:s'), FILE_APPEND);
5550
file_put_contents($file, print_r($response, true), FILE_APPEND);
56-
file_put_contents($file, "===========END OF IPN===========================", FILE_APPEND);
51+
file_put_contents($file, '===========END OF IPN===========================', FILE_APPEND);
5752

5853
$order_status = $data['status'];
5954
$order_invoice = $data['id'];
6055
$endpoint = $gatewayParams['bitpay_checkout_endpoint'];
61-
if ($endpoint == "Test") {
56+
if ($endpoint == 'Test') {
6257
$url_check = TEST_URL . $order_invoice;
6358
} else {
6459
$url_check = PROD_URL . $order_invoice;
@@ -67,7 +62,7 @@ function checkInvoiceStatus($url)
6762

6863
$orderid = checkCbInvoiceID($invoiceStatus->data->orderId, 'bitpaycheckout');
6964
$price = $invoiceStatus->data->price;
70-
#first see if the ipn matches
65+
// First see if the ipn matches
7166
$trans_data = Capsule::table('_bitpay_checkout_transactions')
7267
->select('order_id', 'transaction_id', 'transaction_status')
7368
->where([
@@ -81,15 +76,15 @@ function checkInvoiceStatus($url)
8176

8277
if ($btn_id) {
8378
switch ($data['status']) {
84-
#complete, update invoice table to Paid
79+
// Complete, update invoice table to Paid
8580
case 'complete':
8681
if ($transaction_status == $data['status']) {
8782
exit();
8883
}
8984

90-
#update the bitpay_invoice table
91-
$table = "_bitpay_checkout_transactions";
92-
$update = array("transaction_status" => "complete", "updated_at" => date('Y-m-d H:i:s'));
85+
// Update the bitpay_invoice table
86+
$table = '_bitpay_checkout_transactions';
87+
$update = array('transaction_status' => 'complete', 'updated_at' => date('Y-m-d H:i:s'));
9388
try {
9489
Capsule::table($table)
9590
->where([
@@ -110,10 +105,10 @@ function checkInvoiceStatus($url)
110105
);
111106
break;
112107

113-
#processing - put in Payment Pending
108+
// Processing - put in Payment Pending
114109
case 'paid':
115-
#update the invoices table
116-
$table = "tblinvoices";
110+
// Update the invoices table
111+
$table = 'tblinvoices';
117112
$update = array("status" => 'Payment Pending','datepaid' => date('Y-m-d H:i:s'));
118113
try {
119114
Capsule::table($table)
@@ -126,9 +121,9 @@ function checkInvoiceStatus($url)
126121
file_put_contents($file, $e, FILE_APPEND);
127122
}
128123

129-
#update the bitpay_invoice table
130-
$table = "_bitpay_checkout_transactions";
131-
$update = array("transaction_status" => 'paid', "updated_at" => date('Y-m-d H:i:s'));
124+
// Update the bitpay_invoice table
125+
$table = '_bitpay_checkout_transactions';
126+
$update = array('transaction_status' => 'paid', 'updated_at' => date('Y-m-d H:i:s'));
132127
try {
133128
Capsule::table($table)
134129
->where([
@@ -141,10 +136,10 @@ function checkInvoiceStatus($url)
141136
}
142137
break;
143138

144-
#expired, remove from transaction table, wont be in invoice table
139+
// Expired, remove from transaction table, wont be in invoice table
145140
case 'expired':
146-
#delete any orphans
147-
$table = "_bitpay_checkout_transactions";
141+
// Delete any orphans
142+
$table = '_bitpay_checkout_transactions';
148143
try {
149144
Capsule::table($table)
150145
->where('transaction_id', '=', $order_invoice)
@@ -154,12 +149,12 @@ function checkInvoiceStatus($url)
154149
}
155150
break;
156151

157-
#refunded, set invoice and bitpay transaction to refunded status
152+
// Refunded, set invoice and bitpay transaction to refunded status
158153
case 'pending':
159-
if ($event['name'] == "refund_pending") {
160-
#update the invoices table
161-
$table = "tblinvoices";
162-
$update = array("status" => 'Refunded','datepaid' => date('Y-m-d H:i:s'));
154+
if ($event['name'] == 'refund_pending') {
155+
//update the invoices table
156+
$table = 'tblinvoices';
157+
$update = array('status' => 'Refunded','datepaid' => date('Y-m-d H:i:s'));
163158
try {
164159
Capsule::table($table)
165160
->where([
@@ -171,9 +166,9 @@ function checkInvoiceStatus($url)
171166
file_put_contents($file, $e, FILE_APPEND);
172167
}
173168

174-
#update the bitpay invoice table
175-
$table = "_bitpay_checkout_transactions";
176-
$update = array("transaction_status" => 'refunded', "updated_at" => date('Y-m-d H:i:s'));
169+
// Update the bitpay invoice table
170+
$table = '_bitpay_checkout_transactions';
171+
$update = array('transaction_status' => 'refunded', 'updated_at' => date('Y-m-d H:i:s'));
177172
try {
178173
Capsule::table($table)
179174
->where([
53.8 KB
Loading
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"schema": "1.0",
3+
"type": "whmcs-gateways",
4+
"name": "BitPayCheckout",
5+
"license": "MIT",
6+
"category": "payments",
7+
"description": {
8+
"name": "BitPay Checkout",
9+
"tagline": "Accept payments via crypto currency using BitPay",
10+
"features": [
11+
"Accept bitcoin and bitcoin cash payments from payment protocol compatible wallets",
12+
"Price in your local currency",
13+
"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)",
14+
"By design, chargebacks are not possible with cryptocurrency payments",
15+
"Have an overview of all your bitcoin and bitcoin cash payments in your BitPay merchant account at https://bitpay.com/dashboard",
16+
"Refund your customers in bitcoin or bitcoin cash in your BitPay merchant dashboard at https://bitpay.com/dashboard/payments"
17+
]
18+
},
19+
"logo": {
20+
"filename": "icon-256x256.png"
21+
},
22+
"support": {
23+
"homepage": "https:\/\/www.bitpay.com\/",
24+
"learn_more": "https:\/\/www.bitpay.com\/online-payments",
25+
"email": "[email protected]",
26+
"support_url": "https:\/\/www.bitpay.com\/request-help",
27+
"docs_url": "https:\/\/developer.bitpay.com\/"
28+
},
29+
"authors": [
30+
{
31+
"name": "BitPay",
32+
"homepage": "https:\/\/www.bitpay.com\/"
33+
}
34+
]
35+
}

0 commit comments

Comments
 (0)