@infrab4a/connect 4.20.0-beta.12 → 4.20.0-beta.13

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
@@ -2464,7 +2464,8 @@ class AntifraudPixService {
2464
2464
  }
2465
2465
 
2466
2466
  class GlampointsPaymentService {
2467
- constructor(paymentRepository) {
2467
+ constructor(glamCredentials, paymentRepository) {
2468
+ this.glamCredentials = glamCredentials;
2468
2469
  this.paymentRepository = paymentRepository;
2469
2470
  }
2470
2471
  async pay(checkout) {
@@ -2495,6 +2496,54 @@ class GlampointsPaymentService {
2495
2496
  }));
2496
2497
  return payment;
2497
2498
  }
2499
+ async rewardByOrder(orderId, user, lineItens) {
2500
+ try {
2501
+ const points = lineItens.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
2502
+ const result = await axios__default["default"]({
2503
+ method: 'POST',
2504
+ url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
2505
+ headers: { 'Content-Type': 'application/json' },
2506
+ timeout: 60000,
2507
+ data: {
2508
+ personId: user.id,
2509
+ rewardType: 50,
2510
+ referenceId: 0,
2511
+ referenceName: `Compra - ${points} produto(s)`,
2512
+ points: points,
2513
+ productId: '',
2514
+ token: this.glamCredentials.integrationToken,
2515
+ orderId,
2516
+ },
2517
+ });
2518
+ console.info('[rewards - rewardByOrder] reward success:', JSON.stringify(result));
2519
+ return result.data;
2520
+ }
2521
+ catch (err) {
2522
+ console.error('[rewards - rewardByOrder] reward request error', JSON.stringify(err));
2523
+ return err;
2524
+ }
2525
+ }
2526
+ async negativateRewardByOrderId(orderId, orderNumber) {
2527
+ try {
2528
+ const result = await axios__default["default"]({
2529
+ method: 'POST',
2530
+ url: `${this.glamCredentials.baseUrl}/integration/negativate/reward`,
2531
+ headers: { 'Content-Type': 'application/json' },
2532
+ timeout: 60000,
2533
+ data: {
2534
+ rewardType: 51,
2535
+ referenceName: `Pedido #${orderId} cancelado`,
2536
+ token: '$2a$12$2DAPE64UUWAo4TT/1eQ9TOJO40b5z2jdomOJG3X7LeexwOHYtPydW',
2537
+ orderId,
2538
+ orderNumber: parseInt(orderNumber.replace(/\D/g, ''), 10),
2539
+ },
2540
+ });
2541
+ return result;
2542
+ }
2543
+ catch (error) {
2544
+ return error;
2545
+ }
2546
+ }
2498
2547
  }
2499
2548
 
