-
Notifications
You must be signed in to change notification settings - Fork 3
/
Credit.php
111 lines (93 loc) · 3.54 KB
/
Credit.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Created by PhpStorm.
* User: brunopaz
* Date: 2018-12-26
* Time: 22:50
*/
namespace Gateway\API;
include_once "autoload.php";
use Exception as Exception;
try {
$credential = new Credential("{{mechantID}}", "{{mechantKEY}}",
Environment::SANDBOX);
$gateway = new Gateway($credential);
### CREATE A NEW TRANSACTION
$transaction = new Transaction();
// Set ORDER
$transaction->Order()
->setReference("ss")
->setTotalAmount(150000);
// Set PAYMENT
$transaction->Payment()
->setAcquirer(Acquirers::AZPAY)
->setMethod(Methods::CREDIT_CARD_INTEREST_BY_ISSUER)
->setCurrency(Currency::BRAZIL_BRAZILIAN_REAL_BRL)
->setCountry("BRA")
->setNumberOfPayments(2)
->setSoftDescriptor("NOMEDAEMPRESA")
->Card()
->setBrand(Brand::VISA)
->setCardHolder("Fulano de tal")
->setCardNumber("2223000148400010")
->setCardSecurityCode("123")
->setCardExpirationDate("202001");
// SET CUSTOMER
$transaction->Customer()
->setCustomerIdentity("999999999")
->setName("Bruno")
->setCpf("106.182.848-01")
->setCnpj("18303116000165")
->setEmail("[email protected]");
// SET FRAUD DATA OBJECT
$transaction->FraudData()
->setName("Bruno Paz")
->setDocument("94127918012")
->setEmail("[email protected]")
->setAddress("Rua test")
->setAddress2("Apartamento 23")
->setAddressNumber("300")
->setPostalCode("08742350")
->setCity("São Paulo")
->setState("SP")
->setCountry("BRASIL")
->setPhonePrefix("11")
->setPhoneNumber("99999-9999")
->setDevice("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36")
->setCostumerIP("192.168.0.1")
->setItems([
["productName" => "Iphone X", "quantity" => 1, "price" => "20.00"],
["productName" => "Iphone XL", "quantity" => 12, "price" => "1220.00"]
]);
// Set URL RETURN
$transaction->setUrlReturn("http://127.0.0.1:8989/return.php");
// PROCESS - ACTION
$response = $gateway->sale($transaction);
//$response = $gateway->authorize($transaction);
// REDIRECT IF NECESSARY (Debit uses)
if ($response->isRedirect()) {
$response->redirect();
}
// RESULTED
if ($response->isAuthorized()) { // Action Authorized
print "<br>RESULTED: " . $response->getStatus();
} else { // Action Unauthorized
print "<br>RESULTED:" . $response->getStatus();
}
// CAPTURE
if ($response->canCapture()) {
$response = $gateway->Capture($response->getTransactionID(),
100000);
print "<br>CAPTURED: " . $response->getStatus();
}
// CANCELL
if ($response->canCancel()) {
$response = $gateway->Cancel($response->getTransactionID(), 50000);
print "<br>CANCELED: " . $response->getStatus();
}
// REPORT
$response = $gateway->Report($response->getTransactionID());
print "<br>REPORTING: " . $response->getStatus();
} catch (Exception $e) {
print_r($e->getMessage());
}