@infrab4a/connect 5.3.1-beta.2 → 5.3.1
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 +671 -6
- package/index.esm.js +669 -7
- package/package.json +1 -1
- package/src/domain/catalog/models/product-base.d.ts +3 -1
- package/src/domain/catalog/models/types/brands-shop-menu.type.d.ts +13 -0
- package/src/domain/catalog/models/types/index.d.ts +1 -0
- package/src/domain/catalog/repositories/category.repository.d.ts +1 -0
- package/src/domain/catalog/repositories/product.repository.d.ts +3 -0
- package/src/domain/catalog/repositories/variant.repository.d.ts +1 -0
- package/src/domain/shopping/enums/index.d.ts +2 -0
- package/src/domain/shopping/enums/pagarme-v5-payment-status.enum.d.ts +24 -0
- package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +5 -0
- package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +10 -2
- package/src/domain/shopping/models/enums/order-status.enum.d.ts +1 -1
- package/src/domain/shopping/models/payment-transaction.d.ts +17 -2
- package/src/domain/shopping/models/payment.d.ts +2 -1
- package/src/domain/shopping/types/card-info.type.d.ts +1 -0
- package/src/domain/shopping/types/index.d.ts +1 -0
- package/src/domain/shopping/types/pagarme-card.type.d.ts +9 -3
- package/src/domain/shopping/types/pagarme-credentials-v5.type.d.ts +4 -0
- package/src/domain/shopping/types/pagarme-credentials.type.d.ts +9 -3
- package/src/domain/users/models/user-payment-method.d.ts +2 -0
- package/src/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +1 -0
- package/src/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +4 -1
- package/src/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +3 -0
- package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -0
- package/src/infra/pagarme/adapters/helpers/index.d.ts +2 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +12 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +10 -0
- package/src/infra/pagarme/adapters/index.d.ts +2 -3
- package/src/infra/pagarme/adapters/v4/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/{pagarme-bank-slip-payment-axios.adapter.d.ts → v4/pagarme-bank-slip-payment-axios.adapter.d.ts} +4 -4
- package/src/infra/pagarme/adapters/{pagarme-card-payment-axios.adapter.d.ts → v4/pagarme-card-payment-axios.adapter.d.ts} +7 -6
- package/src/infra/pagarme/adapters/v4/pagarme-pix-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-bank-slip-payment-axios.adapter.d.ts +11 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +24 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-pix-payment-axios.adapter.d.ts +10 -0
- package/src/infra/pagarme/index.d.ts +1 -0
- package/src/infra/pagarme/types/index.d.ts +1 -0
- package/src/infra/pagarme/types/v5/index.d.ts +4 -0
- package/src/infra/pagarme/types/v5/pagarmev5-customer.type.d.ts +19 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +89 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +126 -0
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +11 -0
- package/src/infra/pagarme/adapters/pagarme-pix-payment-axios.adapter.d.ts +0 -11
package/index.cjs.js
CHANGED
|
@@ -73,6 +73,33 @@ exports.PagarmePaymentStatus = void 0;
|
|
|
73
73
|
PagarmePaymentStatus["Chargedback"] = "chargedback";
|
|
74
74
|
})(exports.PagarmePaymentStatus || (exports.PagarmePaymentStatus = {}));
|
|
75
75
|
|
|
76
|
+
exports.PagarMeV5PaymentStatus = void 0;
|
|
77
|
+
(function (PagarMeV5PaymentStatus) {
|
|
78
|
+
PagarMeV5PaymentStatus["Em processamento"] = "processing";
|
|
79
|
+
PagarMeV5PaymentStatus["Gerado"] = "generated";
|
|
80
|
+
PagarMeV5PaymentStatus["Visualizado"] = "viewed";
|
|
81
|
+
PagarMeV5PaymentStatus["Pago a menor"] = "underpaid";
|
|
82
|
+
PagarMeV5PaymentStatus["Pago a maior"] = "overpaid";
|
|
83
|
+
PagarMeV5PaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
84
|
+
PagarMeV5PaymentStatus["Pago"] = "paid";
|
|
85
|
+
PagarMeV5PaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
86
|
+
PagarMeV5PaymentStatus["Autorizada pendente de captura"] = "authorized_pending_capture";
|
|
87
|
+
PagarMeV5PaymentStatus["N\u00E3o autorizada"] = "not_authorized";
|
|
88
|
+
PagarMeV5PaymentStatus["Capturada"] = "captured";
|
|
89
|
+
PagarMeV5PaymentStatus["Aguardando captura"] = "waiting_capture";
|
|
90
|
+
PagarMeV5PaymentStatus["Com erro"] = "with_error";
|
|
91
|
+
PagarMeV5PaymentStatus["Estornado"] = "refunded";
|
|
92
|
+
PagarMeV5PaymentStatus["Cancelado"] = "voided";
|
|
93
|
+
PagarMeV5PaymentStatus["Falha"] = "failed";
|
|
94
|
+
})(exports.PagarMeV5PaymentStatus || (exports.PagarMeV5PaymentStatus = {}));
|
|
95
|
+
exports.PagarMeV5OrderStatus = void 0;
|
|
96
|
+
(function (PagarMeV5OrderStatus) {
|
|
97
|
+
PagarMeV5OrderStatus["Pendente"] = "pending";
|
|
98
|
+
PagarMeV5OrderStatus["Pago"] = "paid";
|
|
99
|
+
PagarMeV5OrderStatus["Cancelado"] = "canceled";
|
|
100
|
+
PagarMeV5OrderStatus["Falha"] = "failed";
|
|
101
|
+
})(exports.PagarMeV5OrderStatus || (exports.PagarMeV5OrderStatus = {}));
|
|
102
|
+
|
|
76
103
|
exports.PaymentMethods = void 0;
|
|
77
104
|
(function (PaymentMethods) {
|
|
78
105
|
PaymentMethods["CARD"] = "card";
|
|
@@ -88,6 +115,13 @@ exports.PaymentProviders = void 0;
|
|
|
88
115
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
89
116
|
})(exports.PaymentProviders || (exports.PaymentProviders = {}));
|
|
90
117
|
|
|
118
|
+
exports.TransactionPaymentMethods = void 0;
|
|
119
|
+
(function (TransactionPaymentMethods) {
|
|
120
|
+
TransactionPaymentMethods["CARD"] = "credit_card";
|
|
121
|
+
TransactionPaymentMethods["BANKSLIP"] = "boleto";
|
|
122
|
+
TransactionPaymentMethods["PIX"] = "pix";
|
|
123
|
+
})(exports.TransactionPaymentMethods || (exports.TransactionPaymentMethods = {}));
|
|
124
|
+
|
|
91
125
|
class BasePaymentMethodFactory {
|
|
92
126
|
constructor(methods) {
|
|
93
127
|
this.methods = methods;
|
|
@@ -1592,7 +1626,7 @@ exports.OrderStatus = void 0;
|
|
|
1592
1626
|
OrderStatus["ENVIADO"] = "Enviado";
|
|
1593
1627
|
OrderStatus["ENTREGUE"] = "Entregue";
|
|
1594
1628
|
OrderStatus["CANCELADO"] = "Cancelado";
|
|
1595
|
-
OrderStatus["
|
|
1629
|
+
OrderStatus["PENDENTE_REENVIO"] = "Pendente reenvio";
|
|
1596
1630
|
})(exports.OrderStatus || (exports.OrderStatus = {}));
|
|
1597
1631
|
|
|
1598
1632
|
class Order extends Checkout {
|
|
@@ -4801,6 +4835,9 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
|
|
|
4801
4835
|
isChild(_id, _parentId) {
|
|
4802
4836
|
return;
|
|
4803
4837
|
}
|
|
4838
|
+
async getBrandsWithProducts() {
|
|
4839
|
+
return;
|
|
4840
|
+
}
|
|
4804
4841
|
}
|
|
4805
4842
|
tslib.__decorate([
|
|
4806
4843
|
Log(),
|
|
@@ -4891,6 +4928,9 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
|
|
|
4891
4928
|
productVariantFullReport() {
|
|
4892
4929
|
return;
|
|
4893
4930
|
}
|
|
4931
|
+
getByEAN(EAN, options) {
|
|
4932
|
+
return;
|
|
4933
|
+
}
|
|
4894
4934
|
}
|
|
4895
4935
|
tslib.__decorate([
|
|
4896
4936
|
Log(),
|
|
@@ -4916,6 +4956,9 @@ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirest
|
|
|
4916
4956
|
});
|
|
4917
4957
|
this.parentRepository = parentRepository;
|
|
4918
4958
|
}
|
|
4959
|
+
getByEAN(EAN) {
|
|
4960
|
+
return;
|
|
4961
|
+
}
|
|
4919
4962
|
}
|
|
4920
4963
|
|
|
4921
4964
|
class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
@@ -6152,7 +6195,8 @@ class CategoryProductOperationsHelper {
|
|
|
6152
6195
|
'isKit',
|
|
6153
6196
|
'sku',
|
|
6154
6197
|
'rate',
|
|
6155
|
-
'
|
|
6198
|
+
'tagsProfile',
|
|
6199
|
+
'tagsCollection',
|
|
6156
6200
|
'type',
|
|
6157
6201
|
'shoppingCount',
|
|
6158
6202
|
'gender',
|
|
@@ -6892,6 +6936,19 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
6892
6936
|
categoryFilterRepository: this.categoryFilterRepository,
|
|
6893
6937
|
});
|
|
6894
6938
|
}
|
|
6939
|
+
async getBrandsWithProducts() {
|
|
6940
|
+
const fields = ['id', 'name', 'slug', 'brand_category', 'published', 'images'];
|
|
6941
|
+
const { brands_with_products_query: data, } = await this.query('brands_with_products_query', fields);
|
|
6942
|
+
return data.map((brand) => Category.toInstance({
|
|
6943
|
+
id: brand.id,
|
|
6944
|
+
name: brand.name,
|
|
6945
|
+
slug: brand.slug,
|
|
6946
|
+
brandCategory: brand.brand_category,
|
|
6947
|
+
shops: brand.shops,
|
|
6948
|
+
published: brand.published,
|
|
6949
|
+
images: brand.images,
|
|
6950
|
+
}));
|
|
6951
|
+
}
|
|
6895
6952
|
}
|
|
6896
6953
|
tslib.__decorate([
|
|
6897
6954
|
Log(),
|
|
@@ -7373,7 +7430,6 @@ const commonFields = [
|
|
|
7373
7430
|
'weight',
|
|
7374
7431
|
'gender',
|
|
7375
7432
|
{ intGender: { columnName: 'int_gender' } },
|
|
7376
|
-
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7377
7433
|
{ filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7378
7434
|
{ isKit: { columnName: 'is_kit' } },
|
|
7379
7435
|
{ createdAt: { columnName: 'created_at' } },
|
|
@@ -7391,6 +7447,9 @@ const commonFields = [
|
|
|
7391
7447
|
},
|
|
7392
7448
|
'group',
|
|
7393
7449
|
'validity',
|
|
7450
|
+
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7451
|
+
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
7452
|
+
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
7394
7453
|
];
|
|
7395
7454
|
const fieldsConfiguration$2 = [
|
|
7396
7455
|
...commonFields,
|
|
@@ -7448,6 +7507,74 @@ const fieldsConfiguration$2 = [
|
|
|
7448
7507
|
}),
|
|
7449
7508
|
},
|
|
7450
7509
|
},
|
|
7510
|
+
{
|
|
7511
|
+
variants: {
|
|
7512
|
+
columnName: 'variants',
|
|
7513
|
+
foreignKeyColumn: { product_id: 'id' },
|
|
7514
|
+
fields: [
|
|
7515
|
+
'id',
|
|
7516
|
+
'ean',
|
|
7517
|
+
{
|
|
7518
|
+
grade: {
|
|
7519
|
+
columnName: 'grade',
|
|
7520
|
+
type: HasuraGraphQLColumnType.Jsonb,
|
|
7521
|
+
},
|
|
7522
|
+
},
|
|
7523
|
+
{
|
|
7524
|
+
price: {
|
|
7525
|
+
columnName: 'price',
|
|
7526
|
+
from: (price, data) => ({
|
|
7527
|
+
price,
|
|
7528
|
+
fullPrice: data.full_price,
|
|
7529
|
+
subscriberDiscountPercentage: data.subscriber_discount_percentage,
|
|
7530
|
+
subscriberPrice: data.subscriber_price,
|
|
7531
|
+
fullPriceDiscountPercentage: data.full_price_discount_percentage,
|
|
7532
|
+
}),
|
|
7533
|
+
bindFindFilter: (sentence) => {
|
|
7534
|
+
const filters = Object.values(sentence).shift();
|
|
7535
|
+
return {
|
|
7536
|
+
...((filters?.price || filters?.price === 0) && { price: filters.price }),
|
|
7537
|
+
...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
|
|
7538
|
+
...((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
|
|
7539
|
+
subscriber_discount_percentage: filters.subscriberDiscountPercentage,
|
|
7540
|
+
}),
|
|
7541
|
+
...((filters.subscriberPrice || filters.subscriberPrice === 0) && {
|
|
7542
|
+
subscriber_price: filters.subscriberPrice,
|
|
7543
|
+
}),
|
|
7544
|
+
...((filters.fullPriceDiscountPercentage || filters.fullPriceDiscountPercentage === 0) && {
|
|
7545
|
+
full_price_discount_percentage: filters.fullPriceDiscountPercentage,
|
|
7546
|
+
}),
|
|
7547
|
+
};
|
|
7548
|
+
},
|
|
7549
|
+
bindPersistData: (priceData) => ({
|
|
7550
|
+
...((priceData?.price || 0) >= 0 && { price: priceData.price }),
|
|
7551
|
+
...((priceData?.fullPrice || 0) >= 0 && { full_price: priceData.fullPrice }),
|
|
7552
|
+
...((priceData?.subscriberDiscountPercentage || 0) >= 0 && {
|
|
7553
|
+
subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
|
|
7554
|
+
}),
|
|
7555
|
+
...((priceData?.subscriberPrice || 0) >= 0 && { subscriber_price: priceData.subscriberPrice }),
|
|
7556
|
+
...(priceData.fullPriceDiscountPercentage >= 0 && {
|
|
7557
|
+
full_price_discount_percentage: priceData.fullPriceDiscountPercentage,
|
|
7558
|
+
}),
|
|
7559
|
+
}),
|
|
7560
|
+
},
|
|
7561
|
+
},
|
|
7562
|
+
'published',
|
|
7563
|
+
{
|
|
7564
|
+
stock: {
|
|
7565
|
+
columnName: 'stock',
|
|
7566
|
+
from: (quantity) => ({ quantity }),
|
|
7567
|
+
to: (value) => (lodash.isNil(value?.quantity) ? value : value?.quantity),
|
|
7568
|
+
},
|
|
7569
|
+
},
|
|
7570
|
+
'description',
|
|
7571
|
+
'images',
|
|
7572
|
+
'miniatures',
|
|
7573
|
+
{ tagsProfile: { columnName: 'tags_profile' } },
|
|
7574
|
+
{ tagsCollection: { columnName: 'tags_collection' } },
|
|
7575
|
+
],
|
|
7576
|
+
},
|
|
7577
|
+
},
|
|
7451
7578
|
];
|
|
7452
7579
|
class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
7453
7580
|
get reviewsFields() {
|
|
@@ -7573,6 +7700,39 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
7573
7700
|
}
|
|
7574
7701
|
return product;
|
|
7575
7702
|
}
|
|
7703
|
+
async getByEAN(EAN, options) {
|
|
7704
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled) {
|
|
7705
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7706
|
+
const cachedData = await this.cache.cacheAdapter.get(cacheKey);
|
|
7707
|
+
if (cachedData) {
|
|
7708
|
+
this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
|
|
7709
|
+
return this.model.toInstance(deserialize(cachedData));
|
|
7710
|
+
}
|
|
7711
|
+
}
|
|
7712
|
+
const result = await this.find({
|
|
7713
|
+
filters: {
|
|
7714
|
+
EAN,
|
|
7715
|
+
},
|
|
7716
|
+
fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
|
|
7717
|
+
options: {
|
|
7718
|
+
enableCount: false,
|
|
7719
|
+
},
|
|
7720
|
+
});
|
|
7721
|
+
if (!result.data.length)
|
|
7722
|
+
return null;
|
|
7723
|
+
const product = result?.data?.shift();
|
|
7724
|
+
RoundProductPricesHelper.roundProductPrices(product);
|
|
7725
|
+
if (this.cache?.cacheAdapter && options?.cache?.enabled && product) {
|
|
7726
|
+
const cacheKey = `${this.model.name.toLowerCase()}:EAN:${EAN}`;
|
|
7727
|
+
await this.cache.cacheAdapter.set({
|
|
7728
|
+
key: cacheKey,
|
|
7729
|
+
data: serialize(product),
|
|
7730
|
+
expirationInSeconds: options?.cache?.ttl || this.cache.ttlDefault,
|
|
7731
|
+
});
|
|
7732
|
+
this.logger.log(`Dados salvos no cache: ${cacheKey}`);
|
|
7733
|
+
}
|
|
7734
|
+
return product;
|
|
7735
|
+
}
|
|
7576
7736
|
async update(params) {
|
|
7577
7737
|
const { kitProducts, reviews, id: checkId, metadata, ...data } = lodash.omit(params, ['categories', 'rate']);
|
|
7578
7738
|
const plainData = this.paramsToPlain({ id: checkId });
|
|
@@ -7817,6 +7977,12 @@ tslib.__decorate([
|
|
|
7817
7977
|
tslib.__metadata("design:paramtypes", [String, Object]),
|
|
7818
7978
|
tslib.__metadata("design:returntype", Promise)
|
|
7819
7979
|
], ProductHasuraGraphQLRepository.prototype, "getBySlug", null);
|
|
7980
|
+
tslib.__decorate([
|
|
7981
|
+
Log(),
|
|
7982
|
+
tslib.__metadata("design:type", Function),
|
|
7983
|
+
tslib.__metadata("design:paramtypes", [String, Object]),
|
|
7984
|
+
tslib.__metadata("design:returntype", Promise)
|
|
7985
|
+
], ProductHasuraGraphQLRepository.prototype, "getByEAN", null);
|
|
7820
7986
|
tslib.__decorate([
|
|
7821
7987
|
Log(),
|
|
7822
7988
|
tslib.__metadata("design:type", Function),
|
|
@@ -7872,6 +8038,13 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
|
|
|
7872
8038
|
{ orderId: { columnName: 'order_id' } },
|
|
7873
8039
|
{ createdAt: { columnName: 'created_at' } },
|
|
7874
8040
|
{ updatedAt: { columnName: 'updated_at' } },
|
|
8041
|
+
{
|
|
8042
|
+
product: {
|
|
8043
|
+
columnName: 'product',
|
|
8044
|
+
foreignKeyColumn: { id: 'productId' },
|
|
8045
|
+
fields: ['id', 'ean', 'sku', 'name', 'brand', 'slug', 'images', 'grade', 'gender'],
|
|
8046
|
+
},
|
|
8047
|
+
},
|
|
7875
8048
|
],
|
|
7876
8049
|
cache,
|
|
7877
8050
|
});
|
|
@@ -8063,8 +8236,12 @@ const fieldsConfiguration$1 = [
|
|
|
8063
8236
|
},
|
|
8064
8237
|
'group',
|
|
8065
8238
|
'validity',
|
|
8066
|
-
{ tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8067
8239
|
'published',
|
|
8240
|
+
{ tagsCollection: { columnName: 'tags_collection', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8241
|
+
{ tagsProfile: { columnName: 'tags_profile', type: HasuraGraphQLColumnType.Jsonb } },
|
|
8242
|
+
{ daysOfUse: { columnName: 'days_of_use' } },
|
|
8243
|
+
'images',
|
|
8244
|
+
'miniatures',
|
|
8068
8245
|
];
|
|
8069
8246
|
class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
|
|
8070
8247
|
constructor({ endpoint, authOptions, interceptors, cache, }) {
|
|
@@ -8093,6 +8270,17 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
|
|
|
8093
8270
|
const { filters, ...options } = params || {};
|
|
8094
8271
|
return super.find({ ...options, filters: { productId: { operator: exports.Where.ISNOTNULL }, ...filters } });
|
|
8095
8272
|
}
|
|
8273
|
+
async getByEAN(EAN) {
|
|
8274
|
+
const { data } = await this.find({
|
|
8275
|
+
filters: {
|
|
8276
|
+
EAN,
|
|
8277
|
+
},
|
|
8278
|
+
options: {
|
|
8279
|
+
enableCount: false,
|
|
8280
|
+
},
|
|
8281
|
+
});
|
|
8282
|
+
return data.at(0);
|
|
8283
|
+
}
|
|
8096
8284
|
async update(params) {
|
|
8097
8285
|
const { productId, id: checkId, ...data } = params;
|
|
8098
8286
|
const dataWithProductId = this.paramsToPlain({ id: checkId, productId });
|
|
@@ -8420,6 +8608,9 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
|
|
|
8420
8608
|
productId: +productId,
|
|
8421
8609
|
});
|
|
8422
8610
|
}
|
|
8611
|
+
async getBrandsWithProducts() {
|
|
8612
|
+
return;
|
|
8613
|
+
}
|
|
8423
8614
|
}
|
|
8424
8615
|
tslib.__decorate([
|
|
8425
8616
|
Log(),
|
|
@@ -8586,6 +8777,201 @@ class PagarmePaymentOperationsHelper {
|
|
|
8586
8777
|
}
|
|
8587
8778
|
}
|
|
8588
8779
|
|
|
8780
|
+
class PagarMeV5RequestHelper {
|
|
8781
|
+
static build(checkout, method, card) {
|
|
8782
|
+
return {
|
|
8783
|
+
items: this.buildItems(checkout),
|
|
8784
|
+
customer: this.buildCustomer(checkout),
|
|
8785
|
+
shipping: this.buildShipping(checkout),
|
|
8786
|
+
payments: this.buildPayment(checkout, method, card),
|
|
8787
|
+
};
|
|
8788
|
+
}
|
|
8789
|
+
static buildItems(checkout) {
|
|
8790
|
+
return checkout.lineItems
|
|
8791
|
+
.filter((item) => !item.isGift)
|
|
8792
|
+
.map((item) => {
|
|
8793
|
+
return {
|
|
8794
|
+
amount: Math.floor(item.pricePaid * 100),
|
|
8795
|
+
description: item.name,
|
|
8796
|
+
quantity: item.quantity,
|
|
8797
|
+
code: item.EAN,
|
|
8798
|
+
};
|
|
8799
|
+
});
|
|
8800
|
+
}
|
|
8801
|
+
static buildCustomer(checkout) {
|
|
8802
|
+
return {
|
|
8803
|
+
name: checkout.user.displayName,
|
|
8804
|
+
email: checkout.user.email,
|
|
8805
|
+
type: 'individual',
|
|
8806
|
+
document: checkout.user.cpf,
|
|
8807
|
+
phones: {
|
|
8808
|
+
home_phone: {
|
|
8809
|
+
country_code: '55',
|
|
8810
|
+
number: checkout.user.phone.slice(2),
|
|
8811
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
8812
|
+
},
|
|
8813
|
+
mobile_phone: {
|
|
8814
|
+
country_code: '55',
|
|
8815
|
+
number: checkout.user.phone.slice(2),
|
|
8816
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
8817
|
+
},
|
|
8818
|
+
},
|
|
8819
|
+
address: {
|
|
8820
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8821
|
+
line_2: `${checkout.billingAddress.extension}`,
|
|
8822
|
+
zip_code: checkout.shippingAddress.zip,
|
|
8823
|
+
city: checkout.billingAddress.city,
|
|
8824
|
+
state: checkout.billingAddress.state,
|
|
8825
|
+
country: 'BR',
|
|
8826
|
+
},
|
|
8827
|
+
};
|
|
8828
|
+
}
|
|
8829
|
+
static buildShipping(checkout) {
|
|
8830
|
+
return {
|
|
8831
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
8832
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
8833
|
+
recipient_name: checkout.shippingAddress.recipient,
|
|
8834
|
+
recipient_phone: checkout.user.phone,
|
|
8835
|
+
address: {
|
|
8836
|
+
line_1: `${checkout.shippingAddress.number}, ${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
8837
|
+
line_2: `${checkout.shippingAddress.extension}`,
|
|
8838
|
+
zip_code: checkout.shippingAddress.zip,
|
|
8839
|
+
city: checkout.shippingAddress.city,
|
|
8840
|
+
state: checkout.shippingAddress.state,
|
|
8841
|
+
country: 'BR',
|
|
8842
|
+
},
|
|
8843
|
+
};
|
|
8844
|
+
}
|
|
8845
|
+
static buildPayment(checkout, method, card) {
|
|
8846
|
+
return [
|
|
8847
|
+
{
|
|
8848
|
+
payment_method: method,
|
|
8849
|
+
amount: Math.floor(checkout.totalPrice * 100),
|
|
8850
|
+
...(method === 'pix' && {
|
|
8851
|
+
pix: this.getPixOrder(),
|
|
8852
|
+
}),
|
|
8853
|
+
...(method === 'boleto' && {
|
|
8854
|
+
boleto: this.getBoletoOrder(),
|
|
8855
|
+
}),
|
|
8856
|
+
...(method === 'credit_card' && {
|
|
8857
|
+
credit_card: this.getCardOrder(checkout, card),
|
|
8858
|
+
}),
|
|
8859
|
+
},
|
|
8860
|
+
];
|
|
8861
|
+
}
|
|
8862
|
+
static getPixOrder() {
|
|
8863
|
+
return {
|
|
8864
|
+
expires_at: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
|
|
8865
|
+
};
|
|
8866
|
+
}
|
|
8867
|
+
static getBoletoOrder() {
|
|
8868
|
+
return {
|
|
8869
|
+
due_at: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
|
|
8870
|
+
instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
8871
|
+
type: 'DM',
|
|
8872
|
+
document_number: new Date().getTime().toString(),
|
|
8873
|
+
};
|
|
8874
|
+
}
|
|
8875
|
+
static getCardOrder(checkout, card) {
|
|
8876
|
+
return {
|
|
8877
|
+
installments: card.installments,
|
|
8878
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
|
|
8879
|
+
card_id: card.cardId,
|
|
8880
|
+
card: {
|
|
8881
|
+
cvv: card.cardCvv,
|
|
8882
|
+
billing_address: {
|
|
8883
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8884
|
+
zip_code: checkout.billingAddress.zip,
|
|
8885
|
+
city: checkout.billingAddress.city,
|
|
8886
|
+
state: checkout.billingAddress.state,
|
|
8887
|
+
country: 'BR',
|
|
8888
|
+
},
|
|
8889
|
+
},
|
|
8890
|
+
};
|
|
8891
|
+
}
|
|
8892
|
+
}
|
|
8893
|
+
|
|
8894
|
+
class PagarMeV5ResponseHelper {
|
|
8895
|
+
static build(method, checkout, response) {
|
|
8896
|
+
return Payment.toInstance({
|
|
8897
|
+
createdAt: new Date(),
|
|
8898
|
+
updatedAt: new Date(),
|
|
8899
|
+
userId: checkout.user.id,
|
|
8900
|
+
checkoutId: checkout.id,
|
|
8901
|
+
totalPrice: checkout.totalPrice,
|
|
8902
|
+
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8903
|
+
pagarMeOrderId: response.id,
|
|
8904
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
8905
|
+
});
|
|
8906
|
+
}
|
|
8907
|
+
static buildPaymentTransaction(method, response) {
|
|
8908
|
+
const charger = response.charges.at(0);
|
|
8909
|
+
const transaction = charger.last_transaction;
|
|
8910
|
+
return PaymentTransaction.toInstance({
|
|
8911
|
+
acquirer_name: 'pagar_me',
|
|
8912
|
+
amount: charger.amount,
|
|
8913
|
+
currency: charger.currency,
|
|
8914
|
+
gateway_id: charger.gateway_id,
|
|
8915
|
+
status: this.getPaymentStatus(transaction.status),
|
|
8916
|
+
payment_method: charger.payment_method,
|
|
8917
|
+
date_created: charger.created_at,
|
|
8918
|
+
date_updated: charger.updated_at,
|
|
8919
|
+
paid_amount: charger.paid_amount,
|
|
8920
|
+
paid_at: charger.paid_at,
|
|
8921
|
+
order_id: response.id,
|
|
8922
|
+
charger_id: charger.id,
|
|
8923
|
+
tid: charger.id,
|
|
8924
|
+
id: charger.id,
|
|
8925
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
|
|
8926
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
|
|
8927
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
|
|
8928
|
+
});
|
|
8929
|
+
}
|
|
8930
|
+
static getPaymentStatus(status) {
|
|
8931
|
+
if (status == exports.PagarMeV5PaymentStatus.Gerado)
|
|
8932
|
+
return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
|
|
8933
|
+
if (status == exports.PagarMeV5PaymentStatus.Capturada)
|
|
8934
|
+
return exports.PagarMeV5PaymentStatus.Pago;
|
|
8935
|
+
return status;
|
|
8936
|
+
}
|
|
8937
|
+
static getBoletoReponse(transaction) {
|
|
8938
|
+
return {
|
|
8939
|
+
boleto_url: transaction.url?.toString(),
|
|
8940
|
+
boleto_barcode: transaction.line?.toString(),
|
|
8941
|
+
boleto_qr_code: transaction.qr_code?.toString(),
|
|
8942
|
+
boleto_expiration_date: transaction.due_at?.toString(),
|
|
8943
|
+
boleto_instructions: transaction.instructions?.toString(),
|
|
8944
|
+
boleto_nosso_numero: transaction.nosso_numero?.toString(),
|
|
8945
|
+
boleto_type: transaction.type?.toString(),
|
|
8946
|
+
boleto_document_number: transaction.document_number?.toString(),
|
|
8947
|
+
};
|
|
8948
|
+
}
|
|
8949
|
+
static getPixReponse(transaction) {
|
|
8950
|
+
return {
|
|
8951
|
+
pix_qr_code: transaction.qr_code?.toString(),
|
|
8952
|
+
pix_qr_code_url: transaction.qr_code_url?.toString(),
|
|
8953
|
+
pix_expiration_date: transaction.expires_at?.toString(),
|
|
8954
|
+
};
|
|
8955
|
+
}
|
|
8956
|
+
static getCardReponse(transaction) {
|
|
8957
|
+
return {
|
|
8958
|
+
soft_descriptor: transaction.statement_descriptor?.toString(),
|
|
8959
|
+
acquirer_name: transaction.acquirer_name?.toString(),
|
|
8960
|
+
acquirer_id: transaction.acquirer_tid?.toString(),
|
|
8961
|
+
acquirer_nsu: transaction.acquirer_nsu?.toString(),
|
|
8962
|
+
acquirer_auth_code: transaction.acquirer_auth_code?.toString(),
|
|
8963
|
+
acquirer_message: transaction.acquirer_message?.toString(),
|
|
8964
|
+
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
8965
|
+
installments: transaction.installments ?? null,
|
|
8966
|
+
card_holder_name: transaction.card?.holder_name?.toString(),
|
|
8967
|
+
card_last_digits: transaction.card?.last_four_digits?.toString(),
|
|
8968
|
+
card_first_digits: transaction.card?.first_six_digits?.toString(),
|
|
8969
|
+
card_brand: transaction.card?.brand?.toString(),
|
|
8970
|
+
card_id: transaction.card?.id?.toString(),
|
|
8971
|
+
};
|
|
8972
|
+
}
|
|
8973
|
+
}
|
|
8974
|
+
|
|
8589
8975
|
class PagarmeCardAxiosAdapter {
|
|
8590
8976
|
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
8591
8977
|
this.credentials = credentials;
|
|
@@ -8642,8 +9028,9 @@ class PagarmeCardAxiosAdapter {
|
|
|
8642
9028
|
});
|
|
8643
9029
|
}
|
|
8644
9030
|
}
|
|
8645
|
-
async createCardHash(bu) {
|
|
8646
|
-
const
|
|
9031
|
+
async createCardHash(bu, shop) {
|
|
9032
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
9033
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
8647
9034
|
try {
|
|
8648
9035
|
const { data } = await axios__default["default"]({
|
|
8649
9036
|
method: 'GET',
|
|
@@ -8806,6 +9193,281 @@ class PagarmePixAxiosAdapter {
|
|
|
8806
9193
|
}
|
|
8807
9194
|
}
|
|
8808
9195
|
|
|
9196
|
+
class PagarmeV5BankSlipAxiosAdapter {
|
|
9197
|
+
constructor(credentials, paymentRepository) {
|
|
9198
|
+
this.credentials = credentials;
|
|
9199
|
+
this.paymentRepository = paymentRepository;
|
|
9200
|
+
}
|
|
9201
|
+
async pay(checkout) {
|
|
9202
|
+
try {
|
|
9203
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
9204
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
9205
|
+
const { data } = await axios__default["default"]({
|
|
9206
|
+
method: 'POST',
|
|
9207
|
+
url: `${this.credentials.URL}/orders`,
|
|
9208
|
+
headers: {
|
|
9209
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9210
|
+
'Content-Type': 'application/json',
|
|
9211
|
+
},
|
|
9212
|
+
data: payload,
|
|
9213
|
+
});
|
|
9214
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9215
|
+
if (data.status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9216
|
+
data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9217
|
+
(data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
|
|
9218
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
|
|
9219
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9220
|
+
checkoutId: checkout.id,
|
|
9221
|
+
userEmail: checkout.user.email,
|
|
9222
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9223
|
+
}));
|
|
9224
|
+
}
|
|
9225
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
9226
|
+
return payment;
|
|
9227
|
+
}
|
|
9228
|
+
catch (error) {
|
|
9229
|
+
if (error instanceof axios.AxiosError) {
|
|
9230
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
9231
|
+
}
|
|
9232
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9233
|
+
checkoutId: checkout.id,
|
|
9234
|
+
userEmail: checkout.user.email,
|
|
9235
|
+
info: error.response?.data,
|
|
9236
|
+
});
|
|
9237
|
+
}
|
|
9238
|
+
}
|
|
9239
|
+
async getBoletoTransaction(paymentId) {
|
|
9240
|
+
try {
|
|
9241
|
+
const { data } = await axios__default["default"]({
|
|
9242
|
+
method: 'GET',
|
|
9243
|
+
url: `${this.credentials.URL}/charges/${paymentId}`,
|
|
9244
|
+
headers: {
|
|
9245
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9246
|
+
'Content-Type': 'application/json',
|
|
9247
|
+
},
|
|
9248
|
+
});
|
|
9249
|
+
const payment = await this.paymentRepository.get({
|
|
9250
|
+
id: data.id,
|
|
9251
|
+
});
|
|
9252
|
+
return payment.transaction;
|
|
9253
|
+
}
|
|
9254
|
+
catch (error) {
|
|
9255
|
+
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
9256
|
+
paymentId,
|
|
9257
|
+
info: error.response.data,
|
|
9258
|
+
});
|
|
9259
|
+
}
|
|
9260
|
+
}
|
|
9261
|
+
}
|
|
9262
|
+
|
|
9263
|
+
class PagarmeV5CardAxiosAdapter {
|
|
9264
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
9265
|
+
this.credentials = credentials;
|
|
9266
|
+
this.paymentRepository = paymentRepository;
|
|
9267
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
9268
|
+
}
|
|
9269
|
+
async pay(checkout, card) {
|
|
9270
|
+
try {
|
|
9271
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'credit_card', card);
|
|
9272
|
+
console.warn('[PAGARME CARD DATA TO SEND]', JSON.stringify(payload));
|
|
9273
|
+
const { data } = await axios__default["default"]({
|
|
9274
|
+
method: 'POST',
|
|
9275
|
+
url: `${this.credentials.URL}/orders`,
|
|
9276
|
+
headers: {
|
|
9277
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9278
|
+
'Content-Type': 'application/json',
|
|
9279
|
+
},
|
|
9280
|
+
data: payload,
|
|
9281
|
+
});
|
|
9282
|
+
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
9283
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha ||
|
|
9284
|
+
data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
|
|
9285
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
9286
|
+
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
9287
|
+
checkout,
|
|
9288
|
+
card,
|
|
9289
|
+
orderBlockedRepository: this.orderBlockedRepository,
|
|
9290
|
+
});
|
|
9291
|
+
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
|
|
9292
|
+
}
|
|
9293
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
9294
|
+
return payment;
|
|
9295
|
+
}
|
|
9296
|
+
catch (error) {
|
|
9297
|
+
if (error instanceof PaymentError) {
|
|
9298
|
+
throw error;
|
|
9299
|
+
}
|
|
9300
|
+
if (error instanceof axios.AxiosError) {
|
|
9301
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
9302
|
+
}
|
|
9303
|
+
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9304
|
+
}
|
|
9305
|
+
}
|
|
9306
|
+
async addCard(card, customer) {
|
|
9307
|
+
try {
|
|
9308
|
+
const { id } = await this.createOrUpdateCustomer(customer);
|
|
9309
|
+
const { data } = await axios__default["default"]({
|
|
9310
|
+
method: 'POST',
|
|
9311
|
+
url: `${this.credentials.URL}/customers/${id}/cards`,
|
|
9312
|
+
headers: {
|
|
9313
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9314
|
+
'Content-Type': 'application/json',
|
|
9315
|
+
},
|
|
9316
|
+
data: {
|
|
9317
|
+
number: card.number,
|
|
9318
|
+
holder_name: card.name,
|
|
9319
|
+
holder_document: card.cpf,
|
|
9320
|
+
exp_month: card.expirationDate.split('/').at(0),
|
|
9321
|
+
exp_year: card.expirationDate.split('/').at(1),
|
|
9322
|
+
cvv: card.cvv,
|
|
9323
|
+
billing_address: {
|
|
9324
|
+
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
9325
|
+
line_2: `${customer.billingAddress.extension}`,
|
|
9326
|
+
zip_code: customer.billingAddress.zip,
|
|
9327
|
+
city: customer.billingAddress.city,
|
|
9328
|
+
state: customer.billingAddress.state,
|
|
9329
|
+
country: 'BR',
|
|
9330
|
+
},
|
|
9331
|
+
},
|
|
9332
|
+
});
|
|
9333
|
+
return data;
|
|
9334
|
+
}
|
|
9335
|
+
catch (error) {
|
|
9336
|
+
console.warn(JSON.stringify(error));
|
|
9337
|
+
throw error;
|
|
9338
|
+
}
|
|
9339
|
+
}
|
|
9340
|
+
async createCardHash(bu, shop) {
|
|
9341
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
9342
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
9343
|
+
try {
|
|
9344
|
+
const { data } = await axios__default["default"]({
|
|
9345
|
+
method: 'GET',
|
|
9346
|
+
headers: {
|
|
9347
|
+
'content-type': 'application/json',
|
|
9348
|
+
},
|
|
9349
|
+
url: `${this.credentials.URL}/transactions/card_hash_key`,
|
|
9350
|
+
data: JSON.stringify({
|
|
9351
|
+
api_key: key,
|
|
9352
|
+
}),
|
|
9353
|
+
});
|
|
9354
|
+
return data;
|
|
9355
|
+
}
|
|
9356
|
+
catch (error) {
|
|
9357
|
+
throw new BusinessError('Houve uma falha gerar o hash', {
|
|
9358
|
+
info: error.response.data,
|
|
9359
|
+
});
|
|
9360
|
+
}
|
|
9361
|
+
}
|
|
9362
|
+
async getCardByToken(customerId, token) {
|
|
9363
|
+
try {
|
|
9364
|
+
const { data } = await axios__default["default"]({
|
|
9365
|
+
method: 'GET',
|
|
9366
|
+
url: `${this.credentials.URL}/cards/${token}`,
|
|
9367
|
+
data: {
|
|
9368
|
+
api_key: this.credentials.API_KEY,
|
|
9369
|
+
},
|
|
9370
|
+
});
|
|
9371
|
+
return data;
|
|
9372
|
+
}
|
|
9373
|
+
catch (error) {
|
|
9374
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
|
|
9375
|
+
info: error.response.data,
|
|
9376
|
+
});
|
|
9377
|
+
}
|
|
9378
|
+
}
|
|
9379
|
+
async createTransaction(info) {
|
|
9380
|
+
return info;
|
|
9381
|
+
}
|
|
9382
|
+
async createOrUpdateCustomer(customer) {
|
|
9383
|
+
try {
|
|
9384
|
+
const { data } = await axios__default["default"]({
|
|
9385
|
+
method: 'POST',
|
|
9386
|
+
url: `${this.credentials.URL}/customers`,
|
|
9387
|
+
headers: {
|
|
9388
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9389
|
+
'Content-Type': 'application/json',
|
|
9390
|
+
},
|
|
9391
|
+
data: {
|
|
9392
|
+
name: customer.displayName,
|
|
9393
|
+
email: customer.email,
|
|
9394
|
+
document: customer.cpf,
|
|
9395
|
+
type: 'individual',
|
|
9396
|
+
document_type: 'CPF',
|
|
9397
|
+
address: {
|
|
9398
|
+
line_1: `${customer.billingAddress.number}, ${customer.billingAddress.street}, ${customer.billingAddress.district}`,
|
|
9399
|
+
line_2: `${customer.billingAddress.extension}`,
|
|
9400
|
+
zip_code: customer.billingAddress.zip,
|
|
9401
|
+
city: customer.billingAddress.city,
|
|
9402
|
+
state: customer.billingAddress.state,
|
|
9403
|
+
country: 'BR',
|
|
9404
|
+
},
|
|
9405
|
+
birthdate: dateFns.format(new Date(customer.birthday), 'MM/dd/yyyy'),
|
|
9406
|
+
phones: {
|
|
9407
|
+
home_phone: {
|
|
9408
|
+
country_code: '55',
|
|
9409
|
+
number: customer.phone.slice(2),
|
|
9410
|
+
area_code: customer.phone.slice(0, 2),
|
|
9411
|
+
},
|
|
9412
|
+
mobile_phone: {
|
|
9413
|
+
country_code: '55',
|
|
9414
|
+
number: customer.phone.slice(2),
|
|
9415
|
+
area_code: customer.phone.slice(0, 2),
|
|
9416
|
+
},
|
|
9417
|
+
},
|
|
9418
|
+
},
|
|
9419
|
+
});
|
|
9420
|
+
return data;
|
|
9421
|
+
}
|
|
9422
|
+
catch (error) {
|
|
9423
|
+
console.warn(error);
|
|
9424
|
+
throw error;
|
|
9425
|
+
}
|
|
9426
|
+
}
|
|
9427
|
+
}
|
|
9428
|
+
|
|
9429
|
+
class PagarmeV5PixAxiosAdapter {
|
|
9430
|
+
constructor(credentials, paymentRepository) {
|
|
9431
|
+
this.credentials = credentials;
|
|
9432
|
+
this.paymentRepository = paymentRepository;
|
|
9433
|
+
}
|
|
9434
|
+
async pay(checkout) {
|
|
9435
|
+
try {
|
|
9436
|
+
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
9437
|
+
console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
|
|
9438
|
+
const { data } = await axios__default["default"]({
|
|
9439
|
+
method: 'POST',
|
|
9440
|
+
url: `${this.credentials.URL}/orders`,
|
|
9441
|
+
headers: {
|
|
9442
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9443
|
+
'Content-Type': 'application/json',
|
|
9444
|
+
},
|
|
9445
|
+
data: payload,
|
|
9446
|
+
});
|
|
9447
|
+
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
9448
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
|
|
9449
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9450
|
+
checkoutId: checkout.id,
|
|
9451
|
+
userEmail: checkout.user.email,
|
|
9452
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9453
|
+
});
|
|
9454
|
+
}
|
|
9455
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
9456
|
+
return payment;
|
|
9457
|
+
}
|
|
9458
|
+
catch (error) {
|
|
9459
|
+
if (error instanceof axios.AxiosError) {
|
|
9460
|
+
console.error('error data: ', JSON.stringify(error.response?.data));
|
|
9461
|
+
}
|
|
9462
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9463
|
+
checkoutId: checkout.id,
|
|
9464
|
+
userEmail: checkout.user.email,
|
|
9465
|
+
info: error.response?.data,
|
|
9466
|
+
});
|
|
9467
|
+
}
|
|
9468
|
+
}
|
|
9469
|
+
}
|
|
9470
|
+
|
|
8809
9471
|
class VertexAxiosAdapter {
|
|
8810
9472
|
constructor(config) {
|
|
8811
9473
|
this.config = config;
|
|
@@ -9162,6 +9824,9 @@ exports.PagarmeBankSlipAxiosAdapter = PagarmeBankSlipAxiosAdapter;
|
|
|
9162
9824
|
exports.PagarmeCardAxiosAdapter = PagarmeCardAxiosAdapter;
|
|
9163
9825
|
exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
|
|
9164
9826
|
exports.PagarmePixAxiosAdapter = PagarmePixAxiosAdapter;
|
|
9827
|
+
exports.PagarmeV5BankSlipAxiosAdapter = PagarmeV5BankSlipAxiosAdapter;
|
|
9828
|
+
exports.PagarmeV5CardAxiosAdapter = PagarmeV5CardAxiosAdapter;
|
|
9829
|
+
exports.PagarmeV5PixAxiosAdapter = PagarmeV5PixAxiosAdapter;
|
|
9165
9830
|
exports.Payment = Payment;
|
|
9166
9831
|
exports.PaymentError = PaymentError;
|
|
9167
9832
|
exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
|