@infrab4a/connect 4.20.0-beta.5 → 4.20.0-beta.6

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
@@ -2415,82 +2415,6 @@ class StockOutError extends BusinessError {
2415
2415
  }
2416
2416
  }
2417
2417
 
2418
- class AdyenCardService {
2419
- constructor(credentials, paymentRepository, orderBlockedRepository) {
2420
- this.credentials = credentials;
2421
- this.paymentRepository = paymentRepository;
2422
- this.orderBlockedRepository = orderBlockedRepository;
2423
- }
2424
- async pay(checkout, card) {
2425
- try {
2426
- const result = await axios__default["default"]({
2427
- method: 'POST',
2428
- url: this.credentials.URL_TRANSACTION,
2429
- headers: {
2430
- 'x-api-key': this.credentials.API_KEY,
2431
- 'content-type': 'application/json',
2432
- },
2433
- data: this.createCardPayment(checkout, card),
2434
- });
2435
- if (result.data.resultCode !== 'Authorised') {
2436
- this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2437
- 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`, {
2438
- checkoutId: checkout.id,
2439
- userEmail: checkout.user.email,
2440
- info: result.data,
2441
- }));
2442
- }
2443
- const payment = await this.paymentRepository.create(Payment.toInstance({
2444
- createdAt: new Date(),
2445
- updatedAt: new Date(),
2446
- userId: checkout.user.id,
2447
- checkoutId: checkout.id,
2448
- totalPrice: checkout.totalPrice,
2449
- paymentProvider: 'adyen',
2450
- transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2451
- }));
2452
- return payment;
2453
- }
2454
- catch (error) {
2455
- 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', {
2456
- checkoutId: checkout.id,
2457
- userEmail: checkout.user.email,
2458
- info: error.message,
2459
- });
2460
- }
2461
- }
2462
- createCardPayment(checkout, card) {
2463
- return {
2464
- amount: {
2465
- currency: 'BRL',
2466
- value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2467
- },
2468
- paymentMethod: {
2469
- type: 'scheme',
2470
- storedPaymentMethodId: card.cardId,
2471
- },
2472
- reference: checkout.id,
2473
- shopperInteraction: 'Ecommerce',
2474
- merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2475
- shopperReference: checkout.user.id,
2476
- recurringProcessingModel: 'CardOnFile',
2477
- returnUrl: this.credentials.URL_POSTBACK,
2478
- installments: {
2479
- value: card.installments,
2480
- },
2481
- };
2482
- }
2483
- addCard() {
2484
- throw new Error('Method not implemented.');
2485
- }
2486
- getCardByToken(token) {
2487
- throw new Error('Method not implemented.');
2488
- }
2489
- createTransaction(info) {
2490
- throw new Error('Method not implemented.');
2491
- }
2492
- }
2493
-
2494
2418
  class AntifraudBankSlipService {
2495
2419
  constructor(orderBlockedRepository) {
2496
2420
  this.orderBlockedRepository = orderBlockedRepository;
@@ -2729,329 +2653,29 @@ class GlampointsPaymentService {
2729
2653
  }
2730
2654
  }
2731
2655
 
2732
- class PagarmeBankSlipService {
2733
- constructor(credentials, paymentRepository) {
2734
- this.credentials = credentials;
2735
- this.paymentRepository = paymentRepository;
2736
- }
2737
- async pay(checkout) {
2738
- try {
2739
- const result = await axios__default["default"]({
2740
- method: 'POST',
2741
- url: `${this.credentials.URL}/transactions`,
2742
- data: this.createBoletoPayment(checkout),
2743
- });
2744
- if (result.data.status !== exports.PagarmePaymentStatus['Em processamento']) {
2745
- return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
2746
- checkoutId: checkout.id,
2747
- userEmail: checkout.user.email,
2748
- info: result.data,
2749
- }));
2750
- }
2751
- const payment = await this.paymentRepository.create(Payment.toInstance({
2752
- createdAt: new Date(),
2753
- updatedAt: new Date(),
2754
- userId: checkout.user.id,
2755
- checkoutId: checkout.id,
2756
- totalPrice: checkout.totalPrice,
2757
- paymentProvider: 'pagarMe',
2758
- transaction: result.data,
2759
- }));
2760
- return payment;
2761
- }
2762
- catch (error) {
2763
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
2764
- checkoutId: checkout.id,
2765
- userEmail: checkout.user.email,
2766
- info: error.response.data,
2767
- });
2768
- }
2769
- }
2770
- async getBoletoTransaction(paymentId) {
2771
- try {
2772
- const { data } = await axios__default["default"]({
2773
- method: 'GET',
2774
- url: `${this.credentials.URL}/transactions/${paymentId}`,
2775
- data: {
2776
- api_key: this.credentials.API_KEY,
2777
- },
2778
- });
2779
- return data;
2656
+ class RoundProductPricesHelper {
2657
+ static roundProductPrices(product) {
2658
+ product.price.price = Number(product.price.price.toFixed(2));
2659
+ product.price.fullPrice = Number(product.price.fullPrice.toFixed(2));
2660
+ if (product.price.subscriberPrice) {
2661
+ product.price.subscriberPrice = Number(product.price.subscriberPrice.toFixed(2));
2780
2662
  }
2781
- catch (error) {
2782
- throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
2783
- paymentId,
2784
- info: error.response.data,
2785
- });
2663
+ if (product instanceof LineItem && product.pricePaid) {
2664
+ product.pricePaid = Number(product.pricePaid.toFixed(2));
2786
2665
  }
2787
- }
2788
- createBoletoPayment(checkout) {
2789
- return {
2790
- api_key: this.credentials.API_KEY,
2791
- amount: Math.floor(checkout.totalPrice * 100),
2792
- boleto_rules: ['strict_expiration_date'],
2793
- boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
2794
- boleto_expiration_date: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
2795
- payment_method: 'boleto',
2796
- postback_url: this.credentials.URL_POSTBACK,
2797
- customer: {
2798
- external_id: checkout.user.id,
2799
- type: 'individual',
2800
- country: 'br',
2801
- name: checkout.user.displayName,
2802
- documents: [
2803
- {
2804
- type: 'cpf',
2805
- number: checkout.user.cpf,
2806
- },
2807
- ],
2808
- },
2809
- };
2666
+ return product;
2810
2667
  }
2811
2668
  }
2812
2669
 
2813
- class PagarmeCardService {
2814
- constructor(credentials, paymentRepository, orderBlockedRepository) {
2815
- this.credentials = credentials;
2816
- this.paymentRepository = paymentRepository;
2817
- this.orderBlockedRepository = orderBlockedRepository;
2818
- }
2819
- async pay(checkout, card) {
2820
- var _a;
2821
- try {
2822
- const result = await axios__default["default"]({
2823
- method: 'POST',
2824
- url: `${this.credentials.URL}/transactions`,
2825
- data: this.createCardPayment(checkout, card),
2826
- });
2827
- if (result.data.status !== exports.PagarmePaymentStatus.Pago) {
2828
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2829
- 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`, {
2830
- checkoutId: checkout.id,
2831
- userEmail: checkout.user.email,
2832
- info: result.data,
2833
- }));
2834
- }
2835
- const payment = await this.paymentRepository.create(Payment.toInstance({
2836
- createdAt: new Date(),
2837
- updatedAt: new Date(),
2838
- userId: checkout.user.id,
2839
- checkoutId: checkout.id,
2840
- totalPrice: checkout.totalPrice,
2841
- paymentProvider: exports.PaymentProviders.PAGARME,
2842
- transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
2843
- }));
2844
- return payment;
2845
- }
2846
- catch (error) {
2847
- 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', {
2848
- checkoutId: checkout.id,
2849
- userEmail: checkout.user.email,
2850
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2851
- });
2852
- }
2853
- }
2854
- async addCard(card) {
2855
- try {
2856
- const { data } = await axios__default["default"]({
2857
- method: 'POST',
2858
- url: `${this.credentials.URL}/cards`,
2859
- data: {
2860
- api_key: this.credentials.API_KEY,
2861
- card_number: card.number,
2862
- card_expiration_date: card.expirationDate.replace('/', ''),
2863
- card_holder_name: card.name,
2864
- card_cvv: card.cvv,
2865
- },
2866
- });
2867
- return data;
2868
- }
2869
- catch (error) {
2870
- throw new BusinessError('Houve uma falha adicionar o cartão', {
2871
- info: error.response.data,
2872
- });
2873
- }
2670
+ class LogDocument extends BaseModel {
2671
+ static get identifiersFields() {
2672
+ return ['id'];
2874
2673
  }
2875
- async createCardHash(bu) {
2876
- const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
2877
- try {
2878
- const { data } = await axios__default["default"]({
2879
- method: 'POST',
2880
- url: `${this.credentials.URL}/transactions/card_hash_key`,
2881
- data: {
2882
- api_key: key,
2883
- },
2884
- });
2885
- return data;
2886
- }
2887
- catch (error) {
2888
- throw new BusinessError('Houve uma falha gerar o hash', {
2889
- info: error.response.data,
2890
- });
2891
- }
2892
- }
2893
- async getCardByToken(id) {
2894
- try {
2895
- const { data } = await axios__default["default"]({
2896
- method: 'POST',
2897
- url: `${this.credentials.URL}/cards/${id}`,
2898
- data: {
2899
- api_key: this.credentials.API_KEY,
2900
- },
2901
- });
2902
- return data;
2903
- }
2904
- catch (error) {
2905
- throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
2906
- info: error.response.data,
2907
- });
2908
- }
2909
- }
2910
- async createTransaction(info) {
2911
- try {
2912
- const { data } = await axios__default["default"]({
2913
- method: 'POST',
2914
- url: `${this.credentials.URL}/transactions`,
2915
- data: Object.assign(Object.assign({}, info), { api_key: this.credentials.API_KEY }),
2916
- });
2917
- return data;
2918
- }
2919
- catch (error) {
2920
- throw new BusinessError('Houve uma falha ao criar a transação', {
2921
- info: error.response.data,
2922
- });
2923
- }
2924
- }
2925
- createCardPayment(checkout, card) {
2926
- var _a, _b, _c, _d, _e, _f;
2927
- return {
2928
- api_key: this.credentials.API_KEY,
2929
- amount: Math.floor(checkout.totalPrice * 100),
2930
- card_id: card.cardId,
2931
- payment_method: 'credit_card',
2932
- installments: card.installments,
2933
- soft_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
2934
- customer: {
2935
- external_id: checkout.user.id,
2936
- name: checkout.user.displayName,
2937
- type: 'individual',
2938
- country: 'br',
2939
- email: checkout.user.email,
2940
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2941
- documents: [
2942
- {
2943
- type: 'cpf',
2944
- number: checkout.user.cpf,
2945
- },
2946
- ],
2947
- },
2948
- billing: {
2949
- name: checkout.user.displayName,
2950
- address: {
2951
- country: 'br',
2952
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
2953
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
2954
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
2955
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
2956
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
2957
- zipcode: checkout.billingAddress
2958
- ? checkout.billingAddress.zip.replace('-', '')
2959
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
2960
- },
2961
- },
2962
- items: checkout.lineItems.map((item) => {
2963
- return {
2964
- id: item.id,
2965
- title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
2966
- unit_price: Math.floor(item.pricePaid * 100),
2967
- quantity: item.quantity,
2968
- tangible: true,
2969
- };
2970
- }),
2971
- };
2972
- }
2973
- }
2974
-
2975
- class PagarmePixService {
2976
- constructor(credentials, paymentRepository) {
2977
- this.credentials = credentials;
2978
- this.paymentRepository = paymentRepository;
2979
- }
2980
- async pay(checkout) {
2981
- var _a;
2982
- try {
2983
- const result = await axios__default["default"]({
2984
- method: 'POST',
2985
- url: `${this.credentials.URL}/transactions`,
2986
- data: this.createPixPayment(checkout),
2987
- });
2988
- const payment = await this.paymentRepository.create(Payment.toInstance({
2989
- createdAt: new Date(),
2990
- updatedAt: new Date(),
2991
- userId: checkout.user.id,
2992
- checkoutId: checkout.id,
2993
- totalPrice: checkout.totalPrice,
2994
- paymentProvider: 'pagarMe',
2995
- transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
2996
- }));
2997
- return payment;
2998
- }
2999
- catch (error) {
3000
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
3001
- checkoutId: checkout.id,
3002
- userEmail: checkout.user.email,
3003
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
3004
- });
3005
- }
3006
- }
3007
- createPixPayment(checkout) {
3008
- return {
3009
- payment_method: 'pix',
3010
- amount: Math.floor(checkout.totalPrice * 100),
3011
- api_key: this.credentials.API_KEY,
3012
- postback_url: this.credentials.URL_POSTBACK,
3013
- pix_expiration_date: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
3014
- customer: {
3015
- external_id: checkout.user.id,
3016
- type: 'individual',
3017
- country: 'br',
3018
- name: checkout.user.displayName,
3019
- email: checkout.user.email.trim(),
3020
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
3021
- documents: [
3022
- {
3023
- type: 'cpf',
3024
- number: checkout.user.cpf,
3025
- },
3026
- ],
3027
- },
3028
- };
3029
- }
3030
- }
3031
-
3032
- class RoundProductPricesHelper {
3033
- static roundProductPrices(product) {
3034
- product.price.price = Number(product.price.price.toFixed(2));
3035
- product.price.fullPrice = Number(product.price.fullPrice.toFixed(2));
3036
- if (product.price.subscriberPrice) {
3037
- product.price.subscriberPrice = Number(product.price.subscriberPrice.toFixed(2));
3038
- }
3039
- if (product instanceof LineItem && product.pricePaid) {
3040
- product.pricePaid = Number(product.pricePaid.toFixed(2));
3041
- }
3042
- return product;
3043
- }
3044
- }
3045
-
3046
- class LogDocument extends BaseModel {
3047
- static get identifiersFields() {
3048
- return ['id'];
3049
- }
3050
- }
3051
-
3052
- class Sequence extends BaseModel {
3053
- static get identifiersFields() {
3054
- return ['id'];
2674
+ }
2675
+
2676
+ class Sequence extends BaseModel {
2677
+ static get identifiersFields() {
2678
+ return ['id'];
3055
2679
  }
3056
2680
  }
3057
2681
 
@@ -3193,6 +2817,82 @@ class ShopSettings extends BaseModel {
3193
2817
  }
3194
2818
  }
