forked from jlopp/lopp.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btcpay_callback.php
30 lines (26 loc) · 1.1 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
<?php
// set the following two values and the rest of the callback script should work
const BTCPAY_IP_ADDRESS = "";
const YOUR_EMAIL_ADDRESS = "";
const YOUR_DOMAIN = "";
if ($_SERVER['REQUEST_METHOD'] != 'POST' || $_SERVER['REMOTE_ADDR'] != BTCPAY_IP_ADDRESS) {
http_response_code(401);
exit;
}
$invoice = file_get_contents("php://input");
// Send email, otherwise ignore until payment is confirmed
if ($invoice->status == "complete") {
// read the JSON encoded data from the relevant file
$orderData = file_get_contents("./messages/" . $invoice->orderId);
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);
}
}
http_response_code(200);
?>