-
Notifications
You must be signed in to change notification settings - Fork 55
/
pagsegurolightbox.php
78 lines (68 loc) · 2.05 KB
/
pagsegurolightbox.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
<?php
/**
* Created by PhpStorm.
* User: Ricardo
* Date: 26/12/2017
* Time: 23:15
*/
if (isset($_POST)) {
require_once "./config/config.php";
if ($config['pagseguro']['testing'] == true) {
$token = $config['pagseguro']['tokentest'];
$url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/checkout?';
} else {
$token = $config['pagseguro']['token'];
$url = 'https://ws.pagseguro.uol.com.br/v2/checkout?';
}
$email = $config['pagseguro']['email'];
function to_xml(SimpleXMLElement $object, array $data)
{
foreach ($data as $key => $value) {
if (is_array($value)) {
$new_object = $object->addChild($key);
to_xml($new_object, $value);
} else {
// if the key is an integer, it needs text with it to actually work.
if ($key == (int) $key) {
$key = "$key";
}
$object->addChild($key, $value);
}
}
}
$product_id = $_POST['pid'];
$account_name = $_POST['accname'];
$price = array_keys($config['donate']['offers'][intval($product_id)])[0];
$coinCount = array_values($config['donate']['offers'][intval($product_id)])[0];
$pagseguroDados = [
"currency" => "BRL",
"items" => [
"item" => [
"id" => 0001,
"description" => $coinCount . " " . $config['pagseguro']['produtoNome'],
"amount" => ($price / 100.0) . ".00",
"quantity" => "1"
]
],
"reference" => $account_name . "-" . $product_id,
//"redirectURL" => $config['pagseguro']['urlNotification'],
"receiver" => [
"email" => $email
]
];
$data = new SimpleXMLElement('<?xml version="1.0"?><checkout/>');
to_xml($data, $pagseguroDados);
$data = $data->asXML();
$curl = curl_init("{$url}email={$email}&token={$token}");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml; charset=ISO-8859-1'));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$xml = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($xml);
echo $xml->code;
} else {
header("Location: ./");
}