@infrab4a/connect 5.0.0 → 5.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +447 -0
- package/index.esm.js +445 -1
- package/package.json +1 -1
- package/src/domain/shopping/enums/index.d.ts +1 -0
- package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
- package/src/domain/shopping/models/payment-transaction.d.ts +14 -0
- package/src/domain/shopping/models/payment.d.ts +1 -0
- package/src/domain/shopping/types/index.d.ts +1 -0
- package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
- package/src/infra/pagarme/adapters/helpers/index.d.ts +2 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +12 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +9 -0
- package/src/infra/pagarme/adapters/index.d.ts +2 -3
- package/src/infra/pagarme/adapters/v4/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/{pagarme-bank-slip-payment-axios.adapter.d.ts → v4/pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/{pagarme-card-payment-axios.adapter.d.ts → v4/pagarme-card-payment-axios.adapter.d.ts} +5 -5
- package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +16 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +10 -0
- package/src/infra/pagarme/index.d.ts +1 -0
- package/src/infra/pagarme/types/index.d.ts +1 -0
- package/src/infra/pagarme/types/v5/index.d.ts +3 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +85 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +126 -0
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
- package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +0 -11
package/index.cjs.js
CHANGED
|
@@ -73,6 +73,33 @@ exports.PagarmePaymentStatus = void 0;
|
|
|
73
73
|
PagarmePaymentStatus["Chargedback"] = "chargedback";
|
|
74
74
|
})(exports.PagarmePaymentStatus || (exports.PagarmePaymentStatus = {}));
|
|
75
75
|
|
|
76
|
+
exports.PagarMeV5PaymentStatus = void 0;
|
|
77
|
+
(function (PagarMeV5PaymentStatus) {
|
|
78
|
+
PagarMeV5PaymentStatus["Em processamento"] = "processing";
|
|
79
|
+
PagarMeV5PaymentStatus["Gerado"] = "generated";
|
|
80
|
+
PagarMeV5PaymentStatus["Visualizado"] = "viewed";
|
|
81
|
+
PagarMeV5PaymentStatus["Pago a menor"] = "underpaid";
|
|
82
|
+
PagarMeV5PaymentStatus["Pago a maior"] = "overpaid";
|
|
83
|
+
PagarMeV5PaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
84
|
+
PagarMeV5PaymentStatus["Pago"] = "paid";
|
|
85
|
+
PagarMeV5PaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
86
|
+
PagarMeV5PaymentStatus["Autorizada pendente de captura"] = "authorized_pending_capture";
|
|
87
|
+
PagarMeV5PaymentStatus["N\u00E3o autorizada"] = "not_authorized";
|
|
88
|
+
PagarMeV5PaymentStatus["Capturada"] = "captured";
|
|
89
|
+
PagarMeV5PaymentStatus["Aguardando captura"] = "waiting_capture";
|
|
90
|
+
PagarMeV5PaymentStatus["Com erro"] = "with_error";
|
|
91
|
+
PagarMeV5PaymentStatus["Estornado"] = "refunded";
|
|
92
|
+
PagarMeV5PaymentStatus["Cancelado"] = "voided";
|
|
93
|
+
PagarMeV5PaymentStatus["Falha"] = "failed";
|
|
94
|
+
})(exports.PagarMeV5PaymentStatus || (exports.PagarMeV5PaymentStatus = {}));
|
|
95
|
+
exports.PagarMeV5OrderStatus = void 0;
|
|
96
|
+
(function (PagarMeV5OrderStatus) {
|
|
97
|
+
PagarMeV5OrderStatus["Pendente"] = "pending";
|
|
98
|
+
PagarMeV5OrderStatus["Pago"] = "paid";
|
|
99
|
+
PagarMeV5OrderStatus["Cancelado"] = "canceled";
|
|
100
|
+
PagarMeV5OrderStatus["Falha"] = "failed";
|
|
101
|
+
})(exports.PagarMeV5OrderStatus || (exports.PagarMeV5OrderStatus = {}));
|
|
102
|
+
|
|
76
103
|
exports.PaymentMethods = void 0;
|
|
77
104
|
(function (PaymentMethods) {
|
|
78
105
|
PaymentMethods["CARD"] = "card";
|
|
@@ -8560,6 +8587,178 @@ class PagarmePaymentOperationsHelper {
|
|
|
8560
8587
|
}
|
|
8561
8588
|
}
|
|
8562
8589
|
|
|
8590
|
+
class PagarMeV5RequestHelper {
|
|
8591
|
+
static build(checkout, type, card) {
|
|
8592
|
+
return {
|
|
8593
|
+
items: this.buildItems(checkout),
|
|
8594
|
+
customer: this.buildCustomer(checkout),
|
|
8595
|
+
shipping: this.buildShipping(checkout),
|
|
8596
|
+
payments: this.buildPayment(checkout, type, card),
|
|
8597
|
+
};
|
|
8598
|
+
}
|
|
8599
|
+
static buildItems(checkout) {
|
|
8600
|
+
return checkout.lineItems.map((item) => {
|
|
8601
|
+
return {
|
|
8602
|
+
amount: Math.floor(item.pricePaid * 100),
|
|
8603
|
+
description: item.name,
|
|
8604
|
+
quantity: item.quantity,
|
|
8605
|
+
};
|
|
8606
|
+
});
|
|
8607
|
+
}
|
|
8608
|
+
static buildCustomer(checkout) {
|
|
8609
|
+
return {
|
|
8610
|
+
name: checkout.user.displayName,
|
|
8611
|
+
email: checkout.user.email,
|
|
8612
|
+
type: 'individual',
|
|
8613
|
+
document: checkout.user.cpf,
|
|
8614
|
+
phones: {
|
|
8615
|
+
mobile_phone: {
|
|
8616
|
+
country_code: '55',
|
|
8617
|
+
number: checkout.user.phone.slice(2),
|
|
8618
|
+
area_code: checkout.user.phone.slice(0, 1),
|
|
8619
|
+
},
|
|
8620
|
+
},
|
|
8621
|
+
address: {
|
|
8622
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8623
|
+
line_2: `${checkout.billingAddress.extension}`,
|
|
8624
|
+
zip_code: checkout.shippingAddress.zip,
|
|
8625
|
+
city: checkout.billingAddress.city,
|
|
8626
|
+
state: checkout.billingAddress.state,
|
|
8627
|
+
country: checkout.billingAddress.country,
|
|
8628
|
+
},
|
|
8629
|
+
};
|
|
8630
|
+
}
|
|
8631
|
+
static buildShipping(checkout) {
|
|
8632
|
+
return {
|
|
8633
|
+
amount: checkout.shipping.ShippingPrice,
|
|
8634
|
+
description: '',
|
|
8635
|
+
recipient_name: checkout.shippingAddress.recipient,
|
|
8636
|
+
recipient_phone: checkout.user.phone,
|
|
8637
|
+
address: {
|
|
8638
|
+
line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
8639
|
+
line_2: `${checkout.shippingAddress.extension}`,
|
|
8640
|
+
zip_code: checkout.shippingAddress.zip,
|
|
8641
|
+
city: checkout.shippingAddress.city,
|
|
8642
|
+
state: checkout.shippingAddress.state,
|
|
8643
|
+
country: checkout.shippingAddress.country,
|
|
8644
|
+
},
|
|
8645
|
+
};
|
|
8646
|
+
}
|
|
8647
|
+
static buildPayment(checkout, type, card) {
|
|
8648
|
+
return [
|
|
8649
|
+
{
|
|
8650
|
+
payment_method: type,
|
|
8651
|
+
amount: Math.floor(checkout.totalPrice * 100),
|
|
8652
|
+
...(type === 'pix' && {
|
|
8653
|
+
pix: this.getPixOrder(),
|
|
8654
|
+
}),
|
|
8655
|
+
...(type === 'boleto' && {
|
|
8656
|
+
boleto: this.getBoletoOrder(),
|
|
8657
|
+
}),
|
|
8658
|
+
...(type === 'credit_card' && {
|
|
8659
|
+
credit_card: this.getCardOrder(checkout, card),
|
|
8660
|
+
}),
|
|
8661
|
+
},
|
|
8662
|
+
];
|
|
8663
|
+
}
|
|
8664
|
+
static getPixOrder() {
|
|
8665
|
+
return {
|
|
8666
|
+
expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
|
|
8667
|
+
};
|
|
8668
|
+
}
|
|
8669
|
+
static getBoletoOrder() {
|
|
8670
|
+
return {
|
|
8671
|
+
due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
|
|
8672
|
+
instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
8673
|
+
type: 'DM',
|
|
8674
|
+
document_number: new Date().getTime().toString(),
|
|
8675
|
+
};
|
|
8676
|
+
}
|
|
8677
|
+
static getCardOrder(checkout, card) {
|
|
8678
|
+
return {
|
|
8679
|
+
installments: card.installments,
|
|
8680
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
|
|
8681
|
+
card_id: card.cardId,
|
|
8682
|
+
card: {
|
|
8683
|
+
cvv: card.cardCvv,
|
|
8684
|
+
},
|
|
8685
|
+
};
|
|
8686
|
+
}
|
|
8687
|
+
}
|
|
8688
|
+
|
|
8689
|
+
class PagarMeV5ResponseHelper {
|
|
8690
|
+
static build(checkout, response) {
|
|
8691
|
+
return Payment.toInstance({
|
|
8692
|
+
createdAt: new Date(),
|
|
8693
|
+
updatedAt: new Date(),
|
|
8694
|
+
userId: checkout.user.id,
|
|
8695
|
+
checkoutId: checkout.id,
|
|
8696
|
+
totalPrice: checkout.totalPrice,
|
|
8697
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8698
|
+
pagarMeOrderId: response.id,
|
|
8699
|
+
transaction: this.buildPaymentTransaction(response),
|
|
8700
|
+
});
|
|
8701
|
+
}
|
|
8702
|
+
static buildPaymentTransaction(response) {
|
|
8703
|
+
const charger = response.charges.at(0);
|
|
8704
|
+
const transaction = charger.last_transaction;
|
|
8705
|
+
return PaymentTransaction.toInstance({
|
|
8706
|
+
acquirer_name: 'pagar_me',
|
|
8707
|
+
amount: charger.amount,
|
|
8708
|
+
currency: charger.currency,
|
|
8709
|
+
gateway_id: charger.gateway_id,
|
|
8710
|
+
status: charger.status,
|
|
8711
|
+
payment_method: charger.payment_method,
|
|
8712
|
+
date_created: charger.created_at,
|
|
8713
|
+
date_updated: charger.updated_at,
|
|
8714
|
+
paid_amount: charger.paid_amount,
|
|
8715
|
+
paid_at: charger.paid_at,
|
|
8716
|
+
order_id: response.id,
|
|
8717
|
+
tid: +transaction.id,
|
|
8718
|
+
id: +transaction.id,
|
|
8719
|
+
...this.getBoletoReponse(transaction),
|
|
8720
|
+
...this.getPixReponse(transaction),
|
|
8721
|
+
...this.getCardReponse(transaction),
|
|
8722
|
+
});
|
|
8723
|
+
}
|
|
8724
|
+
static getBoletoReponse(transaction) {
|
|
8725
|
+
return {
|
|
8726
|
+
boleto_url: transaction.url?.toString(),
|
|
8727
|
+
boleto_barcode: transaction.barcode?.toString(),
|
|
8728
|
+
boleto_qr_code: transaction.qr_code?.toString(),
|
|
8729
|
+
boleto_expiration_date: transaction.due_at?.toString(),
|
|
8730
|
+
boleto_instructions: transaction.instructions?.toString(),
|
|
8731
|
+
boleto_nosso_numero: transaction.nosso_numero?.toString(),
|
|
8732
|
+
boleto_type: transaction.type?.toString(),
|
|
8733
|
+
boleto_document_number: transaction.document_number?.toString(),
|
|
8734
|
+
};
|
|
8735
|
+
}
|
|
8736
|
+
static getPixReponse(transaction) {
|
|
8737
|
+
return {
|
|
8738
|
+
pix_qr_code: transaction.qr_code?.toString(),
|
|
8739
|
+
pix_qr_code_url: transaction.qr_code_url?.toString(),
|
|
8740
|
+
pix_expiration_date: transaction.expires_at?.toString(),
|
|
8741
|
+
};
|
|
8742
|
+
}
|
|
8743
|
+
static getCardReponse(transaction) {
|
|
8744
|
+
return {
|
|
8745
|
+
soft_descriptor: transaction.statement_descriptor?.toString(),
|
|
8746
|
+
acquirer_name: transaction.acquirer_name?.toString(),
|
|
8747
|
+
acquirer_id: transaction.acquirer_tid?.toString(),
|
|
8748
|
+
acquirer_nsu: transaction.acquirer_nsu?.toString(),
|
|
8749
|
+
acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
|
|
8750
|
+
acquirer_message: transaction.acquirer_message?.toString(),
|
|
8751
|
+
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
8752
|
+
installments: transaction.installments ?? null,
|
|
8753
|
+
card_holder_name: transaction.card.holder_name?.toString(),
|
|
8754
|
+
card_last_digits: transaction.card.last_four_digits?.toString(),
|
|
8755
|
+
card_first_digits: transaction.card.first_six_digits?.toString(),
|
|
8756
|
+
card_brand: transaction.card.brand?.toString(),
|
|
8757
|
+
card_id: transaction.card.id?.toString(),
|
|
8758
|
+
};
|
|
8759
|
+
}
|
|
8760
|
+
}
|
|
8761
|
+
|
|
8563
8762
|
class PagarmeCardAxiosAdapter {
|
|
8564
8763
|
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
8565
8764
|
this.credentials = credentials;
|
|
@@ -8780,6 +8979,251 @@ class PagarmePixAxiosAdapter {
|
|
|
8780
8979
|
}
|
|
8781
8980
|
}
|
|
8782
8981
|
|
|
8982
|
+
/* eslint-disable no-console */
|
|
8983
|
+
class PagarmeV5BankSlipAxiosAdapter {
|
|
8984
|
+
constructor(credentials, paymentRepository) {
|
|
8985
|
+
this.credentials = credentials;
|
|
8986
|
+
this.paymentRepository = paymentRepository;
|
|
8987
|
+
}
|
|
8988
|
+
async pay(checkout) {
|
|
8989
|
+
try {
|
|
8990
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
8991
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
8992
|
+
const { data } = await axios__default["default"]({
|
|
8993
|
+
method: 'POST',
|
|
8994
|
+
url: `${this.credentials.URL}/orders`,
|
|
8995
|
+
headers: {
|
|
8996
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
8997
|
+
'Content-Type': 'application/json',
|
|
8998
|
+
},
|
|
8999
|
+
data: payload,
|
|
9000
|
+
});
|
|
9001
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9002
|
+
if (data.charges.at(0).status !== exports.PagarMeV5OrderStatus['Em processamento'] ||
|
|
9003
|
+
data.charges.at(0).status !== exports.PagarMeV5PaymentStatus['Falha']) {
|
|
9004
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9005
|
+
checkoutId: checkout.id,
|
|
9006
|
+
userEmail: checkout.user.email,
|
|
9007
|
+
info: data,
|
|
9008
|
+
}));
|
|
9009
|
+
}
|
|
9010
|
+
const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
|
|
9011
|
+
const payment = await this.paymentRepository.create(paymentData);
|
|
9012
|
+
return payment;
|
|
9013
|
+
}
|
|
9014
|
+
catch (error) {
|
|
9015
|
+
console.log(error.response?.data?.errors);
|
|
9016
|
+
console.log(error.response?.data?.request);
|
|
9017
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9018
|
+
checkoutId: checkout.id,
|
|
9019
|
+
userEmail: checkout.user.email,
|
|
9020
|
+
info: error.response.data,
|
|
9021
|
+
});
|
|
9022
|
+
}
|
|
9023
|
+
}
|
|
9024
|
+
async getBoletoTransaction(paymentId) {
|
|
9025
|
+
try {
|
|
9026
|
+
const { data } = await axios__default["default"]({
|
|
9027
|
+
method: 'GET',
|
|
9028
|
+
url: `${this.credentials.URL}/charges/${paymentId}`,
|
|
9029
|
+
headers: {
|
|
9030
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9031
|
+
'Content-Type': 'application/json',
|
|
9032
|
+
},
|
|
9033
|
+
});
|
|
9034
|
+
const payment = await this.paymentRepository.get({
|
|
9035
|
+
id: +data.id,
|
|
9036
|
+
});
|
|
9037
|
+
return payment.transaction;
|
|
9038
|
+
}
|
|
9039
|
+
catch (error) {
|
|
9040
|
+
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
9041
|
+
paymentId,
|
|
9042
|
+
info: error.response.data,
|
|
9043
|
+
});
|
|
9044
|
+
}
|
|
9045
|
+
}
|
|
9046
|
+
}
|
|
9047
|
+
|
|
9048
|
+
class PagarmeV5CardAxiosAdapter {
|
|
9049
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
9050
|
+
this.credentials = credentials;
|
|
9051
|
+
this.paymentRepository = paymentRepository;
|
|
9052
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
9053
|
+
}
|
|
9054
|
+
async pay(checkout, card) {
|
|
9055
|
+
try {
|
|
9056
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
|
|
9057
|
+
console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
|
|
9058
|
+
const { data } = await axios__default["default"]({
|
|
9059
|
+
method: 'POST',
|
|
9060
|
+
url: `${this.credentials.URL}/orders`,
|
|
9061
|
+
headers: {
|
|
9062
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9063
|
+
'Content-Type': 'application/json',
|
|
9064
|
+
},
|
|
9065
|
+
data: payload,
|
|
9066
|
+
});
|
|
9067
|
+
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
9068
|
+
if (data.charges.at(0).status !== exports.PagarMeV5PaymentStatus.Pago ||
|
|
9069
|
+
data.charges.at(0).status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
9070
|
+
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
9071
|
+
checkout,
|
|
9072
|
+
card,
|
|
9073
|
+
orderBlockedRepository: this.orderBlockedRepository,
|
|
9074
|
+
});
|
|
9075
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
|
|
9076
|
+
}
|
|
9077
|
+
const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
|
|
9078
|
+
const payment = await this.paymentRepository.create(paymentData);
|
|
9079
|
+
return payment;
|
|
9080
|
+
}
|
|
9081
|
+
catch (error) {
|
|
9082
|
+
if (error instanceof PaymentError) {
|
|
9083
|
+
throw error;
|
|
9084
|
+
}
|
|
9085
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9086
|
+
}
|
|
9087
|
+
}
|
|
9088
|
+
// Dúvidas: preciso criar um cliente? como faz na mens?
|
|
9089
|
+
async addCard(card) {
|
|
9090
|
+
try {
|
|
9091
|
+
const { data } = await axios__default["default"]({
|
|
9092
|
+
method: 'POST',
|
|
9093
|
+
url: `${this.credentials.URL}/cards`,
|
|
9094
|
+
data: {
|
|
9095
|
+
api_key: this.credentials.API_KEY,
|
|
9096
|
+
card_number: card.number,
|
|
9097
|
+
card_expiration_date: card.expirationDate.replace('/', ''),
|
|
9098
|
+
card_holder_name: card.name,
|
|
9099
|
+
card_cvv: card.cvv,
|
|
9100
|
+
// number: '4000000000000010',
|
|
9101
|
+
// holder_name: 'Tony Stark',
|
|
9102
|
+
// holder_document: '93095135270',
|
|
9103
|
+
// exp_month: 1,
|
|
9104
|
+
// exp_year: 30,
|
|
9105
|
+
// cvv: '351',
|
|
9106
|
+
// brand: 'Mastercard',
|
|
9107
|
+
// label: 'Sua bandeira',
|
|
9108
|
+
// billing_address: {
|
|
9109
|
+
// line_1: '375, Av. General Osorio, Centro',
|
|
9110
|
+
// line_2: '7º Andar',
|
|
9111
|
+
// zip_code: '220000111',
|
|
9112
|
+
// city: 'Rio de Janeiro',
|
|
9113
|
+
// state: 'RJ',
|
|
9114
|
+
// country: 'BR',
|
|
9115
|
+
// },
|
|
9116
|
+
// options: {
|
|
9117
|
+
// verify_card: true,
|
|
9118
|
+
// },
|
|
9119
|
+
},
|
|
9120
|
+
});
|
|
9121
|
+
return data;
|
|
9122
|
+
}
|
|
9123
|
+
catch (error) {
|
|
9124
|
+
throw new BusinessError('Houve uma falha adicionar o cartão', {
|
|
9125
|
+
info: error.response.data,
|
|
9126
|
+
});
|
|
9127
|
+
}
|
|
9128
|
+
}
|
|
9129
|
+
async createCardHash(bu) {
|
|
9130
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
|
|
9131
|
+
try {
|
|
9132
|
+
const { data } = await axios__default["default"]({
|
|
9133
|
+
method: 'GET',
|
|
9134
|
+
headers: {
|
|
9135
|
+
'content-type': 'application/json',
|
|
9136
|
+
},
|
|
9137
|
+
url: `${this.credentials.URL}/transactions/card_hash_key`,
|
|
9138
|
+
data: JSON.stringify({
|
|
9139
|
+
api_key: key,
|
|
9140
|
+
}),
|
|
9141
|
+
});
|
|
9142
|
+
return data;
|
|
9143
|
+
}
|
|
9144
|
+
catch (error) {
|
|
9145
|
+
throw new BusinessError('Houve uma falha gerar o hash', {
|
|
9146
|
+
info: error.response.data,
|
|
9147
|
+
});
|
|
9148
|
+
}
|
|
9149
|
+
}
|
|
9150
|
+
async getCardByToken(id) {
|
|
9151
|
+
try {
|
|
9152
|
+
const { data } = await axios__default["default"]({
|
|
9153
|
+
method: 'POST',
|
|
9154
|
+
url: `${this.credentials.URL}/cards/${id}`,
|
|
9155
|
+
data: {
|
|
9156
|
+
api_key: this.credentials.API_KEY,
|
|
9157
|
+
},
|
|
9158
|
+
});
|
|
9159
|
+
return data;
|
|
9160
|
+
}
|
|
9161
|
+
catch (error) {
|
|
9162
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
|
|
9163
|
+
info: error.response.data,
|
|
9164
|
+
});
|
|
9165
|
+
}
|
|
9166
|
+
}
|
|
9167
|
+
async createTransaction(info) {
|
|
9168
|
+
try {
|
|
9169
|
+
const { data } = await axios__default["default"]({
|
|
9170
|
+
method: 'POST',
|
|
9171
|
+
url: `${this.credentials.URL}/transactions`,
|
|
9172
|
+
headers: {
|
|
9173
|
+
Authorization: 'Basic ' + Buffer.from(this.credentials.API_KEY).toString('base64'),
|
|
9174
|
+
'Content-Type': 'application/json',
|
|
9175
|
+
},
|
|
9176
|
+
data: {
|
|
9177
|
+
...info,
|
|
9178
|
+
api_key: this.credentials.API_KEY,
|
|
9179
|
+
},
|
|
9180
|
+
});
|
|
9181
|
+
return data;
|
|
9182
|
+
}
|
|
9183
|
+
catch (error) {
|
|
9184
|
+
throw new BusinessError('Houve uma falha ao criar a transação', {
|
|
9185
|
+
info: error.response.data,
|
|
9186
|
+
});
|
|
9187
|
+
}
|
|
9188
|
+
}
|
|
9189
|
+
}
|
|
9190
|
+
|
|
9191
|
+
/* eslint-disable no-console */
|
|
9192
|
+
class PagarmeV5PixAxiosAdapter {
|
|
9193
|
+
constructor(credentials, paymentRepository) {
|
|
9194
|
+
this.credentials = credentials;
|
|
9195
|
+
this.paymentRepository = paymentRepository;
|
|
9196
|
+
}
|
|
9197
|
+
async pay(checkout) {
|
|
9198
|
+
try {
|
|
9199
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
9200
|
+
console.warn('[PAGARME PIX DATA TO SEND]', payload);
|
|
9201
|
+
const { data } = await axios__default["default"]({
|
|
9202
|
+
method: 'POST',
|
|
9203
|
+
url: `${this.credentials.URL}/orders`,
|
|
9204
|
+
headers: {
|
|
9205
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9206
|
+
'Content-Type': 'application/json',
|
|
9207
|
+
},
|
|
9208
|
+
data: payload,
|
|
9209
|
+
});
|
|
9210
|
+
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
9211
|
+
const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
|
|
9212
|
+
const payment = await this.paymentRepository.create(paymentData);
|
|
9213
|
+
return payment;
|
|
9214
|
+
}
|
|
9215
|
+
catch (error) {
|
|
9216
|
+
console.log(error.response?.data?.errors);
|
|
9217
|
+
console.log(error.response?.data?.request);
|
|
9218
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9219
|
+
checkoutId: checkout.id,
|
|
9220
|
+
userEmail: checkout.user.email,
|
|
9221
|
+
info: error.response?.data,
|
|
9222
|
+
});
|
|
9223
|
+
}
|
|
9224
|
+
}
|
|
9225
|
+
}
|
|
9226
|
+
|
|
8783
9227
|
class VertexAxiosAdapter {
|
|
8784
9228
|
constructor(config) {
|
|
8785
9229
|
this.config = config;
|
|
@@ -9136,6 +9580,9 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
|
|
|
9136
9580
|
exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
|
|
9137
9581
|
exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
|
|
9138
9582
|
exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
|
|
9583
|
+
exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
|
|
9584
|
+
exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
|
|
9585
|
+
exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
|
|
9139
9586
|
exports.Payment = Payment;
|
|
9140
9587
|
exports.PaymentError = PaymentError;
|
|
9141
9588
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|