@infrab4a/connect 5.2.0-beta.1 → 5.2.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.
Files changed (40) hide show
  1. package/index.cjs.js +82 -519
  2. package/index.esm.js +83 -517
  3. package/package.json +1 -1
  4. package/src/domain/catalog/models/product-base.d.ts +3 -1
  5. package/src/domain/catalog/repositories/product.repository.d.ts +3 -0
  6. package/src/domain/catalog/repositories/variant.repository.d.ts +1 -0
  7. package/src/domain/shopping/enums/index.d.ts +0 -2
  8. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +2 -10
  9. package/src/domain/shopping/models/payment-transaction.d.ts +2 -17
  10. package/src/domain/shopping/models/payment.d.ts +1 -2
  11. package/src/domain/shopping/types/card-info.type.d.ts +0 -1
  12. package/src/domain/shopping/types/index.d.ts +0 -1
  13. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +3 -9
  14. package/src/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +4 -1
  15. package/src/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +1 -0
  16. package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +3 -0
  17. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -0
  18. package/src/infra/pagarme/adapters/helpers/index.d.ts +0 -2
  19. package/src/infra/pagarme/adapters/index.d.ts +3 -2
  20. package/src/infra/pagarme/adapters/{v4/pagarme-bank-slip-payment-axios.adapter.d.ts → pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
  21. package/src/infra/pagarme/adapters/{v4/pagarme-card-payment-axios.adapter.d.ts → pagarme-card-payment-axios.adapter.d.ts} +6 -7
  22. package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +11 -0
  23. package/src/infra/pagarme/index.d.ts +0 -1
  24. package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +0 -24
  25. package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +0 -5
  26. package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +0 -4
  27. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +0 -12
  28. package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +0 -10
  29. package/src/infra/pagarme/adapters/v4/index.d.ts +0 -3
  30. package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +0 -11
  31. package/src/infra/pagarme/adapters/v5/index.d.ts +0 -3
  32. package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +0 -11
  33. package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +0 -24
  34. package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +0 -10
  35. package/src/infra/pagarme/types/index.d.ts +0 -1
  36. package/src/infra/pagarme/types/v5/index.d.ts +0 -4
  37. package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +0 -19
  38. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +0 -89
  39. package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +0 -126
  40. 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;
@@ -4925,6 +4891,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4925
4891
  productVariantFullReport() {
4926
4892
  return;
4927
4893
  }
4894
+ getByEAN(EAN, options) {
4895
+ return;
4896
+ }
4928
4897
  }
4929
4898
  tslib.__decorate([
4930
4899
  Log(),
@@ -4950,6 +4919,9 @@ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirest
4950
4919
  });
4951
4920
  this.parentRepository = parentRepository;
4952
4921
  }
4922
+ getByEAN(EAN) {
4923
+ return;
4924
+ }
4953
4925
  }
4954
4926
 
4955
4927
  class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
@@ -6186,7 +6158,8 @@ class CategoryProductOperationsHelper {
6186
6158
  'isKit',
6187
6159
  'sku',
6188
6160
  'rate',
6189
- 'tags',
6161
+ 'tagsProfile',
6162
+ 'tagsCollection',
6190
6163
  'type',
6191
6164
  'shoppingCount',
6192
6165
  'gender',
@@ -7407,7 +7380,7 @@ const commonFields = [
7407
7380
  'weight',
7408
7381
  'gender',
7409
7382
  { intGender: { columnName: 'int_gender' } },
7410
- { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
7383
+ // { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
7411
7384
  { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7412
7385
  { isKit: { columnName: 'is_kit' } },
7413
7386
  { createdAt: { columnName: 'created_at' } },
@@ -7425,6 +7398,9 @@ const commonFields = [
7425
7398
  },
7426
7399
  'group',
7427
7400
  'validity',
7401
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7402
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7403
+ { daysOfUse: { columnName: 'days_of_use' } },
7428
7404
  ];
7429
7405
  const fieldsConfiguration$2 = [
7430
7406
  ...commonFields,
@@ -7482,6 +7458,13 @@ const fieldsConfiguration$2 = [
7482
7458
  }),
7483
7459
  },
7484
7460
  },
7461
+ {
7462
+ variants: {
7463
+ columnName: 'variants',
7464
+ foreignKeyColumn: { product_id: 'id' },
7465
+ fields: ['id', 'ean', 'grade', 'price', 'published', 'stock', 'tagsProfile'],
7466
+ },
7467
+ },
7485
7468
  ];
