-
Notifications
You must be signed in to change notification settings - Fork 257
/
btcpay_callback.php
41 lines (36 loc) · 1.69 KB
/
btcpay_callback.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
<?php
// set the following values and the rest of the callback script should work
const BTCPAY_IP_ADDRESS = ""; // external IP of your BTCPay server, used as sanity check / spam prevention
const YOUR_EMAIL_ADDRESS = "";
const FROM_EMAIL_ADDRESS = "[email protected]";
$headers = "From: " . FROM_EMAIL_ADDRESS . "\r\nReply-to: " . FROM_EMAIL_ADDRESS;
if ($_SERVER['REQUEST_METHOD'] != 'POST' || $_SERVER['REMOTE_ADDR'] != BTCPAY_IP_ADDRESS) {
http_response_code(401);
exit;
}
$invoice = json_decode(file_get_contents("php://input"));
// read the JSON encoded data from the relevant file
$orderData = file_get_contents("./messages/" . $invoice->orderId);
// ignore expired and unconfirmed invoices
if ($invoice->status == "expired" || $invoice->status == "paid") {
http_response_code(200);
exit;
}
// Send email, otherwise ignore until payment is confirmed
if ($invoice->status == "complete" || $invoice->status == "confirmed") {
if (!$orderData) {
$message = "Could not find message file for invoice " . $invoice->id . ", order " . $invoice->orderId;
mail(YOUR_EMAIL_ADDRESS, "Paid Message ERROR", $message, $headers);
} else {
$message = json_decode($orderData);
$headers = "From: " . FROM_EMAIL_ADDRESS . "\r\nReply-to: " . $message->email;
mail(YOUR_EMAIL_ADDRESS, "Paid Message: " . $message->subject, $message->emailBody, $headers);
}
} else if (!$orderData) {
$message = "Could not find message file for invoice " . print_r($invoice, true);
mail(YOUR_EMAIL_ADDRESS, "Paid Message ERROR. invoice status: " . $invoice->status, $message, $headers);
} else {
mail(YOUR_EMAIL_ADDRESS, "Paid Message ERROR status ($invoice->status)", $message, $headers);
}
http_response_code(200);
?>