11<?php
22/**
3- * BitPay Checkout IPN 3.1.1.0
3+ * BitPay Checkout IPN 4.0.1
44 *
55 * This file demonstrates how a payment gateway callback should be
66 * handled within WHMCS.
@@ -38,6 +38,7 @@ function checkInvoiceStatus($url){
3838
3939$ all_data = json_decode (file_get_contents ("php://input " ), true );
4040$ file = 'bitpay.txt ' ;
41+ $ err = "bitpay_err.txt " ;
4142
4243file_put_contents ($ file ,"===========INCOMING IPN========================= " ,FILE_APPEND );
4344file_put_contents ($ file ,date ('d.m.Y H:i:s ' ),FILE_APPEND );
@@ -68,14 +69,12 @@ function checkInvoiceStatus($url){
6869$ result = select_query ($ table , $ fields , $ where );
6970$ rowdata = mysql_fetch_array ($ result );
7071$ btn_id = $ rowdata ['transaction_id ' ];
71- $ status_arr = ['confirmed ' ,'complete ' ];
7272
7373if ($ btn_id ):
7474switch ($ event ['name ' ]) {
7575 #complete, update invoice table to Paid
76- case 'invoice_completed ' :
76+ case 'invoice_confirmed ' :
7777
78- if (in_array ($ order_status ,$ status_arr ) && $ order_status == "complete " ):
7978
8079 $ table = "tblinvoices " ;
8180 $ update = array ("status " => 'Paid ' ,'datepaid ' => date ("Y-m-d H:i:s " ));
@@ -84,7 +83,7 @@ function checkInvoiceStatus($url){
8483 update_query ($ table , $ update , $ where );
8584 }
8685 catch (Exception $ e ){
87- file_put_contents ($ file ,$ e ,FILE_APPEND );
86+ file_put_contents ($ err ,$ e ,FILE_APPEND );
8887 }
8988
9089 #update the bitpay_invoice table
@@ -94,7 +93,7 @@ function checkInvoiceStatus($url){
9493 try {
9594 update_query ($ table , $ update , $ where );
9695 }catch (Exception $ e ){
97- file_put_contents ($ file ,$ e ,FILE_APPEND );
96+ file_put_contents ($ err ,$ e ,FILE_APPEND );
9897 }
9998
10099 addInvoicePayment (
@@ -104,9 +103,6 @@ function checkInvoiceStatus($url){
104103 0 ,
105104 'bitpaycheckout '
106105 );
107- endif ;
108-
109-
110106 break ;
111107
112108 #processing - put in Payment Pending
@@ -133,6 +129,8 @@ function checkInvoiceStatus($url){
133129
134130 #confirmation error - put in Unpaid
135131 case 'invoice_failedToConfirm ' :
132+ case 'invoice_declined ' :
133+
136134 $ table = "tblinvoices " ;
137135 $ update = array ("status " => 'Unpaid ' );
138136 $ where = array ("id " => $ orderid , "paymentmethod " => "bitpaycheckout " );
0 commit comments