@infrab4a/connect 5.2.0-beta.4 → 5.3.1-beta.1
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 +2 -510
- package/index.esm.js +3 -508
- package/package.json +1 -1
- package/src/domain/shopping/enums/index.d.ts +0 -2
- package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +2 -10
- package/src/domain/shopping/models/checkout.d.ts +2 -0
- package/src/domain/shopping/models/payment-transaction.d.ts +2 -17
- package/src/domain/shopping/models/payment.d.ts +1 -2
- package/src/domain/shopping/types/card-info.type.d.ts +0 -1
- package/src/domain/shopping/types/index.d.ts +0 -1
- package/src/domain/shopping/types/pagarme-card.type.d.ts +3 -9
- package/src/domain/shopping/types/pagarme-credentials.type.d.ts +3 -9
- package/src/domain/users/models/user-payment-method.d.ts +0 -2
- package/src/infra/pagarme/adapters/helpers/index.d.ts +0 -2
- package/src/infra/pagarme/adapters/index.d.ts +3 -2
- package/src/infra/pagarme/adapters/{v4/pagarme-bank-slip-payment-axios.adapter.d.ts → pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/{v4/pagarme-card-payment-axios.adapter.d.ts → pagarme-card-payment-axios.adapter.d.ts} +6 -7
- package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/index.d.ts +0 -1
- package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +0 -24
- package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +0 -5
- package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +0 -4
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +0 -12
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +0 -10
- package/src/infra/pagarme/adapters/v4/index.d.ts +0 -3
- package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +0 -11
- package/src/infra/pagarme/adapters/v5/index.d.ts +0 -3
- package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +0 -11
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +0 -24
- package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +0 -10
- package/src/infra/pagarme/types/index.d.ts +0 -1
- package/src/infra/pagarme/types/v5/index.d.ts +0 -4
- package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +0 -19
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +0 -89
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +0 -126
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +0 -11
package/index.cjs.js
CHANGED
|
@@ -73,33 +73,6 @@ 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
|
-
|
|
103
76
|
exports.PaymentMethods = void 0;
|
|
104
77
|
(function (PaymentMethods) {
|
|
105
78
|
PaymentMethods["CARD"] = "card";
|
|
@@ -115,13 +88,6 @@ exports.PaymentProviders = void 0;
|
|
|
115
88
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
116
89
|
})(exports.PaymentProviders || (exports.PaymentProviders = {}));
|
|
117
90
|
|
|
118
|
-
exports.TransactionPaymentMethods = void 0;
|
|
119
|
-
(function (TransactionPaymentMethods) {
|
|
120
|
-
TransactionPaymentMethods["CARD"] = "credit_card";
|
|
121
|
-
TransactionPaymentMethods["BANKSLIP"] = "boleto";
|
|
122
|
-
TransactionPaymentMethods["PIX"] = "pix";
|
|
123
|
-
})(exports.TransactionPaymentMethods || (exports.TransactionPaymentMethods = {}));
|
|
124
|
-
|
|
125
91
|
class BasePaymentMethodFactory {
|
|
126
92
|
constructor(methods) {
|
|
127
93
|
this.methods = methods;
|
|
@@ -8620,201 +8586,6 @@ class PagarmePaymentOperationsHelper {
|
|
|
8620
8586
|
}
|
|
8621
8587
|
}
|
|
8622
8588
|
|
|
8623
|
-
class PagarMeV5RequestHelper {
|
|
8624
|
-
static build(checkout, method, card) {
|
|
8625
|
-
return {
|
|
8626
|
-
items: this.buildItems(checkout),
|
|
8627
|
-
customer: this.buildCustomer(checkout),
|
|
8628
|
-
shipping: this.buildShipping(checkout),
|
|
8629
|
-
payments: this.buildPayment(checkout, method, card),
|
|
8630
|
-
};
|
|
8631
|
-
}
|
|
8632
|
-
static buildItems(checkout) {
|
|
8633
|
-
return checkout.lineItems
|
|
8634
|
-
.filter((item) => !item.isGift)
|
|
8635
|
-
.map((item) => {
|
|
8636
|
-
return {
|
|
8637
|
-
amount: Math.floor(item.pricePaid * 100),
|
|
8638
|
-
description: item.name,
|
|
8639
|
-
quantity: item.quantity,
|
|
8640
|
-
code: item.EAN,
|
|
8641
|
-
};
|
|
8642
|
-
});
|
|
8643
|
-
}
|
|
8644
|
-
static buildCustomer(checkout) {
|
|
8645
|
-
return {
|
|
8646
|
-
name: checkout.user.displayName,
|
|
8647
|
-
email: checkout.user.email,
|
|
8648
|
-
type: 'individual',
|
|
8649
|
-
document: checkout.user.cpf,
|
|
8650
|
-
phones: {
|
|
8651
|
-
home_phone: {
|
|
8652
|
-
country_code: '55',
|
|
8653
|
-
number: checkout.user.phone.slice(2),
|
|
8654
|
-
area_code: checkout.user.phone.slice(0, 2),
|
|
8655
|
-
},
|
|
8656
|
-
mobile_phone: {
|
|
8657
|
-
country_code: '55',
|
|
8658
|
-
number: checkout.user.phone.slice(2),
|
|
8659
|
-
area_code: checkout.user.phone.slice(0, 2),
|
|
8660
|
-
},
|
|
8661
|
-
},
|
|
8662
|
-
address: {
|
|
8663
|
-
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8664
|
-
line_2: `${checkout.billingAddress.extension}`,
|
|
8665
|
-
zip_code: checkout.shippingAddress.zip,
|
|
8666
|
-
city: checkout.billingAddress.city,
|
|
8667
|
-
state: checkout.billingAddress.state,
|
|
8668
|
-
country: 'BR',
|
|
8669
|
-
},
|
|
8670
|
-
};
|
|
8671
|
-
}
|
|
8672
|
-
static buildShipping(checkout) {
|
|
8673
|
-
return {
|
|
8674
|
-
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
8675
|
-
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
8676
|
-
recipient_name: checkout.shippingAddress.recipient,
|
|
8677
|
-
recipient_phone: checkout.user.phone,
|
|
8678
|
-
address: {
|
|
8679
|
-
line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
8680
|
-
line_2: `${checkout.shippingAddress.extension}`,
|
|
8681
|
-
zip_code: checkout.shippingAddress.zip,
|
|
8682
|
-
city: checkout.shippingAddress.city,
|
|
8683
|
-
state: checkout.shippingAddress.state,
|
|
8684
|
-
country: 'BR',
|
|
8685
|
-
},
|
|
8686
|
-
};
|
|
8687
|
-
}
|
|
8688
|
-
static buildPayment(checkout, method, card) {
|
|
8689
|
-
return [
|
|
8690
|
-
{
|
|
8691
|
-
payment_method: method,
|
|
8692
|
-
amount: Math.floor(checkout.totalPrice * 100),
|
|
8693
|
-
...(method === 'pix' && {
|
|
8694
|
-
pix: this.getPixOrder(),
|
|
8695
|
-
}),
|
|
8696
|
-
...(method === 'boleto' && {
|
|
8697
|
-
boleto: this.getBoletoOrder(),
|
|
8698
|
-
}),
|
|
8699
|
-
...(method === 'credit_card' && {
|
|
8700
|
-
credit_card: this.getCardOrder(checkout, card),
|
|
8701
|
-
}),
|
|
8702
|
-
},
|
|
8703
|
-
];
|
|
8704
|
-
}
|
|
8705
|
-
static getPixOrder() {
|
|
8706
|
-
return {
|
|
8707
|
-
expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
|
|
8708
|
-
};
|
|
8709
|
-
}
|
|
8710
|
-
static getBoletoOrder() {
|
|
8711
|
-
return {
|
|
8712
|
-
due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
|
|
8713
|
-
instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
8714
|
-
type: 'DM',
|
|
8715
|
-
document_number: new Date().getTime().toString(),
|
|
8716
|
-
};
|
|
8717
|
-
}
|
|
8718
|
-
static getCardOrder(checkout, card) {
|
|
8719
|
-
return {
|
|
8720
|
-
installments: card.installments,
|
|
8721
|
-
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
|
|
8722
|
-
card_id: card.cardId,
|
|
8723
|
-
card: {
|
|
8724
|
-
cvv: card.cardCvv,
|
|
8725
|
-
billing_address: {
|
|
8726
|
-
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8727
|
-
zip_code: checkout.billingAddress.zip,
|
|
8728
|
-
city: checkout.billingAddress.city,
|
|
8729
|
-
state: checkout.billingAddress.state,
|
|
8730
|
-
country: 'BR',
|
|
8731
|
-
},
|
|
8732
|
-
},
|
|
8733
|
-
};
|
|
8734
|
-
}
|
|
8735
|
-
}
|
|
8736
|
-
|
|
8737
|
-
class PagarMeV5ResponseHelper {
|
|
8738
|
-
static build(method, checkout, response) {
|
|
8739
|
-
return Payment.toInstance({
|
|
8740
|
-
createdAt: new Date(),
|
|
8741
|
-
updatedAt: new Date(),
|
|
8742
|
-
userId: checkout.user.id,
|
|
8743
|
-
checkoutId: checkout.id,
|
|
8744
|
-
totalPrice: checkout.totalPrice,
|
|
8745
|
-
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8746
|
-
pagarMeOrderId: response.id,
|
|
8747
|
-
transaction: this.buildPaymentTransaction(method, response),
|
|
8748
|
-
});
|
|
8749
|
-
}
|
|
8750
|
-
static buildPaymentTransaction(method, response) {
|
|
8751
|
-
const charger = response.charges.at(0);
|
|
8752
|
-
const transaction = charger.last_transaction;
|
|
8753
|
-
return PaymentTransaction.toInstance({
|
|
8754
|
-
acquirer_name: 'pagar_me',
|
|
8755
|
-
amount: charger.amount,
|
|
8756
|
-
currency: charger.currency,
|
|
8757
|
-
gateway_id: charger.gateway_id,
|
|
8758
|
-
status: this.getPaymentStatus(transaction.status),
|
|
8759
|
-
payment_method: charger.payment_method,
|
|
8760
|
-
date_created: charger.created_at,
|
|
8761
|
-
date_updated: charger.updated_at,
|
|
8762
|
-
paid_amount: charger.paid_amount,
|
|
8763
|
-
paid_at: charger.paid_at,
|
|
8764
|
-
order_id: response.id,
|
|
8765
|
-
charger_id: charger.id,
|
|
8766
|
-
tid: charger.id,
|
|
8767
|
-
id: charger.id,
|
|
8768
|
-
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
|
|
8769
|
-
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
|
|
8770
|
-
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
|
|
8771
|
-
});
|
|
8772
|
-
}
|
|
8773
|
-
static getPaymentStatus(status) {
|
|
8774
|
-
if (status == exports.PagarMeV5PaymentStatus.Gerado)
|
|
8775
|
-
return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
|
|
8776
|
-
if (status == exports.PagarMeV5PaymentStatus.Capturada)
|
|
8777
|
-
return exports.PagarMeV5PaymentStatus.Pago;
|
|
8778
|
-
return status;
|
|
8779
|
-
}
|
|
8780
|
-
static getBoletoReponse(transaction) {
|
|
8781
|
-
return {
|
|
8782
|
-
boleto_url: transaction.url?.toString(),
|
|
8783
|
-
boleto_barcode: transaction.barcode?.toString(),
|
|
8784
|
-
boleto_qr_code: transaction.qr_code?.toString(),
|
|
8785
|
-
boleto_expiration_date: transaction.due_at?.toString(),
|
|
8786
|
-
boleto_instructions: transaction.instructions?.toString(),
|
|
8787
|
-
boleto_nosso_numero: transaction.nosso_numero?.toString(),
|
|
8788
|
-
boleto_type: transaction.type?.toString(),
|
|
8789
|
-
boleto_document_number: transaction.document_number?.toString(),
|
|
8790
|
-
};
|
|
8791
|
-
}
|
|
8792
|
-
static getPixReponse(transaction) {
|
|
8793
|
-
return {
|
|
8794
|
-
pix_qr_code: transaction.qr_code?.toString(),
|
|
8795
|
-
pix_qr_code_url: transaction.qr_code_url?.toString(),
|
|
8796
|
-
pix_expiration_date: transaction.expires_at?.toString(),
|
|
8797
|
-
};
|
|
8798
|
-
}
|
|
8799
|
-
static getCardReponse(transaction) {
|
|
8800
|
-
return {
|
|
8801
|
-
soft_descriptor: transaction.statement_descriptor?.toString(),
|
|
8802
|
-
acquirer_name: transaction.acquirer_name?.toString(),
|
|
8803
|
-
acquirer_id: transaction.acquirer_tid?.toString(),
|
|
8804
|
-
acquirer_nsu: transaction.acquirer_nsu?.toString(),
|
|
8805
|
-
acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
|
|
8806
|
-
acquirer_message: transaction.acquirer_message?.toString(),
|
|
8807
|
-
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
8808
|
-
installments: transaction.installments ?? null,
|
|
8809
|
-
card_holder_name: transaction.card?.holder_name?.toString(),
|
|
8810
|
-
card_last_digits: transaction.card?.last_four_digits?.toString(),
|
|
8811
|
-
card_first_digits: transaction.card?.first_six_digits?.toString(),
|
|
8812
|
-
card_brand: transaction.card?.brand?.toString(),
|
|
8813
|
-
card_id: transaction.card?.id?.toString(),
|
|
8814
|
-
};
|
|
8815
|
-
}
|
|
8816
|
-
}
|
|
8817
|
-
|
|
8818
8589
|
class PagarmeCardAxiosAdapter {
|
|
8819
8590
|
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
8820
8591
|
this.credentials = credentials;
|
|
@@ -8871,9 +8642,8 @@ class PagarmeCardAxiosAdapter {
|
|
|
8871
8642
|
});
|
|
8872
8643
|
}
|
|
8873
8644
|
}
|
|
8874
|
-
async createCardHash(bu
|
|
8875
|
-
const
|
|
8876
|
-
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
8645
|
+
async createCardHash(bu) {
|
|
8646
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
|
|
8877
8647
|
try {
|
|
8878
8648
|
const { data } = await axios__default["default"]({
|
|
8879
8649
|
method: 'GET',
|
|
@@ -9036,281 +8806,6 @@ class PagarmePixAxiosAdapter {
|
|
|
9036
8806
|
}
|
|
9037
8807
|
}
|
|
9038
8808
|
|
|
9039
|
-
class PagarmeV5BankSlipAxiosAdapter {
|
|
9040
|
-
constructor(credentials, paymentRepository) {
|
|
9041
|
-
this.credentials = credentials;
|
|
9042
|
-
this.paymentRepository = paymentRepository;
|
|
9043
|
-
}
|
|
9044
|
-
async pay(checkout) {
|
|
9045
|
-
try {
|
|
9046
|
-
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
9047
|
-
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
9048
|
-
const { data } = await axios__default["default"]({
|
|
9049
|
-
method: 'POST',
|
|
9050
|
-
url: `${this.credentials.URL}/orders`,
|
|
9051
|
-
headers: {
|
|
9052
|
-
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9053
|
-
'Content-Type': 'application/json',
|
|
9054
|
-
},
|
|
9055
|
-
data: payload,
|
|
9056
|
-
});
|
|
9057
|
-
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9058
|
-
if (data.status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9059
|
-
data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9060
|
-
(data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
|
|
9061
|
-
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
|
|
9062
|
-
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9063
|
-
checkoutId: checkout.id,
|
|
9064
|
-
userEmail: checkout.user.email,
|
|
9065
|
-
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9066
|
-
}));
|
|
9067
|
-
}
|
|
9068
|
-
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
9069
|
-
return payment;
|
|
9070
|
-
}
|
|
9071
|
-
catch (error) {
|
|
9072
|
-
if (error instanceof axios.AxiosError) {
|
|
9073
|
-
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
9074
|
-
}
|
|
9075
|
-
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9076
|
-
checkoutId: checkout.id,
|
|
9077
|
-
userEmail: checkout.user.email,
|
|
9078
|
-
info: error.response?.data,
|
|
9079
|
-
});
|
|
9080
|
-
}
|
|
9081
|
-
}
|
|
9082
|
-
async getBoletoTransaction(paymentId) {
|
|
9083
|
-
try {
|
|
9084
|
-
const { data } = await axios__default["default"]({
|
|
9085
|
-
method: 'GET',
|
|
9086
|
-
url: `${this.credentials.URL}/charges/${paymentId}`,
|
|
9087
|
-
headers: {
|
|
9088
|
-
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9089
|
-
'Content-Type': 'application/json',
|
|
9090
|
-
},
|
|
9091
|
-
});
|
|
9092
|
-
const payment = await this.paymentRepository.get({
|
|
9093
|
-
id: data.id,
|
|
9094
|
-
});
|
|
9095
|
-
return payment.transaction;
|
|
9096
|
-
}
|
|
9097
|
-
catch (error) {
|
|
9098
|
-
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
9099
|
-
paymentId,
|
|
9100
|
-
info: error.response.data,
|
|
9101
|
-
});
|
|
9102
|
-
}
|
|
9103
|
-
}
|
|
9104
|
-
}
|
|
9105
|
-
|
|
9106
|
-
class PagarmeV5CardAxiosAdapter {
|
|
9107
|
-
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
9108
|
-
this.credentials = credentials;
|
|
9109
|
-
this.paymentRepository = paymentRepository;
|
|
9110
|
-
this.orderBlockedRepository = orderBlockedRepository;
|
|
9111
|
-
}
|
|
9112
|
-
async pay(checkout, card) {
|
|
9113
|
-
try {
|
|
9114
|
-
const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
|
|
9115
|
-
console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
|
|
9116
|
-
const { data } = await axios__default["default"]({
|
|
9117
|
-
method: 'POST',
|
|
9118
|
-
url: `${this.credentials.URL}/orders`,
|
|
9119
|
-
headers: {
|
|
9120
|
-
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9121
|
-
'Content-Type': 'application/json',
|
|
9122
|
-
},
|
|
9123
|
-
data: payload,
|
|
9124
|
-
});
|
|
9125
|
-
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
9126
|
-
if (data.status == exports.PagarMeV5OrderStatus.Falha ||
|
|
9127
|
-
data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
|
|
9128
|
-
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
9129
|
-
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
9130
|
-
checkout,
|
|
9131
|
-
card,
|
|
9132
|
-
orderBlockedRepository: this.orderBlockedRepository,
|
|
9133
|
-
});
|
|
9134
|
-
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
|
|
9135
|
-
}
|
|
9136
|
-
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
9137
|
-
return payment;
|
|
9138
|
-
}
|
|
9139
|
-
catch (error) {
|
|
9140
|
-
if (error instanceof PaymentError) {
|
|
9141
|
-
throw error;
|
|
9142
|
-
}
|
|
9143
|
-
if (error instanceof axios.AxiosError) {
|
|
9144
|
-
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
9145
|
-
}
|
|
9146
|
-
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9147
|
-
}
|
|
9148
|
-
}
|
|
9149
|
-
async addCard(card, customer) {
|
|
9150
|
-
try {
|
|
9151
|
-
const { id } = await this.createOrUpdateCustomer(customer);
|
|
9152
|
-
const { data } = await axios__default["default"]({
|
|
9153
|
-
method: 'POST',
|
|
9154
|
-
url: `${this.credentials.URL}/customers/${id}/cards`,
|
|
9155
|
-
headers: {
|
|
9156
|
-
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9157
|
-
'Content-Type': 'application/json',
|
|
9158
|
-
},
|
|
9159
|
-
data: {
|
|
9160
|
-
number: card.number,
|
|
9161
|
-
holder_name: card.name,
|
|
9162
|
-
holder_document: card.cpf,
|
|
9163
|
-
exp_month: card.expirationDate.split('/').at(0),
|
|
9164
|
-
exp_year: card.expirationDate.split('/').at(1),
|
|
9165
|
-
cvv: card.cvv,
|
|
9166
|
-
billing_address: {
|
|
9167
|
-
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
9168
|
-
line_2: `${customer.billingAddress.extension}`,
|
|
9169
|
-
zip_code: customer.billingAddress.zip,
|
|
9170
|
-
city: customer.billingAddress.city,
|
|
9171
|
-
state: customer.billingAddress.state,
|
|
9172
|
-
country: 'BR',
|
|
9173
|
-
},
|
|
9174
|
-
},
|
|
9175
|
-
});
|
|
9176
|
-
return data;
|
|
9177
|
-
}
|
|
9178
|
-
catch (error) {
|
|
9179
|
-
console.warn(JSON.stringify(error));
|
|
9180
|
-
throw error;
|
|
9181
|
-
}
|
|
9182
|
-
}
|
|
9183
|
-
async createCardHash(bu, shop) {
|
|
9184
|
-
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
9185
|
-
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
9186
|
-
try {
|
|
9187
|
-
const { data } = await axios__default["default"]({
|
|
9188
|
-
method: 'GET',
|
|
9189
|
-
headers: {
|
|
9190
|
-
'content-type': 'application/json',
|
|
9191
|
-
},
|
|
9192
|
-
url: `${this.credentials.URL}/transactions/card_hash_key`,
|
|
9193
|
-
data: JSON.stringify({
|
|
9194
|
-
api_key: key,
|
|
9195
|
-
}),
|
|
9196
|
-
});
|
|
9197
|
-
return data;
|
|
9198
|
-
}
|
|
9199
|
-
catch (error) {
|
|
9200
|
-
throw new BusinessError('Houve uma falha gerar o hash', {
|
|
9201
|
-
info: error.response.data,
|
|
9202
|
-
});
|
|
9203
|
-
}
|
|
9204
|
-
}
|
|
9205
|
-
async getCardByToken(customerId, token) {
|
|
9206
|
-
try {
|
|
9207
|
-
const { data } = await axios__default["default"]({
|
|
9208
|
-
method: 'GET',
|
|
9209
|
-
url: `${this.credentials.URL}/cards/${token}`,
|
|
9210
|
-
data: {
|
|
9211
|
-
api_key: this.credentials.API_KEY,
|
|
9212
|
-
},
|
|
9213
|
-
});
|
|
9214
|
-
return data;
|
|
9215
|
-
}
|
|
9216
|
-
catch (error) {
|
|
9217
|
-
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
|
|
9218
|
-
info: error.response.data,
|
|
9219
|
-
});
|
|
9220
|
-
}
|
|
9221
|
-
}
|
|
9222
|
-
async createTransaction(info) {
|
|
9223
|
-
return info;
|
|
9224
|
-
}
|
|
9225
|
-
async createOrUpdateCustomer(customer) {
|
|
9226
|
-
try {
|
|
9227
|
-
const { data } = await axios__default["default"]({
|
|
9228
|
-
method: 'POST',
|
|
9229
|
-
url: `${this.credentials.URL}/customers`,
|
|
9230
|
-
headers: {
|
|
9231
|
-
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9232
|
-
'Content-Type': 'application/json',
|
|
9233
|
-
},
|
|
9234
|
-
data: {
|
|
9235
|
-
name: customer.displayName,
|
|
9236
|
-
email: customer.email,
|
|
9237
|
-
document: customer.cpf,
|
|
9238
|
-
type: 'individual',
|
|
9239
|
-
document_type: 'CPF',
|
|
9240
|
-
address: {
|
|
9241
|
-
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
9242
|
-
line_2: `${customer.billingAddress.extension}`,
|
|
9243
|
-
zip_code: customer.billingAddress.zip,
|
|
9244
|
-
city: customer.billingAddress.city,
|
|
9245
|
-
state: customer.billingAddress.state,
|
|
9246
|
-
country: 'BR',
|
|
9247
|
-
},
|
|
9248
|
-
birthdate: dateFns.format(new Date(customer.birthday), 'MM/dd/yyyy'),
|
|
9249
|
-
phones: {
|
|
9250
|
-
home_phone: {
|
|
9251
|
-
country_code: '55',
|
|
9252
|
-
number: customer.phone.slice(2),
|
|
9253
|
-
area_code: customer.phone.slice(0, 2),
|
|
9254
|
-
},
|
|
9255
|
-
mobile_phone: {
|
|
9256
|
-
country_code: '55',
|
|
9257
|
-
number: customer.phone.slice(2),
|
|
9258
|
-
area_code: customer.phone.slice(0, 2),
|
|
9259
|
-
},
|
|
9260
|
-
},
|
|
9261
|
-
},
|
|
9262
|
-
});
|
|
9263
|
-
return data;
|
|
9264
|
-
}
|
|
9265
|
-
catch (error) {
|
|
9266
|
-
console.warn(error);
|
|
9267
|
-
throw error;
|
|
9268
|
-
}
|
|
9269
|
-
}
|
|
9270
|
-
}
|
|
9271
|
-
|
|
9272
|
-
class PagarmeV5PixAxiosAdapter {
|
|
9273
|
-
constructor(credentials, paymentRepository) {
|
|
9274
|
-
this.credentials = credentials;
|
|
9275
|
-
this.paymentRepository = paymentRepository;
|
|
9276
|
-
}
|
|
9277
|
-
async pay(checkout) {
|
|
9278
|
-
try {
|
|
9279
|
-
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
9280
|
-
console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
|
|
9281
|
-
const { data } = await axios__default["default"]({
|
|
9282
|
-
method: 'POST',
|
|
9283
|
-
url: `${this.credentials.URL}/orders`,
|
|
9284
|
-
headers: {
|
|
9285
|
-
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9286
|
-
'Content-Type': 'application/json',
|
|
9287
|
-
},
|
|
9288
|
-
data: payload,
|
|
9289
|
-
});
|
|
9290
|
-
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
9291
|
-
if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
|
|
9292
|
-
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9293
|
-
checkoutId: checkout.id,
|
|
9294
|
-
userEmail: checkout.user.email,
|
|
9295
|
-
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9296
|
-
});
|
|
9297
|
-
}
|
|
9298
|
-
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
9299
|
-
return payment;
|
|
9300
|
-
}
|
|
9301
|
-
catch (error) {
|
|
9302
|
-
if (error instanceof axios.AxiosError) {
|
|
9303
|
-
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
9304
|
-
}
|
|
9305
|
-
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9306
|
-
checkoutId: checkout.id,
|
|
9307
|
-
userEmail: checkout.user.email,
|
|
9308
|
-
info: error.response?.data,
|
|
9309
|
-
});
|
|
9310
|
-
}
|
|
9311
|
-
}
|
|
9312
|
-
}
|
|
9313
|
-
|
|
9314
8809
|
class VertexAxiosAdapter {
|
|
9315
8810
|
constructor(config) {
|
|
9316
8811
|
this.config = config;
|
|
@@ -9667,9 +9162,6 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
|
|
|
9667
9162
|
exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
|
|
9668
9163
|
exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
|
|
9669
9164
|
exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
|
|
9670
|
-
exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
|
|
9671
|
-
exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
|
|
9672
|
-
exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
|
|
9673
9165
|
exports.Payment = Payment;
|
|
9674
9166
|
exports.PaymentError = PaymentError;
|
|
9675
9167
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|