@infrab4a/connect 5.1.0-beta.8 → 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 -535
  2. package/index.esm.js +36 -533
  3. package/package.json +1 -1
  4. package/src/domain/shopping/enums/index.d.ts +0 -2
  5. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +1 -2
  6. package/src/domain/shopping/models/payment-transaction.d.ts +2 -16
  7. package/src/domain/shopping/models/payment.d.ts +1 -2
  8. package/src/domain/shopping/types/index.d.ts +0 -1
  9. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +3 -9
  10. package/src/infra/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 -17
  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.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;
@@ -2955,7 +2921,13 @@ AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
2955
2921
  return { columnName: attributeName.toString(), attributeName };
2956
2922
  if (Array.isArray(fieldOption))
2957
2923
  return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
2958
- return { attributeName, columnName: attributeName.toString(), ...fieldOption };
2924
+ return {
2925
+ attributeName,
2926
+ columnName: attributeName.toString(),
2927
+ ...fieldOption,
2928
+ // to: fieldOption.to || ((value) => value),
2929
+ // from: fieldOption.from || ((value) => value),
2930
+ };
2959
2931
  };
2960
2932
  AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
2961
2933
  AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
@@ -3503,8 +3475,12 @@ class HasuraDeleteVariablesHelper {
3503
3475
  if (lodash.isNil(instance.identifier[identifierBinded]))
3504
3476
  return ids;
3505
3477
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3506
- const value = columnOption?.to(identifiers[identifier], instance) ||
3507
- identifiers[identifier];
3478
+ // const value =
3479
+ // columnOption?.to(identifiers[identifier as keyof DeleteRepositoryParams<MBase>], instance) ||
3480
+ // identifiers[identifier as keyof DeleteRepositoryParams<MBase>]
3481
+ const value = 'to' in columnOption
3482
+ ? columnOption?.to?.(identifiers[identifier], instance)
3483
+ : identifiers[identifier];
3508
3484
  return {
3509
3485
  ...ids,
3510
3486
  [columnOption.columnName]: {
@@ -3946,8 +3922,12 @@ class HasuraGetVariablesHelper {
3946
3922
  if (lodash.isNil(instance[identifierBinded]))
3947
3923
  return ids;
3948
3924
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, fields);
3949
- const value = columnOption?.to?.(identifiers[identifier], instance) ||
3950
- identifiers[identifier];
3925
+ // const value =
3926
+ // columnOption?.to?.(identifiers[identifier as keyof typeof identifiers], instance) ||
3927
+ // identifiers[identifier as keyof typeof identifiers]
3928
+ const value = 'to' in columnOption
3929
+ ? columnOption?.to?.(identifiers[identifier], instance)
3930
+ : identifiers[identifier];
3951
3931
  return {
3952
3932
  ...ids,
3953
3933
  [columnOption.columnName]: {
@@ -7253,7 +7233,13 @@ class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
7253
7233
  }
7254
7234
 
7255
7235
  const commonFields = [
7256
- { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
7236
+ {
7237
+ id: {
7238
+ columnName: 'id',
7239
+ to: (value) => +value,
7240
+ from: (value) => value.toString(),
7241
+ },
7242
+ },
7257
7243
  { firestoreId: { columnName: 'firestore_id' } },
7258
7244
  { productId: { columnName: 'main_product_id' } },
7259
7245
  { CEST: { columnName: 'cest' } },
@@ -8134,7 +8120,13 @@ class WishlistHasuraGraphQL extends Wishlist {
8134
8120
  }
8135
8121
 
8136
8122
  const fieldsConfiguration = [
8137
- { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
8123
+ {
8124
+ id: {
8125
+ columnName: 'id',
8126
+ to: (value) => +value,
8127
+ from: (value) => value.toString(),
8128
+ },
8129
+ },
8138
8130
  { firestoreId: { columnName: 'firestore_id' } },
8139
8131
  'name',
8140
8132
  'description',
@@ -8594,186 +8586,6 @@ class PagarmePaymentOperationsHelper {
8594
8586
  }
8595
8587
  }
8596
8588
 
8597
- class PagarMeV5RequestHelper {
8598
- static build(checkout, method, card) {
8599
- return {
8600
- items: this.buildItems(checkout),
8601
- customer: this.buildCustomer(checkout),
8602
- shipping: this.buildShipping(checkout),
8603
- payments: this.buildPayment(checkout, method, card),
8604
- };
8605
- }
8606
- static buildItems(checkout) {
8607
- return checkout.lineItems
8608
- .filter((item) => !item.isGift)
8609
- .map((item) => {
8610
- return {
8611
- amount: Math.floor(item.pricePaid * 100),
8612
- description: item.name,
8613
- quantity: item.quantity,
8614
- code: item.EAN,
8615
- };
8616
- });
8617
- }
8618
- static buildCustomer(checkout) {
8619
- return {
8620
- name: checkout.user.displayName,
8621
- email: checkout.user.email,
8622
- type: 'individual',
8623
- document: checkout.user.cpf,
8624
- phones: {
8625
- home_phone: {
8626
- country_code: '55',
8627
- number: checkout.user.phone.slice(2),
8628
- area_code: checkout.user.phone.slice(0, 2),
8629
- },
8630
- mobile_phone: {
8631
- country_code: '55',
8632
- number: checkout.user.phone.slice(2),
8633
- area_code: checkout.user.phone.slice(0, 2),
8634
- },
8635
- },
8636
- address: {
8637
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8638
- line_2: `${checkout.billingAddress.extension}`,
8639
- zip_code: checkout.shippingAddress.zip,
8640
- city: checkout.billingAddress.city,
8641
- state: checkout.billingAddress.state,
8642
- country: 'BR',
8643
- },
8644
- };
8645
- }
8646
- static buildShipping(checkout) {
8647
- return {
8648
- amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8649
- description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8650
- recipient_name: checkout.shippingAddress.recipient,
8651
- recipient_phone: checkout.user.phone,
8652
- address: {
8653
- line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8654
- line_2: `${checkout.shippingAddress.extension}`,
8655
- zip_code: checkout.shippingAddress.zip,
8656
- city: checkout.shippingAddress.city,
8657
- state: checkout.shippingAddress.state,
8658
- country: 'BR',
8659
- },
8660
- };
8661
- }
8662
- static buildPayment(checkout, method, card) {
8663
- return [
8664
- {
8665
- payment_method: method,
8666
- amount: Math.floor(checkout.totalPrice * 100),
8667
- ...(method === 'pix' && {
8668
- pix: this.getPixOrder(),
8669
- }),
8670
- ...(method === 'boleto' && {
8671
- boleto: this.getBoletoOrder(),
8672
- }),
8673
- ...(method === 'credit_card' && {
8674
- credit_card: this.getCardOrder(checkout, card),
8675
- }),
8676
- },
8677
- ];
8678
- }
8679
- static getPixOrder() {
8680
- return {
8681
- expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
8682
- };
8683
- }
8684
- static getBoletoOrder() {
8685
- return {
8686
- due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
8687
- instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
8688
- type: 'DM',
8689
- document_number: new Date().getTime().toString(),
8690
- };
8691
- }
8692
- static getCardOrder(checkout, card) {
8693
- return {
8694
- installments: card.installments,
8695
- statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
8696
- card_id: card.cardId,
8697
- card: {
8698
- cvv: card.cardCvv,
8699
- },
8700
- };
8701
- }
8702
- }
8703
-
8704
- class PagarMeV5ResponseHelper {
8705
- static build(method, checkout, response) {
8706
- return Payment.toInstance({
8707
- createdAt: new Date(),
8708
- updatedAt: new Date(),
8709
- userId: checkout.user.id,
8710
- checkoutId: checkout.id,
8711
- totalPrice: checkout.totalPrice,
8712
- paymentProvider: exports.PaymentProviders.PAGARME,
8713
- pagarMeOrderId: response.id,
8714
- transaction: this.buildPaymentTransaction(method, response),
8715
- });
8716
- }
8717
- static buildPaymentTransaction(method, response) {
8718
- const charger = response.charges.at(0);
8719
- const transaction = charger.last_transaction;
8720
- return PaymentTransaction.toInstance({
8721
- acquirer_name: 'pagar_me',
8722
- amount: charger.amount,
8723
- currency: charger.currency,
8724
- gateway_id: charger.gateway_id,
8725
- status: charger.status,
8726
- payment_method: charger.payment_method,
8727
- date_created: charger.created_at,
8728
- date_updated: charger.updated_at,
8729
- paid_amount: charger.paid_amount,
8730
- paid_at: charger.paid_at,
8731
- order_id: response.id,
8732
- tid: transaction.id,
8733
- id: transaction.id,
8734
- ...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8735
- ...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8736
- ...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8737
- });
8738
- }
8739
- static getBoletoReponse(transaction) {
8740
- return {
8741
- boleto_url: transaction.url?.toString(),
8742
- boleto_barcode: transaction.barcode?.toString(),
8743
- boleto_qr_code: transaction.qr_code?.toString(),
8744
- boleto_expiration_date: transaction.due_at?.toString(),
8745
- boleto_instructions: transaction.instructions?.toString(),
8746
- boleto_nosso_numero: transaction.nosso_numero?.toString(),
8747
- boleto_type: transaction.type?.toString(),
8748
- boleto_document_number: transaction.document_number?.toString(),
8749
- };
8750
- }
8751
- static getPixReponse(transaction) {
8752
- return {
8753
- pix_qr_code: transaction.qr_code?.toString(),
8754
- pix_qr_code_url: transaction.qr_code_url?.toString(),
8755
- pix_expiration_date: transaction.expires_at?.toString(),
8756
- };
8757
- }
8758
- static getCardReponse(transaction) {
8759
- return {
8760
- soft_descriptor: transaction.statement_descriptor?.toString(),
8761
- acquirer_name: transaction.acquirer_name?.toString(),
8762
- acquirer_id: transaction.acquirer_tid?.toString(),
8763
- acquirer_nsu: transaction.acquirer_nsu?.toString(),
8764
- acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8765
- acquirer_message: transaction.acquirer_message?.toString(),
8766
- acquirer_return_code: transaction.acquirer_return_code?.toString(),
8767
- installments: transaction.installments ?? null,
8768
- card_holder_name: transaction.card?.holder_name?.toString(),
8769
- card_last_digits: transaction.card?.last_four_digits?.toString(),
8770
- card_first_digits: transaction.card?.first_six_digits?.toString(),
8771
- card_brand: transaction.card?.brand?.toString(),
8772
- card_id: transaction.card?.id?.toString(),
8773
- };
8774
- }
8775
- }
8776
-
8777
8589
  class PagarmeCardAxiosAdapter {
8778
8590
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8779
8591
  this.credentials = credentials;
@@ -8830,9 +8642,8 @@ class PagarmeCardAxiosAdapter {
8830
8642
  });
8831
8643
  }
8832
8644
  }
8833
- async createCardHash(bu, shop) {
8834
- const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
8835
- const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8645
+ async createCardHash(bu) {
8646
+ const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8836
8647
  try {
8837
8648
  const { data } = await axios__default["default"]({
8838
8649
  method: 'GET',
@@ -8995,314 +8806,6 @@ class PagarmePixAxiosAdapter {
8995
8806
  }
8996
8807
  }
8997
8808
 
8998
- class PagarmeV5BankSlipAxiosAdapter {
8999
- constructor(credentials, paymentRepository) {
9000
- this.credentials = credentials;
9001
- this.paymentRepository = paymentRepository;
9002
- }
9003
- async pay2(payload) {
9004
- try {
9005
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9006
- const { data } = await axios__default["default"]({
9007
- method: 'POST',
9008
- url: `${this.credentials.URL}/orders`,
9009
- headers: {
9010
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9011
- 'Content-Type': 'application/json',
9012
- },
9013
- data: payload,
9014
- });
9015
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9016
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9017
- data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9018
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado) {
9019
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9020
- // checkoutId: checkout.id,
9021
- // userEmail: checkout.user.email,
9022
- info: data,
9023
- }));
9024
- }
9025
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9026
- // const payment = await this.paymentRepository.create(paymentData)
9027
- return data;
9028
- }
9029
- catch (error) {
9030
- if (error instanceof axios.AxiosError) {
9031
- console.error(error.message);
9032
- console.error(error.response.data);
9033
- }
9034
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9035
- // checkoutId: checkout.id,
9036
- // userEmail: checkout.user.email,
9037
- info: error.response.data,
9038
- });
9039
- }
9040
- }
9041
- async pay(checkout) {
9042
- try {
9043
- const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9044
- console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9045
- const { data } = await axios__default["default"]({
9046
- method: 'POST',
9047
- url: `${this.credentials.URL}/orders`,
9048
- headers: {
9049
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9050
- 'Content-Type': 'application/json',
9051
- },
9052
- data: payload,
9053
- });
9054
- console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9055
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9056
- data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9057
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado) {
9058
- return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9059
- checkoutId: checkout.id,
9060
- userEmail: checkout.user.email,
9061
- info: data.charges.at(0).last_transaction?.gateway_response,
9062
- }));
9063
- }
9064
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
9065
- return payment;
9066
- }
9067
- catch (error) {
9068
- console.error('Full error: ', JSON.stringify(error));
9069
- if (error instanceof axios.AxiosError) {
9070
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9071
- }
9072
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9073
- checkoutId: checkout.id,
9074
- userEmail: checkout.user.email,
9075
- info: error.response?.data,
9076
- });
9077
- }
9078
- }
9079
- async getBoletoTransaction(paymentId) {
9080
- try {
9081
- const { data } = await axios__default["default"]({
9082
- method: 'GET',
9083
- url: `${this.credentials.URL}/charges/${paymentId}`,
9084
- headers: {
9085
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9086
- 'Content-Type': 'application/json',
9087
- },
9088
- });
9089
- const payment = await this.paymentRepository.get({
9090
- id: data.id,
9091
- });
9092
- return payment.transaction;
9093
- }
9094
- catch (error) {
9095
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9096
- paymentId,
9097
- info: error.response.data,
9098
- });
9099
- }
9100
- }
9101
- }
9102
-
9103
- class PagarmeV5CardAxiosAdapter {
9104
- constructor(credentials, paymentRepository, orderBlockedRepository) {
9105
- this.credentials = credentials;
9106
- this.paymentRepository = paymentRepository;
9107
- this.orderBlockedRepository = orderBlockedRepository;
9108
- }
9109
- async pay(checkout, card) {
9110
- try {
9111
- const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9112
- console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9113
- const { data } = await axios__default["default"]({
9114
- method: 'POST',
9115
- url: `${this.credentials.URL}/orders`,
9116
- headers: {
9117
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9118
- 'Content-Type': 'application/json',
9119
- },
9120
- data: payload,
9121
- });
9122
- console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9123
- if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9124
- data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
9125
- data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
9126
- await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9127
- checkout,
9128
- card,
9129
- orderBlockedRepository: this.orderBlockedRepository,
9130
- });
9131
- throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9132
- }
9133
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9134
- return payment;
9135
- }
9136
- catch (error) {
9137
- if (error instanceof PaymentError) {
9138
- throw error;
9139
- }
9140
- console.error('Full error: ', JSON.stringify(error));
9141
- if (error instanceof axios.AxiosError) {
9142
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9143
- }
9144
- throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9145
- }
9146
- }
9147
- // Dúvidas: preciso criar um cliente? como faz na mens?
9148
- async addCard(card) {
9149
- try {
9150
- const { data } = await axios__default["default"]({
9151
- method: 'POST',
9152
- url: `${this.credentials.URL}/cards`,
9153
- data: {
9154
- api_key: this.credentials.API_KEY,
9155
- card_number: card.number,
9156
- card_expiration_date: card.expirationDate.replace('/', ''),
9157
- card_holder_name: card.name,
9158
- card_cvv: card.cvv,
9159
- // number: '4000000000000010',
9160
- // holder_name: 'Tony Stark',
9161
- // holder_document: '93095135270',
9162
- // exp_month: 1,
9163
- // exp_year: 30,
9164
- // cvv: '351',
9165
- // brand: 'Mastercard',
9166
- // label: 'Sua bandeira',
9167
- // billing_address: {
9168
- // line_1: '375, Av. General Osorio, Centro',
9169
- // line_2: '7º Andar',
9170
- // zip_code: '220000111',
9171
- // city: 'Rio de Janeiro',
9172
- // state: 'RJ',
9173
- // country: 'BR',
9174
- // },
9175
- // options: {
9176
- // verify_card: true,
9177
- // },
9178
- },
9179
- });
9180
- return data;
9181
- }
9182
- catch (error) {
9183
- throw new BusinessError('Houve uma falha adicionar o cartão', {
9184
- info: error.response.data,
9185
- });
9186
- }
9187
- }
9188
- async createCardHash(bu, shop) {
9189
- const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
9190
- const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9191
- try {
9192
- const { data } = await axios__default["default"]({
9193
- method: 'GET',
9194
- headers: {
9195
- 'content-type': 'application/json',
9196
- },
9197
- url: `${this.credentials.URL}/transactions/card_hash_key`,
9198
- data: JSON.stringify({
9199
- api_key: key,
9200
- }),
9201
- });
9202
- return data;
9203
- }
9204
- catch (error) {
9205
- throw new BusinessError('Houve uma falha gerar o hash', {
9206
- info: error.response.data,
9207
- });
9208
- }
9209
- }
9210
- async getCardByToken(id) {
9211
- try {
9212
- const { data } = await axios__default["default"]({
9213
- method: 'GET',
9214
- url: `${this.credentials.URL}/cards/${id}`,
9215
- data: {
9216
- api_key: this.credentials.API_KEY,
9217
- },
9218
- });
9219
- return data;
9220
- }
9221
- catch (error) {
9222
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
9223
- info: error.response.data,
9224
- });
9225
- }
9226
- }
9227
- async createTransaction(info) {
9228
- return;
9229
- }
9230
- }
9231
-
9232
- class PagarmeV5PixAxiosAdapter {
9233
- constructor(credentials, paymentRepository) {
9234
- this.credentials = credentials;
9235
- this.paymentRepository = paymentRepository;
9236
- }
9237
- async pay2(payload) {
9238
- try {
9239
- // const payload = PagarMeV5RequestHelper.build(checkout, 'pix')
9240
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9241
- const { data } = await axios__default["default"]({
9242
- method: 'POST',
9243
- url: `${this.credentials.URL}/orders`,
9244
- headers: {
9245
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9246
- 'Content-Type': 'application/json',
9247
- },
9248
- data: payload,
9249
- });
9250
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9251
- // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9252
- // const payment = await this.paymentRepository.create(paymentData)
9253
- return data;
9254
- }
9255
- catch (error) {
9256
- if (error instanceof axios.AxiosError) {
9257
- console.error(error.message);
9258
- console.error(error.response.data);
9259
- }
9260
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9261
- // checkoutId: checkout.id,
9262
- // userEmail: checkout.user.email,
9263
- info: error.response?.data,
9264
- });
9265
- }
9266
- }
9267
- async pay(checkout) {
9268
- try {
9269
- const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9270
- console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9271
- const { data } = await axios__default["default"]({
9272
- method: 'POST',
9273
- url: `${this.credentials.URL}/orders`,
9274
- headers: {
9275
- Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9276
- 'Content-Type': 'application/json',
9277
- },
9278
- data: payload,
9279
- });
9280
- console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9281
- if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
9282
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9283
- checkoutId: checkout.id,
9284
- userEmail: checkout.user.email,
9285
- info: data.charges.at(0).last_transaction?.gateway_response,
9286
- });
9287
- }
9288
- const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9289
- return payment;
9290
- }
9291
- catch (error) {
9292
- console.error('Full error: ', JSON.stringify(error));
9293
- if (error instanceof axios.AxiosError) {
9294
- console.error('Error: ', error.message);
9295
- console.error('Error response: ', error.response, 'error data: ', error.response?.data);
9296
- }
9297
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9298
- checkoutId: checkout.id,
9299
- userEmail: checkout.user.email,
9300
- info: error.response?.data,
9301
- });
9302
- }
9303
- }
9304
- }
9305
-
9306
8809
  class VertexAxiosAdapter {
9307
8810
  constructor(config) {
9308
8811
  this.config = config;
@@ -9659,9 +9162,6 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
9659
9162
  exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
9660
9163
  exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
9661
9164
  exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
9662
- exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
9663
- exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
9664
- exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
9665
9165
  exports.Payment = Payment;
9666
9166
  exports.PaymentError = PaymentError;
9667
9167
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;