@infrab4a/connect-nestjs 1.8.0-beta.17 → 1.8.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.
Files changed (3) hide show
  1. package/index.cjs.js +16 -31
  2. package/index.esm.js +17 -32
  3. package/package.json +2 -2
package/index.cjs.js CHANGED
@@ -303,30 +303,26 @@ class PagarmeBankSlipAPIAdapter {
303
303
  async pay(checkout) {
304
304
  try {
305
305
  const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
306
- const payload = this.createBoletoPayment(checkout);
307
- const result = await client.transactions.create(payload);
308
- console.log('[PAGARME BOLETO DATA TO SEND]', payload);
309
- console.log('result PagarmeBankSlipAPIAdapter', JSON.stringify(result));
310
- if (result.status !== connect.PagarmePaymentStatus['Em processamento']) {
306
+ const result = client.transactions.create(Object.assign({}, this.createBoletoPayment(checkout)));
307
+ if (result.data.status !== connect.PagarmePaymentStatus['Em processamento']) {
311
308
  return Promise.reject(new connect.PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
312
309
  checkoutId: checkout.id,
313
310
  userEmail: checkout.user.email,
314
- info: result,
311
+ info: result.data,
315
312
  }));
316
313
  }
317
- const payment = await this.paymentRepository.create({
314
+ const payment = await this.paymentRepository.create(connect.Payment.toInstance({
318
315
  createdAt: new Date(),
319
316
  updatedAt: new Date(),
320
317
  userId: checkout.user.id,
321
318
  checkoutId: checkout.id,
322
319
  totalPrice: checkout.totalPrice,
323
320
  paymentProvider: 'pagarMe',
324
- transaction: result,
325
- });
321
+ transaction: result.data,
322
+ }));
326
323
  return payment;
327
324
  }
328
325
  catch (error) {
329
- console.error('Error PagarmeBankSlipAPIAdapter', JSON.stringify(error));
330
326
  throw new connect.PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
331
327
  checkoutId: checkout.id,
332
328
  userEmail: checkout.user.email,
@@ -381,31 +377,27 @@ class PagarmeCardAPIAdapter {
381
377
  async pay(checkout, card) {
382
378
  try {
383
379
  const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
384
- const payload = this.createCardPayment(checkout, card);
385
- const result = await client.transactions.create(payload);
386
- console.log('[PAGARME CARD DATA TO SEND]', payload);
387
- console.log('result PagarmeCardAPIAdapter', JSON.stringify(result));
388
- if (result.status !== connect.PagarmePaymentStatus.Pago) {
380
+ const result = client.transactions.create(Object.assign({}, this.createCardPayment(checkout, card)));
381
+ if (result.data.status !== connect.PagarmePaymentStatus.Pago) {
389
382
  await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
390
383
  return Promise.reject(new connect.PaymentError(`Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito`, {
391
384
  checkoutId: checkout.id,
392
385
  userEmail: checkout.user.email,
393
- info: result,
386
+ info: result.data,
394
387
  }));
395
388
  }
396
- const payment = await this.paymentRepository.create({
389
+ const payment = await this.paymentRepository.create(connect.Payment.toInstance({
397
390
  createdAt: new Date(),
398
391
  updatedAt: new Date(),
399
392
  userId: checkout.user.id,
400
393
  checkoutId: checkout.id,
401
394
  totalPrice: checkout.totalPrice,
402
395
  paymentProvider: connect.PaymentProviders.PAGARME,
403
- transaction: Object.assign(Object.assign({}, result), { paidAt: new Date() }),
404
- });
396
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
397
+ }));
405
398
  return payment;
406
399
  }
407
400
  catch (error) {
408
- console.error('Error PagarmeCardAPIAdapter', JSON.stringify(error));
409
401
  throw new connect.PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
410
402
  checkoutId: checkout.id,
411
403
  userEmail: checkout.user.email,
@@ -531,23 +523,19 @@ class PagarmePixAPIAdapter {
531
523
  async pay(checkout) {
532
524
  try {
533
525
  const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
534
- const payload = this.createPixPayment(checkout);
535
- const result = await client.transactions.create(payload);
536
- console.log('[PAGARME PIX DATA TO SEND]', payload);
537
- console.log('result PagarmePixAPIAdapter', JSON.stringify(result));
538
- const payment = await this.paymentRepository.create({
526
+ const result = client.transactions.create(Object.assign({}, this.createPixPayment(checkout)));
527
+ const payment = await this.paymentRepository.create(connect.Payment.toInstance({
539
528
  createdAt: new Date(),
540
529
  updatedAt: new Date(),
541
530
  userId: checkout.user.id,
542
531
  checkoutId: checkout.id,
543
532
  totalPrice: checkout.totalPrice,
544
533
  paymentProvider: 'pagarMe',
545
- transaction: result,
546
- });
534
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
535
+ }));
547
536
  return payment;
548
537
  }
549
538
  catch (error) {
550
- console.log('Error PagarmePixAPIAdapter', JSON.stringify(error));
551
539
  throw new connect.PaymentError('Houve uma falha ao processar pagamento com pix', {
552
540
  checkoutId: checkout.id,
553
541
  userEmail: checkout.user.email,
@@ -1022,10 +1010,7 @@ exports.NestFirestoreModule = NestFirestoreModule_1 = __decorate([
1022
1010
  'LegacyOrderRepository',
1023
1011
  'ShopMenuRepository',
1024
1012
  'OrderRepository',
1025
- 'OrderBlockedRepository',
1026
1013
  'PaymentRepository',
1027
- 'SequenceRepository',
1028
- 'LogRepository',
1029
1014
  connect.ProductFirestoreRepository,
1030
1015
  'ShopSettingsRepository',
1031
1016
  'SubscriptionPaymentRepository',
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Client } from '@elastic/elasticsearch';
2
- import { DebugHelper, isEmpty, NotFoundError, PagarmePaymentStatus, PaymentError, BusinessError, format, addDays, PaymentProviders, Shops, ProductsIndex, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, isNil } from '@infrab4a/connect';
2
+ import { DebugHelper, isEmpty, NotFoundError, PagarmePaymentStatus, PaymentError, Payment, BusinessError, format, addDays, PaymentProviders, Shops, ProductsIndex, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, isNil } from '@infrab4a/connect';
3
3
  import { Injectable, Inject, Module } from '@nestjs/common';
4
4
  import pagarme from 'pagarme';
5
5
  import { DocumentServiceClient } from '@google-cloud/discoveryengine';
@@ -295,30 +295,26 @@ class PagarmeBankSlipAPIAdapter {
295
295
  async pay(checkout) {
296
296
  try {
297
297
  const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
298
- const payload = this.createBoletoPayment(checkout);
299
- const result = await client.transactions.create(payload);
300
- console.log('[PAGARME BOLETO DATA TO SEND]', payload);
301
- console.log('result PagarmeBankSlipAPIAdapter', JSON.stringify(result));
302
- if (result.status !== PagarmePaymentStatus['Em processamento']) {
298
+ const result = client.transactions.create(Object.assign({}, this.createBoletoPayment(checkout)));
299
+ if (result.data.status !== PagarmePaymentStatus['Em processamento']) {
303
300
  return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
304
301
  checkoutId: checkout.id,
305
302
  userEmail: checkout.user.email,
306
- info: result,
303
+ info: result.data,
307
304
  }));
308
305
  }
309
- const payment = await this.paymentRepository.create({
306
+ const payment = await this.paymentRepository.create(Payment.toInstance({
310
307
  createdAt: new Date(),
311
308
  updatedAt: new Date(),
312
309
  userId: checkout.user.id,
313
310
  checkoutId: checkout.id,
314
311
  totalPrice: checkout.totalPrice,
315
312
  paymentProvider: 'pagarMe',
316
- transaction: result,
317
- });
313
+ transaction: result.data,
314
+ }));
318
315
  return payment;
319
316
  }
320
317
  catch (error) {
321
- console.error('Error PagarmeBankSlipAPIAdapter', JSON.stringify(error));
322
318
  throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
323
319
  checkoutId: checkout.id,
324
320
  userEmail: checkout.user.email,
@@ -373,31 +369,27 @@ class PagarmeCardAPIAdapter {
373
369
  async pay(checkout, card) {
374
370
  try {
375
371
  const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
376
- const payload = this.createCardPayment(checkout, card);
377
- const result = await client.transactions.create(payload);
378
- console.log('[PAGARME CARD DATA TO SEND]', payload);
379
- console.log('result PagarmeCardAPIAdapter', JSON.stringify(result));
380
- if (result.status !== PagarmePaymentStatus.Pago) {
372
+ const result = client.transactions.create(Object.assign({}, this.createCardPayment(checkout, card)));
373
+ if (result.data.status !== PagarmePaymentStatus.Pago) {
381
374
  await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
382
375
  return Promise.reject(new PaymentError(`Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito`, {
383
376
  checkoutId: checkout.id,
384
377
  userEmail: checkout.user.email,
385
- info: result,
378
+ info: result.data,
386
379
  }));
387
380
  }
388
- const payment = await this.paymentRepository.create({
381
+ const payment = await this.paymentRepository.create(Payment.toInstance({
389
382
  createdAt: new Date(),
390
383
  updatedAt: new Date(),
391
384
  userId: checkout.user.id,
392
385
  checkoutId: checkout.id,
393
386
  totalPrice: checkout.totalPrice,
394
387
  paymentProvider: PaymentProviders.PAGARME,
395
- transaction: Object.assign(Object.assign({}, result), { paidAt: new Date() }),
396
- });
388
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
389
+ }));
397
390
  return payment;
398
391
  }
399
392
  catch (error) {
400
- console.error('Error PagarmeCardAPIAdapter', JSON.stringify(error));
401
393
  throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
402
394
  checkoutId: checkout.id,
403
395
  userEmail: checkout.user.email,
@@ -523,23 +515,19 @@ class PagarmePixAPIAdapter {
523
515
  async pay(checkout) {
524
516
  try {
525
517
  const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
526
- const payload = this.createPixPayment(checkout);
527
- const result = await client.transactions.create(payload);
528
- console.log('[PAGARME PIX DATA TO SEND]', payload);
529
- console.log('result PagarmePixAPIAdapter', JSON.stringify(result));
530
- const payment = await this.paymentRepository.create({
518
+ const result = client.transactions.create(Object.assign({}, this.createPixPayment(checkout)));
519
+ const payment = await this.paymentRepository.create(Payment.toInstance({
531
520
  createdAt: new Date(),
532
521
  updatedAt: new Date(),
533
522
  userId: checkout.user.id,
534
523
  checkoutId: checkout.id,
535
524
  totalPrice: checkout.totalPrice,
536
525
  paymentProvider: 'pagarMe',
537
- transaction: result,
538
- });
526
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
527
+ }));
539
528
  return payment;
540
529
  }
541
530
  catch (error) {
542
- console.log('Error PagarmePixAPIAdapter', JSON.stringify(error));
543
531
  throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
544
532
  checkoutId: checkout.id,
545
533
  userEmail: checkout.user.email,
@@ -1014,10 +1002,7 @@ NestFirestoreModule = NestFirestoreModule_1 = __decorate([
1014
1002
  'LegacyOrderRepository',
1015
1003
  'ShopMenuRepository',
1016
1004
  'OrderRepository',
1017
- 'OrderBlockedRepository',
1018
1005
  'PaymentRepository',
1019
- 'SequenceRepository',
1020
- 'LogRepository',
1021
1006
  ProductFirestoreRepository,
1022
1007
  'ShopSettingsRepository',
1023
1008
  'SubscriptionPaymentRepository',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect-nestjs",
3
- "version": "1.8.0-beta.17",
3
+ "version": "1.8.0-beta.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/B4AGroup/b4a-firebase-libs"
10
10
  },
11
11
  "peerDependencies": {
12
- "@infrab4a/connect": "4.20.0-beta.15",
12
+ "@infrab4a/connect": "^4.20.0-beta.6",
13
13
  "@nestjs/common": "^10.3.3",
14
14
  "@nestjs/core": "^10.3.3",
15
15
  "firebase-admin": "^12.0.0"