forked from cryptoapi/Payment-Gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptobox.newpayment.php
120 lines (104 loc) · 5.16 KB
/
cryptobox.newpayment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* ... Please MODIFY this file ...
*
*
* User-defined function (IPN) for new payments
* ---------------------------------------------
*
* User-defined function - cryptobox_new_payment($paymentID = 0, $payment_details = array(), $box_status = "").
* Use this function to send confirmation email, update database, update user membership, etc.
*
* This IPN function will automatically appear for each new payment usually two times :
* a) when a new payment is received, with values: $box_status = cryptobox_newrecord, $payment_details[confirmed] = 0
* b) and a second time when existing payment is confirmed (6+ confirmations) with values: $box_status = cryptobox_updated, $payment_details[confirmed] = 1.
*
* But sometimes if the payment notification is delayed for 20-30min, the payment/transaction will already be confirmed and the function will
* appear once with values: $box_status = cryptobox_newrecord, $payment_details[confirmed] = 1
*
* If payment received with correct amount, function receive: $payment_details[status] = 'payment_received' and $payment_details[user] = 11, 12, etc (user_id who has made payment)
* If incorrectly paid amount, the system can not recognize user; function receive: $payment_details[status] = 'payment_received_unrecognised' and $payment_details[user] = ''
*
* Function cryptobox_new_payment($paymentID = 0, $payment_details = array(), $box_status = "")
* gets $paymentID from your table crypto_payments, $box_status = 'cryptobox_newrecord' OR 'cryptobox_updated' (description above)
* and payment details as array -
*
* 1. EXAMPLE - CORRECT PAYMENT -
* -----------------------------------------------------
* $payment_details = Array
* {
* "status":"payment_received"
* "err":""
* "private_key":"1206lO6HX76cw9Bitcoin77DOGED82Y8eyBExZ9kZpX"
* "box":"120"
* "boxtype":"paymentbox"
* "order":"order15620A"
* "user":"user26"
* "usercountry":"USA"
* "amount":"0.0479166"
* "amountusd":"11.5"
* "coinlabel":"BTC"
* "coinname":"bitcoin"
* "addr":"14dt2cSbvwghDcETJDuvFGHe5bCsCPR9jW"
* "tx":"95ed924c215f2945e75acfb5650e28384deac382c9629cf0d3f31d0ec23db08d"
* "confirmed":0
* "timestamp":"1422624765 "
* "date":"30 January 2015"
* "datetime":"2015-01-30 13:32:45"
* }
*
* 2. EXAMPLE - INCORRECT PAYMENT/WRONG AMOUNT -
* -----------------------------------------------------
* $payment_details = Array
* {
* "status":"payment_received_unrecognised"
* "err":"An incorrect bitcoin amount has been received"
* "private_key":"1206lO6HX76cw9Bitcoin77DOGED82Y8eyBExZ9kZpX"
* "box":"120"
* "boxtype":"paymentbox"
* "order":""
* "user":""
* "usercountry":""
* "amount":"12.26"
* "amountusd":"0.05"
* "coinlabel":"BTC"
* "coinname":"bitcoin"
* "addr":"14dt2cSbvwghDcETJDuvFGHe5bCsCPR9jW"
* "tx":"6f1c6f34189a27446d18e25b9c79db78be55b0bb775b1768b5aa4520f27d71a8"
* "confirmed":0
* "timestamp":"1422623712"
* "date":"30 January 2015"
* "datetime":"2015-01-30 13:15:12"
* }
*
* Read more - https://gourl.io/api-php.html#ipn
*/
function cryptobox_new_payment($paymentID = 0, $payment_details = array(), $box_status = "")
{
/** .............
.............
PLACE YOUR CODE HERE
Update database with new payment, send email to user, etc
Please note, all received payments store in your table `crypto_payments` also
See - https://gourl.io/api-php.html#payment_history
.............
.............
For example, you have own table `user_orders`...
You can use function run_sql() from cryptobox.class.php ( https://gourl.io/api-php.html#run_sql )
.............
// Save new Bitcoin payment in database
$recordExists = run_sql("select paymentID as nme FROM `user_orders` WHERE paymentID = ".intval($paymentID));
if (!$recordExists) run_sql("INSERT INTO `user_orders` VALUES(".intval($paymentID).",'".$payment_details["user"]."','".$payment_details["order"]."',".floatval($payment_details["amount"]).",".floatval($payment_details["amountusd"]).",'".$payment_details["coinlabel"]."',".intval($payment_details["confirmed"]).",'".$payment_details["status"]."')");
.............
// Bitcoin payment confirmed (6+ transaction confirmations)
if ($recordExists && $box_status == "cryptobox_updated") run_sql("UPDATE `user_orders` SET txconfirmed = ".intval($payment_details["confirmed"])." WHERE paymentID = ".intval($paymentID));
.............
.............
Debug - new payment email notification for webmaster
Uncomment lines below and make any test payment
--------------------------------------------
$email = "....your email address....";
mail($email, "Payment - " . $paymentID . " - " . $box_status, " \n Payment ID: " . $paymentID . " \n\n Status: " . $box_status . " \n\n Details: " . print_r($payment_details, true));
*/
return true;
}