7486
7469
  class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7487
7470
  get reviewsFields() {
@@ -7607,6 +7590,39 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7607
7590
  }
7608
7591
  return product;
7609
7592
  }
7593
+ async getByEAN(EAN, options) {
7594
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7595
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7596
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7597
+ if (cachedData) {
7598
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7599
+ return this.model.toInstance(deserialize(cachedData));
7600
+ }
7601
+ }
7602
+ const result = await this.find({
7603
+ filters: {
7604
+ EAN,
7605
+ },
7606
+ fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
7607
+ options: {
7608
+ enableCount: false,
7609
+ },
7610
+ });
7611
+ if (!result.data.length)
7612
+ return null;
7613
+ const product = result?.data?.shift();
7614
+ RoundProductPricesHelper.roundProductPrices(product);
7615
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7616
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7617
+ await this.cache.cacheAdapter.set({
7618
+ key: cacheKey,
7619
+ data: serialize(product),
7620
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7621
+ });
7622
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7623
+ }
7624
+ return product;
7625
+ }
7610
7626
  async update(params) {
7611
7627
  const { kitProducts, reviews, id: checkId, metadata, ...data } = lodash.omit(params, ['categories', 'rate']);
7612
7628
  const plainData = this.paramsToPlain({ id: checkId });
@@ -7851,6 +7867,12 @@ tslib.__decorate([
7851
7867
  tslib.__metadata("design:paramtypes", [String, Object]),
7852
7868
  tslib.__metadata("design:returntype", Promise)
7853
7869
  ], ProductHasuraGraphQLRepository.prototype, "getBySlug", null);
7870
+ tslib.__decorate([
7871
+ Log(),
7872
+ tslib.__metadata("design:type", Function),
7873
+ tslib.__metadata("design:paramtypes", [String, Object]),
7874
+ tslib.__metadata("design:returntype", Promise)
7875
+ ], ProductHasuraGraphQLRepository.prototype, "getByEAN", null);
7854
7876
  tslib.__decorate([
7855
7877
  Log(),
7856
7878
  tslib.__metadata("design:type", Function),
@@ -7906,6 +7928,13 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7906
7928
  { orderId: { columnName: 'order_id' } },
7907
7929
  { createdAt: { columnName: 'created_at' } },
7908
7930
  { updatedAt: { columnName: 'updated_at' } },
7931
+ {
7932
+ product: {
7933
+ columnName: 'product',
7934
+ foreignKeyColumn: { id: 'productId' },
7935
+ fields: ['id', 'ean', 'sku', 'name', 'brand', 'slug', 'images', 'grade', 'gender'],
7936
+ },
7937
+ },
7909
7938
  ],
7910
7939
  cache,
7911
7940
  });
@@ -8097,8 +8126,11 @@ const fieldsConfiguration$1 = [
8097
8126
  },
8098
8127
  'group',
8099
8128
  'validity',
8100
- { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
8129
+ // { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
8101
8130
  'published',
8131
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8132
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8133
+ { daysOfUse: { columnName: 'days_of_use' } },
8102
8134
  ];
8103
8135
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8104
8136
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8127,6 +8159,17 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8127
8159
  const { filters, ...options } = params || {};
8128
8160
  return super.find({ ...options, filters: { productId: { operator: exports.Where.ISNOTNULL }, ...filters } });
8129
8161
  }
8162
+ async getByEAN(EAN) {
8163
+ const { data } = await this.find({
8164
+ filters: {
8165
+ EAN,
8166
+ },
8167
+ options: {
8168
+ enableCount: false,
8169
+ },
8170
+ });
8171
+ return data.at(0);
8172
+ }
8130
8173
  async update(params) {
8131
8174
  const { productId, id: checkId, ...data } = params;
8132
8175
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
@@ -8620,201 +8663,6 @@ class PagarmePaymentOperationsHelper {
8620
8663
  }
8621
8664
  }
8622
8665
 
