-
Notifications
You must be signed in to change notification settings - Fork 0
/
recurrent.php
108 lines (71 loc) · 3.14 KB
/
recurrent.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
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' and ($_POST['Status'] === 'Cancelled' or $_POST['Status'] === 'PastDue' or $_POST['Status'] === 'Rejected')) {
require('config.php');
if ($_POST['Status'] === 'PastDue') {
$template_id = ERROR_RECURRENT_TEMPLATE; // Шаблон при ошибке ежемесячного платежа
} else if ($_POST['Status'] === 'Rejected') {
$template_id = REJECTED_RECURRENT_TEMPLATE; // Шаблон при отмене подписки после 3 попыток списания
} else if ($_POST['Status'] === 'Cancelled') {
$template_id = CANCELLED_RECURRENT_TEMPLATE; // Шаблон при отмене подписки
}
$url = "https://go1.unisender.ru/ru/transactional/api/v1/email/send.json";
$requestBody = [
"api_key" => API_KEY,
"username" => USER_NAME,
"message" => [
// "template_engine" => "velocity",
"template_id" => $template_id,
"recipients" => [
[
"email" => $_POST['Email'],
// "substitutions" => [
// "to_name" => "Имя получателя 1",
// "person" => [
// "name" => "Иванов Иван Иваныч"
// ],
]
]
],
// "body" => [
// "html" => "<b>Hello, {{to_name}}</b>",
// "plaintext" => "Hello, {{to_name}}",
// "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>"
// ],
// "subject" => "Спасибо за пожертвование",
"from_email" => FROM_EMAIL,
"from_name" => FROM_NAME,
"reply_to" => REPLY_TO,
"track_links" => 0,
"track_read" => 0,
"bypass_global" => 0,
"bypass_unavailable" => 0,
"bypass_unsubscribed" => 0,
"bypass_complained" => 0
];
$content = json_encode($requestBody);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array("Content-type: application/json", "Accept: application/json", "Origin: {$_SERVER['SERVER_NAME']}")
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_RESOLVE, ["go1.unisender.ru:443:217.77.111.132"]);
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$json_response = curl_exec($curl);
// $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// if ( $status != 201 ) {
// die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
// }
curl_close($curl);
$response = json_decode($json_response, true);
$responseCloudPayments = json_encode([
"code" => 0
]);
echo $responseCloudPayments;
} else {
echo 'No request';
}