@infrab4a/connect 5.1.0-beta.9 → 5.1.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.
Files changed (31) hide show
  1. package/index.cjs.js +12 -529
  2. package/index.esm.js +13 -527
  3. package/package.json +1 -1
  4. package/src/domain/shopping/enums/index.d.ts +0 -2
  5. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +1 -3
  6. package/src/domain/shopping/models/payment-transaction.d.ts +2 -17
  7. package/src/domain/shopping/models/payment.d.ts +1 -2
  8. package/src/domain/shopping/types/index.d.ts +0 -1
  9. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +3 -9
  10. package/src/infra/pagarme/adapters/helpers/index.d.ts +0 -2
  11. package/src/infra/pagarme/adapters/index.d.ts +3 -2
  12. package/src/infra/pagarme/adapters/{v4/pagarme-bank-slip-payment-axios.adapter.d.ts → pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
  13. package/src/infra/pagarme/adapters/{v4/pagarme-card-payment-axios.adapter.d.ts → pagarme-card-payment-axios.adapter.d.ts} +6 -7
  14. package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +11 -0
  15. package/src/infra/pagarme/index.d.ts +0 -1
  16. package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +0 -24
  17. package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +0 -5
  18. package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +0 -4
  19. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +0 -12
  20. package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +0 -9
  21. package/src/infra/pagarme/adapters/v4/index.d.ts +0 -3
  22. package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +0 -11
  23. package/src/infra/pagarme/adapters/v5/index.d.ts +0 -3
  24. package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +0 -12
  25. package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +0 -18
  26. package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +0 -11
  27. package/src/infra/pagarme/types/index.d.ts +0 -1
  28. package/src/infra/pagarme/types/v5/index.d.ts +0 -3
  29. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +0 -86
  30. package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +0 -126
  31. 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;
@@ -7657,6 +7623,16 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7657
7623
  return reviews;
7658
7624
  }
