@infrab4a/connect-nestjs 1.8.0-beta.8 → 1.8.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.
package/index.cjs.js CHANGED
@@ -5,15 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var elasticsearch = require('@elastic/elasticsearch');
6
6
  var connect = require('@infrab4a/connect');
7
7
  var common = require('@nestjs/common');
8
- var pagarme = require('pagarme');
9
8
  var discoveryengine = require('@google-cloud/discoveryengine');
10
9
  var v1beta = require('@google-cloud/discoveryengine/build/src/v1beta');
11
10
  var nestjsFirebase = require('nestjs-firebase');
12
11
 
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var pagarme__default = /*#__PURE__*/_interopDefaultLegacy(pagarme);
16
-
17
12
  const ES_CONFIG = 'ES_CONFIG';
18
13
 
19
14
  const HASURA_OPTIONS = 'HASURA_OPTIONS';
@@ -295,285 +290,6 @@ class ConnectFirestoreService {
295
290
  }
296
291
  }
297
292
 
298
- class PagarmeBankSlipAPIAdapter {
299
- constructor(credentials, paymentRepository) {
300
- this.credentials = credentials;
301
- this.paymentRepository = paymentRepository;
302
- }
303
- async pay(checkout) {
304
- try {
305
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
306
- const result = await client.transactions.create(Object.assign({}, this.createBoletoPayment(checkout)));
307
- console.log('result PagarmeBankSlipAPIAdapter', result);
308
- if (result.status !== connect.PagarmePaymentStatus['Em processamento']) {
309
- return Promise.reject(new connect.PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
310
- checkoutId: checkout.id,
311
- userEmail: checkout.user.email,
312
- info: result,
313
- }));
314
- }
315
- const payment = await this.paymentRepository.create(connect.Payment.toInstance({
316
- createdAt: new Date(),
317
- updatedAt: new Date(),
318
- userId: checkout.user.id,
319
- checkoutId: checkout.id,
320
- totalPrice: checkout.totalPrice,
321
- paymentProvider: 'pagarMe',
322
- transaction: result,
323
- }));
324
- return payment;
325
- }
326
- catch (error) {
327
- console.log('Error PagarmeBankSlipAPIAdapter', JSON.stringify(error));
328
- throw new connect.PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
329
- checkoutId: checkout.id,
330
- userEmail: checkout.user.email,
331
- info: error,
332
- });
333
- }
334
- }
335
- async getBoletoTransaction(paymentId) {
336
- try {
337
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
338
- const result = client.transactions.find({ id: paymentId });
339
- return result;
340
- }
341
- catch (error) {
342
- throw new connect.BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
343
- paymentId,
344
- info: error,
345
- });
346
- }
347
- }
348
- createBoletoPayment(checkout) {
349
- return {
350
- api_key: this.credentials.API_KEY,
351
- amount: Math.floor(checkout.totalPrice * 100),
352
- boleto_rules: ['strict_expiration_date'],
353
- boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
354
- boleto_expiration_date: connect.format(connect.addDays(new Date(), 3), 'yyyy-MM-dd'),
355
- payment_method: 'boleto',
356
- postback_url: this.credentials.URL_POSTBACK,
357
- customer: {
358
- external_id: checkout.user.id,
359
- type: 'individual',
360
- country: 'br',
361
- name: checkout.user.displayName,
362
- documents: [
363
- {
364
- type: 'cpf',
365
- number: checkout.user.cpf,
366
- },
367
- ],
368
- },
369
- };
370
- }
371
- }
372
-
373
- class PagarmeCardAPIAdapter {
374
- constructor(credentials, paymentRepository, orderBlockedRepository) {
375
- this.credentials = credentials;
376
- this.paymentRepository = paymentRepository;
377
- this.orderBlockedRepository = orderBlockedRepository;
378
- }
379
- async pay(checkout, card) {
380
- try {
381
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
382
- const result = await client.transactions.create(Object.assign({}, this.createCardPayment(checkout, card)));
383
- console.log('result PagarmeCardAPIAdapter', result);
384
- if (result.status !== connect.PagarmePaymentStatus.Pago) {
385
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
386
- 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`, {
387
- checkoutId: checkout.id,
388
- userEmail: checkout.user.email,
389
- info: result,
390
- }));
391
- }
392
- const payment = await this.paymentRepository.create(connect.Payment.toInstance({
393
- createdAt: new Date(),
394
- updatedAt: new Date(),
395
- userId: checkout.user.id,
396
- checkoutId: checkout.id,
397
- totalPrice: checkout.totalPrice,
398
- paymentProvider: connect.PaymentProviders.PAGARME,
399
- transaction: Object.assign(Object.assign({}, result), { paidAt: new Date() }),
400
- }));
401
- return payment;
402
- }
403
- catch (error) {
404
- console.log('Error PagarmeCardAPIAdapter', JSON.stringify(error));
405
- 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', {
406
- checkoutId: checkout.id,
407
- userEmail: checkout.user.email,
408
- info: error,
409
- });
410
- }
411
- }
412
- async addCard(card) {
413
- try {
414
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
415
- const result = client.cards.create({
416
- card_number: card.number,
417
- card_expiration_date: card.expirationDate.replace('/', ''),
418
- card_holder_name: card.name,
419
- card_cvv: card.cvv,
420
- });
421
- return result;
422
- }
423
- catch (error) {
424
- throw new connect.BusinessError('Houve uma falha adicionar o cartão', {
425
- info: error,
426
- });
427
- }
428
- }
429
- async createCardHash(bu, card) {
430
- try {
431
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
432
- const result = await client.security.encrypt({
433
- card_number: card.number,
434
- card_expiration_date: card.expirationDate.replace('/', ''),
435
- card_holder_name: card.name,
436
- card_cvv: card.cvv,
437
- });
438
- return result;
439
- }
440
- catch (error) {
441
- throw new connect.BusinessError('Houve uma falha ao gerar o hash do cartão', {
442
- info: error,
443
- });
444
- }
445
- }
446
- async getCardByToken(id) {
447
- try {
448
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
449
- const result = client.cards.find({
450
- id,
451
- });
452
- return result;
453
- }
454
- catch (error) {
455
- throw new connect.BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
456
- info: error,
457
- });
458
- }
459
- }
460
- async createTransaction(data) {
461
- try {
462
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
463
- const result = await client.transactions.create(data);
464
- return result;
465
- }
466
- catch (error) {
467
- throw new connect.BusinessError('Houve uma falha ao criar a transação', {
468
- info: error,
469
- });
470
- }
471
- }
472
- createCardPayment(checkout, card) {
473
- var _a, _b, _c, _d, _e, _f;
474
- return {
475
- api_key: this.credentials.API_KEY,
476
- amount: Math.floor(checkout.totalPrice * 100),
477
- card_id: card.cardId,
478
- payment_method: 'credit_card',
479
- installments: card.installments,
480
- soft_descriptor: checkout.shop === connect.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
481
- customer: {
482
- external_id: checkout.user.id,
483
- name: checkout.user.displayName,
484
- type: 'individual',
485
- country: 'br',
486
- email: checkout.user.email,
487
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
488
- documents: [
489
- {
490
- type: 'cpf',
491
- number: checkout.user.cpf,
492
- },
493
- ],
494
- },
495
- billing: {
496
- name: checkout.user.displayName,
497
- address: {
498
- country: 'br',
499
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
500
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
501
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
502
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
503
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
504
- zipcode: checkout.billingAddress
505
- ? checkout.billingAddress.zip.replace('-', '')
506
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
507
- },
508
- },
509
- items: checkout.lineItems.map((item) => {
510
- return {
511
- id: item.id,
512
- title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
513
- unit_price: Math.floor(item.pricePaid * 100),
514
- quantity: item.quantity,
515
- tangible: true,
516
- };
517
- }),
518
- };
519
- }
520
- }
521
-
522
- class PagarmePixAPIAdapter {
523
- constructor(credentials, paymentRepository) {
524
- this.credentials = credentials;
525
- this.paymentRepository = paymentRepository;
526
- }
527
- async pay(checkout) {
528
- try {
529
- const client = await pagarme__default["default"].client.connect({ api_key: this.credentials.API_KEY });
530
- const result = await client.transactions.create(Object.assign({}, this.createPixPayment(checkout)));
531
- console.log('result PagarmePixAPIAdapter', result);
532
- const payment = await this.paymentRepository.create(connect.Payment.toInstance({
533
- createdAt: new Date(),
534
- updatedAt: new Date(),
535
- userId: checkout.user.id,
536
- checkoutId: checkout.id,
537
- totalPrice: checkout.totalPrice,
538
- paymentProvider: 'pagarMe',
539
- transaction: Object.assign(Object.assign({}, result), { paidAt: new Date() }),
540
- }));
541
- return payment;
542
- }
543
- catch (error) {
544
- console.log('Error PagarmePixAPIAdapter', JSON.stringify(error));
545
- throw new connect.PaymentError('Houve uma falha ao processar pagamento com pix', {
546
- checkoutId: checkout.id,
547
- userEmail: checkout.user.email,
548
- info: error,
549
- });
550
- }
551
- }
552
- createPixPayment(checkout) {
553
- return {
554
- payment_method: 'pix',
555
- amount: Math.floor(checkout.totalPrice * 100),
556
- api_key: this.credentials.API_KEY,
557
- postback_url: this.credentials.URL_POSTBACK,
558
- pix_expiration_date: connect.format(connect.addDays(new Date(), 1), 'yyyy-MM-dd'),
559
- customer: {
560
- external_id: checkout.user.id,
561
- type: 'individual',
562
- country: 'br',
563
- name: checkout.user.displayName,
564
- email: checkout.user.email.trim(),
565
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
566
- documents: [
567
- {
568
- type: 'cpf',
569
- number: checkout.user.cpf,
570
- },
571
- ],
572
- },
573
- };
574
- }
575
- }
576
-
577
293
  class ProductVertexHelper {
578
294
  constructor() { }
579
295
  static productMapper(product) {
@@ -993,13 +709,6 @@ exports.NestFirestoreModule = NestFirestoreModule_1 = __decorate([
993
709
  },
994
710
  inject: ['FirestoreOptions'],
995
711
  },
996
- {
997
- provide: 'SequenceRepository',
998
- useFactory: (options) => {
999
- return new connect.SequenceFirestoreRepository(options);
1000
- },
1001
- inject: ['FirestoreOptions'],
1002
- },
1003
712
  ],
1004
713
  exports: [
1005
714
  'BeautyProfileRepository',
@@ -1016,10 +725,7 @@ exports.NestFirestoreModule = NestFirestoreModule_1 = __decorate([
1016
725
  'LegacyOrderRepository',
1017
726
  'ShopMenuRepository',
1018
727
  'OrderRepository',
1019
- 'OrderBlockedRepository',
1020
728
  'PaymentRepository',
1021
- 'SequenceRepository',
1022
- 'LogRepository',
1023
729
  connect.ProductFirestoreRepository,
1024
730
  'ShopSettingsRepository',
1025
731
  'SubscriptionPaymentRepository',
@@ -1246,8 +952,5 @@ exports.ConnectFirestoreService = ConnectFirestoreService;
1246
952
  exports.ES_CONFIG = ES_CONFIG;
1247
953
  exports.FIREBASE_STORAGE = FIREBASE_STORAGE;
1248
954
  exports.HASURA_OPTIONS = HASURA_OPTIONS;
1249
- exports.PagarmeBankSlipAPIAdapter = PagarmeBankSlipAPIAdapter;
1250
- exports.PagarmeCardAPIAdapter = PagarmeCardAPIAdapter;
1251
- exports.PagarmePixAPIAdapter = PagarmePixAPIAdapter;
1252
955
  exports.ProductVertexHelper = ProductVertexHelper;
1253
956
  exports.VERTEX_CONFIG = VERTEX_CONFIG;
package/index.esm.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Client } from '@elastic/elasticsearch';
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';
2
+ import { DebugHelper, isEmpty, NotFoundError, 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, 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
- import pagarme from 'pagarme';
5
4
  import { DocumentServiceClient } from '@google-cloud/discoveryengine';
6
5
  import { SearchServiceClient } from '@google-cloud/discoveryengine/build/src/v1beta';
7
6
  import { FirebaseConstants, FirebaseModule } from 'nestjs-firebase';
@@ -287,285 +286,6 @@ class ConnectFirestoreService {
287
286
  }
288
287
  }
289
288
 
290
- class PagarmeBankSlipAPIAdapter {
291
- constructor(credentials, paymentRepository) {
292
- this.credentials = credentials;
293
- this.paymentRepository = paymentRepository;
294
- }
295
- async pay(checkout) {
296
- try {
297
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
298
- const result = await client.transactions.create(Object.assign({}, this.createBoletoPayment(checkout)));
299
- console.log('result PagarmeBankSlipAPIAdapter', result);
300
- if (result.status !== PagarmePaymentStatus['Em processamento']) {
301
- return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
302
- checkoutId: checkout.id,
303
- userEmail: checkout.user.email,
304
- info: result,
305
- }));
306
- }
307
- const payment = await this.paymentRepository.create(Payment.toInstance({
308
- createdAt: new Date(),
309
- updatedAt: new Date(),
310
- userId: checkout.user.id,
311
- checkoutId: checkout.id,
312
- totalPrice: checkout.totalPrice,
313
- paymentProvider: 'pagarMe',
314
- transaction: result,
315
- }));
316
- return payment;
317
- }
318
- catch (error) {
319
- console.log('Error PagarmeBankSlipAPIAdapter', JSON.stringify(error));
320
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
321
- checkoutId: checkout.id,
322
- userEmail: checkout.user.email,
323
- info: error,
324
- });
325
- }
326
- }
327
- async getBoletoTransaction(paymentId) {
328
- try {
329
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
330
- const result = client.transactions.find({ id: paymentId });
331
- return result;
332
- }
333
- catch (error) {
334
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
335
- paymentId,
336
- info: error,
337
- });
338
- }
339
- }
340
- createBoletoPayment(checkout) {
341
- return {
342
- api_key: this.credentials.API_KEY,
343
- amount: Math.floor(checkout.totalPrice * 100),
344
- boleto_rules: ['strict_expiration_date'],
345
- boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
346
- boleto_expiration_date: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
347
- payment_method: 'boleto',
348
- postback_url: this.credentials.URL_POSTBACK,
349
- customer: {
350
- external_id: checkout.user.id,
351
- type: 'individual',
352
- country: 'br',
353
- name: checkout.user.displayName,
354
- documents: [
355
- {
356
- type: 'cpf',
357
- number: checkout.user.cpf,
358
- },
359
- ],
360
- },
361
- };
362
- }
363
- }
364
-
365
- class PagarmeCardAPIAdapter {
366
- constructor(credentials, paymentRepository, orderBlockedRepository) {
367
- this.credentials = credentials;
368
- this.paymentRepository = paymentRepository;
369
- this.orderBlockedRepository = orderBlockedRepository;
370
- }
371
- async pay(checkout, card) {
372
- try {
373
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
374
- const result = await client.transactions.create(Object.assign({}, this.createCardPayment(checkout, card)));
375
- console.log('result PagarmeCardAPIAdapter', result);
376
- if (result.status !== PagarmePaymentStatus.Pago) {
377
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
378
- 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`, {
379
- checkoutId: checkout.id,
380
- userEmail: checkout.user.email,
381
- info: result,
382
- }));
383
- }
384
- const payment = await this.paymentRepository.create(Payment.toInstance({
385
- createdAt: new Date(),
386
- updatedAt: new Date(),
387
- userId: checkout.user.id,
388
- checkoutId: checkout.id,
389
- totalPrice: checkout.totalPrice,
390
- paymentProvider: PaymentProviders.PAGARME,
391
- transaction: Object.assign(Object.assign({}, result), { paidAt: new Date() }),
392
- }));
393
- return payment;
394
- }
395
- catch (error) {
396
- console.log('Error PagarmeCardAPIAdapter', JSON.stringify(error));
397
- 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', {
398
- checkoutId: checkout.id,
399
- userEmail: checkout.user.email,
400
- info: error,
401
- });
402
- }
403
- }
404
- async addCard(card) {
405
- try {
406
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
407
- const result = client.cards.create({
408
- card_number: card.number,
409
- card_expiration_date: card.expirationDate.replace('/', ''),
410
- card_holder_name: card.name,
411
- card_cvv: card.cvv,
412
- });
413
- return result;
414
- }
415
- catch (error) {
416
- throw new BusinessError('Houve uma falha adicionar o cartão', {
417
- info: error,
418
- });
419
- }
420
- }
421
- async createCardHash(bu, card) {
422
- try {
423
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
424
- const result = await client.security.encrypt({
425
- card_number: card.number,
426
- card_expiration_date: card.expirationDate.replace('/', ''),
427
- card_holder_name: card.name,
428
- card_cvv: card.cvv,
429
- });
430
- return result;
431
- }
432
- catch (error) {
433
- throw new BusinessError('Houve uma falha ao gerar o hash do cartão', {
434
- info: error,
435
- });
436
- }
437
- }
438
- async getCardByToken(id) {
439
- try {
440
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
441
- const result = client.cards.find({
442
- id,
443
- });
444
- return result;
445
- }
446
- catch (error) {
447
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
448
- info: error,
449
- });
450
- }
451
- }
452
- async createTransaction(data) {
453
- try {
454
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
455
- const result = await client.transactions.create(data);
456
- return result;
457
- }
458
- catch (error) {
459
- throw new BusinessError('Houve uma falha ao criar a transação', {
460
- info: error,
461
- });
462
- }
463
- }
464
- createCardPayment(checkout, card) {
465
- var _a, _b, _c, _d, _e, _f;
466
- return {
467
- api_key: this.credentials.API_KEY,
468
- amount: Math.floor(checkout.totalPrice * 100),
469
- card_id: card.cardId,
470
- payment_method: 'credit_card',
471
- installments: card.installments,
472
- soft_descriptor: checkout.shop === Shops.GLAMSHOP ? 'Glam' : "Men's Market",
473
- customer: {
474
- external_id: checkout.user.id,
475
- name: checkout.user.displayName,
476
- type: 'individual',
477
- country: 'br',
478
- email: checkout.user.email,
479
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
480
- documents: [
481
- {
482
- type: 'cpf',
483
- number: checkout.user.cpf,
484
- },
485
- ],
486
- },
487
- billing: {
488
- name: checkout.user.displayName,
489
- address: {
490
- country: 'br',
491
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
492
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
493
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
494
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
495
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
496
- zipcode: checkout.billingAddress
497
- ? checkout.billingAddress.zip.replace('-', '')
498
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
499
- },
500
- },
501
- items: checkout.lineItems.map((item) => {
502
- return {
503
- id: item.id,
504
- title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
505
- unit_price: Math.floor(item.pricePaid * 100),
506
- quantity: item.quantity,
507
- tangible: true,
508
- };
509
- }),
510
- };
511
- }
512
- }
513
-
514
- class PagarmePixAPIAdapter {
515
- constructor(credentials, paymentRepository) {
516
- this.credentials = credentials;
517
- this.paymentRepository = paymentRepository;
518
- }
519
- async pay(checkout) {
520
- try {
521
- const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY });
522
- const result = await client.transactions.create(Object.assign({}, this.createPixPayment(checkout)));
523
- console.log('result PagarmePixAPIAdapter', result);
524
- const payment = await this.paymentRepository.create(Payment.toInstance({
525
- createdAt: new Date(),
526
- updatedAt: new Date(),
527
- userId: checkout.user.id,
528
- checkoutId: checkout.id,
529
- totalPrice: checkout.totalPrice,
530
- paymentProvider: 'pagarMe',
531
- transaction: Object.assign(Object.assign({}, result), { paidAt: new Date() }),
532
- }));
533
- return payment;
534
- }
535
- catch (error) {
536
- console.log('Error PagarmePixAPIAdapter', JSON.stringify(error));
537
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
538
- checkoutId: checkout.id,
539
- userEmail: checkout.user.email,
540
- info: error,
541
- });
542
- }
543
- }
544
- createPixPayment(checkout) {
545
- return {
546
- payment_method: 'pix',
547
- amount: Math.floor(checkout.totalPrice * 100),
548
- api_key: this.credentials.API_KEY,
549
- postback_url: this.credentials.URL_POSTBACK,
550
- pix_expiration_date: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
551
- customer: {
552
- external_id: checkout.user.id,
553
- type: 'individual',
554
- country: 'br',
555
- name: checkout.user.displayName,
556
- email: checkout.user.email.trim(),
557
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
558
- documents: [
559
- {
560
- type: 'cpf',
561
- number: checkout.user.cpf,
562
- },
563
- ],
564
- },
565
- };
566
- }
567
- }
568
-
569
289
  class ProductVertexHelper {
570
290
  constructor() { }
571
291
  static productMapper(product) {
@@ -985,13 +705,6 @@ NestFirestoreModule = NestFirestoreModule_1 = __decorate([
985
705
  },
986
706
  inject: ['FirestoreOptions'],
987
707
  },
988
- {
989
- provide: 'SequenceRepository',
990
- useFactory: (options) => {
991
- return new SequenceFirestoreRepository(options);
992
- },
993
- inject: ['FirestoreOptions'],
994
- },
995
708
  ],
996
709
  exports: [
997
710
  'BeautyProfileRepository',
@@ -1008,10 +721,7 @@ NestFirestoreModule = NestFirestoreModule_1 = __decorate([
1008
721
  'LegacyOrderRepository',
1009
722
  'ShopMenuRepository',
1010
723
  'OrderRepository',
1011
- 'OrderBlockedRepository',
1012
724
  'PaymentRepository',
1013
- 'SequenceRepository',
1014
- 'LogRepository',
1015
725
  ProductFirestoreRepository,
1016
726
  'ShopSettingsRepository',
1017
727
  'SubscriptionPaymentRepository',
@@ -1232,4 +942,4 @@ NestConnectModule = NestConnectModule_1 = __decorate([
1232
942
  Module({})
1233
943
  ], NestConnectModule);
1234
944
 
1235
- export { ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, DiscoveryEngineVertexAdapter, ES_CONFIG, FIREBASE_STORAGE, HASURA_OPTIONS, NativeElasticSearchAdapter, NestConnectModule, NestElasticSeachModule, NestFirestoreModule, NestHasuraGraphQLModule, NestStorageModule, PagarmeBankSlipAPIAdapter, PagarmeCardAPIAdapter, PagarmePixAPIAdapter, ProductVertexHelper, VERTEX_CONFIG };
945
+ export { ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, DiscoveryEngineVertexAdapter, ES_CONFIG, FIREBASE_STORAGE, HASURA_OPTIONS, NativeElasticSearchAdapter, NestConnectModule, NestElasticSeachModule, NestFirestoreModule, NestHasuraGraphQLModule, NestStorageModule, ProductVertexHelper, VERTEX_CONFIG };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect-nestjs",
3
- "version": "1.8.0-beta.8",
3
+ "version": "1.8.0",
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.6",
12
+ "@infrab4a/connect": "^4.20.0",
13
13
  "@nestjs/common": "^10.3.3",
14
14
  "@nestjs/core": "^10.3.3",
15
15
  "firebase-admin": "^12.0.0"
@@ -17,8 +17,7 @@
17
17
  "dependencies": {
18
18
  "@elastic/elasticsearch": "^8.13.1",
19
19
  "@google-cloud/discoveryengine": "^1.14.0",
20
- "nestjs-firebase": "^10.4.0",
21
- "pagarme": "4.35.2"
20
+ "nestjs-firebase": "^10.4.0"
22
21
  },
23
22
  "exports": {
24
23
  "./package.json": "./package.json",
@@ -1,4 +1,3 @@
1
1
  export * from './elasticsearch';
2
2
  export * from './firebase';
3
- export * from './pagarme';
4
3
  export * from './vertex-ai';
@@ -1,3 +0,0 @@
1
- export * from './pagarme-bank-slip-api.adapter';
2
- export * from './pagarme-card-api.adapter';
3
- export * from './pagarme-pix-api.adapter';
@@ -1,9 +0,0 @@
1
- import { Checkout, PagarmeCredentials, Payment, PaymentProviderBankSlip, PaymentRepository, PaymentTransaction } from '@infrab4a/connect';
2
- export declare class PagarmeBankSlipAPIAdapter implements PaymentProviderBankSlip {
3
- private credentials;
4
- private paymentRepository;
5
- constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository);
6
- pay(checkout: Checkout): Promise<Payment>;
7
- getBoletoTransaction(paymentId: number): Promise<PaymentTransaction>;
8
- private createBoletoPayment;
9
- }
@@ -1,13 +0,0 @@
1
- import { BusinessUnitEnum, CardInfo, Checkout, OrderBlockedRepository, PagarMeCard, PagarmeCredentials, Payment, PaymentCardInfo, PaymentProviderCard, PaymentRepository, PaymentTransaction } from '@infrab4a/connect';
2
- export declare class PagarmeCardAPIAdapter implements PaymentProviderCard<PagarMeCard> {
3
- private credentials;
4
- private paymentRepository;
5
- private orderBlockedRepository;
6
- constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
7
- pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
8
- addCard(card: CardInfo): Promise<PagarMeCard>;
9
- createCardHash(bu: BusinessUnitEnum, card: CardInfo): Promise<string>;
10
- getCardByToken(id: string): Promise<PagarMeCard>;
11
- createTransaction(data: any): Promise<PaymentTransaction>;
12
- private createCardPayment;
13
- }
@@ -1,8 +0,0 @@
1
- import { Checkout, PagarmeCredentials, Payment, PaymentProviderPix, PaymentRepository } from '@infrab4a/connect';
2
- export declare class PagarmePixAPIAdapter implements PaymentProviderPix {
3
- private credentials;
4
- private paymentRepository;
5
- constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository);
6
- pay(checkout: Checkout): Promise<Payment>;
7
- private createPixPayment;
8
- }
@@ -1 +0,0 @@
1
- export * from './adapters';