2500
2549
  class RoundProductPricesHelper {
package/index.esm.js CHANGED
@@ -2458,7 +2458,8 @@ class AntifraudPixService {
2458
2458
  }
2459
2459
 
2460
2460
  class GlampointsPaymentService {
2461
- constructor(paymentRepository) {
2461
+ constructor(glamCredentials, paymentRepository) {
2462
+ this.glamCredentials = glamCredentials;
2462
2463
  this.paymentRepository = paymentRepository;
2463
2464
  }
2464
2465
  async pay(checkout) {
@@ -2489,6 +2490,54 @@ class GlampointsPaymentService {
2489
2490
  }));
2490
2491
  return payment;
2491
2492
  }
2493
+ async rewardByOrder(orderId, user, lineItens) {
2494
+ try {
2495
+ const points = lineItens.filter((item) => !item.isGift).reduce((acc, li) => acc + li.quantity, 0);
2496
+ const result = await axios({
2497
+ method: 'POST',
2498
+ url: `${this.glamCredentials.baseUrl}/integration/win/reward`,
2499
+ headers: { 'Content-Type': 'application/json' },
2500
+ timeout: 60000,
2501
+ data: {
2502
+ personId: user.id,
2503
+ rewardType: 50,
2504
+ referenceId: 0,
2505
+ referenceName: `Compra - ${points} produto(s)`,
2506
+ points: points,
2507
+ productId: '',
2508
+ token: this.glamCredentials.integrationToken,
2509
+ orderId,
2510
+ },
2511
+ });
2512
+ console.info('[rewards - rewardByOrder] reward success:', JSON.stringify(result));
2513
+ return result.data;
2514
+ }
2515
+ catch (err) {
2516
+ console.error('[rewards - rewardByOrder] reward request error', JSON.stringify(err));
2517
+ return err;
2518
+ }
2519
+ }
2520
+ async negativateRewardByOrderId(orderId, orderNumber) {
2521
+ try {
2522
+ const result = await axios({
2523
+ method: 'POST',
2524
+ url: `${this.glamCredentials.baseUrl}/integration/negativate/reward`,
2525
+ headers: { 'Content-Type': 'application/json' },
2526
+ timeout: 60000,
2527
+ data: {
2528
+ rewardType: 51,
2529
+ referenceName: `Pedido #${orderId} cancelado`,
2530
+ token: '$2a$12$2DAPE64UUWAo4TT/1eQ9TOJO40b5z2jdomOJG3X7LeexwOHYtPydW',
2531
+ orderId,
2532
+ orderNumber: parseInt(orderNumber.replace(/\D/g, ''), 10),
2533
+ },
2534
+ });
2535
+ return result;
2536
+ }
2537
+ catch (error) {
2538
+ return error;
2539
+ }
2540
+ }
2492
2541
  }
2493
2542
 
2494
2543
  class RoundProductPricesHelper {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.20.0-beta.12",
3
+ "version": "4.20.0-beta.13",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1,5 +1,9 @@
1
+ import { User } from '../../users';
2
+ import { LineItem } from '../models';
1
3
  import { Checkout } from '../models/checkout';
2
4
  import { Payment } from '../models/payment';
3
5
  export interface PaymentProviderGlampoints {
4
6
  pay(checkout: Checkout): Promise<Payment>;
7
+ rewardByOrder(orderId: string, user: User, lineItems: LineItem[]): Promise<void>;
8
+ negativateRewardByOrderId(orderId: string, orderNumber: string): Promise<any>;
5
9
  }
@@ -1,8 +1,13 @@
1
+ import { User } from '../../users';
1
2
  import { PaymentProviderGlampoints } from '../interfaces';
2
- import { Checkout, Payment } from '../models';
3
+ import { Checkout, LineItem, Payment } from '../models';
3
4
  import { PaymentRepository } from '../repositories';
5
+ import { GlamCredentials } from '../types';
4
6
  export declare class GlampointsPaymentService implements PaymentProviderGlampoints {
7
+ private glamCredentials;
5
8
  private paymentRepository;
6
- constructor(paymentRepository: PaymentRepository);
9
+ constructor(glamCredentials: GlamCredentials, paymentRepository: PaymentRepository);
7
10
  pay(checkout: Checkout): Promise<Payment>;
11
+ rewardByOrder(orderId: string, user: User, lineItens: LineItem[]): Promise<any>;
12
+ negativateRewardByOrderId(orderId: string, orderNumber: string): Promise<any>;
8
13
  }
@@ -0,0 +1,6 @@
1
+ export type GlamCredentials = {
2
+ baseUrl: string;
3
+ username: string;
4
+ password: string;
5
+ integrationToken: string;
6
+ };
@@ -2,6 +2,7 @@ export * from './adyen-card.type';
2
2
  export * from './adyen-credentials.type';
3
3
  export * from './antifraud-provider.type';
4
4
  export * from './card-info.type';
5
+ export * from './glam-credentials.type';
5
6
  export * from './order-tracking-events.type';
6
7
  export * from './pagarme-card.type';
7
8
  export * from './pagarme-credentials.type';