7659
7625
  async findCatalog(params, mainGender, options) {
7626
+ // eslint-disable-next-line no-console
7627
+ console.log('findCatalog', JSON.stringify({
7628
+ ...params,
7629
+ filters: { ...params.filters, published: true },
7630
+ orderBy: {
7631
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7632
+ ...lodash.omit(params.orderBy, ['hasStock', 'intGender']),
7633
+ hasStock: 'desc',
7634
+ },
7635
+ }));
7660
7636
  const result = await this.find({
7661
7637
  ...params,
7662
7638
  filters: { ...params.filters, published: true },
@@ -8594,187 +8570,6 @@ class PagarmePaymentOperationsHelper {
8594
8570
  }
8595
8571
  }
8596
8572
 
8597
- class PagarMeV5RequestHelper {
8598
- static build(checkout, method, card) {
8599
- return {
8600
- items: this.buildItems(checkout),
8601
- customer: this.buildCustomer(checkout),
8602
- shipping: this.buildShipping(checkout),
8603
- payments: this.buildPayment(checkout, method, card),
8604
- };
8605
- }
8606
- static buildItems(checkout) {
8607
- return checkout.lineItems
8608
- .filter((item) => !item.isGift)
8609
- .map((item) => {
8610
- return {
8611
- amount: Math.floor(item.pricePaid * 100),
8612
- description: item.name,
8613
- quantity: item.quantity,
8614
- code: item.EAN,
8615
- };
8616
- });
8617
- }
8618
- static buildCustomer(checkout) {
8619
- return {
8620
- name: checkout.user.displayName,
8621
- email: checkout.user.email,
8622
- type: 'individual',
8623
- document: checkout.user.cpf,
8624
- phones: {
8625
- home_phone: {
8626
- country_code: '55',
8627
- number: checkout.user.phone.slice(2),
8628
- area_code: checkout.user.phone.slice(0, 2),
8629
- },
8630
- mobile_phone: {
8631
- country_code: '55',
8632
- number: checkout.user.phone.slice(2),
8633
- area_code: checkout.user.phone.slice(0, 2),
8634
- },
8635
- },
8636
- address: {
8637
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8638
- line_2: `${checkout.billingAddress.extension}`,
8639
- zip_code: checkout.shippingAddress.zip,
8640
- city: checkout.billingAddress.city,
8641
- state: checkout.billingAddress.state,
8642
- country: 'BR',
8643
- },
8644
- };
8645
- }
8646
- static buildShipping(checkout) {
8647
- return {
8648
- amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8649
- description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8650
- recipient_name: checkout.shippingAddress.recipient,
8651
- recipient_phone: checkout.user.phone,
8652
- address: {
8653
- line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8654
- line_2: `${checkout.shippingAddress.extension}`,
8655
- zip_code: checkout.shippingAddress.zip,
8656
- city: checkout.shippingAddress.city,
8657
- state: checkout.shippingAddress.state,
8658
- country: 'BR',
8659
- },
8660
- };
8661
- }
8662
- static buildPayment(checkout, method, card) {
8663
- return [
8664
- {
8665
- payment_method: method,
8666
- amount: Math.floor(checkout.totalPrice * 100),
8667
- ...(method === 'pix' && {
8668
- pix: this.getPixOrder(),
8669
- }),
8670
- ...(method === 'boleto' && {
8671
- boleto: this.getBoletoOrder(),
8672
- }),
8673
- ...(method === 'credit_card' && {
8674
- credit_card: this.getCardOrder(checkout, card),
8675
- }),
8676
- },
8677
- ];
8678
- }
8679
- static getPixOrder() {
8680
- return {
8681
- expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
8682
- };
8683
- }
8684
- static getBoletoOrder() {
8685
- return {
8686
- due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
8687
- instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
8688
- type: 'DM',
8689
- document_number: new Date().getTime().toString(),
8690
- };
8691
- }
8692
- static getCardOrder(checkout, card) {
8693
- return {
8694
- installments: card.installments,
8695
- statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
8696
- card_id: card.cardId,
8697
- card: {
8698
- cvv: card.cardCvv,
8699
- },
8700
- };
8701
- }
8702
- }
8703
-
8704
- class PagarMeV5ResponseHelper {
8705
- static build(method, checkout, response) {
8706
- return Payment.toInstance({
8707
- createdAt: new Date(),
8708
- updatedAt: new Date(),
8709
- userId: checkout.user.id,
8710
- checkoutId: checkout.id,
8711
- totalPrice: checkout.totalPrice,
8712
- paymentProvider: exports.PaymentProviders.PAGARME,
8713
- pagarMeOrderId: response.id,
8714
- transaction: this.buildPaymentTransaction(method, response),
8715
- });
8716
- }
8717
- static buildPaymentTransaction(method, response) {
8718
- const charger = response.charges.at(0);
8719
- const transaction = charger.last_transaction;
8720
- return PaymentTransaction.toInstance({
8721
- acquirer_name: 'pagar_me',
8722
- amount: charger.amount,
8723
- currency: charger.currency,
8724
- gateway_id: charger.gateway_id,
8725
- status: charger.status,
8726
- payment_method: charger.payment_method,
8727
- date_created: charger.created_at,
8728
- date_updated: charger.updated_at,
8729
- paid_amount: charger.paid_amount,
8730
- paid_at: charger.paid_at,
8731
- order_id: response.id,
8732
- charger_id: charger.id,
8733
- tid: charger.id,
8734
- id: charger.id,
8735
- ...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8736
- ...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8737
- ...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8738
- });
8739
- }
8740
- static getBoletoReponse(transaction) {
8741
- return {
8742
- boleto_url: transaction.url?.toString(),
8743
- boleto_barcode: transaction.barcode?.toString(),
8744
- boleto_qr_code: transaction.qr_code?.toString(),
8745
- boleto_expiration_date: transaction.due_at?.toString(),
8746
- boleto_instructions: transaction.instructions?.toString(),
8747
- boleto_nosso_numero: transaction.nosso_numero?.toString(),
8748
- boleto_type: transaction.type?.toString(),
8749
- boleto_document_number: transaction.document_number?.toString(),
8750
- };
8751
- }
8752
- static getPixReponse(transaction) {
8753
- return {
8754
- pix_qr_code: transaction.qr_code?.toString(),
8755
- pix_qr_code_url: transaction.qr_code_url?.toString(),
8756
- pix_expiration_date: transaction.expires_at?.toString(),
8757
- };
8758
- }
8759
- static getCardReponse(transaction) {
8760
- return {
8761
- soft_descriptor: transaction.statement_descriptor?.toString(),
8762
- acquirer_name: transaction.acquirer_name?.toString(),
8763
- acquirer_id: transaction.acquirer_tid?.toString(),
8764
- acquirer_nsu: transaction.acquirer_nsu?.toString(),
8765
- acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8766
- acquirer_message: transaction.acquirer_message?.toString(),
8767
- acquirer_return_code: transaction.acquirer_return_code?.toString(),
8768
- installments: transaction.installments ?? null,
8769
- card_holder_name: transaction.card?.holder_name?.toString(),
8770
- card_last_digits: transaction.card?.last_four_digits?.toString(),
8771
- card_first_digits: transaction.card?.first_six_digits?.toString(),
8772
- card_brand: transaction.card?.brand?.toString(),
8773
- card_id: transaction.card?.id?.toString(),
8774
- };
8775
- }
8776
- }
8777
-
8778
8573
  class PagarmeCardAxiosAdapter {
8779
8574
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8780
8575
  this.credentials = credentials;
@@ -8831,9 +8626,8 @@ class PagarmeCardAxiosAdapter {
8831
8626
  });
8832
8627
  }
8833
8628
  }
