This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
52 lines (44 loc) · 1.55 KB
/
index.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
<?php
// CONFIG
// Create token
// https://www.tucuota.com/dashboard/developers
$tuCuotaToken = getenv('TC_API_KEY');
// Get current url
$currentUrl = "http" . (($_SERVER['SERVER_PORT'] == 443) ? "s" : "") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$currentUrl = strtok($currentUrl, '?');
// Check required data
if (!isset($_GET['customer_id']) || !isset($_GET['customer_name']) || !isset($_GET['customer_email'])) {
print "A la dirección le faltan datos, tiene que estar construida como <br>" . $currentUrl . "?customer_id=123&customer_name=Pedro Giménez&customer_email=pedro@gimenez.com";
exit;
}
// set data for request
$endpoint = 'https://tucuota.com/api/sessions';
$post_data = [
'kind' => 'mandate',
// 'success_url' => $currentUrl,
'customer_id' => $_GET['customer_id'],
'customer_name' => $_GET['customer_name'],
'customer_email' => $_GET['customer_email']
];
$headers = [
'Authorization: Bearer ' . $tuCuotaToken
];
// Prepare data
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Api call
$response = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// close connection
curl_close($ch);
$response = json_decode($response, true);
if ($responseCode >= 400) {
echo "<pre>" . print_r($response) . "</pre>";
} else {
header('Location: ' . $response['data']['public_uri']);
exit;
}