-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpagseguroapilite.php
71 lines (64 loc) · 3.22 KB
/
pagseguroapilite.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
<?php
function pagseguroapilite_config()
{
return array(
'FriendlyName' => array('Type' => 'System', 'Value' => 'PagSeguro API Lite (SuporteWHMCS.Com.Br)'),
'email' => array('FriendlyName' => 'Email', 'Type' => 'text', 'Size' => '40'),
'token' => array('FriendlyName' => 'Token', 'Type' => 'text', 'Size' => '50'),
);
}
function pagseguroapilite_link($params)
{
$xml_checkout = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<checkout>
<currency>BRL</currency>
<items>
<item>
<id>1</id>
<description>' . htmlspecialchars($params['description']) . '</description>
<amount>' . $params['amount'] . '</amount>
<quantity>1</quantity>
</item>
</items>
<reference>' . $params['invoiceid'] . '</reference>
<redirectURL>' . $params['systemurl'] . '/viewinvoice.php?id=' . $params['invoiceid'] . '</redirectURL>
<notificationURL>' . $params['systemurl'] . '/modules/gateways/' . basename(__FILE__) . '</notificationURL>
</checkout>';
$curl = curl_init('https://ws.pagseguro.uol.com.br/v2/checkout/?email=' . $params['email'] . '&token=' . $params['token']);
curl_setopt_array($curl, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $xml_checkout,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => array('Content-Type: application/xml; charset=UTF-8')));
$retorno_curl = curl_exec($curl);
$checkout_parsed = simplexml_load_string($retorno_curl);
if ($checkout_parsed->code) {
$result = '<form action="https://pagseguro.uol.com.br/v2/checkout/payment.html" method="get">' . "\n";
$result .= ' <input type="hidden" name="code" value="' . $checkout_parsed->code . '">' . "\n";
$result .= ' <input type="submit" value="Pagar Agora">' . "\n";
$result .= '</form>' . "\n";
} else {
$result = '<font style="color:red">Ocorreu um erro na comunicação com o PagSeguro</font>';
logTransaction($params['name'], $retorno_curl . print_r($params, true) . ($checkout_parsed ? " / " . $checkout_parsed : ""), 'Unsuccessful');
}
return $result;
}
if (basename(__FILE__) == basename($_SERVER['SCRIPT_NAME'])) {
if (!array_key_exists('notificationCode', $_POST) || !array_key_exists('notificationType', $_POST)) {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
die();
}
require '../../init.php';
require '../../includes/invoicefunctions.php';
require '../../includes/gatewayfunctions.php';
$GATEWAY = getGatewayVariables('pagseguroapilite');
$curl = curl_init('https://ws.pagseguro.uol.com.br/v3/transactions/notifications/' . $_POST['notificationCode'] . '?email=' . $GATEWAY['email'] . '&token=' . $GATEWAY['token']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$xml = simplexml_load_string(curl_exec($curl));
logTransaction($GATEWAY['name'], print_r($_POST, true) . print_r($xml, true), 'Successful');
$invoiceid = checkCbInvoiceID($xml->reference, $GATEWAY["name"]);
checkCbTransID($xml->code);
if ($xml->status == 3 || $xml->status == 4) {
addInvoicePayment($invoiceid, $xml->code, (float)$xml->grossAmount, 0, 'pagseguroapilite');
}
}