3
3
/**
4
4
* BitPay Checkout IPN 5.0.0
5
5
*
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.
14
9
*
15
10
* @see https://developers.whmcs.com/payment-gateways/callbacks/
16
11
*
30
25
31
26
// Fetch gateway configuration parameters.
32
27
$ 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/ ' );
35
30
36
31
function checkInvoiceStatus ($ url )
37
32
{
@@ -48,17 +43,17 @@ function checkInvoiceStatus($url)
48
43
$ data = $ response ['data ' ];
49
44
50
45
$ file = 'bitpay.txt ' ;
51
- $ err = " bitpay_err.txt " ;
46
+ $ err = ' bitpay_err.txt ' ;
52
47
53
- file_put_contents ($ file , " ===========INCOMING IPN========================= " , FILE_APPEND );
48
+ file_put_contents ($ file , ' ===========INCOMING IPN========================= ' , FILE_APPEND );
54
49
file_put_contents ($ file , date ('d.m.Y H:i:s ' ), FILE_APPEND );
55
50
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 );
57
52
58
53
$ order_status = $ data ['status ' ];
59
54
$ order_invoice = $ data ['id ' ];
60
55
$ endpoint = $ gatewayParams ['bitpay_checkout_endpoint ' ];
61
- if ($ endpoint == " Test " ) {
56
+ if ($ endpoint == ' Test ' ) {
62
57
$ url_check = TEST_URL . $ order_invoice ;
63
58
} else {
64
59
$ url_check = PROD_URL . $ order_invoice ;
@@ -67,7 +62,7 @@ function checkInvoiceStatus($url)
67
62
68
63
$ orderid = checkCbInvoiceID ($ invoiceStatus ->data ->orderId , 'bitpaycheckout ' );
69
64
$ price = $ invoiceStatus ->data ->price ;
70
- #first see if the ipn matches
65
+ // First see if the ipn matches
71
66
$ trans_data = Capsule::table ('_bitpay_checkout_transactions ' )
72
67
->select ('order_id ' , 'transaction_id ' , 'transaction_status ' )
73
68
->where ([
@@ -81,15 +76,15 @@ function checkInvoiceStatus($url)
81
76
82
77
if ($ btn_id ) {
83
78
switch ($ data ['status ' ]) {
84
- #complete , update invoice table to Paid
79
+ // Complete , update invoice table to Paid
85
80
case 'complete ' :
86
81
if ($ transaction_status == $ data ['status ' ]) {
87
82
exit ();
88
83
}
89
84
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 ' ));
93
88
try {
94
89
Capsule::table ($ table )
95
90
->where ([
@@ -110,10 +105,10 @@ function checkInvoiceStatus($url)
110
105
);
111
106
break ;
112
107
113
- #processing - put in Payment Pending
108
+ // Processing - put in Payment Pending
114
109
case 'paid ' :
115
- #update the invoices table
116
- $ table = " tblinvoices " ;
110
+ // Update the invoices table
111
+ $ table = ' tblinvoices ' ;
117
112
$ update = array ("status " => 'Payment Pending ' ,'datepaid ' => date ('Y-m-d H:i:s ' ));
118
113
try {
119
114
Capsule::table ($ table )
@@ -126,9 +121,9 @@ function checkInvoiceStatus($url)
126
121
file_put_contents ($ file , $ e , FILE_APPEND );
127
122
}
128
123
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 ' ));
132
127
try {
133
128
Capsule::table ($ table )
134
129
->where ([
@@ -141,10 +136,10 @@ function checkInvoiceStatus($url)
141
136
}
142
137
break ;
143
138
144
- #expired , remove from transaction table, wont be in invoice table
139
+ // Expired , remove from transaction table, wont be in invoice table
145
140
case 'expired ' :
146
- #delete any orphans
147
- $ table = " _bitpay_checkout_transactions " ;
141
+ // Delete any orphans
142
+ $ table = ' _bitpay_checkout_transactions ' ;
148
143
try {
149
144
Capsule::table ($ table )
150
145
->where ('transaction_id ' , '= ' , $ order_invoice )
@@ -154,12 +149,12 @@ function checkInvoiceStatus($url)
154
149
}
155
150
break ;
156
151
157
- #refunded , set invoice and bitpay transaction to refunded status
152
+ // Refunded , set invoice and bitpay transaction to refunded status
158
153
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 ' ));
163
158
try {
164
159
Capsule::table ($ table )
165
160
->where ([
@@ -171,9 +166,9 @@ function checkInvoiceStatus($url)
171
166
file_put_contents ($ file , $ e , FILE_APPEND );
172
167
}
173
168
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 ' ));
177
172
try {
178
173
Capsule::table ($ table )
179
174
->where ([
0 commit comments