@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.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;
@@ -4900,6 +4866,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
4900
4866
  productVariantFullReport() {
4901
4867
  return;
4902
4868
  }
4869
+ getByEAN(EAN, options) {
4870
+ return;
4871
+ }
4903
4872
  }
4904
4873
  __decorate([
4905
4874
  Log(),
@@ -4925,6 +4894,9 @@ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirest
4925
4894
  });
4926
4895
  this.parentRepository = parentRepository;
4927
4896
  }
4897
+ getByEAN(EAN) {
4898
+ return;
4899
+ }
4928
4900
  }
4929
4901
 
4930
4902
  class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
@@ -6161,7 +6133,8 @@ class CategoryProductOperationsHelper {
6161
6133
  'isKit',
6162
6134
  'sku',
6163
6135
  'rate',
6164
- 'tags',
6136
+ 'tagsProfile',
6137
+ 'tagsCollection',
6165
6138
  'type',
6166
6139
  'shoppingCount',
6167
6140
  'gender',
@@ -7382,7 +7355,7 @@ const commonFields = [
7382
7355
  'weight',
7383
7356
  'gender',
7384
7357
  { intGender: { columnName: 'int_gender' } },
7385
- { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
7358
+ // { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
7386
7359
  { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
7387
7360
  { isKit: { columnName: 'is_kit' } },
7388
7361
  { createdAt: { columnName: 'created_at' } },
@@ -7400,6 +7373,9 @@ const commonFields = [
7400
7373
  },
7401
7374
  'group',
7402
7375
  'validity',
7376
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
7377
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
7378
+ { daysOfUse: { columnName: 'days_of_use' } },
7403
7379
  ];
7404
7380
  const fieldsConfiguration$2 = [
7405
7381
  ...commonFields,
@@ -7457,6 +7433,13 @@ const fieldsConfiguration$2 = [
7457
7433
  }),
7458
7434
  },
7459
7435
  },
7436
+ {
7437
+ variants: {
7438
+ columnName: 'variants',
7439
+ foreignKeyColumn: { product_id: 'id' },
7440
+ fields: ['id', 'ean', 'grade', 'price', 'published', 'stock', 'tagsProfile'],
7441
+ },
7442
+ },
7460
7443
  ];
7461
7444
  class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7462
7445
  get reviewsFields() {
@@ -7582,6 +7565,39 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
7582
7565
  }
7583
7566
  return product;
7584
7567
  }
7568
+ async getByEAN(EAN, options) {
7569
+ if (this.cache?.cacheAdapter && options?.cache?.enabled) {
7570
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7571
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
7572
+ if (cachedData) {
7573
+ this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
7574
+ return this.model.toInstance(deserialize(cachedData));
7575
+ }
7576
+ }
7577
+ const result = await this.find({
7578
+ filters: {
7579
+ EAN,
7580
+ },
7581
+ fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
7582
+ options: {
7583
+ enableCount: false,
7584
+ },
7585
+ });
7586
+ if (!result.data.length)
7587
+ return null;
7588
+ const product = result?.data?.shift();
7589
+ RoundProductPricesHelper.roundProductPrices(product);
7590
+ if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
7591
+ const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
7592
+ await this.cache.cacheAdapter.set({
7593
+ key: cacheKey,
7594
+ data: serialize(product),
7595
+ expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
7596
+ });
7597
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
7598
+ }
7599
+ return product;
7600
+ }
7585
7601
  async update(params) {
7586
7602
  const { kitProducts, reviews, id: checkId, metadata, ...data } = omit(params, ['categories', 'rate']);
7587
7603
  const plainData = this.paramsToPlain({ id: checkId });
@@ -7826,6 +7842,12 @@ __decorate([
7826
7842
  __metadata("design:paramtypes", [String, Object]),
7827
7843
  __metadata("design:returntype", Promise)
7828
7844
  ], ProductHasuraGraphQLRepository.prototype, "getBySlug", null);
7845
+ __decorate([
7846
+ Log(),
7847
+ __metadata("design:type", Function),
7848
+ __metadata("design:paramtypes", [String, Object]),
7849
+ __metadata("design:returntype", Promise)
7850
+ ], ProductHasuraGraphQLRepository.prototype, "getByEAN", null);
7829
7851
  __decorate([
7830
7852
  Log(),
7831
7853
  __metadata("design:type", Function),
@@ -7881,6 +7903,13 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7881
7903
  { orderId: { columnName: 'order_id' } },
7882
7904
  { createdAt: { columnName: 'created_at' } },
7883
7905
  { updatedAt: { columnName: 'updated_at' } },
7906
+ {
7907
+ product: {
7908
+ columnName: 'product',
7909
+ foreignKeyColumn: { id: 'productId' },
7910
+ fields: ['id', 'ean', 'sku', 'name', 'brand', 'slug', 'images', 'grade', 'gender'],
7911
+ },
7912
+ },
7884
7913
  ],
7885
7914
  cache,
7886
7915
  });
