@infrab4a/connect 5.1.0-beta.0 → 5.1.0-beta.2

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.
package/index.cjs.js CHANGED
@@ -8597,7 +8597,9 @@ class PagarMeV5RequestHelper {
8597
8597
  };
8598
8598
  }
8599
8599
  static buildItems(checkout) {
8600
- return checkout.lineItems.map((item) => {
8600
+ return checkout.lineItems
8601
+ .filter((item) => !item.isGift)
8602
+ .map((item) => {
8601
8603
  return {
8602
8604
  amount: Math.floor(item.pricePaid * 100),
8603
8605
  description: item.name,
@@ -8624,14 +8626,14 @@ class PagarMeV5RequestHelper {
8624
8626
  zip_code: checkout.shippingAddress.zip,
8625
8627
  city: checkout.billingAddress.city,
8626
8628
  state: checkout.billingAddress.state,
8627
- country: checkout.billingAddress.country,
8629
+ country: 'BR',
8628
8630
  },
8629
8631
  };
8630
8632
  }
8631
8633
  static buildShipping(checkout) {
8632
8634
  return {
8633
- amount: checkout.shipping.ShippingPrice,
8634
- description: '',
8635
+ amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8636
+ description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8635
8637
  recipient_name: checkout.shippingAddress.recipient,
8636
8638
  recipient_phone: checkout.user.phone,
8637
8639
  address: {
@@ -8640,7 +8642,7 @@ class PagarMeV5RequestHelper {
8640
8642
  zip_code: checkout.shippingAddress.zip,
8641
8643
  city: checkout.shippingAddress.city,
8642
8644
  state: checkout.shippingAddress.state,
8643
- country: checkout.shippingAddress.country,
8645
+ country: 'BR',
8644
8646
  },
8645
8647
  };
8646
8648
  }
@@ -8979,12 +8981,48 @@ class PagarmePixAxiosAdapter {
8979
8981
  }
8980
8982
  }
8981
8983
 
8982
- /* eslint-disable no-console */
8983
8984
  class PagarmeV5BankSlipAxiosAdapter {
8984
8985
  constructor(credentials, paymentRepository) {
8985
8986
  this.credentials = credentials;
8986
8987
  this.paymentRepository = paymentRepository;
8987
8988
  }
8989
+ async pay2(payload) {
8990
+ try {
8991
+ console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
8992
+ const { data } = await axios__default["default"]({
8993
+ method: 'POST',
8994
+ url: `${this.credentials.URL}/orders`,
8995
+ headers: {
8996
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
8997
+ 'Content-Type': 'application/json',
8998
+ },
8999
+ data: payload,
9000
+ });
9001
+ console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
9002
+ if (data.charges.at(0).status !== exports.PagarMeV5OrderStatus['Em processamento'] ||
9003
+ data.charges.at(0).status !== exports.PagarMeV5PaymentStatus['Falha']) {
9004
+ return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9005
+ // checkoutId: checkout.id,
9006
+ // userEmail: checkout.user.email,
9007
+ info: data,
9008
+ }));
9009
+ }
9010
+ // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
9011
+ // const payment = await this.paymentRepository.create(paymentData)
9012
+ return data;
9013
+ }
9014
+ catch (error) {
9015
+ if (error instanceof axios.AxiosError) {
9016
+ console.error(error.message);
9017
+ console.error(error.response.data);
9018
+ }
9019
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9020
+ // checkoutId: checkout.id,
9021
+ // userEmail: checkout.user.email,
9022
+ info: error.response.data,
9023
+ });
9024
+ }
9025
+ }
8988
9026
  async pay(checkout) {
8989
9027
  try {
8990
9028
  const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
@@ -9012,8 +9050,10 @@ class PagarmeV5BankSlipAxiosAdapter {
9012
9050
  return payment;
9013
9051
  }
9014
9052
  catch (error) {
9015
- console.log(error.response?.data?.errors);
9016
- console.log(error.response?.data?.request);
9053
+ if (error instanceof axios.AxiosError) {
9054
+ console.error(error.message);
9055
+ console.error(error.response.data);
9056
+ }
9017
9057
  throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
9018
9058
  checkoutId: checkout.id,
9019
9059
  userEmail: checkout.user.email,
@@ -9082,6 +9122,10 @@ class PagarmeV5CardAxiosAdapter {
9082
9122
  if (error instanceof PaymentError) {
9083
9123
  throw error;
9084
9124
  }
9125
+ if (error instanceof axios.AxiosError) {
9126
+ console.error(error.message);
9127
+ console.error(error.response.data);
9128
+ }
9085
9129
  throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9086
9130
  }
9087
9131
  }
@@ -9188,7 +9232,6 @@ class PagarmeV5CardAxiosAdapter {
9188
9232
  }
9189
9233
  }
9190
9234
 
9191
- /* eslint-disable no-console */
9192
9235
  class PagarmeV5PixAxiosAdapter {
9193
9236
  constructor(credentials, paymentRepository) {
9194
9237
  this.credentials = credentials;
@@ -9197,7 +9240,7 @@ class PagarmeV5PixAxiosAdapter {
9197
9240
  async pay(checkout) {
9198
9241
  try {
9199
9242
  const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9200
- console.warn('[PAGARME PIX DATA TO SEND]', payload);
9243
+ console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9201
9244
  const { data } = await axios__default["default"]({
9202
9245
  method: 'POST',
9203
9246
  url: `${this.credentials.URL}/orders`,
@@ -9213,8 +9256,10 @@ class PagarmeV5PixAxiosAdapter {
9213
9256
  return payment;
9214
9257
  }
9215
9258
  catch (error) {
9216
- console.log(error.response?.data?.errors);
9217
- console.log(error.response?.data?.request);
9259
+ if (error instanceof axios.AxiosError) {
9260
+ console.error(error.message);
9261
+ console.error(error.response.data);
9262
+ }
9218
9263
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9219
9264
  checkoutId: checkout.id,
9220
9265
  userEmail: checkout.user.email,
package/index.esm.js CHANGED
@@ -8572,7 +8572,9 @@ class PagarMeV5RequestHelper {
8572
8572
  };
8573
8573
  }
8574
8574
  static buildItems(checkout) {
8575
- return checkout.lineItems.map((item) => {
8575
+ return checkout.lineItems
8576
+ .filter((item) => !item.isGift)
8577
+ .map((item) => {
8576
8578
  return {
8577
8579
  amount: Math.floor(item.pricePaid * 100),
8578
8580
  description: item.name,
@@ -8599,14 +8601,14 @@ class PagarMeV5RequestHelper {
8599
8601
  zip_code: checkout.shippingAddress.zip,
8600
8602
  city: checkout.billingAddress.city,
8601
8603
  state: checkout.billingAddress.state,
8602
- country: checkout.billingAddress.country,
8604
+ country: 'BR',
8603
8605
  },
8604
8606
  };
8605
8607
  }
8606
8608
  static buildShipping(checkout) {
8607
8609
  return {
8608
- amount: checkout.shipping.ShippingPrice,
8609
- description: '',
8610
+ amount: Math.floor(checkout.shipping.ShippingPrice * 100),
8611
+ description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
8610
8612
  recipient_name: checkout.shippingAddress.recipient,
8611
8613
  recipient_phone: checkout.user.phone,
8612
8614
  address: {
@@ -8615,7 +8617,7 @@ class PagarMeV5RequestHelper {
8615
8617
  zip_code: checkout.shippingAddress.zip,
8616
8618
  city: checkout.shippingAddress.city,
8617
8619
  state: checkout.shippingAddress.state,
8618
- country: checkout.shippingAddress.country,
8620
+ country: 'BR',
8619
8621
  },
8620
8622
  };
8621
8623
  }
@@ -8954,12 +8956,48 @@ class PagarmePixAxiosAdapter {
8954
8956
  }
8955
8957
  }
8956
8958
 
8957
- /* eslint-disable no-console */
8958
8959
  class PagarmeV5BankSlipAxiosAdapter {
8959
8960
  constructor(credentials, paymentRepository) {
8960
8961
  this.credentials = credentials;
8961
8962
  this.paymentRepository = paymentRepository;
8962
8963
  }
8964
+ async pay2(payload) {
8965
+ try {
8966
+ console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
8967
+ const { data } = await axios({
8968
+ method: 'POST',
8969
+ url: `${this.credentials.URL}/orders`,
8970
+ headers: {
8971
+ Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
8972
+ 'Content-Type': 'application/json',
8973
+ },
8974
+ data: payload,
8975
+ });
8976
+ console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
8977
+ if (data.charges.at(0).status !== PagarMeV5OrderStatus['Em processamento'] ||
8978
+ data.charges.at(0).status !== PagarMeV5PaymentStatus['Falha']) {
8979
+ return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8980
+ // checkoutId: checkout.id,
8981
+ // userEmail: checkout.user.email,
8982
+ info: data,
8983
+ }));
8984
+ }
8985
+ // const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
8986
+ // const payment = await this.paymentRepository.create(paymentData)
8987
+ return data;
8988
+ }
8989
+ catch (error) {
8990
+ if (error instanceof AxiosError) {
8991
+ console.error(error.message);
8992
+ console.error(error.response.data);
8993
+ }
8994
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8995
+ // checkoutId: checkout.id,
8996
+ // userEmail: checkout.user.email,
8997
+ info: error.response.data,
8998
+ });
8999
+ }
9000
+ }
8963
9001
  async pay(checkout) {
8964
9002
  try {
8965
9003
  const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
@@ -8987,8 +9025,10 @@ class PagarmeV5BankSlipAxiosAdapter {
8987
9025
  return payment;
8988
9026
  }
8989
9027
  catch (error) {
8990
- console.log(error.response?.data?.errors);
8991
- console.log(error.response?.data?.request);
9028
+ if (error instanceof AxiosError) {
9029
+ console.error(error.message);
9030
+ console.error(error.response.data);
9031
+ }
8992
9032
  throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
8993
9033
  checkoutId: checkout.id,
8994
9034
  userEmail: checkout.user.email,
@@ -9057,6 +9097,10 @@ class PagarmeV5CardAxiosAdapter {
9057
9097
  if (error instanceof PaymentError) {
9058
9098
  throw error;
9059
9099
  }
9100
+ if (error instanceof AxiosError) {
9101
+ console.error(error.message);
9102
+ console.error(error.response.data);
9103
+ }
9060
9104
  throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
9061
9105
  }
9062
9106
  }
@@ -9163,7 +9207,6 @@ class PagarmeV5CardAxiosAdapter {
9163
9207
  }
9164
9208
  }
9165
9209
 
9166
- /* eslint-disable no-console */
9167
9210
  class PagarmeV5PixAxiosAdapter {
9168
9211
  constructor(credentials, paymentRepository) {
9169
9212
  this.credentials = credentials;
@@ -9172,7 +9215,7 @@ class PagarmeV5PixAxiosAdapter {
9172
9215
  async pay(checkout) {
9173
9216
  try {
9174
9217
  const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
9175
- console.warn('[PAGARME PIX DATA TO SEND]', payload);
9218
+ console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
9176
9219
  const { data } = await axios({
9177
9220
  method: 'POST',
9178
9221
  url: `${this.credentials.URL}/orders`,
@@ -9188,8 +9231,10 @@ class PagarmeV5PixAxiosAdapter {
9188
9231
  return payment;
9189
9232
  }
9190
9233
  catch (error) {
9191
- console.log(error.response?.data?.errors);
9192
- console.log(error.response?.data?.request);
9234
+ if (error instanceof AxiosError) {
9235
+ console.error(error.message);
9236
+ console.error(error.response.data);
9237
+ }
9193
9238
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
9194
9239
  checkoutId: checkout.id,
9195
9240
  userEmail: checkout.user.email,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.1.0-beta.0",
3
+ "version": "5.1.0-beta.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -6,6 +6,7 @@ export declare class PagarmeV5BankSlipAxiosAdapter implements PaymentProviderBan
6
6
  private credentials;
7
7
  private paymentRepository;
8
8
  constructor(credentials: PagarmeCredentialsV5, paymentRepository: PaymentRepository);
9
+ pay2(payload: any): Promise<any>;
9
10
  pay(checkout: Checkout): Promise<Payment>;
10
11
  getBoletoTransaction(paymentId: number): Promise<PaymentTransaction>;
11
12
  }