@infrab4a/connect 5.1.0-beta.8 → 5.1.1-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 (31) hide show
  1. package/index.cjs.js +13 -529
  2. package/index.esm.js +14 -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 -2
  6. package/src/domain/shopping/models/payment-transaction.d.ts +2 -16
  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 -17
  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.esm.js CHANGED
@@ -48,33 +48,6 @@ var PagarmePaymentStatus;
48
48
  PagarmePaymentStatus["Chargedback"] = "chargedback";
49
49
  })(PagarmePaymentStatus || (PagarmePaymentStatus = {}));
50
50
 
51
- var PagarMeV5PaymentStatus;
52
- (function (PagarMeV5PaymentStatus) {
53
- PagarMeV5PaymentStatus["Em processamento"] = "processing";
54
- PagarMeV5PaymentStatus["Gerado"] = "generated";
55
- PagarMeV5PaymentStatus["Visualizado"] = "viewed";
56
- PagarMeV5PaymentStatus["Pago a menor"] = "underpaid";
57
- PagarMeV5PaymentStatus["Pago a maior"] = "overpaid";
58
- PagarMeV5PaymentStatus["Aguardando pagamento"] = "waiting_payment";
59
- PagarMeV5PaymentStatus["Pago"] = "paid";
60
- PagarMeV5PaymentStatus["Aguardando estorno"] = "pending_refund";
61
- PagarMeV5PaymentStatus["Autorizada pendente de captura"] = "authorized_pending_capture";
62
- PagarMeV5PaymentStatus["N\u00E3o autorizada"] = "not_authorized";
63
- PagarMeV5PaymentStatus["Capturada"] = "captured";
64
- PagarMeV5PaymentStatus["Aguardando captura"] = "waiting_capture";
65
- PagarMeV5PaymentStatus["Com erro"] = "with_error";
66
- PagarMeV5PaymentStatus["Estornado"] = "refunded";
67
- PagarMeV5PaymentStatus["Cancelado"] = "voided";
68
- PagarMeV5PaymentStatus["Falha"] = "failed";
69
- })(PagarMeV5PaymentStatus || (PagarMeV5PaymentStatus = {}));
70
- var PagarMeV5OrderStatus;
71
- (function (PagarMeV5OrderStatus) {
72
- PagarMeV5OrderStatus["Pendente"] = "pending";
73
- PagarMeV5OrderStatus["Pago"] = "paid";
74
- PagarMeV5OrderStatus["Cancelado"] = "canceled";
75
- PagarMeV5OrderStatus["Falha"] = "failed";
76
- })(PagarMeV5OrderStatus || (PagarMeV5OrderStatus = {}));
77
-
78
51
  var PaymentMethods;
79
52
  (function (PaymentMethods) {
80
53
  PaymentMethods["CARD"] = "card";
@@ -90,13 +63,6 @@ var PaymentProviders;
90
63
  PaymentProviders["GLAMPOINTS"] = "glampoints";
91
64
  })(PaymentProviders || (PaymentProviders = {}));
92
65
 
