forked from vinaocruz/Cielo-PHP-Library
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.php
More file actions
131 lines (113 loc) · 3.21 KB
/
example.php
File metadata and controls
131 lines (113 loc) · 3.21 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
use
CieloCheckout\Order,
CieloCheckout\Item,
CieloCheckout\Discount,
CieloCheckout\Cart,
CieloCheckout\Address,
CieloCheckout\Services,
CieloCheckout\Shipping,
CieloCheckout\Payment,
CieloCheckout\Customer,
CieloCheckout\Options,
CieloCheckout\Transaction,
Cielo\Merchant;
include_once "vendor/autoload.php";
try {
// Instantiate cart's item object and set it to an array of product items.
$properties = [
'Name' => 'Nome do produto',
'Description' => 'Descrição do produto',
'UnitPrice' => 100,
'Quantity' => 2,
'Type' => 'Asset',
'Sku' => 'Sku do item no carrinho',
'Weight' => 200,
];
$Items = [
new Item($properties),
];
// Instantiate cart discount object.
$properties = [
'Type' => 'Percent',
'Value' => 10,
];
$Discount = new Discount($properties);
// Instantiate shipping address' object.
$properties = [
'Street' => 'Rua Em Algum Lugar',
'Number' => '123',
'Complement' => '',
'District' => 'Setor F',
'City' => 'Alta Floresta',
'State' => 'MT',
];
$Address = new Address($properties);
// Instantiate shipping services' object.
$properties = [
'Name' => 'Serviço de frete',
'Price' => 123,
'DeadLine' => 15,
];
$Services = [
new Services($properties),
];
// Instantiate shipping's object.
$properties = [
'Type' => 'Free',
'SourceZipCode' => '78580000',
'TargetZipCode' => '78580000',
'Address' => $Address,
'Services' => $Services,
];
$Shipping = new Shipping($properties);
// Instantiate payment's object.
$properties = [
'BoletoDiscount' => 0,
'DebitDiscount' => 10,
];
$Payment = new Payment($properties);
// Instantiate customer's object.
$properties = [
'Identity' => '83255885515',
'FullName' => 'Fulano Comprador da Silva',
'Email' => 'fulano@email.com',
'Phone' => '11999999999',
];
$Customer = new Customer($properties);
// Instantiate options' object.
$properties = [
'AntifraudEnabled' => FALSE,
];
$Options = new Options($properties);
// Instantiate order's object.
$properties = [
'OrderNumber' => '1234',
'SoftDescriptor' => 'Test',
// Instantiate cart's object.
'Cart' => new Cart(['Discount' => $Discount, 'Items' => $Items]),
'Shipping' => $Shipping,
'Payment' => $Payment,
'Customer' => $Customer,
'Options' => $Options,
];
$Order = new Order($properties);
// Instantiate merchant's object.
$Merchant = new Merchant($id, $key);
// Instantiate transaction's object.
$Transaction = new Transaction($Merchant, $Order);
$Transaction->request_new_transaction();
print_r($Transaction->response);
// This will throw an exception when running from terminal cli.
//$Transaction->redirect_to_cielo();
}
catch(Exception $e) {
$msg = $e->getMessage();
print "$msg\n";
}
// Check out the Transaction class at src/Checkout/Transaction.php
// There you will find a constant for each of the transaction status codes that
// will eventually be sent by Cielo to your app via POST method.
// There is also a static method for retrieving an array of all transaction
// status codes available.
$statuses = Transaction::get_response_statuses();