8623
- class PagarMeV5RequestHelper {
8624
- static build(checkout, method, card) {
8625
- return {
8626
- items: this.buildItems(checkout),
8627
- customer: this.buildCustomer(checkout),
8628
- shipping: this.buildShipping(checkout),
8629
- payments: this.buildPayment(checkout, method, card),
8630
- };
8631
- }
8632
- static buildItems(checkout) {
8633
- return checkout.lineItems
8634
- .filter((item) => !item.isGift)
8635
- .map((item) => {
8636
- return {
8637
- amount: Math.floor(item.pricePaid * 100),
8638
- description: item.name,
8639
- quantity: item.quantity,
8640
- code: item.EAN,
8641
- };
8642
- });
8643
- }
8644
- static buildCustomer(checkout) {
8645
- return {
8646
- name: checkout.user.displayName,
8647
- email: checkout.user.email,
8648
- type: 'individual',
8649
- document: checkout.user.cpf,
8650
- phones: {
8651
- home_phone: {
8652
- country_code: '55',
8653
- number: checkout.user.phone.slice(2),
8654
- area_code: checkout.user.phone.slice(0, 2),
8655
- },
8656
- mobile_phone: {
8657
- country_code: '55',
8658
- number: checkout.user.phone.slice(2),
8659
- area_code: checkout.user.phone.slice(0, 2),
8660
- },
8661
- },
8662
- address: {
8663
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8664
- line_2: `${checkout.billingAddress.extension}`,
8665
- zip_code: checkout.shippingAddress.zip,
8666
- city: checkout.billingAddress.city,
8667
- state: checkout.billingAddress.state,
8668
- country: 'BR',
8669
- },
8670
- };
8671
- }
8672
- static buildShipping(checkout) {
8673
- return {
8674
- amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8675
- description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8676
- recipient_name: checkout.shippingAddress.recipient,
8677
- recipient_phone: checkout.user.phone,
8678
- address: {
8679
- line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8680
- line_2: `${checkout.shippingAddress.extension}`,
8681
- zip_code: checkout.shippingAddress.zip,
8682
- city: checkout.shippingAddress.city,
8683
- state: checkout.shippingAddress.state,
8684
- country: 'BR',
8685
- },
8686
- };
8687
- }
8688
- static buildPayment(checkout, method, card) {
8689
- return [
8690
- {
8691
- payment_method: method,
8692
- amount: Math.floor(checkout.totalPrice * 100),
8693
- ...(method === 'pix' && {
8694
- pix: this.getPixOrder(),
8695
- }),
8696
- ...(method === 'boleto' && {
8697
- boleto: this.getBoletoOrder(),
8698
- }),
8699
- ...(method === 'credit_card' && {
8700
- credit_card: this.getCardOrder(checkout, card),
8701
- }),
8702
- },
8703
- ];
8704
- }
8705
- static getPixOrder() {
8706
- return {
8707
- expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
8708
- };
8709
- }
8710
- static getBoletoOrder() {
8711
- return {
8712
- due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
8713
- instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
8714
- type: 'DM',
8715
- document_number: new Date().getTime().toString(),
8716
- };
8717
- }
8718
- static getCardOrder(checkout, card) {
8719
- return {
8720
- installments: card.installments,
8721
- statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
8722
- card_id: card.cardId,
8723
- card: {
8724
- cvv: card.cardCvv,
8725
- billing_address: {
8726
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8727
- zip_code: checkout.billingAddress.zip,
8728
- city: checkout.billingAddress.city,
8729
- state: checkout.billingAddress.state,
8730
- country: 'BR',
8731
- },
8732
- },
8733
- };
8734
- }
8735
- }
8736
-
8737
- class PagarMeV5ResponseHelper {
8738
- static build(method, checkout, response) {
8739
- return Payment.toInstance({
8740
- createdAt: new Date(),
8741
- updatedAt: new Date(),
8742
- userId: checkout.user.id,
8743
- checkoutId: checkout.id,
8744
- totalPrice: checkout.totalPrice,
8745
- paymentProvider: exports.PaymentProviders.PAGARME,
8746
- pagarMeOrderId: response.id,
8747
- transaction: this.buildPaymentTransaction(method, response),
8748
- });
8749
- }
8750
- static buildPaymentTransaction(method, response) {
8751
- const charger = response.charges.at(0);
8752
- const transaction = charger.last_transaction;
8753
- return PaymentTransaction.toInstance({
8754
- acquirer_name: 'pagar_me',
8755
- amount: charger.amount,
8756
- currency: charger.currency,
8757
- gateway_id: charger.gateway_id,
8758
- status: this.getPaymentStatus(transaction.status),
8759
- payment_method: charger.payment_method,
8760
- date_created: charger.created_at,
8761
- date_updated: charger.updated_at,
8762
- paid_amount: charger.paid_amount,
8763
- paid_at: charger.paid_at,
8764
- order_id: response.id,
8765
- charger_id: charger.id,
8766
- tid: charger.id,
8767
- id: charger.id,
8768
- ...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8769
- ...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8770
- ...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8771
- });
8772
- }
8773
- static getPaymentStatus(status) {
8774
- if (status == exports.PagarMeV5PaymentStatus.Gerado)
8775
- return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
8776
- if (status == exports.PagarMeV5PaymentStatus.Capturada)
8777
- return exports.PagarMeV5PaymentStatus.Pago;
8778
- return status;
8779
- }
8780
- static getBoletoReponse(transaction) {
8781
- return {
8782
- boleto_url: transaction.url?.toString(),
8783
- boleto_barcode: transaction.barcode?.toString(),
8784
- boleto_qr_code: transaction.qr_code?.toString(),
8785
- boleto_expiration_date: transaction.due_at?.toString(),
8786
- boleto_instructions: transaction.instructions?.toString(),
8787
- boleto_nosso_numero: transaction.nosso_numero?.toString(),
8788
- boleto_type: transaction.type?.toString(),
8789
- boleto_document_number: transaction.document_number?.toString(),
8790
- };
8791
- }
8792
- static getPixReponse(transaction) {
8793
- return {
8794
- pix_qr_code: transaction.qr_code?.toString(),
8795
- pix_qr_code_url: transaction.qr_code_url?.toString(),
8796
- pix_expiration_date: transaction.expires_at?.toString(),
8797
- };
8798
- }
8799
- static getCardReponse(transaction) {
8800
- return {
8801
- soft_descriptor: transaction.statement_descriptor?.toString(),
8802
- acquirer_name: transaction.acquirer_name?.toString(),
8803
- acquirer_id: transaction.acquirer_tid?.toString(),
8804
- acquirer_nsu: transaction.acquirer_nsu?.toString(),
8805
- acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8806
- acquirer_message: transaction.acquirer_message?.toString(),
8807
- acquirer_return_code: transaction.acquirer_return_code?.toString(),
8808
- installments: transaction.installments ?? null,
8809
- card_holder_name: transaction.card?.holder_name?.toString(),
8810
- card_last_digits: transaction.card?.last_four_digits?.toString(),
8811
- card_first_digits: transaction.card?.first_six_digits?.toString(),
8812
- card_brand: transaction.card?.brand?.toString(),
8813
- card_id: transaction.card?.id?.toString(),
8814
- };
8815
- }
8816
- }
8817
-
8818
8666
  class PagarmeCardAxiosAdapter {
8819
8667
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8820
8668
  this.credentials = credentials;
@@ -8871,9 +8719,8 @@ class PagarmeCardAxiosAdapter {
8871
8719
  });
