@infrab4a/connect 5.1.0-beta.1 → 5.1.0-beta.10

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 CHANGED
@@ -115,6 +115,13 @@ exports.PaymentProviders = void 0;
115
115
  PaymentProviders["GLAMPOINTS"] = "glampoints";
116
116
  })(exports.PaymentProviders || (exports.PaymentProviders = {}));
117
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
+
118
125
  class BasePaymentMethodFactory {
119
126
  constructor(methods) {
120
127
  this.methods = methods;
@@ -8588,20 +8595,23 @@ class PagarmePaymentOperationsHelper {
8588
8595
  }
8589
8596
 
8590
8597
  class PagarMeV5RequestHelper {
8591
- static build(checkout, type, card) {
8598
+ static build(checkout, method, card) {
8592
8599
  return {
8593
8600
  items: this.buildItems(checkout),
8594
8601
  customer: this.buildCustomer(checkout),
8595
8602
  shipping: this.buildShipping(checkout),
8596
- payments: this.buildPayment(checkout, type, card),
8603
+ payments: this.buildPayment(checkout, method, card),
8597
8604
  };
8598
8605
  }
8599
8606
  static buildItems(checkout) {
8600
- return checkout.lineItems.map((item) => {
8607
+ return checkout.lineItems
8608
+ .filter((item) => !item.isGift)
8609
+ .map((item) => {
8601
8610
  return {
8602
8611
  amount: Math.floor(item.pricePaid * 100),
8603
8612
  description: item.name,
8604
8613
  quantity: item.quantity,
8614
+ code: item.EAN,
8605
8615
  };
8606
8616
  });
8607
8617
  }
@@ -8612,10 +8622,15 @@ class PagarMeV5RequestHelper {
8612
8622
  type: 'individual',
8613
8623
  document: checkout.user.cpf,
8614
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
+ },
8615
8630
  mobile_phone: {
8616
8631
  country_code: '55',
8617
8632
  number: checkout.user.phone.slice(2),
8618
- area_code: checkout.user.phone.slice(0, 1),
8633
+ area_code: checkout.user.phone.slice(0, 2),
8619
8634
  },
8620
8635
  },
8621
8636
  address: {
@@ -8624,14 +8639,14 @@ class PagarMeV5RequestHelper {
8624
8639
  zip_code: checkout.shippingAddress.zip,
8625
8640
  city: checkout.billingAddress.city,
8626
8641
  state: checkout.billingAddress.state,
8627
- country: checkout.billingAddress.country,
8642
+ country: 'BR',
8628
8643
  },
8629
8644
  };
8630
8645
  }
8631
8646
  static buildShipping(checkout) {
8632
8647
  return {
8633
- amount: checkout.shipping.ShippingPrice,
8634
- description: '',
8648
+ amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8649
+ description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8635
8650
  recipient_name: checkout.shippingAddress.recipient,
8636
8651
  recipient_phone: checkout.user.phone,
8637
8652
  address: {
@@ -8640,22 +8655,22 @@ class PagarMeV5RequestHelper {
8640
8655
  zip_code: checkout.shippingAddress.zip,
8641
8656
  city: checkout.shippingAddress.city,
8642
8657
  state: checkout.shippingAddress.state,
8643
- country: checkout.shippingAddress.country,
8658
+ country: 'BR',
8644
8659
  },
8645
8660
  };
8646
8661
  }
8647
- static buildPayment(checkout, type, card) {
8662
+ static buildPayment(checkout, method, card) {
8648
8663
  return [
8649
8664
  {
8650
- payment_method: type,
8665
+ payment_method: method,
8651
8666
  amount: Math.floor(checkout.totalPrice * 100),
8652
- ...(type === 'pix' && {
8667
+ ...(method === 'pix' && {
8653
8668
  pix: this.getPixOrder(),
8654
8669
  }),
8655
- ...(type === 'boleto' && {
8670
+ ...(method === 'boleto' && {
8656
8671
  boleto: this.getBoletoOrder(),
8657
8672
  }),
8658
- ...(type === 'credit_card' && {
8673
+ ...(method === 'credit_card' && {
8659
8674
  credit_card: this.getCardOrder(checkout, card),
8660
8675
  }),
8661
8676
  },
@@ -8687,7 +8702,7 @@ class PagarMeV5RequestHelper {
8687
8702
  }
8688
8703
 
8689
8704
  class PagarMeV5ResponseHelper {
8690
- static build(checkout, response) {
8705
+ static build(method, checkout, response) {
8691
8706
  return Payment.toInstance({
8692
8707
  createdAt: new Date(),
8693
8708
  updatedAt: new Date(),
@@ -8696,10 +8711,10 @@ class PagarMeV5ResponseHelper {
8696
8711
  totalPrice: checkout.totalPrice,
8697
8712
  paymentProvider: exports.PaymentProviders.PAGARME,
8698
8713
  pagarMeOrderId: response.id,
8699
- transaction: this.buildPaymentTransaction(response),
8714
+ transaction: this.buildPaymentTransaction(method, response),
8700
8715
  });
8701
8716
  }
8702
- static buildPaymentTransaction(response) {
8717
+ static buildPaymentTransaction(method, response) {
8703
8718
  const charger = response.charges.at(0);
8704
8719
  const transaction = charger.last_transaction;
8705
8720
  return PaymentTransaction.toInstance({
@@ -8707,20 +8722,28 @@ class PagarMeV5ResponseHelper {
8707
8722
  amount: charger.amount,
8708
8723
  currency: charger.currency,
8709
8724
  gateway_id: charger.gateway_id,
8710
- status: charger.status,
8725
+ status: this.getPaymentStatus(transaction.status),
8711
8726
  payment_method: charger.payment_method,
8712
8727
  date_created: charger.created_at,
8713
8728
  date_updated: charger.updated_at,
8714
8729
  paid_amount: charger.paid_amount,
8715
8730
  paid_at: charger.paid_at,
8716
8731
  order_id: response.id,
8717
- tid: +transaction.id,
8718
- id: +transaction.id,
8719
- ...this.getBoletoReponse(transaction),
8720
- ...this.getPixReponse(transaction),
8721
- ...this.getCardReponse(transaction),
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)),
8722
8738
  });
8723
8739
  }
8740
+ static getPaymentStatus(status) {
8741
+ if (status == exports.PagarMeV5PaymentStatus.Gerado)
8742
+ return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
8743
+ if (status == exports.PagarMeV5PaymentStatus.Capturada)
8744
+ return exports.PagarMeV5PaymentStatus.Pago;
8745
+ return status;
8746
+ }
8724
8747
  static getBoletoReponse(transaction) {
8725
8748
  return {
8726
8749
  boleto_url: transaction.url?.toString(),
@@ -8750,11 +8773,11 @@ class PagarMeV5ResponseHelper {
8750
8773
  acquirer_message: transaction.acquirer_message?.toString(),
8751
8774
  acquirer_return_code: transaction.acquirer_return_code?.toString(),
8752
8775
  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(),
8776
+ card_holder_name: transaction.card?.holder_name?.toString(),
8777
+ card_last_digits: transaction.card?.last_four_digits?.toString(),
8778
+ card_first_digits: transaction.card?.first_six_digits?.toString(),
8779
+ card_brand: transaction.card?.brand?.toString(),
8780
+ card_id: transaction.card?.id?.toString(),
8758
8781
  };
8759
8782
  }
8760
8783
  }
@@ -8815,8 +8838,9 @@ class PagarmeCardAxiosAdapter {
8815
8838
  });
8816
8839
  }
8817
8840
  }
8818
- async createCardHash(bu) {
8819
- const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8841
+ async createCardHash(bu, shop) {
8842
+ const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
8843
+ const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8820
8844
  try {
8821
8845
  const { data } = await axios__default["default"]({
8822
8846
  method: 'GET',
@@ -8998,26 +9022,28 @@ class PagarmeV5BankSlipAxiosAdapter {
8998
9022
  data: payload,
8999
9023
  });
9000
9024
  console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9001
- if (data.charges.at(0).status !== exports.PagarMeV5OrderStatus['Em processamento'] ||
9002
- data.charges.at(0).status !== exports.PagarMeV5PaymentStatus['Falha']) {
9025
+ if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9026
+ data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9027
+ data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado ||
9028
+ data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento']) {
9003
9029
  return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9004
9030
  checkoutId: checkout.id,
9005
9031
  userEmail: checkout.user.email,
9006
- info: data,
9032
+ info: data.charges.at(0).last_transaction?.gateway_response,
9007
9033
  }));
9008
9034
  }
9009
- const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
9010
- const payment = await this.paymentRepository.create(paymentData);
9035
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
9011
9036
  return payment;
9012
9037
  }
9013
9038
  catch (error) {
9014
- console.warn(error.response?.data);
9015
- console.warn(error.response?.data?.errors);
9016
- console.warn(error.response?.data?.request);
9039
+ console.error('Full error: ', JSON.stringify(error));
9040
+ if (error instanceof axios.AxiosError) {
9041
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9042
+ }
9017
9043
  throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9018
9044
  checkoutId: checkout.id,
9019
9045
  userEmail: checkout.user.email,
9020
- info: error.response.data,
9046
+ info: error.response?.data,
9021
9047
  });
9022
9048
  }
9023
9049
  }
@@ -9032,7 +9058,7 @@ class PagarmeV5BankSlipAxiosAdapter {
9032
9058
  },
9033
9059
  });
9034
9060
  const payment = await this.paymentRepository.get({
9035
- id: +data.id,
9061
+ id: data.id,
9036
9062
  });
9037
9063
  return payment.transaction;
9038
9064
  }
@@ -9065,8 +9091,9 @@ class PagarmeV5CardAxiosAdapter {
9065
9091
  data: payload,
9066
9092
  });
9067
9093
  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) {
9094
+ if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9095
+ data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
9096
+ data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
9070
9097
  await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9071
9098
  checkout,
9072
9099
  card,
@@ -9074,63 +9101,26 @@ class PagarmeV5CardAxiosAdapter {
9074
9101
  });
9075
9102
  throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9076
9103
  }
9077
- const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
9078
- const payment = await this.paymentRepository.create(paymentData);
9104
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9079
9105
  return payment;
9080
9106
  }
9081
9107
  catch (error) {
9082
9108
  if (error instanceof PaymentError) {
9083
9109
  throw error;
9084
9110
  }
9085
- console.warn(error.response?.data);
9086
- console.warn(error.response?.data?.errors);
9087
- console.warn(error.response?.data?.request);
9111
+ console.error('Full error: ', JSON.stringify(error));
9112
+ if (error instanceof axios.AxiosError) {
9113
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9114
+ }
9088
9115
  throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9089
9116
  }
9090
9117
  }
9091
- // Dúvidas: preciso criar um cliente? como faz na mens?
9092
9118
  async addCard(card) {
9093
- try {
9094
- const { data } = await axios__default["default"]({
9095
- method: 'POST',
9096
- url: `${this.credentials.URL}/cards`,
9097
- data: {
9098
- api_key: this.credentials.API_KEY,
9099
- card_number: card.number,
9100
- card_expiration_date: card.expirationDate.replace('/', ''),
9101
- card_holder_name: card.name,
9102
- card_cvv: card.cvv,
9103
- // number: '4000000000000010',
9104
- // holder_name: 'Tony Stark',
9105
- // holder_document: '93095135270',
9106
- // exp_month: 1,
9107
- // exp_year: 30,
9108
- // cvv: '351',
9109
- // brand: 'Mastercard',
9110
- // label: 'Sua bandeira',
9111
- // billing_address: {
9112
- // line_1: '375, Av. General Osorio, Centro',
9113
- // line_2: '7º Andar',
9114
- // zip_code: '220000111',
9115
- // city: 'Rio de Janeiro',
9116
- // state: 'RJ',
9117
- // country: 'BR',
9118
- // },
9119
- // options: {
9120
- // verify_card: true,
9121
- // },
9122
- },
9123
- });
9124
- return data;
9125
- }
9126
- catch (error) {
9127
- throw new BusinessError('Houve uma falha adicionar o cartão', {
9128
- info: error.response.data,
9129
- });
9130
- }
9119
+ return;
9131
9120
  }
9132
- async createCardHash(bu) {
9133
- const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
9121
+ async createCardHash(bu, shop) {
9122
+ const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
9123
+ const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9134
9124
  try {
9135
9125
  const { data } = await axios__default["default"]({
9136
9126
  method: 'GET',
@@ -9150,11 +9140,11 @@ class PagarmeV5CardAxiosAdapter {
9150
9140
  });
9151
9141
  }
9152
9142
  }
9153
- async getCardByToken(id) {
9143
+ async getCardByToken(customerId, token) {
9154
9144
  try {
9155
9145
  const { data } = await axios__default["default"]({
9156
- method: 'POST',
9157
- url: `${this.credentials.URL}/cards/${id}`,
9146
+ method: 'GET',
9147
+ url: `${this.credentials.URL}/cards/${token}`,
9158
9148
  data: {
9159
9149
  api_key: this.credentials.API_KEY,
9160
9150
  },
@@ -9162,32 +9152,13 @@ class PagarmeV5CardAxiosAdapter {
9162
9152
  return data;
9163
9153
  }
9164
9154
  catch (error) {
9165
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
9155
+ throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9166
9156
  info: error.response.data,
9167
9157
  });
9168
9158
  }
9169
9159
  }
9170
9160
  async createTransaction(info) {
9171
- try {
9172
- const { data } = await axios__default["default"]({
9173
- method: 'POST',
9174
- url: `${this.credentials.URL}/transactions`,
9175
- headers: {
9176
- Authorization: 'Basic ' + Buffer.from(this.credentials.API_KEY).toString('base64'),
9177
- 'Content-Type': 'application/json',
9178
- },
9179
- data: {
9180
- ...info,
9181
- api_key: this.credentials.API_KEY,
9182
- },
9183
- });
9184
- return data;
9185
- }
9186
- catch (error) {
9187
- throw new BusinessError('Houve uma falha ao criar a transação', {
9188
- info: error.response.data,
9189
- });
9190
- }
9161
+ return;
9191
9162
  }
9192
9163
  }
9193
9164
 
@@ -9210,14 +9181,22 @@ class PagarmeV5PixAxiosAdapter {
9210
9181
  data: payload,
9211
9182
  });
9212
9183
  console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9213
- const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
9214
- const payment = await this.paymentRepository.create(paymentData);
9184
+ if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
9185
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9186
+ checkoutId: checkout.id,
9187
+ userEmail: checkout.user.email,
9188
+ info: data.charges.at(0).last_transaction?.gateway_response,
9189
+ });
9190
+ }
9191
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9215
9192
  return payment;
9216
9193
  }
9217
9194
  catch (error) {
9218
- console.warn(error.response?.data);
9219
- console.warn(error.response?.data?.errors);
9220
- console.warn(error.response?.data?.request);
9195
+ console.error('Full error: ', JSON.stringify(error));
9196
+ if (error instanceof axios.AxiosError) {
9197
+ console.error('Error: ', error.message);
9198
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9199
+ }
9221
9200
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9222
9201
  checkoutId: checkout.id,
9223
9202
  userEmail: checkout.user.email,
package/index.esm.js CHANGED
@@ -90,6 +90,13 @@ var PaymentProviders;
90
90
  PaymentProviders["GLAMPOINTS"] = "glampoints";
91
91
  })(PaymentProviders || (PaymentProviders = {}));
