-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
94 lines (85 loc) · 2.29 KB
/
example.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
<?php
// Requires
require_once('configs.php');
require_once('generateXML.php');
// Credentials
$urlPagseguro = URL_PAGSEGURO;
$emailPagSeguro = EMAIL_PAGSEGURO;
$tokenPagSeguro = TOKEN_PAGSEGURO;
$notificationURL = URL_NOTIFICATION;
// Basic Infos
$client = array(
"code" => '001',
"name" => 'Julimar Gomes da Silva Junior',
"cpf" => str_replace('.', '', str_replace('-', '', '797.710.720-13')),
"ddd" => '11',
"phone" => '912341234',
"hash" => '123456789',
"email" => 'contato@julimarjunior.com.br',
"cep" => '78040-290',
"city" => 'Cuiabá',
"state" => 'MT',
"district" => 'Santa Rosa',
"address" => 'Rua Polônia',
"number" => '123',
"complement" => ''
);
// Credit Card
$client['card'] = array(
"token" => '123456789',
"quantity" => '18',
"value" => '20.00',
"valueTotal" => '360.00',
"name" => 'Julimar Gomes da Silva Junior',
"cpf" => str_replace('.', '', str_replace('-', '', '797.710.720-13')),
"birthDate" => '2001-07-10',
"ddd" => '11',
"phone" => '912341234',
"cep" => '78040-290',
"city" => 'Cuiabá',
"state" => 'MT',
"district" => 'Santa Rosa',
"address" => 'Rua Polônia',
"number" => '123',
"complement" => ''
);
// Products
$products = array(
0 => array(
"code" => '001',
"name" => 'Nome produto 01',
"amount" => '2.00',
"quantity" => '10'
),
1 => array(
"code" => '002',
"name" => 'Nome produto 02',
"amount" => '6.00',
"quantity" => '5'
)
);
// Shipping Value
$shipping = "20.00";
// XML
$xml = generateXML($products, $client, $shipping, $notificationURL);
// cURL
$url = $urlPagseguro . "transactions?email=$emailPagseguro&token=$tokenPagseguro";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml;charset=UTF-8'));
$data = curl_exec($ch);
if($data && $data != "Internal Server Error") {
$dataXML = simplexml_load_string($data);
$dataArray = get_object_vars($dataXML);
if($dataXML->error) {
// Error
var_dump($dataXML->error);
exit;
} else {
// Success
}
}
curl_close($ch);