forked from jlopp/lopp.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btcpay_callback.php
40 lines (35 loc) · 1.65 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
<?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 YOUR_DOMAIN = "";
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;
$headers = "From: paidform@" . YOUR_DOMAIN . "\r\nReply-to: paidform@" . YOUR_DOMAIN;
mail(YOUR_EMAIL_ADDRESS, "Paid Message ERROR", $message, $headers);
} else {
$message = json_decode($orderData);
$headers = "From: " . $message->email . "\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);
$headers = "From: paidform@" . YOUR_DOMAIN . "\r\nReply-to: paidform@" . YOUR_DOMAIN;
mail(YOUR_EMAIL_ADDRESS, "Paid Message ERROR. invoice status: " . $invoice->status, $message, $headers);
}
http_response_code(200);
?>