@infrab4a/connect 5.1.2-alpha.0 → 5.2.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.
Files changed (34) hide show
  1. package/index.cjs.js +516 -2
  2. package/index.esm.js +514 -3
  3. package/package.json +1 -1
  4. package/src/domain/shopping/enums/index.d.ts +2 -0
  5. package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
  6. package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +5 -0
  7. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +10 -2
  8. package/src/domain/shopping/models/payment-transaction.d.ts +17 -2
  9. package/src/domain/shopping/models/payment.d.ts +2 -1
  10. package/src/domain/shopping/types/card-info.type.d.ts +1 -0
  11. package/src/domain/shopping/types/index.d.ts +1 -0
  12. package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
  13. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +9 -3
  14. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  15. package/src/infra/pagarme/adapters/helpers/index.d.ts +2 -0
  16. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +12 -0
  17. package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +10 -0
  18. package/src/infra/pagarme/adapters/index.d.ts +2 -3
  19. package/src/infra/pagarme/adapters/v4/index.d.ts +3 -0
  20. package/src/infra/pagarme/adapters/{pagarme-bank-slip-payment-axios.adapter.d.ts → v4/pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
  21. package/src/infra/pagarme/adapters/{pagarme-card-payment-axios.adapter.d.ts → v4/pagarme-card-payment-axios.adapter.d.ts} +7 -6
  22. package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +11 -0
  23. package/src/infra/pagarme/adapters/v5/index.d.ts +3 -0
  24. package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
  25. package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +24 -0
  26. package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +10 -0
  27. package/src/infra/pagarme/index.d.ts +1 -0
  28. package/src/infra/pagarme/types/index.d.ts +1 -0
  29. package/src/infra/pagarme/types/v5/index.d.ts +4 -0
  30. package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +19 -0
  31. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +89 -0
  32. package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +126 -0
  33. package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
  34. 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";
@@ -88,6 +115,13 @@ exports.PaymentProviders = void 0;
88
115
  PaymentProviders["GLAMPOINTS"] = "glampoints";
89
116
  })(exports.PaymentProviders || (exports.PaymentProviders = {}));
90
117
 
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
+
91
125
  class BasePaymentMethodFactory {
92
126
  constructor(methods) {
93
127
  this.methods = methods;
@@ -8586,6 +8620,201 @@ class PagarmePaymentOperationsHelper {
8586
8620
  }
8587
8621
  }
8588
8622
 
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' : "Men's 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
+
8589
8818
  class PagarmeCardAxiosAdapter {
8590
8819
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8591
8820
  this.credentials = credentials;
@@ -8642,8 +8871,9 @@ class PagarmeCardAxiosAdapter {
8642
8871
  });
8643
8872
  }
8644
8873
  }