3195
2819
 
2820
+ class AdyenCardAxiosAdapter {
2821
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2822
+ this.credentials = credentials;
2823
+ this.paymentRepository = paymentRepository;
2824
+ this.orderBlockedRepository = orderBlockedRepository;
2825
+ }
2826
+ async pay(checkout, card) {
2827
+ try {
2828
+ const result = await axios__default["default"]({
2829
+ method: 'POST',
2830
+ url: this.credentials.URL_TRANSACTION,
2831
+ headers: {
2832
+ 'x-api-key': this.credentials.API_KEY,
2833
+ 'content-type': 'application/json',
2834
+ },
2835
+ data: this.createCardPayment(checkout, card),
2836
+ });
2837
+ if (result.data.resultCode !== 'Authorised') {
2838
+ this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2839
+ 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`, {
2840
+ checkoutId: checkout.id,
2841
+ userEmail: checkout.user.email,
2842
+ info: result.data,
2843
+ }));
2844
+ }
2845
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2846
+ createdAt: new Date(),
2847
+ updatedAt: new Date(),
2848
+ userId: checkout.user.id,
2849
+ checkoutId: checkout.id,
2850
+ totalPrice: checkout.totalPrice,
2851
+ paymentProvider: 'adyen',
2852
+ transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2853
+ }));
2854
+ return payment;
2855
+ }
2856
+ catch (error) {
2857
+ 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', {
2858
+ checkoutId: checkout.id,
2859
+ userEmail: checkout.user.email,
2860
+ info: error.message,
2861
+ });
2862
+ }
2863
+ }
2864
+ createCardPayment(checkout, card) {
2865
+ return {
2866
+ amount: {
2867
+ currency: 'BRL',
2868
+ value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2869
+ },
2870
+ paymentMethod: {
2871
+ type: 'scheme',
2872
+ storedPaymentMethodId: card.cardId,
2873
+ },
2874
+ reference: checkout.id,
2875
+ shopperInteraction: 'Ecommerce',
2876
+ merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2877
+ shopperReference: checkout.user.id,
2878
+ recurringProcessingModel: 'CardOnFile',
2879
+ returnUrl: this.credentials.URL_POSTBACK,
2880
+ installments: {
2881
+ value: card.installments,
2882
+ },
2883
+ };
2884
+ }
2885
+ addCard() {
2886
+ throw new Error('Method not implemented.');
2887
+ }
2888
+ getCardByToken(token) {
2889
+ throw new Error('Method not implemented.');
2890
+ }
2891
+ createTransaction(info) {
2892
+ throw new Error('Method not implemented.');
2893
+ }
2894
+ }
2895
+
3196
2896
  class AxiosAdapter {
3197
2897
  constructor(config) {
3198
2898
  this.config = config;
@@ -7245,6 +6945,306 @@ tslib.__decorate([
7245
6945
  tslib.__metadata("design:returntype", Promise)
7246
6946
  ], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
7247
6947
 
6948
+ class PagarmeBankSlipAxiosAdapter {
6949
+ constructor(credentials, paymentRepository) {
6950
+ this.credentials = credentials;
6951
+ this.paymentRepository = paymentRepository;
6952
+ }
6953
+ async pay(checkout) {
6954
+ try {
6955
+ const result = await axios__default["default"]({
6956
+ method: 'POST',
6957
+ url: `${this.credentials.URL}/transactions`,
6958
+ data: this.createBoletoPayment(checkout),
6959
+ });
6960
+ if (result.data.status !== exports.PagarmePaymentStatus['Em processamento']) {
6961
+ return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
6962
+ checkoutId: checkout.id,
6963
+ userEmail: checkout.user.email,
6964
+ info: result.data,
6965
+ }));
6966
+ }
6967
+ const payment = await this.paymentRepository.create(Payment.toInstance({
6968
+ createdAt: new Date(),
6969
+ updatedAt: new Date(),
6970
+ userId: checkout.user.id,
6971
+ checkoutId: checkout.id,
6972
+ totalPrice: checkout.totalPrice,
6973
+ paymentProvider: 'pagarMe',
6974
+ transaction: result.data,
6975
+ }));
6976
+ return payment;
6977
+ }
6978
+ catch (error) {
6979
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
6980
+ checkoutId: checkout.id,
6981
+ userEmail: checkout.user.email,
6982
+ info: error.response.data,
6983
+ });
6984
+ }
6985
+ }
6986
+ async getBoletoTransaction(paymentId) {
6987
+ try {
6988
+ const { data } = await axios__default["default"]({
6989
+ method: 'GET',
6990
+ url: `${this.credentials.URL}/transactions/${paymentId}`,
6991
+ data: {
6992
+ api_key: this.credentials.API_KEY,
6993
+ },
6994
+ });
6995
+ return data;
6996
+ }
6997
+ catch (error) {
6998
+ throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
6999
+ paymentId,
7000
+ info: error.response.data,
7001
+ });
7002
+ }
7003
+ }
7004
+ createBoletoPayment(checkout) {
7005
+ return {
7006
+ api_key: this.credentials.API_KEY,
7007
+ amount: Math.floor(checkout.totalPrice * 100),
7008
+ boleto_rules: ['strict_expiration_date'],
7009
+ boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
7010
+ boleto_expiration_date: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
7011
+ payment_method: 'boleto',
7012
+ postback_url: this.credentials.URL_POSTBACK,
7013
+ customer: {
7014
+ external_id: checkout.user.id,
7015
+ type: 'individual',
7016
+ country: 'br',
7017
+ name: checkout.user.displayName,
7018
+ documents: [
7019
+ {
7020
+ type: 'cpf',
7021
+ number: checkout.user.cpf,
7022
+ },
7023
+ ],
7024
+ },
7025
+ };
7026
+ }
7027
+ }
7028
+
7029
+ class PagarmeCardAxiosAdapter {
7030
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
7031
+ this.credentials = credentials;
7032
+ this.paymentRepository = paymentRepository;
7033
+ this.orderBlockedRepository = orderBlockedRepository;
7034
+ }
7035
+ async pay(checkout, card) {
7036
+ var _a;
7037
+ try {
7038
+ const result = await axios__default["default"]({
7039
+ method: 'POST',
7040
+ url: `${this.credentials.URL}/transactions`,
7041
+ data: this.createCardPayment(checkout, card),
7042
+ });
7043
+ if (result.data.status !== exports.PagarmePaymentStatus.Pago) {
7044
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
7045
+ 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`, {
7046
+ checkoutId: checkout.id,
7047
+ userEmail: checkout.user.email,
7048
+ info: result.data,
7049
+ }));
7050
+ }
7051
+ const payment = await this.paymentRepository.create(Payment.toInstance({
7052
+ createdAt: new Date(),
7053
+ updatedAt: new Date(),
7054
+ userId: checkout.user.id,
7055
+ checkoutId: checkout.id,
7056
+ totalPrice: checkout.totalPrice,
7057
+ paymentProvider: exports.PaymentProviders.PAGARME,
7058
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
7059
+ }));
7060
+ return payment;
7061
+ }
7062
+ catch (error) {
7063
+ 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', {
7064
+ checkoutId: checkout.id,
7065
+ userEmail: checkout.user.email,
7066
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
7067
+ });
7068
+ }
7069
+ }
7070
+ async addCard(card) {
7071
+ try {
7072
+ const { data } = await axios__default["default"]({
7073
+ method: 'POST',
7074
+ url: `${this.credentials.URL}/cards`,
7075
+ data: {
7076
+ api_key: this.credentials.API_KEY,
7077
+ card_number: card.number,
7078
+ card_expiration_date: card.expirationDate.replace('/', ''),
7079
+ card_holder_name: card.name,
7080
+ card_cvv: card.cvv,
7081
+ },
7082
+ });
7083
+ return data;
7084
+ }
7085
+ catch (error) {
7086
+ throw new BusinessError('Houve uma falha adicionar o cartão', {
7087
+ info: error.response.data,
7088
+ });
7089
+ }
7090
+ }
7091
+ async createCardHash(bu) {
7092
+ const key = bu === exports.BusinessUnitEnum.SHOP ? this.credentials.API_KEY : this.credentials.SUBSCRIPTION_API_KEY;
7093
+ try {
7094
+ const { data } = await axios__default["default"]({
7095
+ method: 'POST',
7096
+ url: `${this.credentials.URL}/transactions/card_hash_key`,
7097
+ data: {
7098
+ api_key: key,
7099
+ },
7100
+ });
7101
+ return data;
7102
+ }
7103
+ catch (error) {
7104
+ throw new BusinessError('Houve uma falha gerar o hash', {
7105
+ info: error.response.data,
7106
+ });
7107
+ }
7108
+ }
7109
+ async getCardByToken(id) {
7110
+ try {
7111
+ const { data } = await axios__default["default"]({
7112
+ method: 'POST',
7113
+ url: `${this.credentials.URL}/cards/${id}`,
7114
+ data: {
7115
+ api_key: this.credentials.API_KEY,
7116
+ },
7117
+ });
7118
+ return data;
7119
+ }
7120
+ catch (error) {
7121
+ throw new BusinessError('Houve uma falha buscar o cartão com id: ' + id, {
7122
+ info: error.response.data,
7123
+ });
7124
+ }
7125
+ }
7126
+ async createTransaction(info) {
7127
+ try {
7128
+ const { data } = await axios__default["default"]({
7129
+ method: 'POST',
7130
+ url: `${this.credentials.URL}/transactions`,
7131
+ data: Object.assign(Object.assign({}, info), { api_key: this.credentials.API_KEY }),
7132
+ });
7133
+ return data;
7134
+ }
7135
+ catch (error) {
7136
+ throw new BusinessError('Houve uma falha ao criar a transação', {
7137
+ info: error.response.data,
7138
+ });
7139
+ }
7140
+ }
7141
+ createCardPayment(checkout, card) {
7142
+ var _a, _b, _c, _d, _e, _f;
7143
+ return {
7144
+ api_key: this.credentials.API_KEY,
7145
+ amount: Math.floor(checkout.totalPrice * 100),
7146
+ card_id: card.cardId,
7147
+ payment_method: 'credit_card',
7148
+ installments: card.installments,
7149
+ soft_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
7150
+ customer: {
7151
+ external_id: checkout.user.id,
7152
+ name: checkout.user.displayName,
7153
+ type: 'individual',
7154
+ country: 'br',
7155
+ email: checkout.user.email,
7156
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
7157
+ documents: [
7158
+ {
7159
+ type: 'cpf',
7160
+ number: checkout.user.cpf,
7161
+ },
7162
+ ],
7163
+ },
7164
+ billing: {
7165
+ name: checkout.user.displayName,
7166
+ address: {
7167
+ country: 'br',
7168
+ state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
7169
+ city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
7170
+ neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
7171
+ street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
7172
+ street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
7173
+ zipcode: checkout.billingAddress
7174
+ ? checkout.billingAddress.zip.replace('-', '')
7175
+ : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
7176
+ },
7177
+ },
7178
+ items: checkout.lineItems.map((item) => {
7179
+ return {
7180
+ id: item.id,
7181
+ title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
7182
+ unit_price: Math.floor(item.pricePaid * 100),
7183
+ quantity: item.quantity,
7184
+ tangible: true,
7185
+ };
7186
+ }),
7187
+ };
7188
+ }
7189
+ }
7190
+
7191
+ class PagarmePixAxiosAdapter {
7192
+ constructor(credentials, paymentRepository) {
7193
+ this.credentials = credentials;
7194
+ this.paymentRepository = paymentRepository;
7195
+ }
7196
+ async pay(checkout) {
7197
+ var _a;
7198
+ try {
7199
+ const result = await axios__default["default"]({
7200
+ method: 'POST',
7201
+ url: `${this.credentials.URL}/transactions`,
7202
+ data: this.createPixPayment(checkout),
7203
+ });
7204
+ const payment = await this.paymentRepository.create(Payment.toInstance({
7205
+ createdAt: new Date(),
7206
+ updatedAt: new Date(),
7207
+ userId: checkout.user.id,
7208
+ checkoutId: checkout.id,
7209
+ totalPrice: checkout.totalPrice,
7210
+ paymentProvider: 'pagarMe',
7211
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
7212
+ }));
7213
+ return payment;
7214
+ }
7215
+ catch (error) {
7216
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
7217
+ checkoutId: checkout.id,
7218
+ userEmail: checkout.user.email,
7219
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
7220
+ });
7221
+ }
7222
+ }
7223
+ createPixPayment(checkout) {
7224
+ return {
7225
+ payment_method: 'pix',
7226
+ amount: Math.floor(checkout.totalPrice * 100),
7227
+ api_key: this.credentials.API_KEY,
7228
+ postback_url: this.credentials.URL_POSTBACK,
7229
+ pix_expiration_date: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
7230
+ customer: {
7231
+ external_id: checkout.user.id,
7232
+ type: 'individual',
7233
+ country: 'br',
7234
+ name: checkout.user.displayName,
7235
+ email: checkout.user.email.trim(),
7236
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
7237
+ documents: [
7238
+ {
7239
+ type: 'cpf',
7240
+ number: checkout.user.cpf,
7241
+ },
7242
+ ],
7243
+ },
7244
+ };
7245
+ }
7246
+ }
7247
+
7248
7248
  class VertexAxiosAdapter {
7249
7249
  constructor(config) {
7250
7250
  this.config = config;
@@ -7519,7 +7519,7 @@ Object.defineProperty(exports, 'unset', {
7519
7519
  get: function () { return lodash.unset; }
7520
7520
  });
7521
7521
  exports.Address = Address;
7522
- exports.AdyenCardService = AdyenCardService;
7522
+ exports.AdyenCardAxiosAdapter = AdyenCardAxiosAdapter;
7523
7523
  exports.AdyenPaymentMethodFactory = AdyenPaymentMethodFactory;
7524
7524
  exports.AntifraudBankSlipService = AntifraudBankSlipService;
7525
7525
  exports.AntifraudCardService = AntifraudCardService;
@@ -7592,10 +7592,10 @@ exports.Order = Order;
7592
7592
  exports.OrderBlocked = OrderBlocked;
7593
7593
  exports.OrderBlockedFirestoreRepository = OrderBlockedFirestoreRepository;
7594
7594
  exports.OrderFirestoreRepository = OrderFirestoreRepository;
7595
- exports.PagarmeBankSlipService = PagarmeBankSlipService;
7596
- exports.PagarmeCardService = PagarmeCardService;
7595
+ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
7596
+ exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
7597
7597
  exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
7598
- exports.PagarmePixService = PagarmePixService;
7598
+ exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
7599
7599
  exports.Payment = Payment;
7600
7600
  exports.PaymentError = PaymentError;
7601
7601
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;