@infrab4a/connect 5.1.0-beta.9 → 5.1.1-alpha.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 (32) hide show
  1. package/index.cjs.js +35 -536
  2. package/index.esm.js +36 -534
  3. package/package.json +1 -1
  4. package/src/domain/shopping/enums/index.d.ts +0 -2
  5. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +1 -3
  6. package/src/domain/shopping/models/payment-transaction.d.ts +2 -17
  7. package/src/domain/shopping/models/payment.d.ts +1 -2
  8. package/src/domain/shopping/types/index.d.ts +0 -1
  9. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +3 -9
  10. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  11. package/src/infra/pagarme/adapters/helpers/index.d.ts +0 -2
  12. package/src/infra/pagarme/adapters/index.d.ts +3 -2
  13. package/src/infra/pagarme/adapters/{v4/pagarme-bank-slip-payment-axios.adapter.d.ts → pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
  14. package/src/infra/pagarme/adapters/{v4/pagarme-card-payment-axios.adapter.d.ts → pagarme-card-payment-axios.adapter.d.ts} +6 -7
  15. package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +11 -0
  16. package/src/infra/pagarme/index.d.ts +0 -1
  17. package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +0 -24
  18. package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +0 -5
  19. package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +0 -4
  20. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +0 -12
  21. package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +0 -9
  22. package/src/infra/pagarme/adapters/v4/index.d.ts +0 -3
  23. package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +0 -11
  24. package/src/infra/pagarme/adapters/v5/index.d.ts +0 -3
  25. package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +0 -12
  26. package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +0 -18
  27. package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +0 -11
  28. package/src/infra/pagarme/types/index.d.ts +0 -1
  29. package/src/infra/pagarme/types/v5/index.d.ts +0 -3
  30. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +0 -86
  31. package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +0 -126
  32. 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;
@@ -2930,7 +2896,13 @@ AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
2930
2896
  return { columnName: attributeName.toString(), attributeName };
2931
2897
  if (Array.isArray(fieldOption))
2932
2898
  return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
2933
- return { attributeName, columnName: attributeName.toString(), ...fieldOption };
2899
+ return {
2900
+ attributeName,
2901
+ columnName: attributeName.toString(),
2902
+ ...fieldOption,
2903
+ // to: fieldOption.to || ((value) => value),
2904
+ // from: fieldOption.from || ((value) => value),
2905
+ };
2934
2906
  };
2935
2907
  AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
2936
2908
  AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
