Skip to content

Commit 2515c01

Browse files
IPN Updates
1 parent a5f8705 commit 2515c01

File tree

4 files changed

+25
-108
lines changed

4 files changed

+25
-108
lines changed

modules/gateways/bitpaycheckout.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* BitPay Checkout 4.0.1
3+
* BitPay Checkout 4.0.2
44
*
55
* Within the module itself, all functions must be prefixed with the module
66
* filename, followed by an underscore, and then the function name. For this
@@ -50,15 +50,6 @@ function ($table) {
5050
* @return array
5151
*/
5252

53-
function bitpaycheckout_MetaData()
54-
{
55-
return array(
56-
'DisplayName' => 'BitPay_Checkout_WHMCS',
57-
'APIVersion' => '4.0.1', // Use API Version 1.1
58-
'DisableLocalCreditCardInput' => false,
59-
'TokenisedStorage' => false,
60-
);
61-
}
6253

6354
/**
6455
* Define gateway configuration options.
@@ -83,6 +74,7 @@ function bitpaycheckout_MetaData()
8374
* @return array
8475
*/
8576

77+
if (!function_exists('bitpaycheckout_config')) {
8678
function bitpaycheckout_config()
8779
{
8880
return array(
@@ -125,6 +117,7 @@ function bitpaycheckout_config()
125117

126118
);
127119
}
120+
}
128121

129122
function BPC_autoloader($class)
130123
{
@@ -220,20 +213,16 @@ function bitpaycheckout_link($config_params)
220213
$protocol = 'https://';
221214

222215
$callback_url = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/bitpaycheckout_callback.php';
223-
$params->extension_version = bitpaycheckout_MetaData();
224-
$params->extension_version = $params->extension_version['DisplayName'] . '_' . $params->extension_version['APIVersion'];
216+
$params->extension_version = "BitPay_Checkout_WHMCS_4.0.2";
225217
$params->price = $amount;
226218
$params->currency = $currencyCode;
227219
$params->orderId = trim($invoiceId);
228220

229221
$params->notificationURL = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/bitpaycheckout_ipn.php';
230222
$params->redirectURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
231-
232-
$params->extendedNotifications = true;
233-
234-
#set the transaction speed in the plugin and override the plugin
223+
$params->fullNotifications = true;
224+
#$params->extendedNotifications = true;
235225

236-
$params->acceptanceWindow = 1200000;
237226
if (!empty($email)):
238227
$buyerInfo = new stdClass();
239228
$buyerInfo->name = $firstname . ' ' . $lastname;
@@ -322,7 +311,7 @@ function showModal(invoiceData) {
322311
data: $encodedData,
323312
dataType: "text",
324313
success: function(resultData) {
325-
location.reload();
314+
window.location.reload();
326315
},
327316
error: function(resultData) {
328317
//console.log('error', resultData)

modules/gateways/bitpaycheckout/bitpaycheckout.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* BitPay Checkout 4.0.1
3+
* BitPay Checkout 4.0.2
44
*
55
* Within the module itself, all functions must be prefixed with the module
66
* filename, followed by an underscore, and then the function name. For this
@@ -50,15 +50,6 @@ function ($table) {
5050
* @return array
5151
*/
5252

53-
function bitpaycheckout_MetaData()
54-
{
55-
return array(
56-
'DisplayName' => 'BitPay_Checkout_WHMCS',
57-
'APIVersion' => '4.0.1', // Use API Version 1.1
58-
'DisableLocalCreditCardInput' => false,
59-
'TokenisedStorage' => false,
60-
);
61-
}
6253

6354
/**
6455
* Define gateway configuration options.
@@ -82,7 +73,7 @@ function bitpaycheckout_MetaData()
8273
*
8374
* @return array
8475
*/
85-
76+
if (!function_exists('bitpaycheckout_config')) {
8677
function bitpaycheckout_config()
8778
{
8879
return array(
@@ -125,6 +116,7 @@ function bitpaycheckout_config()
125116

126117
);
127118
}
119+
}
128120

129121
function BPC_autoloader($class)
130122
{
@@ -220,20 +212,16 @@ function bitpaycheckout_link($config_params)
220212
$protocol = 'https://';
221213

222214
$callback_url = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/bitpaycheckout_callback.php';
223-
$params->extension_version = bitpaycheckout_MetaData();
224-
$params->extension_version = $params->extension_version['DisplayName'] . '_' . $params->extension_version['APIVersion'];
215+
$params->extension_version = "BitPay_Checkout_WHMCS_4.0.2";
225216
$params->price = $amount;
226217
$params->currency = $currencyCode;
227218
$params->orderId = trim($invoiceId);
228219

229220
$params->notificationURL = $protocol . $_SERVER['SERVER_NAME'] . $dir . '/modules/gateways/bitpaycheckout/bitpaycheckout_ipn.php';
230221
$params->redirectURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
231-
232-
$params->extendedNotifications = true;
233-
234-
#set the transaction speed in the plugin and override the plugin
222+
$params->fullNotifications = true;
223+
#$params->extendedNotifications = true;
235224

236-
$params->acceptanceWindow = 1200000;
237225
if (!empty($email)):
238226
$buyerInfo = new stdClass();
239227
$buyerInfo->name = $firstname . ' ' . $lastname;
@@ -322,7 +310,7 @@ function showModal(invoiceData) {
322310
data: $encodedData,
323311
dataType: "text",
324312
success: function(resultData) {
325-
location.reload();
313+
window.location.reload();
326314
},
327315
error: function(resultData) {
328316
//console.log('error', resultData)

modules/gateways/bitpaycheckout/bitpaycheckout_callback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* BitPay Checkout Callback 4.0.1
4+
* BitPay Checkout Callback 4.0.2
55
*
66
* This file demonstrates how a payment gateway callback should be
77
* handled within WHMCS.
Lines changed: 10 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* BitPay Checkout IPN 4.0.1
3+
* BitPay Checkout IPN 4.0.2
44
*
55
* This file demonstrates how a payment gateway callback should be
66
* handled within WHMCS.
@@ -36,18 +36,17 @@ function checkInvoiceStatus($url){
3636
return $result;
3737
}
3838

39-
$all_data = json_decode(file_get_contents("php://input"), true);
39+
$event = json_decode(file_get_contents("php://input"), true);
4040
$file = 'bitpay.txt';
4141
$err = "bitpay_err.txt";
4242

4343
file_put_contents($file,"===========INCOMING IPN=========================",FILE_APPEND);
4444
file_put_contents($file,date('d.m.Y H:i:s'),FILE_APPEND);
45-
file_put_contents($file,print_r($all_data, true),FILE_APPEND);
45+
file_put_contents($file,print_r($event, true),FILE_APPEND);
4646
file_put_contents($file,"===========END OF IPN===========================",FILE_APPEND);
4747

48-
$data = $all_data['data'];
49-
$order_status = $data['status'];
50-
$order_invoice = $data['id'];
48+
$order_status = $event['status'];
49+
$order_invoice = $event['id'];
5150
$endpoint = $gatewayParams['bitpay_checkout_endpoint'];
5251
if($endpoint == "Test"):
5352
$url_check = 'https://test.bitpay.com/invoices/'.$order_invoice;
@@ -56,10 +55,8 @@ function checkInvoiceStatus($url){
5655
endif;
5756
$invoiceStatus = json_decode(checkInvoiceStatus($url_check));
5857

59-
$event = $all_data['event'];
6058
$orderid = $invoiceStatus->data->orderId;
6159
$price = $invoiceStatus->data->price;
62-
6360
#first see if the ipn matches
6461
#get the user id first
6562
$table = "_bitpay_checkout_transactions";
@@ -71,10 +68,9 @@ function checkInvoiceStatus($url){
7168
$btn_id = $rowdata['transaction_id'];
7269

7370
if($btn_id):
74-
switch ($event['name']) {
71+
switch ($event['status']) {
7572
#complete, update invoice table to Paid
76-
case 'invoice_confirmed':
77-
73+
case 'complete ':
7874

7975
$table = "tblinvoices";
8076
$update = array("status" => 'Paid','datepaid' => date("Y-m-d H:i:s"));
@@ -88,7 +84,7 @@ function checkInvoiceStatus($url){
8884

8985
#update the bitpay_invoice table
9086
$table = "_bitpay_checkout_transactions";
91-
$update = array("transaction_status" => $event['name']);
87+
$update = array("transaction_status" => "complete");
9288
$where = array("order_id" => $orderid, "transaction_id" => $order_invoice);
9389
try{
9490
update_query($table, $update, $where);
@@ -106,7 +102,7 @@ function checkInvoiceStatus($url){
106102
break;
107103

108104
#processing - put in Payment Pending
109-
case 'invoice_paidInFull':
105+
case 'paid':
110106
$table = "tblinvoices";
111107
$update = array("status" => 'Payment Pending','datepaid' => date("Y-m-d H:i:s"));
112108
$where = array("id" => $orderid, "paymentmethod" => "bitpaycheckout");
@@ -127,33 +123,8 @@ function checkInvoiceStatus($url){
127123
}
128124
break;
129125

130-
#confirmation error - put in Unpaid
131-
case 'invoice_failedToConfirm':
132-
case 'invoice_declined':
133-
134-
$table = "tblinvoices";
135-
$update = array("status" => 'Unpaid');
136-
$where = array("id" => $orderid, "paymentmethod" => "bitpaycheckout");
137-
try{
138-
update_query($table, $update, $where);
139-
}catch (Exception $e ){
140-
file_put_contents($file,$e,FILE_APPEND);
141-
}
142-
143-
#update the bitpay_invoice table
144-
$table = "_bitpay_checkout_transactions";
145-
$update = array("transaction_status" => $event['name']);
146-
$where = array("order_id" => $orderid, "transaction_id" => $order_invoice);
147-
try{
148-
update_query($table, $update, $where);
149-
}catch (Exception $e ){
150-
file_put_contents($file,$e,FILE_APPEND);
151-
}
152-
153-
break;
154-
155126
#expired, remove from transaction table, wont be in invoice table
156-
case 'invoice_expired':
127+
case 'expired':
157128
#delete any orphans
158129
$table = "_bitpay_checkout_transactions";
159130
$delete = 'DELETE FROM _bitpay_checkout_transactions WHERE transaction_id = "' . $order_invoice.'"';
@@ -163,37 +134,6 @@ function checkInvoiceStatus($url){
163134
file_put_contents($file,$e,FILE_APPEND);
164135
}
165136
break;
166-
167-
#update both table to refunded
168-
case 'invoice_refundComplete':
169-
170-
#get the user id first
171-
$table = "tblaccounts";
172-
$fields = "id,userid";
173-
$where = array("transid" => $order_invoice);
174-
$result = select_query($table, $fields, $where);
175-
$rowdata = mysql_fetch_array($result);
176-
$id = $rowdata['id'];
177-
$userid = $rowdata['userid'];
178-
179-
180-
#do an insert on tblaccounts
181-
$values = array("userid" => $userid, "description" => "BitPay Refund of Transaction ID: ".$order_invoice, "amountin" => "0","currency"=>"0","amountout" => $price,"invoiceid" =>$orderid,"date"=>date("Y-m-d H:i:s"));
182-
$newid = insert_query($table, $values);
183-
184-
#update the tblinvoices to show Refunded
185-
$table = "tblinvoices";
186-
$update = array("status" => 'Refunded','datepaid' => date("Y-m-d H:i:s"));
187-
$where = array("id" => $orderid, "paymentmethod" => "bitpaycheckout");
188-
update_query($table, $update, $where);
189-
190-
#update the bitpay_invoice table
191-
$table = "_bitpay_checkout_transactions";
192-
$update = array("transaction_status" => $event['name']);
193-
$where = array("order_id" => $orderid, "transaction_id" => $order_invoice);
194-
update_query($table, $update, $where);
195-
196-
break;
197137
}
198138
http_response_code(200);
199139
endif;#end of the table lookup

0 commit comments

Comments
 (0)