8834
- async createCardHash(bu, shop) {
8835
- const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
8836
- const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8629
+ async createCardHash(bu) {
8630
+ const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8837
8631
  try {
8838
8632
  const { data } = await axios__default["default"]({
8839
8633
  method: 'GET',
@@ -8996,314 +8790,6 @@ class PagarmePixAxiosAdapter {
8996
8790
  }
8997
8791
  }
8998
8792
 
8999
- class PagarmeV5BankSlipAxiosAdapter {
9000
- constructor(credentials, paymentRepository) {
9001
- this.credentials = credentials;
9002
- this.paymentRepository = paymentRepository;
9003
- }
9004
- async pay2(payload) {
9005
- try {
9006
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9007
- const { data } = await axios__default["default"]({
9008
- method: 'POST',
9009
- url: `${this.credentials.URL}/orders`,
9010
- headers: {
9011
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9012
- 'Content-Type': 'application/json',
9013
- },
9014
- data: payload,
9015
- });
9016
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9017
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9018
- data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9019
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado) {
9020
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9021
- // checkoutId: checkout.id,
9022
- // userEmail: checkout.user.email,
9023
- info: data,
9024
- }));
9025
- }
9026
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9027
- // const payment = await this.paymentRepository.create(paymentData)
9028
- return data;
9029
- }
9030
- catch (error) {
9031
- if (error instanceof axios.AxiosError) {
9032
- console.error(error.message);
9033
- console.error(error.response.data);
9034
- }
9035
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9036
- // checkoutId: checkout.id,
9037
- // userEmail: checkout.user.email,
9038
- info: error.response.data,
9039
- });
9040
- }
9041
- }
9042
- async pay(checkout) {
9043
- try {
9044
- const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9045
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9046
- const { data } = await axios__default["default"]({
9047
- method: 'POST',
9048
- url: `${this.credentials.URL}/orders`,
9049
- headers: {
9050
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9051
- 'Content-Type': 'application/json',
9052
- },
9053
- data: payload,
9054
- });
9055
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9056
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9057
- data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9058
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado) {
9059
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9060
- checkoutId: checkout.id,
9061
- userEmail: checkout.user.email,
9062
- info: data.charges.at(0).last_transaction?.gateway_response,
9063
- }));
9064
- }
9065
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
9066
- return payment;
9067
- }
9068
- catch (error) {
9069
- console.error('Full error: ', JSON.stringify(error));
9070
- if (error instanceof axios.AxiosError) {
9071
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9072
- }
9073
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9074
- checkoutId: checkout.id,
9075
- userEmail: checkout.user.email,
9076
- info: error.response?.data,
9077
- });
9078
- }
9079
- }
9080
- async getBoletoTransaction(paymentId) {
9081
- try {
9082
- const { data } = await axios__default["default"]({
9083
- method: 'GET',
9084
- url: `${this.credentials.URL}/charges/${paymentId}`,
9085
- headers: {
9086
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9087
- 'Content-Type': 'application/json',
9088
- },
9089
- });
9090
- const payment = await this.paymentRepository.get({
9091
- id: data.id,
9092
- });
9093
- return payment.transaction;
9094
- }
9095
- catch (error) {
9096
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9097
- paymentId,
9098
- info: error.response.data,
9099
- });
9100
- }
9101
- }
9102
- }
9103
-
9104
- class PagarmeV5CardAxiosAdapter {
9105
- constructor(credentials, paymentRepository, orderBlockedRepository) {
9106
- this.credentials = credentials;
9107
- this.paymentRepository = paymentRepository;
9108
- this.orderBlockedRepository = orderBlockedRepository;
9109
- }
9110
- async pay(checkout, card) {
9111
- try {
9112
- const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9113
- console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9114
- const { data } = await axios__default["default"]({
9115
- method: 'POST',
9116
- url: `${this.credentials.URL}/orders`,
9117
- headers: {
9118
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9119
- 'Content-Type': 'application/json',
9120
- },
9121
- data: payload,
9122
- });
9123
- console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9124
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9125
- data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
9126
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
9127
- await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9128
- checkout,
9129
- card,
9130
- orderBlockedRepository: this.orderBlockedRepository,
9131
- });
9132
- throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9133
- }
9134
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9135
- return payment;
9136
- }
9137
- catch (error) {
9138
- if (error instanceof PaymentError) {
9139
- throw error;
9140
- }
9141
- console.error('Full error: ', JSON.stringify(error));
9142
- if (error instanceof axios.AxiosError) {
9143
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9144
- }
9145
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9146
- }
9147
- }
9148
- // Dúvidas: preciso criar um cliente? como faz na mens?
9149
- async addCard(card) {
9150
- try {
9151
- const { data } = await axios__default["default"]({
9152
- method: 'POST',
9153
- url: `${this.credentials.URL}/cards`,
9154
- data: {
9155
- api_key: this.credentials.API_KEY,
9156
- card_number: card.number,
9157
- card_expiration_date: card.expirationDate.replace('/', ''),
9158
- card_holder_name: card.name,
9159
- card_cvv: card.cvv,
9160
- // number: '4000000000000010',
9161
- // holder_name: 'Tony Stark',
9162
- // holder_document: '93095135270',
9163
- // exp_month: 1,
9164
- // exp_year: 30,
9165
- // cvv: '351',
9166
- // brand: 'Mastercard',
9167
- // label: 'Sua bandeira',
9168
- // billing_address: {
9169
- // line_1: '375, Av. General Osorio, Centro',
9170
- // line_2: '7º Andar',
9171
- // zip_code: '220000111',
9172
- // city: 'Rio de Janeiro',
9173
- // state: 'RJ',
9174
- // country: 'BR',
9175
- // },
9176
- // options: {
9177
- // verify_card: true,
9178
- // },
9179
- },
9180
- });
9181
- return data;
9182
- }
9183
- catch (error) {
9184
- throw new BusinessError('Houve uma falha adicionar o cartão', {
9185
- info: error.response.data,
9186
- });
9187
- }
9188
- }
9189
- async createCardHash(bu, shop) {
9190
- const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
9191
- const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9192
- try {
9193
- const { data } = await axios__default["default"]({
9194
- method: 'GET',
9195
- headers: {
9196
- 'content-type': 'application/json',
9197
- },
9198
- url: `${this.credentials.URL}/transactions/card_hash_key`,
9199
- data: JSON.stringify({
9200
- api_key: key,
9201
- }),
9202
- });
9203
- return data;
9204
- }
9205
- catch (error) {
9206
- throw new BusinessError('Houve uma falha gerar o hash', {
9207
- info: error.response.data,
9208
- });
9209
- }
9210
- }
9211
- async getCardByToken(customerId, token) {
9212
- try {
9213
- const { data } = await axios__default["default"]({
9214
- method: 'GET',
9215
- url: `${this.credentials.URL}/cards/${token}`,
9216
- data: {
9217
- api_key: this.credentials.API_KEY,
9218
- },
9219
- });
9220
- return data;
9221
- }
9222
- catch (error) {
9223
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9224
- info: error.response.data,
9225
- });
9226
- }
9227
- }
9228
- async createTransaction(info) {
9229
- return;
9230
- }
9231
- }
9232
-
9233
- class PagarmeV5PixAxiosAdapter {
9234
- constructor(credentials, paymentRepository) {
9235
- this.credentials = credentials;
9236
- this.paymentRepository = paymentRepository;
9237
- }
9238
- async pay2(payload) {
9239
- try {
9240
- // const payload = PagarMeV5RequestHelper.build(checkout, 'pix')
9241
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9242
- const { data } = await axios__default["default"]({
9243
- method: 'POST',
9244
- url: `${this.credentials.URL}/orders`,
9245
- headers: {
9246
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9247
- 'Content-Type': 'application/json',
9248
- },
9249
- data: payload,
9250
- });
9251
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9252
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9253
- // const payment = await this.paymentRepository.create(paymentData)
9254
- return data;
9255
- }
9256
- catch (error) {
9257
- if (error instanceof axios.AxiosError) {
9258
- console.error(error.message);
9259
- console.error(error.response.data);
9260
- }
9261
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9262
- // checkoutId: checkout.id,
9263
- // userEmail: checkout.user.email,
9264
- info: error.response?.data,
9265
- });
9266
- }
9267
- }
9268
- async pay(checkout) {
9269
- try {
9270
- const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9271
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9272
- const { data } = await axios__default["default"]({
9273
- method: 'POST',
9274
- url: `${this.credentials.URL}/orders`,
9275
- headers: {
9276
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9277
- 'Content-Type': 'application/json',
9278
- },
9279
- data: payload,
9280
- });
9281
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9282
- if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
9283
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9284
- checkoutId: checkout.id,
9285
- userEmail: checkout.user.email,
9286
- info: data.charges.at(0).last_transaction?.gateway_response,
9287
- });
9288
- }
9289
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9290
- return payment;
9291
- }
9292
- catch (error) {
9293
- console.error('Full error: ', JSON.stringify(error));
9294
- if (error instanceof axios.AxiosError) {
9295
- console.error('Error: ', error.message);
9296
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9297
- }
9298
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9299
- checkoutId: checkout.id,
9300
- userEmail: checkout.user.email,
9301
- info: error.response?.data,
9302
- });
9303
- }
9304
- }
9305
- }
9306
-
9307
8793
  class VertexAxiosAdapter {
9308
8794
  constructor(config) {
9309
8795
  this.config = config;
@@ -9660,9 +9146,6 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
9660
9146
  exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
9661
9147
  exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
9662
9148
  exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
9663
- exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
9664
- exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
9665
- exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
9666
9149
  exports.Payment = Payment;
9667
9150
  exports.PaymentError = PaymentError;
9668
9151
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;