@infrab4a/connect 5.3.0-beta.2 → 5.3.0-beta.4

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 (35) hide show
  1. package/index.cjs.js +544 -6
  2. package/index.esm.js +542 -7
  3. package/package.json +1 -1
  4. package/src/domain/catalog/models/product-base.d.ts +1 -0
  5. package/src/domain/shopping/enums/index.d.ts +2 -0
  6. package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
  7. package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +5 -0
  8. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +10 -2
  9. package/src/domain/shopping/models/payment-transaction.d.ts +17 -2
  10. package/src/domain/shopping/models/payment.d.ts +2 -1
  11. package/src/domain/shopping/types/card-info.type.d.ts +1 -0
  12. package/src/domain/shopping/types/index.d.ts +1 -0
  13. package/src/domain/shopping/types/pagarme-card.type.d.ts +9 -3
  14. package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
  15. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +9 -3
  16. package/src/domain/users/models/user-payment-method.d.ts +2 -0
  17. package/src/infra/pagarme/adapters/helpers/index.d.ts +2 -0
  18. package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +12 -0
  19. package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +10 -0
  20. package/src/infra/pagarme/adapters/index.d.ts +2 -3
  21. package/src/infra/pagarme/adapters/v4/index.d.ts +3 -0
  22. package/src/infra/pagarme/adapters/{pagarme-bank-slip-payment-axios.adapter.d.ts → v4/pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
  23. package/src/infra/pagarme/adapters/{pagarme-card-payment-axios.adapter.d.ts → v4/pagarme-card-payment-axios.adapter.d.ts} +7 -6
  24. package/src/infra/pagarme/adapters/{pagarme-pix-payment-axios.adapter.d.ts → v4/pagarme-pix-payment-axios.adapter.d.ts} +4 -4
  25. package/src/infra/pagarme/adapters/v5/index.d.ts +3 -0
  26. package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
  27. package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +24 -0
  28. package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +10 -0
  29. package/src/infra/pagarme/index.d.ts +1 -0
  30. package/src/infra/pagarme/types/index.d.ts +1 -0
  31. package/src/infra/pagarme/types/v5/index.d.ts +4 -0
  32. package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +19 -0
  33. package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +89 -0
  34. package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +126 -0
  35. package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
package/index.cjs.js CHANGED
@@ -73,6 +73,33 @@ 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
+
76
103
  exports.PaymentMethods = void 0;
77
104
  (function (PaymentMethods) {
78
105
  PaymentMethods["CARD"] = "card";
@@ -88,6 +115,13 @@ exports.PaymentProviders = void 0;
88
115
  PaymentProviders["GLAMPOINTS"] = "glampoints";
89
116
  })(exports.PaymentProviders || (exports.PaymentProviders = {}));
90
117
 
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
+
91
125
  class BasePaymentMethodFactory {
92
126
  constructor(methods) {
93
127
  this.methods = methods;
@@ -7319,6 +7353,12 @@ const commonFields = [
7319
7353
  to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7320
7354
  },
7321
7355
  },
7356
+ {
7357
+ imagesCard: {
7358
+ columnName: 'images_card',
7359
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
7360
+ },
7361
+ },
7322
7362
  'name',
7323
7363
  {
7324
7364
  price: {
@@ -7462,7 +7502,16 @@ const fieldsConfiguration$2 = [
7462
7502
  variants: {
7463
7503
  columnName: 'variants',
7464
7504
  foreignKeyColumn: { product_id: 'id' },
7465
- fields: ['id', 'ean', 'grade', 'price', 'published', 'stock', 'tagsProfile'],
7505
+ fields: [
7506
+ 'id',
7507
+ 'ean',
7508
+ 'grade',
7509
+ 'price',
7510
+ 'published',
7511
+ 'stock',
7512
+ { tagsCollection: { columnName: 'tags_collection' } },
7513
+ { tagsProfile: { columnName: 'tags_profile' } },
7514
+ ],
7466
7515
  },
7467
7516
  },
7468
7517
  ];
@@ -8128,9 +8177,24 @@ const fieldsConfiguration$1 = [
8128
8177
  'validity',
8129
8178
  // { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
8130
8179
  'published',
8131
- { tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
8132
- { tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
8133
- { daysOfUse: { columnName: 'days_of_use' } },
8180
+ {
8181
+ images: {
8182
+ columnName: 'images',
8183
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8184
+ },
8185
+ },
8186
+ {
8187
+ miniatures: {
8188
+ columnName: 'miniatures',
8189
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8190
+ },
8191
+ },
8192
+ {
8193
+ imagesCard: {
8194
+ columnName: 'images_card',
8195
+ to: (value) => (value?.length > 0 ? `{"${value?.join?.('","') || ''}"}` : '{}'),
8196
+ },
8197
+ },
8134
8198
  ];
8135
8199
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
8136
8200
  constructor({ endpoint, authOptions, interceptors, cache, }) {
@@ -8663,6 +8727,201 @@ class PagarmePaymentOperationsHelper {
8663
8727
  }
8664
8728
  }
8665
8729
 
8730
+ class PagarMeV5RequestHelper {
8731
+ static build(checkout, method, card) {
8732
+ return {
8733
+ items: this.buildItems(checkout),
8734
+ customer: this.buildCustomer(checkout),
8735
+ shipping: this.buildShipping(checkout),
8736
+ payments: this.buildPayment(checkout, method, card),
8737
+ };
8738
+ }
8739
+ static buildItems(checkout) {
8740
+ return checkout.lineItems
8741
+ .filter((item) => !item.isGift)
8742
+ .map((item) => {
8743
+ return {
8744
+ amount: Math.floor(item.pricePaid * 100),
8745
+ description: item.name,
8746
+ quantity: item.quantity,
8747
+ code: item.EAN,
8748
+ };
8749
+ });
8750
+ }
8751
+ static buildCustomer(checkout) {
8752
+ return {
8753
+ name: checkout.user.displayName,
8754
+ email: checkout.user.email,
8755
+ type: 'individual',
8756
+ document: checkout.user.cpf,
8757
+ phones: {
8758
+ home_phone: {
8759
+ country_code: '55',
8760
+ number: checkout.user.phone.slice(2),
8761
+ area_code: checkout.user.phone.slice(0, 2),
8762
+ },
8763
+ mobile_phone: {
8764
+ country_code: '55',
8765
+ number: checkout.user.phone.slice(2),
8766
+ area_code: checkout.user.phone.slice(0, 2),
8767
+ },
8768
+ },
8769
+ address: {
8770
+ line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8771
+ line_2: `${checkout.billingAddress.extension}`,
8772
+ zip_code: checkout.shippingAddress.zip,
8773
+ city: checkout.billingAddress.city,
8774
+ state: checkout.billingAddress.state,
8775
+ country: 'BR',
8776
+ },
8777
+ };
8778
+ }
8779
+ static buildShipping(checkout) {
8780
+ return {
8781
+ amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8782
+ description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8783
+ recipient_name: checkout.shippingAddress.recipient,
8784
+ recipient_phone: checkout.user.phone,
8785
+ address: {
8786
+ line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
8787
+ line_2: `${checkout.shippingAddress.extension}`,
8788
+ zip_code: checkout.shippingAddress.zip,
8789
+ city: checkout.shippingAddress.city,
8790
+ state: checkout.shippingAddress.state,
8791
+ country: 'BR',
8792
+ },
8793
+ };
8794
+ }
8795
+ static buildPayment(checkout, method, card) {
8796
+ return [
8797
+ {
8798
+ payment_method: method,
8799
+ amount: Math.floor(checkout.totalPrice * 100),
8800
+ ...(method === 'pix' && {
8801
+ pix: this.getPixOrder(),
8802
+ }),
8803
+ ...(method === 'boleto' && {
8804
+ boleto: this.getBoletoOrder(),
8805
+ }),
8806
+ ...(method === 'credit_card' && {
8807
+ credit_card: this.getCardOrder(checkout, card),
8808
+ }),
8809
+ },
8810
+ ];
8811
+ }
8812
+ static getPixOrder() {
8813
+ return {
8814
+ expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
8815
+ };
8816
+ }
8817
+ static getBoletoOrder() {
8818
+ return {
8819
+ due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
8820
+ instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
8821
+ type: 'DM',
8822
+ document_number: new Date().getTime().toString(),
8823
+ };
8824
+ }
8825
+ static getCardOrder(checkout, card) {
8826
+ return {
8827
+ installments: card.installments,
8828
+ statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
8829
+ card_id: card.cardId,
8830
+ card: {
8831
+ cvv: card.cardCvv,
8832
+ billing_address: {
8833
+ line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
8834
+ zip_code: checkout.billingAddress.zip,
8835
+ city: checkout.billingAddress.city,
8836
+ state: checkout.billingAddress.state,
8837
+ country: 'BR',
8838
+ },
8839
+ },
8840
+ };
8841
+ }
8842
+ }
8843
+
8844
+ class PagarMeV5ResponseHelper {
8845
+ static build(method, checkout, response) {
8846
+ return Payment.toInstance({
8847
+ createdAt: new Date(),
8848
+ updatedAt: new Date(),
8849
+ userId: checkout.user.id,
8850
+ checkoutId: checkout.id,
8851
+ totalPrice: checkout.totalPrice,
8852
+ paymentProvider: exports.PaymentProviders.PAGARME,
8853
+ pagarMeOrderId: response.id,
8854
+ transaction: this.buildPaymentTransaction(method, response),
8855
+ });
8856
+ }
8857
+ static buildPaymentTransaction(method, response) {
8858
+ const charger = response.charges.at(0);
8859
+ const transaction = charger.last_transaction;
8860
+ return PaymentTransaction.toInstance({
8861
+ acquirer_name: 'pagar_me',
8862
+ amount: charger.amount,
8863
+ currency: charger.currency,
8864
+ gateway_id: charger.gateway_id,
8865
+ status: this.getPaymentStatus(transaction.status),
8866
+ payment_method: charger.payment_method,
8867
+ date_created: charger.created_at,
8868
+ date_updated: charger.updated_at,
8869
+ paid_amount: charger.paid_amount,
8870
+ paid_at: charger.paid_at,
8871
+ order_id: response.id,
8872
+ charger_id: charger.id,
8873
+ tid: charger.id,
8874
+ id: charger.id,
8875
+ ...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
8876
+ ...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
8877
+ ...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
8878
+ });
8879
+ }
8880
+ static getPaymentStatus(status) {
8881
+ if (status == exports.PagarMeV5PaymentStatus.Gerado)
8882
+ return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
8883
+ if (status == exports.PagarMeV5PaymentStatus.Capturada)
8884
+ return exports.PagarMeV5PaymentStatus.Pago;
8885
+ return status;
8886
+ }
8887
+ static getBoletoReponse(transaction) {
8888
+ return {
8889
+ boleto_url: transaction.url?.toString(),
8890
+ boleto_barcode: transaction.line?.toString(),
8891
+ boleto_qr_code: transaction.qr_code?.toString(),
8892
+ boleto_expiration_date: transaction.due_at?.toString(),
8893
+ boleto_instructions: transaction.instructions?.toString(),
8894
+ boleto_nosso_numero: transaction.nosso_numero?.toString(),
8895
+ boleto_type: transaction.type?.toString(),
8896
+ boleto_document_number: transaction.document_number?.toString(),
8897
+ };
8898
+ }
8899
+ static getPixReponse(transaction) {
8900
+ return {
8901
+ pix_qr_code: transaction.qr_code?.toString(),
8902
+ pix_qr_code_url: transaction.qr_code_url?.toString(),
8903
+ pix_expiration_date: transaction.expires_at?.toString(),
8904
+ };
8905
+ }
8906
+ static getCardReponse(transaction) {
8907
+ return {
8908
+ soft_descriptor: transaction.statement_descriptor?.toString(),
8909
+ acquirer_name: transaction.acquirer_name?.toString(),
8910
+ acquirer_id: transaction.acquirer_tid?.toString(),
8911
+ acquirer_nsu: transaction.acquirer_nsu?.toString(),
8912
+ acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
8913
+ acquirer_message: transaction.acquirer_message?.toString(),
8914
+ acquirer_return_code: transaction.acquirer_return_code?.toString(),
8915
+ installments: transaction.installments ?? null,
8916
+ card_holder_name: transaction.card?.holder_name?.toString(),
8917
+ card_last_digits: transaction.card?.last_four_digits?.toString(),
8918
+ card_first_digits: transaction.card?.first_six_digits?.toString(),
8919
+ card_brand: transaction.card?.brand?.toString(),
8920
+ card_id: transaction.card?.id?.toString(),
8921
+ };
8922
+ }
8923
+ }
8924
+
8666
8925
  class PagarmeCardAxiosAdapter {
8667
8926
  constructor(credentials, paymentRepository, orderBlockedRepository) {
8668
8927
  this.credentials = credentials;
@@ -8719,8 +8978,9 @@ class PagarmeCardAxiosAdapter {
8719
8978
  });
8720
8979
  }
8721
8980
  }
8722
- async createCardHash(bu) {
8723
- const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.SHOP_API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
8981
+ async createCardHash(bu, shop) {
8982
+ const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
8983
+ const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
8724
8984
  try {
8725
8985
  const { data } = await axios__default["default"]({
8726
8986
  method: 'GET',
@@ -8883,6 +9143,281 @@ class PagarmePixAxiosAdapter {
8883
9143
  }
8884
9144
  }
8885
9145
 
9146
+ class PagarmeV5BankSlipAxiosAdapter {
9147
+ constructor(credentials, paymentRepository) {
9148
+ this.credentials = credentials;
9149
+ this.paymentRepository = paymentRepository;
9150
+ }
9151
+ async pay(checkout) {
9152
+ try {
9153
+ const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
9154
+ console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
9155
+ const { data } = await axios__default["default"]({
9156
+ method: 'POST',
9157
+ url: `${this.credentials.URL}/orders`,
9158
+ headers: {
9159
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9160
+ 'Content-Type': 'application/json',
9161
+ },
9162
+ data: payload,
9163
+ });
9164
+ console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9165
+ if (data.status === exports.PagarMeV5OrderStatus.Falha ||
9166
+ data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
9167
+ (data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
9168
+ data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
9169
+ return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9170
+ checkoutId: checkout.id,
9171
+ userEmail: checkout.user.email,
9172
+ info: data.charges.at(0).last_transaction?.gateway_response,
9173
+ }));
9174
+ }
9175
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
9176
+ return payment;
9177
+ }
9178
+ catch (error) {
9179
+ if (error instanceof axios.AxiosError) {
9180
+ console.error('error data: ', JSON.stringify(error.response?.data));
9181
+ }
9182
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9183
+ checkoutId: checkout.id,
9184
+ userEmail: checkout.user.email,
9185
+ info: error.response?.data,
9186
+ });
9187
+ }
9188
+ }
9189
+ async getBoletoTransaction(paymentId) {
9190
+ try {
9191
+ const { data } = await axios__default["default"]({
9192
+ method: 'GET',
9193
+ url: `${this.credentials.URL}/charges/${paymentId}`,
9194
+ headers: {
9195
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9196
+ 'Content-Type': 'application/json',
9197
+ },
9198
+ });
9199
+ const payment = await this.paymentRepository.get({
9200
+ id: data.id,
9201
+ });
9202
+ return payment.transaction;
9203
+ }
9204
+ catch (error) {
9205
+ throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
9206
+ paymentId,
9207
+ info: error.response.data,
9208
+ });
9209
+ }
9210
+ }
9211
+ }
9212
+
9213
+ class PagarmeV5CardAxiosAdapter {
9214
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
9215
+ this.credentials = credentials;
9216
+ this.paymentRepository = paymentRepository;
9217
+ this.orderBlockedRepository = orderBlockedRepository;
9218
+ }
9219
+ async pay(checkout, card) {
9220
+ try {
9221
+ const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
9222
+ console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
9223
+ const { data } = await axios__default["default"]({
9224
+ method: 'POST',
9225
+ url: `${this.credentials.URL}/orders`,
9226
+ headers: {
9227
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9228
+ 'Content-Type': 'application/json',
9229
+ },
9230
+ data: payload,
9231
+ });
9232
+ console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
9233
+ if (data.status == exports.PagarMeV5OrderStatus.Falha ||
9234
+ data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
9235
+ data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
9236
+ await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
9237
+ checkout,
9238
+ card,
9239
+ orderBlockedRepository: this.orderBlockedRepository,
9240
+ });
9241
+ throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
9242
+ }
9243
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
9244
+ return payment;
9245
+ }
9246
+ catch (error) {
9247
+ if (error instanceof PaymentError) {
9248
+ throw error;
9249
+ }
9250
+ if (error instanceof axios.AxiosError) {
9251
+ console.error('error data: ', JSON.stringify(error.response?.data));
9252
+ }
9253
+ throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9254
+ }
9255
+ }
9256
+ async addCard(card, customer) {
9257
+ try {
9258
+ const { id } = await this.createOrUpdateCustomer(customer);
9259
+ const { data } = await axios__default["default"]({
9260
+ method: 'POST',
9261
+ url: `${this.credentials.URL}/customers/${id}/cards`,
9262
+ headers: {
9263
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9264
+ 'Content-Type': 'application/json',
9265
+ },
9266
+ data: {
9267
+ number: card.number,
9268
+ holder_name: card.name,
9269
+ holder_document: card.cpf,
9270
+ exp_month: card.expirationDate.split('/').at(0),
9271
+ exp_year: card.expirationDate.split('/').at(1),
9272
+ cvv: card.cvv,
9273
+ billing_address: {
9274
+ line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9275
+ line_2: `${customer.billingAddress.extension}`,
9276
+ zip_code: customer.billingAddress.zip,
9277
+ city: customer.billingAddress.city,
9278
+ state: customer.billingAddress.state,
9279
+ country: 'BR',
9280
+ },
9281
+ },
9282
+ });
9283
+ return data;
9284
+ }
9285
+ catch (error) {
9286
+ console.warn(JSON.stringify(error));
9287
+ throw error;
9288
+ }
9289
+ }
9290
+ async createCardHash(bu, shop) {
9291
+ const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
9292
+ const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
9293
+ try {
9294
+ const { data } = await axios__default["default"]({
9295
+ method: 'GET',
9296
+ headers: {
9297
+ 'content-type': 'application/json',
9298
+ },
9299
+ url: `${this.credentials.URL}/transactions/card_hash_key`,
9300
+ data: JSON.stringify({
9301
+ api_key: key,
9302
+ }),
9303
+ });
9304
+ return data;
9305
+ }
9306
+ catch (error) {
9307
+ throw new BusinessError('Houve uma falha gerar o hash', {
9308
+ info: error.response.data,
9309
+ });
9310
+ }
9311
+ }
9312
+ async getCardByToken(customerId, token) {
9313
+ try {
9314
+ const { data } = await axios__default["default"]({
9315
+ method: 'GET',
9316
+ url: `${this.credentials.URL}/cards/${token}`,
9317
+ data: {
9318
+ api_key: this.credentials.API_KEY,
9319
+ },
9320
+ });
9321
+ return data;
9322
+ }
9323
+ catch (error) {
9324
+ throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
9325
+ info: error.response.data,
9326
+ });
9327
+ }
9328
+ }
9329
+ async createTransaction(info) {
9330
+ return info;
9331
+ }
9332
+ async createOrUpdateCustomer(customer) {
9333
+ try {
9334
+ const { data } = await axios__default["default"]({
9335
+ method: 'POST',
9336
+ url: `${this.credentials.URL}/customers`,
9337
+ headers: {
9338
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9339
+ 'Content-Type': 'application/json',
9340
+ },
9341
+ data: {
9342
+ name: customer.displayName,
9343
+ email: customer.email,
9344
+ document: customer.cpf,
9345
+ type: 'individual',
9346
+ document_type: 'CPF',
9347
+ address: {
9348
+ line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
9349
+ line_2: `${customer.billingAddress.extension}`,
9350
+ zip_code: customer.billingAddress.zip,
9351
+ city: customer.billingAddress.city,
9352
+ state: customer.billingAddress.state,
9353
+ country: 'BR',
9354
+ },
9355
+ birthdate: dateFns.format(new Date(customer.birthday), 'MM/dd/yyyy'),
9356
+ phones: {
9357
+ home_phone: {
9358
+ country_code: '55',
9359
+ number: customer.phone.slice(2),
9360
+ area_code: customer.phone.slice(0, 2),
9361
+ },
9362
+ mobile_phone: {
9363
+ country_code: '55',
9364
+ number: customer.phone.slice(2),
9365
+ area_code: customer.phone.slice(0, 2),
9366
+ },
9367
+ },
9368
+ },
9369
+ });
9370
+ return data;
9371
+ }
9372
+ catch (error) {
9373
+ console.warn(error);
9374
+ throw error;
9375
+ }
9376
+ }
9377
+ }
9378
+
9379
+ class PagarmeV5PixAxiosAdapter {
9380
+ constructor(credentials, paymentRepository) {
9381
+ this.credentials = credentials;
9382
+ this.paymentRepository = paymentRepository;
9383
+ }
9384
+ async pay(checkout) {
9385
+ try {
9386
+ const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9387
+ console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9388
+ const { data } = await axios__default["default"]({
9389
+ method: 'POST',
9390
+ url: `${this.credentials.URL}/orders`,
9391
+ headers: {
9392
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
9393
+ 'Content-Type': 'application/json',
9394
+ },
9395
+ data: payload,
9396
+ });
9397
+ console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
9398
+ if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
9399
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9400
+ checkoutId: checkout.id,
9401
+ userEmail: checkout.user.email,
9402
+ info: data.charges.at(0).last_transaction?.gateway_response,
9403
+ });
9404
+ }
9405
+ const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
9406
+ return payment;
9407
+ }
9408
+ catch (error) {
9409
+ if (error instanceof axios.AxiosError) {
9410
+ console.error('error data: ', JSON.stringify(error.response?.data));
9411
+ }
9412
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9413
+ checkoutId: checkout.id,
9414
+ userEmail: checkout.user.email,
9415
+ info: error.response?.data,
9416
+ });
9417
+ }
9418
+ }
9419
+ }
9420
+
8886
9421
  class VertexAxiosAdapter {
8887
9422
  constructor(config) {
8888
9423
  this.config = config;
@@ -9239,6 +9774,9 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
9239
9774
  exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
9240
9775
  exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
9241
9776
  exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
9777
+ exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
9778
+ exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
9779
+ exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
9242
9780
  exports.Payment = Payment;
9243
9781
  exports.PaymentError = PaymentError;
9244
9782
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;