92
92
 
93
+ var TransactionPaymentMethods;
94
+ (function (TransactionPaymentMethods) {
95
+ TransactionPaymentMethods["CARD"] = "credit_card";
96
+ TransactionPaymentMethods["BANKSLIP"] = "boleto";
97
+ TransactionPaymentMethods["PIX"] = "pix";
98
+ })(TransactionPaymentMethods || (TransactionPaymentMethods = {}));
99
+
93
100
  class BasePaymentMethodFactory {
94
101
  constructor(methods) {
95
102
  this.methods = methods;
@@ -8563,20 +8570,23 @@ class PagarmePaymentOperationsHelper {
8563
8570
  }
8564
8571
 
8565
8572
  class PagarMeV5RequestHelper {
8566
- static build(checkout, type, card) {
8573
+ static build(checkout, method, card) {
8567
8574
  return {
8568
8575
  items: this.buildItems(checkout),
8569
8576
  customer: this.buildCustomer(checkout),
8570
8577
  shipping: this.buildShipping(checkout),
8571
- payments: this.buildPayment(checkout, type, card),
8578
+ payments: this.buildPayment(checkout, method, card),
8572
8579
  };
8573
8580
  }
8574
8581
  static buildItems(checkout) {
8575
- return checkout.lineItems.map((item) => {
8582
+ return checkout.lineItems
8583
+ .filter((item) => !item.isGift)
8584
+ .map((item) => {
8576
8585
  return {
8577
8586
  amount: Math.floor(item.pricePaid * 100),
8578
8587
  description: item.name,
8579
8588
  quantity: item.quantity,
8589
+ code: item.EAN,
8580
8590
  };
8581
8591
  });
8582
8592
  }
@@ -8587,10 +8597,15 @@ class PagarMeV5RequestHelper {
8587
8597
  type: 'individual',
8588
8598
  document: checkout.user.cpf,
8589
8599
  phones: {
8600
+ home_phone: {
8601
+ country_code: '55',
8602
+ number: checkout.user.phone.slice(2),
8603
+ area_code: checkout.user.phone.slice(0, 2),
8604
+ },
8590
8605
  mobile_phone: {
8591
8606
  country_code: '55',
8592
8607
  number: checkout.user.phone.slice(2),
8593
- area_code: checkout.user.phone.slice(0, 1),
8608
+ area_code: checkout.user.phone.slice(0, 2),
8594
8609
  },
8595
8610
  },
8596
8611
  address: {
@@ -8599,14 +8614,14 @@ class PagarMeV5RequestHelper {
8599
8614
  zip_code: checkout.shippingAddress.zip,
8600
8615
  city: checkout.billingAddress.city,
8601
8616
  state: checkout.billingAddress.state,
8602
- country: checkout.billingAddress.country,
8617
+ country: 'BR',
8603
8618
  },
8604
8619
  };
8605
8620
  }
8606
8621
  static buildShipping(checkout) {
8607
8622
  return {
8608
- amount: checkout.shipping.ShippingPrice,
8609
- description: '',
8623
+ amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8624
+ description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8610
8625
  recipient_name: checkout.shippingAddress.recipient,
8611
8626
  recipient_phone: checkout.user.phone,
8612
8627
  address: {
@@ -8615,22 +8630,22 @@ class PagarMeV5RequestHelper {
8615
8630
  zip_code: checkout.shippingAddress.zip,
8616
8631
  city: checkout.shippingAddress.city,
8617
8632
  state: checkout.shippingAddress.state,
8618
- country: checkout.shippingAddress.country,
8633
+ country: 'BR',
8619
8634
  },
8620
8635
  };
8621
8636
  }
8622
- static buildPayment(checkout, type, card) {
8637
+ static buildPayment(checkout, method, card) {
8623
8638
  return [
8624
8639
  {
8625
- payment_method: type,
8640
+ payment_method: method,
8626
8641
  amount: Math.floor(checkout.totalPrice * 100),
8627
- ...(type === 'pix' && {
8642
+ ...(method === 'pix' && {
8628
8643
  pix: this.getPixOrder(),
8629
8644
  }),
8630
- ...(type === 'boleto' && {
8645
+ ...(method === 'boleto' && {
8631
8646
  boleto: this.getBoletoOrder(),
8632
8647
  }),
8633
- ...(type === 'credit_card' && {
8648
+ ...(method === 'credit_card' && {
8634
8649
  credit_card: this.getCardOrder(checkout, card),
8635
8650
  }),
8636
8651
  },
@@ -8662,7 +8677,7 @@ class PagarMeV5RequestHelper {
8662
8677
  }
8663
8678
 
8664
8679
  class PagarMeV5ResponseHelper {
8665
- static build(checkout, response) {
8680
+ static build(method, checkout, response) {
8666
8681
  return Payment.toInstance({
8667
8682
  createdAt: new Date(),
8668
8683
  updatedAt: new Date(),
@@ -8671,10 +8686,10 @@ class PagarMeV5ResponseHelper {
8671
8686
  totalPrice: checkout.totalPrice,
8672
8687
  paymentProvider: PaymentProviders.PAGARME,
8673
8688
  pagarMeOrderId: response.id,
8674
- transaction: this.buildPaymentTransaction(response),
8689
+ transaction: this.buildPaymentTransaction(method, response),
8675
8690
  });
8676
8691
  }
8677
- static buildPaymentTransaction(response) {
8692
+ static buildPaymentTransaction(method, response) {
8678
8693
  const charger = response.charges.at(0);
8679
8694
  const transaction = charger.last_transaction;
8680
8695
  return PaymentTransaction.toInstance({
@@ -8682,20 +8697,28 @@ class PagarMeV5ResponseHelper {
8682
8697
  amount: charger.amount,
8683
8698
  currency: charger.currency,
8684
8699
  gateway_id: charger.gateway_id,
8685
- status: charger.status,
8700
+ status: this.getPaymentStatus(transaction.status),
8686
8701
  payment_method: charger.payment_method,
8687
8702
  date_created: charger.created_at,
8688
8703
  date_updated: charger.updated_at,
8689
8704
  paid_amount: charger.paid_amount,
8690
8705
  paid_at: charger.paid_at,
8691
8706
  order_id: response.id,
8692
- tid: +transaction.id,
8693
- id: +transaction.id,
8694
- ...this.getBoletoReponse(transaction),
8695
- ...this.getPixReponse(transaction),
8696
- ...this.getCardReponse(transaction),
8707
+ charger_id: charger.id,
8708
+ tid: charger.id,
8709
+ id: charger.id,
8710
+ ...(method == TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8711
+ ...(method == TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8712
+ ...(method == TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8697
8713
  });
8698
8714
  }
8715
+ static getPaymentStatus(status) {
8716
+ if (status == PagarMeV5PaymentStatus.Gerado)
8717
+ return PagarMeV5PaymentStatus['Aguardando pagamento'];
8718
+ if (status == PagarMeV5PaymentStatus.Capturada)
8719
+ return PagarMeV5PaymentStatus.Pago;
8720
+ return status;
8721
+ }
8699
8722
  static getBoletoReponse(transaction) {
8700
8723
  return {
8701
8724
  boleto_url: transaction.url?.toString(),
@@ -8725,11 +8748,11 @@ class PagarMeV5ResponseHelper {
8725
8748
  acquirer_message: transaction.acquirer_message?.toString(),
8726
8749
  acquirer_return_code: transaction.acquirer_return_code?.toString(),
8727
8750
  installments: transaction.installments ?? null,
8728
- card_holder_name: transaction.card.holder_name?.toString(),
8729
- card_last_digits: transaction.card.last_four_digits?.toString(),
8730
- card_first_digits: transaction.card.first_six_digits?.toString(),
8731
- card_brand: transaction.card.brand?.toString(),
8732
- card_id: transaction.card.id?.toString(),
8751
+ card_holder_name: transaction.card?.holder_name?.toString(),
8752
+ card_last_digits: transaction.card?.last_four_digits?.toString(),
8753
+ card_first_digits: transaction.card?.first_six_digits?.toString(),
8754
+ card_brand: transaction.card?.brand?.toString(),
8755
+ card_id: transaction.card?.id?.toString(),
8733
8756
  };
8734
8757
  }
8735
8758
  }
@@ -8790,8 +8813,9 @@ class PagarmeCardAxiosAdapter {
8790
8813
  });
8791
8814
  }
8792
8815
  }
8793
- async createCardHash(bu) {
8794
- const key = bu === BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8816
+ async createCardHash(bu, shop) {
8817
+ const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
8818
+ const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8795
8819
  try {
8796
8820
  const { data } = await axios({
8797
8821
  method: 'GET',
@@ -8973,26 +8997,28 @@ class PagarmeV5BankSlipAxiosAdapter {
8973
8997
  data: payload,
8974
8998
  });
8975
8999
  console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
8976
- if (data.charges.at(0).status !== PagarMeV5OrderStatus['Em processamento'] ||
8977
- data.charges.at(0).status !== PagarMeV5PaymentStatus['Falha']) {
9000
+ if (data.status == PagarMeV5OrderStatus.Falha ||
9001
+ data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
9002
+ data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado ||
9003
+ data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus['Em processamento']) {
8978
9004
  return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8979
9005
  checkoutId: checkout.id,
8980
9006
  userEmail: checkout.user.email,
8981
- info: data,
9007
+ info: data.charges.at(0).last_transaction?.gateway_response,
8982
9008
  }));
8983
9009
  }
8984
- const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
8985
- const payment = await this.paymentRepository.create(paymentData);
9010
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.BANKSLIP, checkout, data));
8986
9011
  return payment;
8987
9012
  }
8988
9013
  catch (error) {
8989
- console.warn(error.response?.data);
8990
- console.warn(error.response?.data?.errors);
8991
- console.warn(error.response?.data?.request);
9014
+ console.error('Full error: ', JSON.stringify(error));
9015
+ if (error instanceof AxiosError) {
9016
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9017
+ }
8992
9018
  throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8993
9019
  checkoutId: checkout.id,
8994
9020
  userEmail: checkout.user.email,
8995
- info: error.response.data,
9021
+ info: error.response?.data,
8996
9022
  });
8997
9023
  }
8998
9024
  }
@@ -9007,7 +9033,7 @@ class PagarmeV5BankSlipAxiosAdapter {
9007
9033
  },
9008
9034
  });
9009
9035
  const payment = await this.paymentRepository.get({
9010
- id: +data.id,
9036
+ id: data.id,
9011
9037
  });
9012
9038
  return payment.transaction;
9013
9039
  }
@@ -9040,8 +9066,9 @@ class PagarmeV5CardAxiosAdapter {
9040
9066
  data: payload,
9041
9067
  });
9042
9068
  console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9043
- if (data.charges.at(0).status !== PagarMeV5PaymentStatus.Pago ||
9044
- data.charges.at(0).status !== PagarMeV5PaymentStatus.Capturada) {
9069
+ if (data.status == PagarMeV5OrderStatus.Falha ||
9070
+ data.charges.at(0).status !== PagarMeV5OrderStatus.Pago ||
9071
+ data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Capturada) {
9045
9072
  await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9046
9073
  checkout,
9047
9074
  card,
@@ -9049,63 +9076,26 @@ class PagarmeV5CardAxiosAdapter {
9049
9076
  });
9050
9077
  throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9051
9078
  }
9052
- const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
9053
- const payment = await this.paymentRepository.create(paymentData);
9079
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.CARD, checkout, data));
9054
9080
  return payment;
9055
9081
  }
9056
9082
  catch (error) {
9057
9083
  if (error instanceof PaymentError) {
9058
9084
  throw error;
9059
9085
  }
9060
- console.warn(error.response?.data);
9061
- console.warn(error.response?.data?.errors);
9062
- console.warn(error.response?.data?.request);
9086
+ console.error('Full error: ', JSON.stringify(error));
9087
+ if (error instanceof AxiosError) {
9088
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9089
+ }
9063
9090
  throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9064
9091
  }
9065
9092
  }
9066
- // Dúvidas: preciso criar um cliente? como faz na mens?
9067
9093
  async addCard(card) {
9068
- try {
9069
- const { data } = await axios({
9070
- method: 'POST',
9071
- url: `${this.credentials.URL}/cards`,
9072
- data: {
9073
- api_key: this.credentials.API_KEY,
9074
- card_number: card.number,
9075
- card_expiration_date: card.expirationDate.replace('/', ''),
9076
- card_holder_name: card.name,
9077
- card_cvv: card.cvv,
9078
- // number: '4000000000000010',
9079
- // holder_name: 'Tony Stark',
9080
- // holder_document: '93095135270',
9081
- // exp_month: 1,
9082
- // exp_year: 30,
9083
- // cvv: '351',
9084
- // brand: 'Mastercard',
9085
- // label: 'Sua bandeira',
9086
- // billing_address: {
9087
- // line_1: '375, Av. General Osorio, Centro',
9088
- // line_2: '7º Andar',
9089
- // zip_code: '220000111',
9090
- // city: 'Rio de Janeiro',
9091
- // state: 'RJ',
9092
- // country: 'BR',
9093
- // },
9094
- // options: {
9095
- // verify_card: true,
9096
- // },
9097
- },
9098
- });
9099
- return data;
9100
- }
9101
- catch (error) {
9102
- throw new BusinessError('Houve uma falha adicionar o cartão', {
9103
- info: error.response.data,
9104
- });
9105
- }
9094
+ return;
9106
9095
  }
9107
- async createCardHash(bu) {
9108
- const key = bu === BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
9096
+ async createCardHash(bu, shop) {
9097
+ const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
9098
+ const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9109
9099
  try {
9110
9100
  const { data } = await axios({
9111
9101
  method: 'GET',
@@ -9125,11 +9115,11 @@ class PagarmeV5CardAxiosAdapter {
9125
9115
  });
9126
9116
  }
9127
9117
  }
9128
- async getCardByToken(id) {
9118
+ async getCardByToken(customerId, token) {
9129
9119
  try {
9130
9120
  const { data } = await axios({
9131
- method: 'POST',
9132
- url: `${this.credentials.URL}/cards/${id}`,
9121
+ method: 'GET',
9122
+ url: `${this.credentials.URL}/cards/${token}`,
9133
9123
  data: {
9134
9124
  api_key: this.credentials.API_KEY,
9135
9125
  },
@@ -9137,32 +9127,13 @@ class PagarmeV5CardAxiosAdapter {
9137
9127
  return data;
9138
9128
  }
9139
9129
  catch (error) {
9140
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
9130
+ throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9141
9131
  info: error.response.data,
9142
9132
  });
9143
9133
  }
9144
9134
  }
9145
9135
  async createTransaction(info) {
9146
- try {
9147
- const { data } = await axios({
9148
- method: 'POST',
9149
- url: `${this.credentials.URL}/transactions`,
9150
- headers: {
9151
- Authorization: 'Basic ' + Buffer.from(this.credentials.API_KEY).toString('base64'),
9152
- 'Content-Type': 'application/json',
9153
- },
9154
- data: {
9155
- ...info,
9156
- api_key: this.credentials.API_KEY,
9157
- },
9158
- });
9159
- return data;
9160
- }
9161
- catch (error) {
9162
- throw new BusinessError('Houve uma falha ao criar a transação', {
9163
- info: error.response.data,
9164
- });
9165
- }
9136
+ return;
9166
9137
  }
9167
9138
  }
9168
9139
 
@@ -9185,14 +9156,22 @@ class PagarmeV5PixAxiosAdapter {
9185
9156
  data: payload,
9186
9157
  });
9187
9158
  console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9188
- const paymentData = PagarMeV5ResponseHelper.build(checkout, data);
9189
- const payment = await this.paymentRepository.create(paymentData);
9159
+ if (data.status == PagarMeV5OrderStatus.Falha || data.status == PagarMeV5OrderStatus.Cancelado) {
9160
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9161
+ checkoutId: checkout.id,
9162
+ userEmail: checkout.user.email,
9163
+ info: data.charges.at(0).last_transaction?.gateway_response,
9164
+ });
9165
+ }
9166
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.PIX, checkout, data));
9190
9167
  return payment;
9191
9168
  }
9192
9169
  catch (error) {
9193
- console.warn(error.response?.data);
9194
- console.warn(error.response?.data?.errors);
9195
- console.warn(error.response?.data?.request);
9170
+ console.error('Full error: ', JSON.stringify(error));
9171
+ if (error instanceof AxiosError) {
9172
+ console.error('Error: ', error.message);
9173
+ console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9174
+ }
9196
9175
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9197
9176
  checkoutId: checkout.id,
9198
9177
  userEmail: checkout.user.email,
@@ -9355,4 +9334,4 @@ class ProductsVertexSearch {
9355
9334
  }
9356
9335
  }
9357
9336
 
9358
- export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
9337
+ export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.1.0-beta.1",
3
+ "version": "5.1.0-beta.10",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -5,3 +5,4 @@ export * from './pagarme-payment-status.enum';
5
5
  export * from './pagarme-v5-payment-status.enum';
6
6
  export * from './payment-methods.enum';
7
7
  export * from './payment-providers.enum';
8
+ export * from './transaction-payment-methods.enum';
@@ -0,0 +1,5 @@
1
+ export declare enum TransactionPaymentMethods {
2
+ CARD = "credit_card",
3
+ BANKSLIP = "boleto",
4
+ PIX = "pix"
5
+ }
@@ -1,3 +1,4 @@
1
+ import { Shops } from '../../catalog';
1
2
  import { BusinessUnitEnum } from '../enums';
2
3
  import { PaymentTransaction } from '../models';
3
4
  import { Checkout } from '../models/checkout';
@@ -8,6 +9,7 @@ export interface PaymentProviderCard<Card extends BaseCard = BaseCard> {
8
9
  pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
9
10
  addCard(card: CardInfo): Promise<Card>;
10
11
  getCardByToken(token: string): Promise<Card>;
11
- createCardHash<T>(bu: BusinessUnitEnum, card?: CardInfo): Promise<string | T>;
12
+ getCardByToken(customerId: string, token: string): Promise<Card>;
13
+ createCardHash<T>(bu: BusinessUnitEnum, shop: Shops, card?: CardInfo): Promise<string | T>;
12
14
  createTransaction(info: any): Promise<PaymentTransaction>;
13
15
  }
@@ -1,10 +1,10 @@
1
1
  import { BaseModel } from '../../generic/model/base.model';
2
2
  import { PaymentBilling, PaymentCard, PaymentCustomer, PaymentItem, PaymentShipping } from './types';
3
3
  export declare class PaymentTransaction extends BaseModel<PaymentTransaction> {
4
- id?: number;
4
+ id?: string;
5
5
  object?: string;
6
6
  status?: string;
7
- tid?: number;
7
+ tid?: string;
8
8
  gateway_id?: string;
9
9
  nsu?: number;
10
10
  amount: number;
@@ -72,6 +72,7 @@ export declare class PaymentTransaction extends BaseModel<PaymentTransaction> {
72
72
  fraudCovered?: boolean;
73
73
  fraud_reimbursed?: string;
74
74
  order_id?: string;
75
+ charger_id?: string;
75
76
  risk_level?: string;
76
77
  receipt_url?: string;
77
78
  private_label?: string;
@@ -2,7 +2,7 @@ import { BaseModel, GenericIdentifier } from '../../generic/model/base.model';
2
2
  import { PaymentProvider } from '../types';
3
3
  import { PaymentTransaction } from './payment-transaction';
4
4
  export declare class Payment extends BaseModel<Payment> {
5
- id: number;
5
+ id: string | number;
6
6
  checkoutId: string;
7
7
  orderId?: string;
8
8
  pagarMeOrderId?: string;
@@ -1,7 +1,13 @@
1
1
  export type PagarmeCredentials = {
2
2
  URL: string;
3
- URL_POSTBACK: string;
3
+ URL_POSTBACK?: string;
4
4
  API_KEY: string;
5
- SUBSCRIPTION_API_KEY: string;
6
- SHOP_API_KEY: string;
5
+ Glamshop: {
6
+ SUBSCRIPTION_API_KEY: string;
7
+ SHOP_API_KEY: string;
8
+ };
9
+ mensmarket: {
10
+ SUBSCRIPTION_API_KEY: string;
11
+ SHOP_API_KEY: string;
12
+ };
7
13
  };
@@ -1,7 +1,7 @@
1
1
  import { Checkout, PaymentCardInfo } from '../../../../domain';
2
2
  import { PagarMeV5RequestPayload } from '../../types';
3
3
  export declare class PagarMeV5RequestHelper {
4
- static build(checkout: Checkout, type: 'pix' | 'boleto' | 'credit_card', card?: PaymentCardInfo): PagarMeV5RequestPayload;
4
+ static build(checkout: Checkout, method: 'pix' | 'boleto' | 'credit_card', card?: PaymentCardInfo): PagarMeV5RequestPayload;
5
5
  private static buildItems;
6
6
  private static buildCustomer;
7
7
  private static buildShipping;
@@ -1,8 +1,9 @@
1
- import { Checkout, Payment } from '../../../../domain';
1
+ import { Checkout, Payment, TransactionPaymentMethods } from '../../../../domain';
2
2
  import { PagarMeV5Response } from '../../types';
3
3
  export declare class PagarMeV5ResponseHelper {
4
- static build(checkout: Checkout, response: PagarMeV5Response): Payment;
4
+ static build(method: TransactionPaymentMethods, checkout: Checkout, response: PagarMeV5Response): Payment;
5
5
  private static buildPaymentTransaction;
6
+ private static getPaymentStatus;
6
7
  private static getBoletoReponse;
7
8
  private static getPixReponse;
8
9
  private static getCardReponse;
@@ -1,3 +1,4 @@
1
+ import { Shops } from '../../../../domain/catalog';
1
2
  import { BusinessUnitEnum } from '../../../../domain/shopping/enums';
2
3
  import { PaymentProviderCard } from '../../../../domain/shopping/interfaces';
3
4
  import { Checkout, Payment, PaymentTransaction } from '../../../../domain/shopping/models';
@@ -10,7 +11,7 @@ export declare class PagarmeCardAxiosAdapter implements PaymentProviderCard<Paga
10
11
  constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
11
12
  pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
12
13
  addCard(card: CardInfo): Promise<PagarMeCard>;
13
- createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum): Promise<PagarMeCardManualHash>;
14
+ createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum, shop?: Shops): Promise<PagarMeCardManualHash>;
14
15
  getCardByToken(id: string): Promise<PagarMeCard>;
15
16
  createTransaction(info: any): Promise<PaymentTransaction>;
16
17
  private createCardPayment;
@@ -1,3 +1,4 @@
1
+ import { Shops } from '../../../../domain';
1
2
  import { BusinessUnitEnum } from '../../../../domain/shopping/enums';
2
3
  import { PaymentProviderCard } from '../../../../domain/shopping/interfaces';
3
4
  import { Checkout, Payment, PaymentTransaction } from '../../../../domain/shopping/models';
@@ -10,7 +11,8 @@ export declare class PagarmeV5CardAxiosAdapter implements PaymentProviderCard<Pa
10
11
  constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
11
12
  pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
12
13
  addCard(card: CardInfo): Promise<PagarMeCard>;
13
- createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum): Promise<PagarMeCardManualHash>;
14
- getCardByToken(id: string): Promise<PagarMeCard>;
14
+ createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum, shop?: Shops): Promise<PagarMeCardManualHash>;
15
+ getCardByToken(token: string): Promise<PagarMeCard>;
16
+ getCardByToken(customerId: string, token: string): Promise<PagarMeCard>;
15
17
  createTransaction(info: any): Promise<PaymentTransaction>;
16
18
  }
@@ -34,6 +34,7 @@ export type PagarMeV5Orderitems = {
34
34
  amount: number;
35
35
  description: string;
36
36
  quantity: number;
37
+ code?: string;
37
38
  };
38
39
  export type PagarMeV5OrderPaymentInfo = {
39
40
  payment_method: 'boleto' | 'pix' | 'credit_card';
@@ -41,7 +41,7 @@ export type PagarMeV5Charger = {
41
41
  code: string;
42
42
  gateway_id: string;
43
43
  amount: number;
44
- status: PagarMeV5PaymentStatus;
44
+ status: PagarMeV5OrderStatus;
45
45
  currency: string;
46
46
  payment_method: string;
47
47
  paid_amount: number;
@@ -65,7 +65,7 @@ export type PagarMeV5Transaction = {
65
65
  transaction_type?: string;
66
66
  gateway_id?: string;
67
67
  amount: number;
68
- status?: string;
68
+ status?: PagarMeV5PaymentStatus;
69
69
  success: boolean;
70
70
  installments: number;
71
71
  installment_type?: string;
@@ -103,7 +103,7 @@ export type PagarMeV5Transaction = {
103
103
  type: string;
104
104
  created_at: string;
105
105
  updated_at: string;
106
- billing_address: {
106
+ billing_address?: {
107
107
  zip_code: string;
108
108
  city: string;
109
109
  state: string;
@@ -112,10 +112,10 @@ export type PagarMeV5Transaction = {
112
112
  };
113
113
  };
114
114
  gateway_response?: {
115
- code: '404';
116
- errors: [
115
+ code: string;
116
+ errors?: [
117
117
  {
118
- message: 'Card not found';
118
+ message?: string;
119
119
  }
120
120
  ];
121
121
  };