@@ -3478,8 +3450,12 @@ class HasuraDeleteVariablesHelper {
3478
3450
  if (isNil(instance.identifier[identifierBinded]))
3479
3451
  return ids;
3480
3452
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3481
- const value = columnOption?.to(identifiers[identifier], instance) ||
3482
- identifiers[identifier];
3453
+ // const value =
3454
+ // columnOption?.to(identifiers[identifier as keyof DeleteRepositoryParams<MBase>], instance) ||
3455
+ // identifiers[identifier as keyof DeleteRepositoryParams<MBase>]
3456
+ const value = 'to' in columnOption
3457
+ ? columnOption?.to?.(identifiers[identifier], instance)
3458
+ : identifiers[identifier];
3483
3459
  return {
3484
3460
  ...ids,
3485
3461
  [columnOption.columnName]: {
@@ -3921,8 +3897,12 @@ class HasuraGetVariablesHelper {
3921
3897
  if (isNil(instance[identifierBinded]))
3922
3898
  return ids;
3923
3899
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3924
- const value = columnOption?.to?.(identifiers[identifier], instance) ||
3925
- identifiers[identifier];
3900
+ // const value =
3901
+ // columnOption?.to?.(identifiers[identifier as keyof typeof identifiers], instance) ||
3902
+ // identifiers[identifier as keyof typeof identifiers]
3903
+ const value = 'to' in columnOption
3904
+ ? columnOption?.to?.(identifiers[identifier], instance)
3905
+ : identifiers[identifier];
3926
3906
  return {
3927
3907
  ...ids,
3928
3908
  [columnOption.columnName]: {
@@ -7228,7 +7208,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7228
7208
  }
7229
7209
 
7230
7210
  const commonFields = [
7231
- { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
7211
+ {
7212
+ id: {
7213
+ columnName: 'id',
7214
+ to: (value) => +value,
7215
+ from: (value) => value.toString(),
7216
+ },
7217
+ },
7232
7218
  { firestoreId: { columnName: 'firestore_id' } },
7233
7219
  { productId: { columnName: 'main_product_id' } },
7234
7220
  { CEST: { columnName: 'cest' } },
@@ -8109,7 +8095,13 @@ class WishlistHasuraGraphQL extends Wishlist {
8109
8095
  }
8110
8096
 
8111
8097
  const fieldsConfiguration = [
8112
- { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
8098
+ {
8099
+ id: {
8100
+ columnName: 'id',
8101
+ to: (value) => +value,
8102
+ from: (value) => value.toString(),
8103
+ },
8104
+ },
8113
8105
  { firestoreId: { columnName: 'firestore_id' } },
8114
8106
  'name',
8115
8107
  'description',
@@ -8569,187 +8561,6 @@ class PagarmePaymentOperationsHelper {
8569
8561
  }
8570
8562
  }
8571
8563
 
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
- charger_id: charger.id,
8708
- tid: charger.id,
8709
- id: charger.id,
8710
- ...(method == TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8711
- ...(method == TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8712
- ...(method == TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8713
- });
8714
- }
8715
- static getBoletoReponse(transaction) {
8716
- return {
8717
- boleto_url: transaction.url?.toString(),
8718
- boleto_barcode: transaction.barcode?.toString(),
8719
- boleto_qr_code: transaction.qr_code?.toString(),
8720
- boleto_expiration_date: transaction.due_at?.toString(),
8721
- boleto_instructions: transaction.instructions?.toString(),
8722
- boleto_nosso_numero: transaction.nosso_numero?.toString(),
8723
- boleto_type: transaction.type?.toString(),
8724
- boleto_document_number: transaction.document_number?.toString(),
8725
- };
8726
- }
8727
- static getPixReponse(transaction) {
8728
- return {
8729
- pix_qr_code: transaction.qr_code?.toString(),
8730
- pix_qr_code_url: transaction.qr_code_url?.toString(),
8731
- pix_expiration_date: transaction.expires_at?.toString(),
8732
- };
8733
- }
8734
- static getCardReponse(transaction) {
8735
- return {
8736
- soft_descriptor: transaction.statement_descriptor?.toString(),
8737
- acquirer_name: transaction.acquirer_name?.toString(),
8738
- acquirer_id: transaction.acquirer_tid?.toString(),
8739
- acquirer_nsu: transaction.acquirer_nsu?.toString(),
8740
- acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8741
- acquirer_message: transaction.acquirer_message?.toString(),
8742
- acquirer_return_code: transaction.acquirer_return_code?.toString(),
8743
- installments: transaction.installments ?? null,
8744
- card_holder_name: transaction.card?.holder_name?.toString(),
8745
- card_last_digits: transaction.card?.last_four_digits?.toString(),
8746
- card_first_digits: transaction.card?.first_six_digits?.toString(),
8747
- card_brand: transaction.card?.brand?.toString(),
8748
- card_id: transaction.card?.id?.toString(),
8749
- };
8750
- }
8751
- }
8752
-
8753
8564
  class PagarmeCardAxiosAdapter {
8754
8565
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8755
8566
  this.credentials = credentials;
@@ -8806,9 +8617,8 @@ class PagarmeCardAxiosAdapter {
8806
8617
  });
8807
8618
  }
8808
8619
  }
8809
- async createCardHash(bu, shop) {
8810
- const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
8811
- const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8620
+ async createCardHash(bu) {
8621
+ const key = bu === BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8812
8622
  try {
8813
8623
  const { data } = await axios({
8814
8624
  method: 'GET',
@@ -8971,314 +8781,6 @@ class PagarmePixAxiosAdapter {
8971
8781
  }
8972
8782
  }
8973
8783
 
8974
- class PagarmeV5BankSlipAxiosAdapter {
8975
- constructor(credentials, paymentRepository) {
8976
- this.credentials = credentials;
8977
- this.paymentRepository = paymentRepository;
8978
- }
8979
- async pay2(payload) {
8980
- try {
8981
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
8982
- const { data } = await axios({
8983
- method: 'POST',
8984
- url: `${this.credentials.URL}/orders`,
8985
- headers: {
8986
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
8987
- 'Content-Type': 'application/json',
8988
- },
8989
- data: payload,
8990
- });
8991
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
8992
- if (data.status == PagarMeV5OrderStatus.Falha ||
8993
- data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
8994
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado) {
8995
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8996
- // checkoutId: checkout.id,
8997
- // userEmail: checkout.user.email,
8998
- info: data,
8999
- }));
9000
- }
9001
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9002
- // const payment = await this.paymentRepository.create(paymentData)
9003
- return data;
9004
- }
9005
- catch (error) {
9006
- if (error instanceof AxiosError) {
9007
- console.error(error.message);
9008
- console.error(error.response.data);
9009
- }
9010
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9011
- // checkoutId: checkout.id,
9012
- // userEmail: checkout.user.email,
9013
- info: error.response.data,
9014
- });
9015
- }
9016
- }
9017
- async pay(checkout) {
9018
- try {
9019
- const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9020
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9021
- const { data } = await axios({
9022
- method: 'POST',
9023
- url: `${this.credentials.URL}/orders`,
9024
- headers: {
9025
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9026
- 'Content-Type': 'application/json',
9027
- },
9028
- data: payload,
9029
- });
9030
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9031
- if (data.status == PagarMeV5OrderStatus.Falha ||
9032
- data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
9033
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado) {
9034
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9035
- checkoutId: checkout.id,
9036
- userEmail: checkout.user.email,
9037
- info: data.charges.at(0).last_transaction?.gateway_response,
9038
- }));
9039
- }
9040
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.BANKSLIP, checkout, data));
9041
- return payment;
9042
- }
9043
- catch (error) {
9044
- console.error('Full error: ', JSON.stringify(error));
9045
- if (error instanceof AxiosError) {
9046
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9047
- }
9048
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9049
- checkoutId: checkout.id,
9050
- userEmail: checkout.user.email,
9051
- info: error.response?.data,
9052
- });
9053
- }
9054
- }
9055
- async getBoletoTransaction(paymentId) {
9056
- try {
9057
- const { data } = await axios({
9058
- method: 'GET',
9059
- url: `${this.credentials.URL}/charges/${paymentId}`,
9060
- headers: {
9061
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9062
- 'Content-Type': 'application/json',
9063
- },
9064
- });
9065
- const payment = await this.paymentRepository.get({
9066
- id: data.id,
9067
- });
9068
- return payment.transaction;
9069
- }
9070
- catch (error) {
9071
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9072
- paymentId,
9073
- info: error.response.data,
9074
- });
9075
- }
9076
- }
9077
- }
9078
-
9079
- class PagarmeV5CardAxiosAdapter {
9080
- constructor(credentials, paymentRepository, orderBlockedRepository) {
9081
- this.credentials = credentials;
9082
- this.paymentRepository = paymentRepository;
9083
- this.orderBlockedRepository = orderBlockedRepository;
9084
- }
9085
- async pay(checkout, card) {
9086
- try {
9087
- const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9088
- console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9089
- const { data } = await axios({
9090
- method: 'POST',
9091
- url: `${this.credentials.URL}/orders`,
9092
- headers: {
9093
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9094
- 'Content-Type': 'application/json',
9095
- },
9096
- data: payload,
9097
- });
9098
- console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9099
- if (data.status == PagarMeV5OrderStatus.Falha ||
9100
- data.charges.at(0).status !== PagarMeV5OrderStatus.Pago ||
9101
- data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Capturada) {
9102
- await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9103
- checkout,
9104
- card,
9105
- orderBlockedRepository: this.orderBlockedRepository,
9106
- });
9107
- throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9108
- }
9109
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.CARD, checkout, data));
9110
- return payment;
9111
- }
9112
- catch (error) {
9113
- if (error instanceof PaymentError) {
9114
- throw error;
9115
- }
9116
- console.error('Full error: ', JSON.stringify(error));
9117
- if (error instanceof AxiosError) {
9118
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9119
- }
9120
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9121
- }
9122
- }
9123
- // Dúvidas: preciso criar um cliente? como faz na mens?
9124
- async addCard(card) {
9125
- try {
9126
- const { data } = await axios({
9127
- method: 'POST',
9128
- url: `${this.credentials.URL}/cards`,
9129
- data: {
9130
- api_key: this.credentials.API_KEY,
9131
- card_number: card.number,
9132
- card_expiration_date: card.expirationDate.replace('/', ''),
9133
- card_holder_name: card.name,
9134
- card_cvv: card.cvv,
9135
- // number: '4000000000000010',
9136
- // holder_name: 'Tony Stark',
9137
- // holder_document: '93095135270',
9138
- // exp_month: 1,
9139
- // exp_year: 30,
9140
- // cvv: '351',
9141
- // brand: 'Mastercard',
9142
- // label: 'Sua bandeira',
9143
- // billing_address: {
9144
- // line_1: '375, Av. General Osorio, Centro',
9145
- // line_2: '7º Andar',
9146
- // zip_code: '220000111',
9147
- // city: 'Rio de Janeiro',
9148
- // state: 'RJ',
9149
- // country: 'BR',
9150
- // },
9151
- // options: {
9152
- // verify_card: true,
9153
- // },
9154
- },
9155
- });
9156
- return data;
9157
- }
9158
- catch (error) {
9159
- throw new BusinessError('Houve uma falha adicionar o cartão', {
9160
- info: error.response.data,
9161
- });
9162
- }
9163
- }
9164
- async createCardHash(bu, shop) {
9165
- const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
9166
- const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9167
- try {
9168
- const { data } = await axios({
9169
- method: 'GET',
9170
- headers: {
9171
- 'content-type': 'application/json',
9172
- },
9173
- url: `${this.credentials.URL}/transactions/card_hash_key`,
9174
- data: JSON.stringify({
9175
- api_key: key,
9176
- }),
9177
- });
9178
- return data;
9179
- }
9180
- catch (error) {
9181
- throw new BusinessError('Houve uma falha gerar o hash', {
9182
- info: error.response.data,
9183
- });
9184
- }
9185
- }
9186
- async getCardByToken(customerId, token) {
9187
- try {
9188
- const { data } = await axios({
9189
- method: 'GET',
9190
- url: `${this.credentials.URL}/cards/${token}`,
9191
- data: {
9192
- api_key: this.credentials.API_KEY,
9193
- },
9194
- });
9195
- return data;
9196
- }
9197
- catch (error) {
9198
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9199
- info: error.response.data,
9200
- });
9201
- }
9202
- }
9203
- async createTransaction(info) {
9204
- return;
9205
- }
9206
- }
9207
-
9208
- class PagarmeV5PixAxiosAdapter {
9209
- constructor(credentials, paymentRepository) {
9210
- this.credentials = credentials;
9211
- this.paymentRepository = paymentRepository;
9212
- }
9213
- async pay2(payload) {
9214
- try {
9215
- // const payload = PagarMeV5RequestHelper.build(checkout, 'pix')
9216
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9217
- const { data } = await axios({
9218
- method: 'POST',
9219
- url: `${this.credentials.URL}/orders`,
9220
- headers: {
9221
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9222
- 'Content-Type': 'application/json',
9223
- },
9224
- data: payload,
9225
- });
9226
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9227
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9228
- // const payment = await this.paymentRepository.create(paymentData)
9229
- return data;
9230
- }
9231
- catch (error) {
9232
- if (error instanceof AxiosError) {
9233
- console.error(error.message);
9234
- console.error(error.response.data);
9235
- }
9236
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9237
- // checkoutId: checkout.id,
9238
- // userEmail: checkout.user.email,
9239
- info: error.response?.data,
9240
- });
9241
- }
9242
- }
9243
- async pay(checkout) {
9244
- try {
9245
- const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9246
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9247
- const { data } = await axios({
9248
- method: 'POST',
9249
- url: `${this.credentials.URL}/orders`,
9250
- headers: {
9251
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9252
- 'Content-Type': 'application/json',
9253
- },
9254
- data: payload,
9255
- });
9256
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9257
- if (data.status == PagarMeV5OrderStatus.Falha || data.status == PagarMeV5OrderStatus.Cancelado) {
9258
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9259
- checkoutId: checkout.id,
9260
- userEmail: checkout.user.email,
9261
- info: data.charges.at(0).last_transaction?.gateway_response,
9262
- });
9263
- }
9264
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.PIX, checkout, data));
9265
- return payment;
9266
- }
9267
- catch (error) {
9268
- console.error('Full error: ', JSON.stringify(error));
9269
- if (error instanceof AxiosError) {
9270
- console.error('Error: ', error.message);
9271
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9272
- }
9273
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9274
- checkoutId: checkout.id,
9275
- userEmail: checkout.user.email,
9276
- info: error.response?.data,
9277
- });
9278
- }
9279
- }
9280
- }
9281
-
9282
8784
  class VertexAxiosAdapter {
9283
8785
  constructor(config) {
9284
8786
  this.config = config;
@@ -9432,4 +8934,4 @@ class ProductsVertexSearch {
9432
8934
  }
9433
8935
  }
9434
8936
 
9435
- 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 };
8937
+ 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.9",
3
+ "version": "5.1.1-alpha.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';