-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
164 lines (146 loc) · 5.47 KB
/
index.js
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
const ApiClient = require('./ApiClient');
// const CreditCard = require('./One/DataContract/Request/CreateSaleRequestData/CreditCard');
const CreditCardTransaction = require('./One/DataContract/Request/CreateSaleRequestData/CreditCardTransaction');
const CreditCardBrandEnum = require('./One/DataContract/Enum/CreditCardBrandEnum');
// const Order = require('./One/DataContract/Request/CreateSaleRequestData/Order');
const CreateSaleRequest = require('./One/DataContract/Request/CreateSaleRequest');
const CreditCardOperationEnum = require('./One/DataContract/Enum/CreditCardOperationEnum');
const AddressTypeEnum = require('./One/DataContract/Enum/AddressTypeEnum');
const CountryEnum = require('./One/DataContract/Enum/CountryEnum');
const CurrencyIsoEnum = require('./One/DataContract/Enum/CurrencyIsoEnum');
const PaymentMethodEnum = require('./One/DataContract/Enum/PaymentMethodEnum');
const PersonTypeEnum = require('./One/DataContract/Enum/PersonTypeEnum');
const BuyerCategoryEnum = require('./One/DataContract/Enum/BuyerCategoryEnum');
const DocumentTypeEnum = require('./One/DataContract/Enum/DocumentTypeEnum');
const EmailTypeEnum = require('./One/DataContract/Enum/EmailTypeEnum');
const GenderEnum = require('./One/DataContract/Enum/GenderEnum');
const EcommerceCategoryEnum = require('./One/DataContract/Enum/EcommerceCategoryEnum');
// Cria objeto requisição
let request = new CreateSaleRequest();
let uuid = 1231231323123;
let api = new ApiClient();
// Dados da transação de cartão de crédito
let creditCardTransaction = new CreditCardTransaction();
request.addCreditCardTransaction(creditCardTransaction);
creditCardTransaction
.setAmountInCents(100)
.setInstallmentCount(1)
.setCreditCardOperation(CreditCardOperationEnum['AUTH_ONLY'])
.setTransactionDateInMerchant(new Date())
.setTransactionReference(uuid)
.getCreditCard()
.setCreditCardBrand(CreditCardBrandEnum['MASTERCARD'])
.setCreditCardNumber('5555444433332222')
.setExpMonth(12)
.setExpYear(2030)
.setHolderName('gateway TESTE')
.setSecurityCode('999')
.getBillingAddress()
.setAddressType(AddressTypeEnum['BILLING'])
.setStreet('Rua da Quitanda')
.setNumber('199')
.setComplement('10º andar')
.setDistrict('Centro')
.setCity('Rio de Janeiro')
.setState('RJ')
.setZipCode('20091005')
.setCountry(CountryEnum['BRAZIL']);
// Options do credit card transaction
creditCardTransaction
.getOptions()
.setCurrencyIso(CurrencyIsoEnum['BRL'])
.setCaptureDelayInMinutes(0)
.setIataAmountInCents(0)
.setInterestRate(0)
.setPaymentMethodCode(PaymentMethodEnum['SIMULATOR'])
.setSoftDescriptorText('TESTE');
// Dados do comprador
request
.getBuyer()
.setName('Comprador Mundi')
.setPersonType(PersonTypeEnum['COMPANY'])
.setBuyerReference('123456')
.setBuyerCategory(BuyerCategoryEnum['PLUS'])
.setDocumentNumber('58828172000138')
.setDocumentType(DocumentTypeEnum['CNPJ'])
.setEmail('[email protected]')
.setEmailType(EmailTypeEnum['COMERCIAL'])
.setGender(GenderEnum['MALE'])
.setHomePhone('3003-0460')
.setMobilePhone('99999-8888')
.setWorkPhone('99999-7777')
.setBirthDate('11/05/1990')
.setFacebookId('1234567890')
.setTwitterId('1234567890')
.setCreateDateInMerchant(new Date())
.setLastBuyerUpdateInMerchant(new Date())
.addAddress()
.setAddressType(AddressTypeEnum['COMMERCIAL'])
.setStreet('Rua da Quitanda')
.setNumber('199')
.setComplement('10º andar')
.setDistrict('Centro')
.setCity('Rio de Janeiro')
.setState('RJ')
.setZipCode('20091005')
.setCountry(CountryEnum['BRAZIL']);
request
.getMerchant()
.setMerchantReference('gateway LOJA 1');
request
.getOptions()
.disableAntiFraud()
.setAntiFraudServiceCode('123')
.setCurrencyIso(CurrencyIsoEnum['BRL'])
.setRetries(3);
request
.getOrder()
.setOrderReference(uuid);
request
.getRequestData()
.setEcommerceCategory(EcommerceCategoryEnum['B2B'])
.setIpAddress('255.255.255.255')
.setOrigin('123')
.setSessionId(uuid);
// Carrinho de compras
let shoppingCart = request.addShoppingCart();
shoppingCart.setDeliveryDeadline(new Date());
shoppingCart.setEstimatedDeliveryDate(new Date());
shoppingCart.setFreightCostInCents(199);
shoppingCart.setShippingCompany('Correios');
shoppingCart
.getDeliveryAddress()
.setAddressType(AddressTypeEnum['SHIPPING'])
.setStreet('Rua da Quitanda')
.setNumber('199')
.setComplement('10º andar')
.setDistrict('Centro')
.setCity('Rio de Janeiro')
.setState('RJ')
.setZipCode('20091005')
.setCountry(CountryEnum['BRAZIL']);
shoppingCart
.addShoppingCartItem()
.setDescription('Apple iPhone 5s 16gb')
.setDiscountAmountInCents(160000)
.setItemReference('AI5S')
.setName('iPhone 5S')
.setQuantity(1)
.setUnitCostInCents(1800)
.setTotalCostInCents(1600);
shoppingCart
.addShoppingCartItem()
.setDescription('TESTE')
.setDiscountAmountInCents(0)
.setItemReference('TESTE')
.setName('TESTE')
.setQuantity(2)
.setUnitCostInCents(1099)
.setTotalCostInCents(2198);
//Cria um objeto ApiClient
// let client = new ApiClient;
// Faz a chamada para criação
// let response = client.createSale(request);
let response = api.createSale(request);
console.log('api response', response);