@@ -8072,8 +8101,11 @@ const fieldsConfiguration$1 = [
8072
8101
  },
8073
8102
  'group',
8074
8103
  'validity',
8075
- { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
8104
+ // { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
8076
8105
  'published',
8106
+ { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8107
+ { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8108
+ { daysOfUse: { columnName: 'days_of_use' } },
8077
8109
  ];
8078
8110
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8079
8111
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8102,6 +8134,17 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
8102
8134
  const { filters, ...options } = params || {};
8103
8135
  return super.find({ ...options, filters: { productId: { operator: Where.ISNOTNULL }, ...filters } });
8104
8136
  }
8137
+ async getByEAN(EAN) {
8138
+ const { data } = await this.find({
8139
+ filters: {
8140
+ EAN,
8141
+ },
8142
+ options: {
8143
+ enableCount: false,
8144
+ },
8145
+ });
8146
+ return data.at(0);
8147
+ }
8105
8148
  async update(params) {
8106
8149
  const { productId, id: checkId, ...data } = params;
8107
8150
  const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
@@ -8595,201 +8638,6 @@ class PagarmePaymentOperationsHelper {
8595
8638
  }
8596
8639
  }
8597
8640
 
8598
- class PagarMeV5RequestHelper {
8599
- static build(checkout, method, card) {
8600
- return {
8601
- items: this.buildItems(checkout),
8602
- customer: this.buildCustomer(checkout),
8603
- shipping: this.buildShipping(checkout),
8604
- payments: this.buildPayment(checkout, method, card),
8605
- };
8606
- }
8607
- static buildItems(checkout) {
8608
- return checkout.lineItems
8609
- .filter((item) => !item.isGift)
8610
- .map((item) => {
8611
- return {
8612
- amount: Math.floor(item.pricePaid * 100),
8613
- description: item.name,
8614
- quantity: item.quantity,
8615
- code: item.EAN,
8616
- };
8617
- });
8618
- }
8619
- static buildCustomer(checkout) {
8620
- return {
8621
- name: checkout.user.displayName,
8622
- email: checkout.user.email,
8623
- type: 'individual',
8624
- document: checkout.user.cpf,
8625
- phones: {
8626
- home_phone: {
8627
- country_code: '55',
8628
- number: checkout.user.phone.slice(2),
8629
- area_code: checkout.user.phone.slice(0, 2),
8630
- },
8631
- mobile_phone: {
8632
- country_code: '55',
8633
- number: checkout.user.phone.slice(2),
8634
- area_code: checkout.user.phone.slice(0, 2),
8635
- },
8636
- },
8637
- address: {
8638
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8639
- line_2: `${checkout.billingAddress.extension}`,
8640
- zip_code: checkout.shippingAddress.zip,
8641
- city: checkout.billingAddress.city,
8642
- state: checkout.billingAddress.state,
8643
- country: 'BR',
8644
- },
8645
- };
8646
- }
8647
- static buildShipping(checkout) {
8648
- return {
8649
- amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8650
- description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8651
- recipient_name: checkout.shippingAddress.recipient,
8652
- recipient_phone: checkout.user.phone,
8653
- address: {
8654
- line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8655
- line_2: `${checkout.shippingAddress.extension}`,
8656
- zip_code: checkout.shippingAddress.zip,
8657
- city: checkout.shippingAddress.city,
8658
- state: checkout.shippingAddress.state,
8659
- country: 'BR',
8660
- },
8661
- };
8662
- }
8663
- static buildPayment(checkout, method, card) {
8664
- return [
8665
- {
8666
- payment_method: method,
8667
- amount: Math.floor(checkout.totalPrice * 100),
8668
- ...(method === 'pix' && {
8669
- pix: this.getPixOrder(),
8670
- }),
8671
- ...(method === 'boleto' && {
8672
- boleto: this.getBoletoOrder(),
8673
- }),
8674
- ...(method === 'credit_card' && {
8675
- credit_card: this.getCardOrder(checkout, card),
8676
- }),
8677
- },
8678
- ];
8679
- }
8680
- static getPixOrder() {
8681
- return {
8682
- expires_at: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
8683
- };
8684
- }
8685
- static getBoletoOrder() {
8686
- return {
8687
- due_at: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
8688
- instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
8689
- type: 'DM',
8690
- document_number: new Date().getTime().toString(),
8691
- };
8692
- }
8693
- static getCardOrder(checkout, card) {
8694
- return {
8695
- installments: card.installments,
8696
- statement_descriptor: checkout.shop === Shops.GLAMSHOP ? 'Glam' : "Men's Market",
8697
- card_id: card.cardId,
8698
- card: {
8699
- cvv: card.cardCvv,
8700
- billing_address: {
8701
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8702
- zip_code: checkout.billingAddress.zip,
8703
- city: checkout.billingAddress.city,
8704
- state: checkout.billingAddress.state,
8705
- country: 'BR',
8706
- },
8707
- },
8708
- };
8709
- }
8710
- }
8711
-
8712
- class PagarMeV5ResponseHelper {
8713
- static build(method, checkout, response) {
8714
- return Payment.toInstance({
8715
- createdAt: new Date(),
8716
- updatedAt: new Date(),
8717
- userId: checkout.user.id,
8718
- checkoutId: checkout.id,
8719
- totalPrice: checkout.totalPrice,
8720
- paymentProvider: PaymentProviders.PAGARME,
8721
- pagarMeOrderId: response.id,
8722
- transaction: this.buildPaymentTransaction(method, response),
8723
- });
8724
- }
8725
- static buildPaymentTransaction(method, response) {
8726
- const charger = response.charges.at(0);
8727
- const transaction = charger.last_transaction;
8728
- return PaymentTransaction.toInstance({
8729
- acquirer_name: 'pagar_me',
8730
- amount: charger.amount,
8731
- currency: charger.currency,
8732
- gateway_id: charger.gateway_id,
8733
- status: this.getPaymentStatus(transaction.status),
8734
- payment_method: charger.payment_method,
8735
- date_created: charger.created_at,
8736
- date_updated: charger.updated_at,
8737
- paid_amount: charger.paid_amount,
8738
- paid_at: charger.paid_at,
8739
- order_id: response.id,
8740
- charger_id: charger.id,
8741
- tid: charger.id,
8742
- id: charger.id,
8743
- ...(method == TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8744
- ...(method == TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8745
- ...(method == TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8746
- });
8747
- }
8748
- static getPaymentStatus(status) {
8749
- if (status == PagarMeV5PaymentStatus.Gerado)
8750
- return PagarMeV5PaymentStatus['Aguardando pagamento'];
8751
- if (status == PagarMeV5PaymentStatus.Capturada)
8752
- return PagarMeV5PaymentStatus.Pago;
8753
- return status;
8754
- }
8755
- static getBoletoReponse(transaction) {
8756
- return {
8757
- boleto_url: transaction.url?.toString(),
8758
- boleto_barcode: transaction.barcode?.toString(),
8759
- boleto_qr_code: transaction.qr_code?.toString(),
8760
- boleto_expiration_date: transaction.due_at?.toString(),
8761
- boleto_instructions: transaction.instructions?.toString(),
8762
- boleto_nosso_numero: transaction.nosso_numero?.toString(),
8763
- boleto_type: transaction.type?.toString(),
8764
- boleto_document_number: transaction.document_number?.toString(),
8765
- };
8766
- }
8767
- static getPixReponse(transaction) {
8768
- return {
8769
- pix_qr_code: transaction.qr_code?.toString(),
8770
- pix_qr_code_url: transaction.qr_code_url?.toString(),
8771
- pix_expiration_date: transaction.expires_at?.toString(),
8772
- };
8773
- }
8774
- static getCardReponse(transaction) {
8775
- return {
8776
- soft_descriptor: transaction.statement_descriptor?.toString(),
8777
- acquirer_name: transaction.acquirer_name?.toString(),
8778
- acquirer_id: transaction.acquirer_tid?.toString(),
8779
- acquirer_nsu: transaction.acquirer_nsu?.toString(),
8780
- acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8781
- acquirer_message: transaction.acquirer_message?.toString(),
8782
- acquirer_return_code: transaction.acquirer_return_code?.toString(),
8783
- installments: transaction.installments ?? null,
8784
- card_holder_name: transaction.card?.holder_name?.toString(),
8785
- card_last_digits: transaction.card?.last_four_digits?.toString(),
8786
- card_first_digits: transaction.card?.first_six_digits?.toString(),
8787
- card_brand: transaction.card?.brand?.toString(),
8788
- card_id: transaction.card?.id?.toString(),
8789
- };
8790
- }
8791
- }
8792
-
8793
8641
  class PagarmeCardAxiosAdapter {
8794
8642
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8795
8643
  this.credentials = credentials;
@@ -8846,9 +8694,8 @@ class PagarmeCardAxiosAdapter {
8846
8694
  });
8847
8695
  }
8848
8696
  }
8849
- async createCardHash(bu, shop) {
8850
- const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
8851
- const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8697
+ async createCardHash(bu) {
8698
+ const key = bu === BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8852
8699
  try {
8853
8700
  const { data } = await axios({
8854
8701
  method: 'GET',
@@ -9011,287 +8858,6 @@ class PagarmePixAxiosAdapter {
9011
8858
  }
9012
8859
  }
9013
8860
 
9014
- class PagarmeV5BankSlipAxiosAdapter {
9015
- constructor(credentials, paymentRepository) {
9016
- this.credentials = credentials;
9017
- this.paymentRepository = paymentRepository;
9018
- }
9019
- async pay(checkout) {
9020
- try {
9021
- const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9022
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9023
- const { data } = await axios({
9024
- method: 'POST',
9025
- url: `${this.credentials.URL}/orders`,
9026
- headers: {
9027
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9028
- 'Content-Type': 'application/json',
9029
- },
9030
- data: payload,
9031
- });
9032
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9033
- if (data.status === PagarMeV5OrderStatus.Falha ||
9034
- data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
9035
- (data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado &&
9036
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus['Em processamento'])) {
9037
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9038
- checkoutId: checkout.id,
9039
- userEmail: checkout.user.email,
9040
- info: data.charges.at(0).last_transaction?.gateway_response,
9041
- }));
9042
- }
9043
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.BANKSLIP, checkout, data));
9044
- return payment;
9045
- }
9046
- catch (error) {
9047
- console.error('Full error: ', JSON.stringify(error));
9048
- if (error instanceof AxiosError) {
9049
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9050
- }
9051
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9052
- checkoutId: checkout.id,
9053
- userEmail: checkout.user.email,
9054
- info: error.response?.data,
9055
- });
9056
- }
9057
- }
9058
- async getBoletoTransaction(paymentId) {
9059
- try {
9060
- const { data } = await axios({
9061
- method: 'GET',
9062
- url: `${this.credentials.URL}/charges/${paymentId}`,
9063
- headers: {
9064
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9065
- 'Content-Type': 'application/json',
9066
- },
9067
- });
9068
- const payment = await this.paymentRepository.get({
9069
- id: data.id,
9070
- });
9071
- return payment.transaction;
9072
- }
9073
- catch (error) {
9074
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9075
- paymentId,
9076
- info: error.response.data,
9077
- });
9078
- }
9079
- }
9080
- }
9081
-
9082
- class PagarmeV5CardAxiosAdapter {
9083
- constructor(credentials, paymentRepository, orderBlockedRepository) {
9084
- this.credentials = credentials;
9085
- this.paymentRepository = paymentRepository;
9086
- this.orderBlockedRepository = orderBlockedRepository;
9087
- }
9088
- async pay(checkout, card) {
9089
- try {
9090
- const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9091
- console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9092
- const { data } = await axios({
9093
- method: 'POST',
9094
- url: `${this.credentials.URL}/orders`,
9095
- headers: {
9096
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9097
- 'Content-Type': 'application/json',
9098
- },
9099
- data: payload,
9100
- });
9101
- console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9102
- if (data.status == PagarMeV5OrderStatus.Falha ||
9103
- data.charges.at(0).status !== PagarMeV5OrderStatus.Pago ||
9104
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Capturada) {
9105
- await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9106
- checkout,
9107
- card,
9108
- orderBlockedRepository: this.orderBlockedRepository,
9109
- });
9110
- throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9111
- }
9112
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.CARD, checkout, data));
9113
- return payment;
9114
- }
9115
- catch (error) {
9116
- if (error instanceof PaymentError) {
9117
- throw error;
9118
- }
9119
- console.error('Full error: ', JSON.stringify(error));
9120
- if (error instanceof AxiosError) {
9121
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9122
- }
9123
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9124
- }
9125
- }
9126
- async addCard(card, customer) {
9127
- try {
9128
- const { id } = await this.createOrUpdateCustomer(customer);
9129
- const { data } = await axios({
9130
- method: 'POST',
9131
- url: `${this.credentials.URL}/customers/${id}/cards`,
9132
- headers: {
9133
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9134
- 'Content-Type': 'application/json',
9135
- },
9136
- data: {
9137
- number: card.number,
9138
- holder_name: card.name,
9139
- holder_document: card.cpf,
9140
- exp_month: card.expirationDate.split('/').at(0),
9141
- exp_year: card.expirationDate.split('/').at(1),
9142
- cvv: card.cvv,
9143
- brand: card.flag,
9144
- label: card.flag,
9145
- billing_address: {
9146
- line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9147
- line_2: `${customer.billingAddress.extension}`,
9148
- zip_code: customer.billingAddress.zip,
9149
- city: customer.billingAddress.city,
9150
- state: customer.billingAddress.state,
9151
- country: 'BR',
9152
- },
9153
- },
9154
- });
9155
- return data;
9156
- }
9157
- catch (error) {
9158
- console.warn(error);
9159
- throw error;
9160
- }
9161
- }
9162
- async createCardHash(bu, shop) {
9163
- const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
9164
- const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9165
- try {
9166
- const { data } = await axios({
9167
- method: 'GET',
9168
- headers: {
9169
- 'content-type': 'application/json',
9170
- },
9171
- url: `${this.credentials.URL}/transactions/card_hash_key`,
9172
- data: JSON.stringify({
9173
- api_key: key,
9174
- }),
9175
- });
9176
- return data;
9177
- }
9178
- catch (error) {
9179
- throw new BusinessError('Houve uma falha gerar o hash', {
9180
- info: error.response.data,
9181
- });
9182
- }
9183
- }
9184
- async getCardByToken(customerId, token) {
9185
- try {
9186
- const { data } = await axios({
9187
- method: 'GET',
9188
- url: `${this.credentials.URL}/cards/${token}`,
9189
- data: {
9190
- api_key: this.credentials.API_KEY,
9191
- },
9192
- });
9193
- return data;
9194
- }
9195
- catch (error) {
9196
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9197
- info: error.response.data,
9198
- });
9199
- }
9200
- }
9201
- async createTransaction(info) {
9202
- return info;
9203
- }
9204
- async createOrUpdateCustomer(customer) {
9205
- try {
9206
- const { data } = await axios({
9207
- method: 'POST',
9208
- url: `${this.credentials.URL}/customers`,
9209
- headers: {
9210
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9211
- 'Content-Type': 'application/json',
9212
- },
9213
- data: {
9214
- name: customer.displayName,
9215
- email: customer.email,
9216
- document: customer.cpf,
9217
- type: 'individual',
9218
- document_type: 'CPF',
9219
- address: {
9220
- line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9221
- line_2: `${customer.billingAddress.extension}`,
9222
- zip_code: customer.billingAddress.zip,
9223
- city: customer.billingAddress.city,
9224
- state: customer.billingAddress.state,
9225
- country: 'BR',
9226
- },
9227
- birthdate: format(new Date(customer.birthday), 'MM/dd/yyyy'),
9228
- phones: {
9229
- home_phone: {
9230
- country_code: '55',
9231
- number: customer.phone.slice(2),
9232
- area_code: customer.phone.slice(0, 2),
9233
- },
9234
- mobile_phone: {
9235
- country_code: '55',
9236
- number: customer.phone.slice(2),
9237
- area_code: customer.phone.slice(0, 2),
9238
- },
9239
- },
9240
- },
9241
- });
9242
- return data;
9243
- }
9244
- catch (error) {
9245
- console.warn(error);
9246
- throw error;
9247
- }
9248
- }
9249
- }
9250
-
9251
- class PagarmeV5PixAxiosAdapter {
9252
- constructor(credentials, paymentRepository) {
9253
- this.credentials = credentials;
9254
- this.paymentRepository = paymentRepository;
9255
- }
9256
- async pay(checkout) {
9257
- try {
9258
- const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9259
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9260
- const { data } = await axios({
9261
- method: 'POST',
9262
- url: `${this.credentials.URL}/orders`,
9263
- headers: {
9264
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9265
- 'Content-Type': 'application/json',
9266
- },
9267
- data: payload,
9268
- });
9269
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9270
- if (data.status == PagarMeV5OrderStatus.Falha || data.status == PagarMeV5OrderStatus.Cancelado) {
9271
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9272
- checkoutId: checkout.id,
9273
- userEmail: checkout.user.email,
9274
- info: data.charges.at(0).last_transaction?.gateway_response,
9275
- });
9276
- }
9277
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.PIX, checkout, data));
9278
- return payment;
9279
- }
9280
- catch (error) {
9281
- console.error('Full error: ', JSON.stringify(error));
9282
- if (error instanceof AxiosError) {
9283
- console.error('Error: ', error.message);
9284
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9285
- }
9286
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9287
- checkoutId: checkout.id,
9288
- userEmail: checkout.user.email,
9289
- info: error.response?.data,
9290
- });
9291
- }
9292
- }
9293
- }
9294
-
9295
8861
  class VertexAxiosAdapter {
9296
8862
  constructor(config) {
9297
8863
  this.config = config;
@@ -9445,4 +9011,4 @@ class ProductsVertexSearch {
9445
9011
  }
9446
9012
  }
9447
9013
 
9448
- 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 };
9014
+ 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 };