8872
8720
  }
8873
8721
  }
8874
- async createCardHash(bu, shop) {
8875
- const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
8876
- const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8722
+ async createCardHash(bu) {
8723
+ const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8877
8724
  try {
8878
8725
  const { data } = await axios__default["default"]({
8879
8726
  method: 'GET',
@@ -9036,287 +8883,6 @@ class PagarmePixAxiosAdapter {
9036
8883
  }
9037
8884
  }
9038
8885
 
9039
- class PagarmeV5BankSlipAxiosAdapter {
9040
- constructor(credentials, paymentRepository) {
9041
- this.credentials = credentials;
9042
- this.paymentRepository = paymentRepository;
9043
- }
9044
- async pay(checkout) {
9045
- try {
9046
- const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9047
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9048
- const { data } = await axios__default["default"]({
9049
- method: 'POST',
9050
- url: `${this.credentials.URL}/orders`,
9051
- headers: {
9052
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9053
- 'Content-Type': 'application/json',
9054
- },
9055
- data: payload,
9056
- });
9057
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9058
- if (data.status === exports.PagarMeV5OrderStatus.Falha ||
9059
- data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9060
- (data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
9061
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
9062
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9063
- checkoutId: checkout.id,
9064
- userEmail: checkout.user.email,
9065
- info: data.charges.at(0).last_transaction?.gateway_response,
9066
- }));
9067
- }
9068
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
9069
- return payment;
9070
- }
9071
- catch (error) {
9072
- console.error('Full error: ', JSON.stringify(error));
9073
- if (error instanceof axios.AxiosError) {
9074
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9075
- }
9076
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9077
- checkoutId: checkout.id,
9078
- userEmail: checkout.user.email,
9079
- info: error.response?.data,
9080
- });
9081
- }
9082
- }
9083
- async getBoletoTransaction(paymentId) {
9084
- try {
9085
- const { data } = await axios__default["default"]({
9086
- method: 'GET',
9087
- url: `${this.credentials.URL}/charges/${paymentId}`,
9088
- headers: {
9089
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9090
- 'Content-Type': 'application/json',
9091
- },
9092
- });
9093
- const payment = await this.paymentRepository.get({
9094
- id: data.id,
9095
- });
9096
- return payment.transaction;
9097
- }
9098
- catch (error) {
9099
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9100
- paymentId,
9101
- info: error.response.data,
9102
- });
9103
- }
9104
- }
9105
- }
9106
-
9107
- class PagarmeV5CardAxiosAdapter {
9108
- constructor(credentials, paymentRepository, orderBlockedRepository) {
9109
- this.credentials = credentials;
9110
- this.paymentRepository = paymentRepository;
9111
- this.orderBlockedRepository = orderBlockedRepository;
9112
- }
9113
- async pay(checkout, card) {
9114
- try {
9115
- const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9116
- console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9117
- const { data } = await axios__default["default"]({
9118
- method: 'POST',
9119
- url: `${this.credentials.URL}/orders`,
9120
- headers: {
9121
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9122
- 'Content-Type': 'application/json',
9123
- },
9124
- data: payload,
9125
- });
9126
- console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9127
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9128
- data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
9129
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
9130
- await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9131
- checkout,
9132
- card,
9133
- orderBlockedRepository: this.orderBlockedRepository,
9134
- });
9135
- throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9136
- }
9137
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9138
- return payment;
9139
- }
9140
- catch (error) {
9141
- if (error instanceof PaymentError) {
9142
- throw error;
9143
- }
9144
- console.error('Full error: ', JSON.stringify(error));
9145
- if (error instanceof axios.AxiosError) {
9146
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9147
- }
9148
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9149
- }
9150
- }
9151
- async addCard(card, customer) {
9152
- try {
9153
- const { id } = await this.createOrUpdateCustomer(customer);
9154
- const { data } = await axios__default["default"]({
9155
- method: 'POST',
9156
- url: `${this.credentials.URL}/customers/${id}/cards`,
9157
- headers: {
9158
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9159
- 'Content-Type': 'application/json',
9160
- },
9161
- data: {
9162
- number: card.number,
9163
- holder_name: card.name,
9164
- holder_document: card.cpf,
9165
- exp_month: card.expirationDate.split('/').at(0),
9166
- exp_year: card.expirationDate.split('/').at(1),
9167
- cvv: card.cvv,
9168
- brand: card.flag,
9169
- label: card.flag,
9170
- billing_address: {
9171
- line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9172
- line_2: `${customer.billingAddress.extension}`,
9173
- zip_code: customer.billingAddress.zip,
9174
- city: customer.billingAddress.city,
9175
- state: customer.billingAddress.state,
9176
- country: 'BR',
9177
- },
9178
- },
9179
- });
9180
- return data;
9181
- }
9182
- catch (error) {
9183
- console.warn(error);
9184
- throw error;
9185
- }
9186
- }
9187
- async createCardHash(bu, shop) {
9188
- const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
9189
- const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9190
- try {
9191
- const { data } = await axios__default["default"]({
9192
- method: 'GET',
9193
- headers: {
9194
- 'content-type': 'application/json',
9195
- },
9196
- url: `${this.credentials.URL}/transactions/card_hash_key`,
9197
- data: JSON.stringify({
9198
- api_key: key,
9199
- }),
9200
- });
9201
- return data;
9202
- }
9203
- catch (error) {
9204
- throw new BusinessError('Houve uma falha gerar o hash', {
9205
- info: error.response.data,
9206
- });
9207
- }
9208
- }
9209
- async getCardByToken(customerId, token) {
9210
- try {
9211
- const { data } = await axios__default["default"]({
9212
- method: 'GET',
9213
- url: `${this.credentials.URL}/cards/${token}`,
9214
- data: {
9215
- api_key: this.credentials.API_KEY,
9216
- },
9217
- });
9218
- return data;
9219
- }
9220
- catch (error) {
9221
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9222
- info: error.response.data,
9223
- });
9224
- }
9225
- }
9226
- async createTransaction(info) {
9227
- return info;
9228
- }
9229
- async createOrUpdateCustomer(customer) {
9230
- try {
9231
- const { data } = await axios__default["default"]({
9232
- method: 'POST',
9233
- url: `${this.credentials.URL}/customers`,
9234
- headers: {
9235
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9236
- 'Content-Type': 'application/json',
9237
- },
9238
- data: {
9239
- name: customer.displayName,
9240
- email: customer.email,
9241
- document: customer.cpf,
9242
- type: 'individual',
9243
- document_type: 'CPF',
9244
- address: {
9245
- line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9246
- line_2: `${customer.billingAddress.extension}`,
9247
- zip_code: customer.billingAddress.zip,
9248
- city: customer.billingAddress.city,
9249
- state: customer.billingAddress.state,
9250
- country: 'BR',
9251
- },
9252
- birthdate: dateFns.format(new Date(customer.birthday), 'MM/dd/yyyy'),
9253
- phones: {
9254
- home_phone: {
9255
- country_code: '55',
9256
- number: customer.phone.slice(2),
9257
- area_code: customer.phone.slice(0, 2),
9258
- },
9259
- mobile_phone: {
9260
- country_code: '55',
9261
- number: customer.phone.slice(2),
9262
- area_code: customer.phone.slice(0, 2),
9263
- },
9264
- },
9265
- },
9266
- });
9267
- return data;
9268
- }
9269
- catch (error) {
9270
- console.warn(error);
9271
- throw error;
9272
- }
9273
- }
9274
- }
9275
-
9276
- class PagarmeV5PixAxiosAdapter {
9277
- constructor(credentials, paymentRepository) {
9278
- this.credentials = credentials;
9279
- this.paymentRepository = paymentRepository;
9280
- }
9281
- async pay(checkout) {
9282
- try {
9283
- const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9284
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9285
- const { data } = await axios__default["default"]({
9286
- method: 'POST',
9287
- url: `${this.credentials.URL}/orders`,
9288
- headers: {
9289
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9290
- 'Content-Type': 'application/json',
9291
- },
9292
- data: payload,
9293
- });
9294
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9295
- if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
9296
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9297
- checkoutId: checkout.id,
9298
- userEmail: checkout.user.email,
9299
- info: data.charges.at(0).last_transaction?.gateway_response,
9300
- });
9301
- }
9302
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9303
- return payment;
9304
- }
9305
- catch (error) {
9306
- console.error('Full error: ', JSON.stringify(error));
9307
- if (error instanceof axios.AxiosError) {
9308
- console.error('Error: ', error.message);
9309
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9310
- }
9311
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9312
- checkoutId: checkout.id,
9313
- userEmail: checkout.user.email,
9314
- info: error.response?.data,
9315
- });
9316
- }
9317
- }
9318
- }
9319
-
9320
8886
  class VertexAxiosAdapter {
9321
8887
  constructor(config) {
9322
8888
  this.config = config;
@@ -9673,9 +9239,6 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
9673
9239
  exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
9674
9240
  exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
9675
9241
  exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
9676
- exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
9677
- exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
9678
- exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
9679
9242
  exports.Payment = Payment;
9680
9243
  exports.PaymentError = PaymentError;
9681
9244
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;