93
- var TransactionPaymentMethods;
94
- (function (TransactionPaymentMethods) {
95
- TransactionPaymentMethods["CARD"] = "credit_card";
96
- TransactionPaymentMethods["BANKSLIP"] = "boleto";
97
- TransactionPaymentMethods["PIX"] = "pix";
98
- })(TransactionPaymentMethods || (TransactionPaymentMethods = {}));
99
-
100
66
  class BasePaymentMethodFactory {
101
67
  constructor(methods) {
102
68
  this.methods = methods;
@@ -7632,13 +7598,23 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7632
7598
  return reviews;
7633
7599
  }
7634
7600
  async findCatalog(params, mainGender, options) {
7635
- const result = await this.find({
7601
+ // eslint-disable-next-line no-console
7602
+ console.log(JSON.stringify({
7636
7603
  ...params,
7637
7604
  filters: { ...params.filters, published: true },
7638
7605
  orderBy: {
7606
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7607
+ ...omit(params.orderBy, ['hasStock', 'intGender']),
7639
7608
  hasStock: 'desc',
7609
+ },
7610
+ }));
7611
+ const result = await this.find({
7612
+ ...params,
7613
+ filters: { ...params.filters, published: true },
7614
+ orderBy: {
7640
7615
  ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
7641
7616
  ...omit(params.orderBy, ['hasStock', 'intGender']),
7617
+ hasStock: 'desc',
7642
7618
  },
7643
7619
  }, options);
7644
7620
  return result;
@@ -8569,186 +8545,6 @@ class PagarmePaymentOperationsHelper {
8569
8545
  }
8570
8546
  }
8571
8547
 
8572
- class PagarMeV5RequestHelper {
8573
- static build(checkout, method, card) {
8574
- return {
8575
- items: this.buildItems(checkout),
8576
- customer: this.buildCustomer(checkout),
8577
- shipping: this.buildShipping(checkout),
8578
- payments: this.buildPayment(checkout, method, card),
8579
- };
8580
- }
8581
- static buildItems(checkout) {
8582
- return checkout.lineItems
8583
- .filter((item) => !item.isGift)
8584
- .map((item) => {
8585
- return {
8586
- amount: Math.floor(item.pricePaid * 100),
8587
- description: item.name,
8588
- quantity: item.quantity,
8589
- code: item.EAN,
8590
- };
8591
- });
8592
- }
8593
- static buildCustomer(checkout) {
8594
- return {
8595
- name: checkout.user.displayName,
8596
- email: checkout.user.email,
8597
- type: 'individual',
8598
- document: checkout.user.cpf,
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
- },
8605
- mobile_phone: {
8606
- country_code: '55',
8607
- number: checkout.user.phone.slice(2),
8608
- area_code: checkout.user.phone.slice(0, 2),
8609
- },
8610
- },
8611
- address: {
8612
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8613
- line_2: `${checkout.billingAddress.extension}`,
8614
- zip_code: checkout.shippingAddress.zip,
8615
- city: checkout.billingAddress.city,
8616
- state: checkout.billingAddress.state,
8617
- country: 'BR',
8618
- },
8619
- };
8620
- }
8621
- static buildShipping(checkout) {
8622
- return {
8623
- amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8624
- description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8625
- recipient_name: checkout.shippingAddress.recipient,
8626
- recipient_phone: checkout.user.phone,
8627
- address: {
8628
- line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8629
- line_2: `${checkout.shippingAddress.extension}`,
8630
- zip_code: checkout.shippingAddress.zip,
8631
- city: checkout.shippingAddress.city,
8632
- state: checkout.shippingAddress.state,
8633
- country: 'BR',
8634
- },
8635
- };
8636
- }
8637
- static buildPayment(checkout, method, card) {
8638
- return [
8639
- {
8640
- payment_method: method,
8641
- amount: Math.floor(checkout.totalPrice * 100),
8642
- ...(method === 'pix' && {
8643
- pix: this.getPixOrder(),
8644
- }),
8645
- ...(method === 'boleto' && {
8646
- boleto: this.getBoletoOrder(),
8647
- }),
8648
- ...(method === 'credit_card' && {
8649
- credit_card: this.getCardOrder(checkout, card),
8650
- }),
8651
- },
8652
- ];
8653
- }
8654
- static getPixOrder() {
8655
- return {
8656
- expires_at: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
8657
- };
8658
- }
8659
- static getBoletoOrder() {
8660
- return {
8661
- due_at: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
8662
- instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
8663
- type: 'DM',
8664
- document_number: new Date().getTime().toString(),
8665
- };
8666
- }
8667
- static getCardOrder(checkout, card) {
8668
- return {
8669
- installments: card.installments,
8670
- statement_descriptor: checkout.shop === Shops.GLAMSHOP ? 'Glam' : "Men's Market",
8671
- card_id: card.cardId,
8672
- card: {
8673
- cvv: card.cardCvv,
8674
- },
8675
- };
8676
- }
8677
- }
8678
-
8679
- class PagarMeV5ResponseHelper {
8680
- static build(method, checkout, response) {
8681
- return Payment.toInstance({
8682
- createdAt: new Date(),
8683
- updatedAt: new Date(),
8684
- userId: checkout.user.id,
8685
- checkoutId: checkout.id,
8686
- totalPrice: checkout.totalPrice,
8687
- paymentProvider: PaymentProviders.PAGARME,
8688
- pagarMeOrderId: response.id,
8689
- transaction: this.buildPaymentTransaction(method, response),
8690
- });
8691
- }
8692
- static buildPaymentTransaction(method, response) {
8693
- const charger = response.charges.at(0);
8694
- const transaction = charger.last_transaction;
8695
- return PaymentTransaction.toInstance({
8696
- acquirer_name: 'pagar_me',
8697
- amount: charger.amount,
8698
- currency: charger.currency,
8699
- gateway_id: charger.gateway_id,
8700
- status: charger.status,
8701
- payment_method: charger.payment_method,
8702
- date_created: charger.created_at,
8703
- date_updated: charger.updated_at,
8704
- paid_amount: charger.paid_amount,
8705
- paid_at: charger.paid_at,
8706
- order_id: response.id,
8707
- tid: transaction.id,
8708
- id: transaction.id,
8709
- ...(method == TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8710
- ...(method == TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8711
- ...(method == TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8712
- });
8713
- }
8714
- static getBoletoReponse(transaction) {
8715
- return {
8716
- boleto_url: transaction.url?.toString(),
8717
- boleto_barcode: transaction.barcode?.toString(),
8718
- boleto_qr_code: transaction.qr_code?.toString(),
8719
- boleto_expiration_date: transaction.due_at?.toString(),
8720
- boleto_instructions: transaction.instructions?.toString(),
8721
- boleto_nosso_numero: transaction.nosso_numero?.toString(),
8722
- boleto_type: transaction.type?.toString(),
8723
- boleto_document_number: transaction.document_number?.toString(),
8724
- };
8725
- }
8726
- static getPixReponse(transaction) {
8727
- return {
8728
- pix_qr_code: transaction.qr_code?.toString(),
8729
- pix_qr_code_url: transaction.qr_code_url?.toString(),
8730
- pix_expiration_date: transaction.expires_at?.toString(),
8731
- };
8732
- }
8733
- static getCardReponse(transaction) {
8734
- return {
8735
- soft_descriptor: transaction.statement_descriptor?.toString(),
8736
- acquirer_name: transaction.acquirer_name?.toString(),
8737
- acquirer_id: transaction.acquirer_tid?.toString(),
8738
- acquirer_nsu: transaction.acquirer_nsu?.toString(),
8739
- acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8740
- acquirer_message: transaction.acquirer_message?.toString(),
8741
- acquirer_return_code: transaction.acquirer_return_code?.toString(),
8742
- installments: transaction.installments ?? null,
8743
- card_holder_name: transaction.card?.holder_name?.toString(),
8744
- card_last_digits: transaction.card?.last_four_digits?.toString(),
8745
- card_first_digits: transaction.card?.first_six_digits?.toString(),
8746
- card_brand: transaction.card?.brand?.toString(),
8747
- card_id: transaction.card?.id?.toString(),
8748
- };
8749
- }
8750
- }
8751
-
8752
8548
  class PagarmeCardAxiosAdapter {
8753
8549
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8754
8550
  this.credentials = credentials;
@@ -8805,9 +8601,8 @@ class PagarmeCardAxiosAdapter {
8805
8601
  });
8806
8602
  }
8807
8603
  }
8808
- async createCardHash(bu, shop) {
8809
- const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
8810
- const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8604
+ async createCardHash(bu) {
8605
+ const key = bu === BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8811
8606
  try {
8812
8607
  const { data } = await axios({
8813
8608
  method: 'GET',
@@ -8970,314 +8765,6 @@ class PagarmePixAxiosAdapter {
8970
8765
  }
8971
8766
  }
8972
8767
 
8973
- class PagarmeV5BankSlipAxiosAdapter {
8974
- constructor(credentials, paymentRepository) {
8975
- this.credentials = credentials;
8976
- this.paymentRepository = paymentRepository;
8977
- }
8978
- async pay2(payload) {
8979
- try {
8980
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
8981
- const { data } = await axios({
8982
- method: 'POST',
8983
- url: `${this.credentials.URL}/orders`,
8984
- headers: {
8985
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
8986
- 'Content-Type': 'application/json',
8987
- },
8988
- data: payload,
8989
- });
8990
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
8991
- if (data.status == PagarMeV5OrderStatus.Falha ||
8992
- data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
8993
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado) {
8994
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8995
- // checkoutId: checkout.id,
8996
- // userEmail: checkout.user.email,
8997
- info: data,
8998
- }));
8999
- }
9000
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9001
- // const payment = await this.paymentRepository.create(paymentData)
9002
- return data;
9003
- }
9004
- catch (error) {
9005
- if (error instanceof AxiosError) {
9006
- console.error(error.message);
9007
- console.error(error.response.data);
9008
- }
9009
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9010
- // checkoutId: checkout.id,
9011
- // userEmail: checkout.user.email,
9012
- info: error.response.data,
9013
- });
9014
- }
9015
- }
9016
- async pay(checkout) {
9017
- try {
9018
- const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9019
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9020
- const { data } = await axios({
9021
- method: 'POST',
9022
- url: `${this.credentials.URL}/orders`,
9023
- headers: {
9024
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9025
- 'Content-Type': 'application/json',
9026
- },
9027
- data: payload,
9028
- });
9029
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9030
- if (data.status == PagarMeV5OrderStatus.Falha ||
9031
- data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
9032
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado) {
9033
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9034
- checkoutId: checkout.id,
9035
- userEmail: checkout.user.email,
9036
- info: data.charges.at(0).last_transaction?.gateway_response,
9037
- }));
9038
- }
9039
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.BANKSLIP, checkout, data));
9040
- return payment;
9041
- }
9042
- catch (error) {
9043
- console.error('Full error: ', JSON.stringify(error));
9044
- if (error instanceof AxiosError) {
9045
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9046
- }
9047
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9048
- checkoutId: checkout.id,
9049
- userEmail: checkout.user.email,
9050
- info: error.response?.data,
9051
- });
9052
- }
9053
- }
9054
- async getBoletoTransaction(paymentId) {
9055
- try {
9056
- const { data } = await axios({
9057
- method: 'GET',
9058
- url: `${this.credentials.URL}/charges/${paymentId}`,
9059
- headers: {
9060
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9061
- 'Content-Type': 'application/json',
9062
- },
9063
- });
9064
- const payment = await this.paymentRepository.get({
9065
- id: data.id,
9066
- });
9067
- return payment.transaction;
9068
- }
9069
- catch (error) {
9070
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9071
- paymentId,
9072
- info: error.response.data,
9073
- });
9074
- }
9075
- }
9076
- }
9077
-
9078
- class PagarmeV5CardAxiosAdapter {
9079
- constructor(credentials, paymentRepository, orderBlockedRepository) {
9080
- this.credentials = credentials;
9081
- this.paymentRepository = paymentRepository;
9082
- this.orderBlockedRepository = orderBlockedRepository;
9083
- }
9084
- async pay(checkout, card) {
9085
- try {
9086
- const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9087
- console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9088
- const { data } = await axios({
9089
- method: 'POST',
9090
- url: `${this.credentials.URL}/orders`,
9091
- headers: {
9092
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9093
- 'Content-Type': 'application/json',
9094
- },
9095
- data: payload,
9096
- });
9097
- console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9098
- if (data.status == PagarMeV5OrderStatus.Falha ||
9099
- data.charges.at(0).status !== PagarMeV5OrderStatus.Pago ||
9100
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Capturada) {
9101
- await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9102
- checkout,
9103
- card,
9104
- orderBlockedRepository: this.orderBlockedRepository,
9105
- });
9106
- throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9107
- }
9108
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.CARD, checkout, data));
9109
- return payment;
9110
- }
9111
- catch (error) {
9112
- if (error instanceof PaymentError) {
9113
- throw error;
9114
- }
9115
- console.error('Full error: ', JSON.stringify(error));
9116
- if (error instanceof AxiosError) {
9117
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9118
- }
9119
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9120
- }
9121
- }
9122
- // Dúvidas: preciso criar um cliente? como faz na mens?
9123
- async addCard(card) {
9124
- try {
9125
- const { data } = await axios({
9126
- method: 'POST',
9127
- url: `${this.credentials.URL}/cards`,
9128
- data: {
9129
- api_key: this.credentials.API_KEY,
9130
- card_number: card.number,
9131
- card_expiration_date: card.expirationDate.replace('/', ''),
9132
- card_holder_name: card.name,
9133
- card_cvv: card.cvv,
9134
- // number: '4000000000000010',
9135
- // holder_name: 'Tony Stark',
9136
- // holder_document: '93095135270',
9137
- // exp_month: 1,
9138
- // exp_year: 30,
9139
- // cvv: '351',
9140
- // brand: 'Mastercard',
9141
- // label: 'Sua bandeira',
9142
- // billing_address: {
9143
- // line_1: '375, Av. General Osorio, Centro',
9144
- // line_2: '7º Andar',
9145
- // zip_code: '220000111',
9146
- // city: 'Rio de Janeiro',
9147
- // state: 'RJ',
9148
- // country: 'BR',
9149
- // },
9150
- // options: {
9151
- // verify_card: true,
9152
- // },
9153
- },
9154
- });
9155
- return data;
9156
- }
9157
- catch (error) {
9158
- throw new BusinessError('Houve uma falha adicionar o cartão', {
9159
- info: error.response.data,
9160
- });
9161
- }
9162
- }
9163
- async createCardHash(bu, shop) {
9164
- const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
9165
- const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9166
- try {
9167
- const { data } = await axios({
9168
- method: 'GET',
9169
- headers: {
9170
- 'content-type': 'application/json',
9171
- },
9172
- url: `${this.credentials.URL}/transactions/card_hash_key`,
9173
- data: JSON.stringify({
9174
- api_key: key,
9175
- }),
9176
- });
9177
- return data;
9178
- }
9179
- catch (error) {
9180
- throw new BusinessError('Houve uma falha gerar o hash', {
9181
- info: error.response.data,
9182
- });
9183
- }
9184
- }
9185
- async getCardByToken(id) {
9186
- try {
9187
- const { data } = await axios({
9188
- method: 'GET',
9189
- url: `${this.credentials.URL}/cards/${id}`,
9190
- data: {
9191
- api_key: this.credentials.API_KEY,
9192
- },
9193
- });
9194
- return data;
9195
- }
9196
- catch (error) {
9197
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
9198
- info: error.response.data,
9199
- });
9200
- }
9201
- }
9202
- async createTransaction(info) {
9203
- return;
9204
- }
9205
- }
9206
-
9207
- class PagarmeV5PixAxiosAdapter {
9208
- constructor(credentials, paymentRepository) {
9209
- this.credentials = credentials;
9210
- this.paymentRepository = paymentRepository;
9211
- }
9212
- async pay2(payload) {
9213
- try {
9214
- // const payload = PagarMeV5RequestHelper.build(checkout, 'pix')
9215
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9216
- const { data } = await axios({
9217
- method: 'POST',
9218
- url: `${this.credentials.URL}/orders`,
9219
- headers: {
9220
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9221
- 'Content-Type': 'application/json',
9222
- },
9223
- data: payload,
9224
- });
9225
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9226
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9227
- // const payment = await this.paymentRepository.create(paymentData)
9228
- return data;
9229
- }
9230
- catch (error) {
9231
- if (error instanceof AxiosError) {
9232
- console.error(error.message);
9233
- console.error(error.response.data);
9234
- }
9235
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9236
- // checkoutId: checkout.id,
9237
- // userEmail: checkout.user.email,
9238
- info: error.response?.data,
9239
- });
9240
- }
9241
- }
9242
- async pay(checkout) {
9243
- try {
9244
- const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9245
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9246
- const { data } = await axios({
9247
- method: 'POST',
9248
- url: `${this.credentials.URL}/orders`,
9249
- headers: {
9250
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9251
- 'Content-Type': 'application/json',
9252
- },
9253
- data: payload,
9254
- });
9255
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9256
- if (data.status == PagarMeV5OrderStatus.Falha || data.status == PagarMeV5OrderStatus.Cancelado) {
9257
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9258
- checkoutId: checkout.id,
9259
- userEmail: checkout.user.email,
9260
- info: data.charges.at(0).last_transaction?.gateway_response,
9261
- });
9262
- }
9263
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.PIX, checkout, data));
9264
- return payment;
9265
- }
9266
- catch (error) {
9267
- console.error('Full error: ', JSON.stringify(error));
9268
- if (error instanceof AxiosError) {
9269
- console.error('Error: ', error.message);
9270
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9271
- }
9272
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9273
- checkoutId: checkout.id,
9274
- userEmail: checkout.user.email,
9275
- info: error.response?.data,
9276
- });
9277
- }
9278
- }
9279
- }
9280
-
9281
8768
  class VertexAxiosAdapter {
9282
8769
  constructor(config) {
9283
8770
  this.config = config;
@@ -9431,4 +8918,4 @@ class ProductsVertexSearch {
9431
8918
  }
9432
8919
  }
9433
8920
 
9434
- 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 };
8921
+ 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, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.1.0-beta.8",
3
+ "version": "5.1.1-beta.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -2,7 +2,5 @@ export * from './antifraud-providers.enum';
2
2
  export * from './business-unit.enum';
3
3
  export * from './order-blocked.enum';
4
4
  export * from './pagarme-payment-status.enum';
5
- export * from './pagarme-v5-payment-status.enum';
6
5
  export * from './payment-methods.enum';
7
6
  export * from './payment-providers.enum';
8
- export * from './transaction-payment-methods.enum';
@@ -1,4 +1,3 @@
1
- import { Shops } from '../../catalog';
2
1
  import { BusinessUnitEnum } from '../enums';
3
2
  import { PaymentTransaction } from '../models';
4
3
  import { Checkout } from '../models/checkout';
@@ -9,6 +8,6 @@ export interface PaymentProviderCard<Card extends BaseCard = BaseCard> {
9
8
  pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
10
9
  addCard(card: CardInfo): Promise<Card>;
11
10
  getCardByToken(token: string): Promise<Card>;
12
- createCardHash<T>(bu: BusinessUnitEnum, shop: Shops, card?: CardInfo): Promise<string | T>;
11
+ createCardHash<T>(bu: BusinessUnitEnum, card?: CardInfo): Promise<string | T>;
13
12
  createTransaction(info: any): Promise<PaymentTransaction>;
14
13
  }