8645
- async createCardHash(bu) {
8646
- const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8874
+ async createCardHash(bu, shop) {
8875
+ const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
8876
+ const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8647
8877
  try {
8648
8878
  const { data } = await axios__default["default"]({
8649
8879
  method: 'GET',
@@ -8806,6 +9036,287 @@ class PagarmePixAxiosAdapter {
8806
9036
  }
8807
9037
  }
8808
9038
 
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
+ console.error('Full error: ', JSON.stringify(error));
9073
+ if (error instanceof axios.AxiosError) {
9074
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9075
+ }
9076
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9077
+ checkoutId: checkout.id,
9078
+ userEmail: checkout.user.email,
9079
+ info: error.response?.data,
9080
+ });
9081
+ }
9082
+ }
9083
+ async getBoletoTransaction(paymentId) {
9084
+ try {
9085
+ const { data } = await axios__default["default"]({
9086
+ method: 'GET',
9087
+ url: `${this.credentials.URL}/charges/${paymentId}`,
9088
+ headers: {
9089
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9090
+ 'Content-Type': 'application/json',
9091
+ },
9092
+ });
9093
+ const payment = await this.paymentRepository.get({
9094
+ id: data.id,
9095
+ });
9096
+ return payment.transaction;
9097
+ }
9098
+ catch (error) {
9099
+ throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9100
+ paymentId,
9101
+ info: error.response.data,
9102
+ });
9103
+ }
9104
+ }
9105
+ }
9106
+
9107
+ class PagarmeV5CardAxiosAdapter {
9108
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
9109
+ this.credentials = credentials;
9110
+ this.paymentRepository = paymentRepository;
9111
+ this.orderBlockedRepository = orderBlockedRepository;
9112
+ }
9113
+ async pay(checkout, card) {
9114
+ try {
9115
+ const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9116
+ console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9117
+ const { data } = await axios__default["default"]({
9118
+ method: 'POST',
9119
+ url: `${this.credentials.URL}/orders`,
9120
+ headers: {
9121
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9122
+ 'Content-Type': 'application/json',
9123
+ },
9124
+ data: payload,
9125
+ });
9126
+ console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9127
+ if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9128
+ data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
9129
+ data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
9130
+ await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9131
+ checkout,
9132
+ card,
9133
+ orderBlockedRepository: this.orderBlockedRepository,
9134
+ });
9135
+ throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9136
+ }
9137
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9138
+ return payment;
9139
+ }
9140
+ catch (error) {
9141
+ if (error instanceof PaymentError) {
9142
+ throw error;
9143
+ }
9144
+ console.error('Full error: ', JSON.stringify(error));
9145
+ if (error instanceof axios.AxiosError) {
9146
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9147
+ }
9148
+ throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9149
+ }
9150
+ }
9151
+ async addCard(card, customer) {
9152
+ try {
9153
+ const { id } = await this.createOrUpdateCustomer(customer);
9154
+ const { data } = await axios__default["default"]({
9155
+ method: 'POST',
9156
+ url: `${this.credentials.URL}/customers/${id}/cards`,
9157
+ headers: {
9158
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9159
+ 'Content-Type': 'application/json',
9160
+ },
9161
+ data: {
9162
+ number: card.number,
9163
+ holder_name: card.name,
9164
+ holder_document: card.cpf,
9165
+ exp_month: card.expirationDate.split('/').at(0),
9166
+ exp_year: card.expirationDate.split('/').at(1),
9167
+ cvv: card.cvv,
9168
+ brand: card.flag,
9169
+ label: card.flag,
9170
+ billing_address: {
9171
+ line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9172
+ line_2: `${customer.billingAddress.extension}`,
9173
+ zip_code: customer.billingAddress.zip,
9174
+ city: customer.billingAddress.city,
9175
+ state: customer.billingAddress.state,
9176
+ country: 'BR',
9177
+ },
9178
+ },
9179
+ });
9180
+ return data;
9181
+ }
9182
+ catch (error) {
9183
+ console.warn(error);
9184
+ throw error;
9185
+ }
9186
+ }
9187
+ async createCardHash(bu, shop) {
9188
+ const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
9189
+ const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9190
+ try {
9191
+ const { data } = await axios__default["default"]({
9192
+ method: 'GET',
9193
+ headers: {
9194
+ 'content-type': 'application/json',
9195
+ },
9196
+ url: `${this.credentials.URL}/transactions/card_hash_key`,
9197
+ data: JSON.stringify({
9198
+ api_key: key,
9199
+ }),
9200
+ });
9201
+ return data;
9202
+ }
9203
+ catch (error) {
9204
+ throw new BusinessError('Houve uma falha gerar o hash', {
9205
+ info: error.response.data,
9206
+ });
9207
+ }
9208
+ }
9209
+ async getCardByToken(customerId, token) {
9210
+ try {
9211
+ const { data } = await axios__default["default"]({
9212
+ method: 'GET',
9213
+ url: `${this.credentials.URL}/cards/${token}`,
9214
+ data: {
9215
+ api_key: this.credentials.API_KEY,
9216
+ },
9217
+ });
9218
+ return data;
9219
+ }
9220
+ catch (error) {
9221
+ throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9222
+ info: error.response.data,
9223
+ });
9224
+ }
9225
+ }
9226
+ async createTransaction(info) {
9227
+ return info;
9228
+ }
9229
+ async createOrUpdateCustomer(customer) {
9230
+ try {
9231
+ const { data } = await axios__default["default"]({
9232
+ method: 'POST',
9233
+ url: `${this.credentials.URL}/customers`,
9234
+ headers: {
9235
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9236
+ 'Content-Type': 'application/json',
9237
+ },
9238
+ data: {
9239
+ name: customer.displayName,
9240
+ email: customer.email,
9241
+ document: customer.cpf,
9242
+ type: 'individual',
9243
+ document_type: 'CPF',
9244
+ address: {
9245
+ line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9246
+ line_2: `${customer.billingAddress.extension}`,
9247
+ zip_code: customer.billingAddress.zip,
9248
+ city: customer.billingAddress.city,
9249
+ state: customer.billingAddress.state,
9250
+ country: 'BR',
9251
+ },
9252
+ birthdate: dateFns.format(customer.birthday, 'MM/dd/yyyy'),
9253
+ phones: {
9254
+ home_phone: {
9255
+ country_code: '55',
9256
+ number: customer.phone.slice(2),
9257
+ area_code: customer.phone.slice(0, 2),
9258
+ },
9259
+ mobile_phone: {
9260
+ country_code: '55',
9261
+ number: customer.phone.slice(2),
9262
+ area_code: customer.phone.slice(0, 2),
9263
+ },
9264
+ },
9265
+ },
9266
+ });
9267
+ return data;
9268
+ }
9269
+ catch (error) {
9270
+ console.warn(error);
9271
+ throw error;
9272
+ }
9273
+ }
9274
+ }
9275
+
9276
+ class PagarmeV5PixAxiosAdapter {
9277
+ constructor(credentials, paymentRepository) {
9278
+ this.credentials = credentials;
9279
+ this.paymentRepository = paymentRepository;
9280
+ }
9281
+ async pay(checkout) {
9282
+ try {
9283
+ const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9284
+ console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9285
+ const { data } = await axios__default["default"]({
9286
+ method: 'POST',
9287
+ url: `${this.credentials.URL}/orders`,
9288
+ headers: {
9289
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9290
+ 'Content-Type': 'application/json',
9291
+ },
9292
+ data: payload,
9293
+ });
9294
+ console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9295
+ if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
9296
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9297
+ checkoutId: checkout.id,
9298
+ userEmail: checkout.user.email,
9299
+ info: data.charges.at(0).last_transaction?.gateway_response,
9300
+ });
9301
+ }
9302
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9303
+ return payment;
9304
+ }
9305
+ catch (error) {
9306
+ console.error('Full error: ', JSON.stringify(error));
9307
+ if (error instanceof axios.AxiosError) {
9308
+ console.error('Error: ', error.message);
9309
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9310
+ }
9311
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9312
+ checkoutId: checkout.id,
9313
+ userEmail: checkout.user.email,
9314
+ info: error.response?.data,
9315
+ });
9316
+ }
9317
+ }
9318
+ }
9319
+
8809
9320
  class VertexAxiosAdapter {
8810
9321
  constructor(config) {
8811
9322
  this.config = config;
@@ -9162,6 +9673,9 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
9162
9673
  exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
9163
9674
  exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
9164
9675
  exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
9676
+ exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
9677
+ exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
9678
+ exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
9165
9679
  exports.Payment = Payment;
9166
9680
  exports.PaymentError = PaymentError;
9167
9681
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;