@infrab4a/connect 5.3.0-beta.15 → 5.3.0-beta.16
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 +553 -11
- package/index.esm.js +546 -12
- package/package.json +1 -1
- package/src/domain/catalog/models/category-brand.d.ts +17 -0
- package/src/domain/catalog/models/index.d.ts +1 -0
- package/src/domain/catalog/models/product-review.d.ts +1 -1
- package/src/domain/catalog/repositories/category-brand.repository.d.ts +4 -0
- package/src/domain/catalog/repositories/index.d.ts +1 -0
- package/src/domain/shopping/enums/index.d.ts +1 -0
- package/src/domain/shopping/enums/order-payment-status.enum.d.ts +10 -0
- package/src/domain/shopping/enums/payment-providers.enum.d.ts +2 -1
- package/src/domain/shopping/factories/index.d.ts +1 -0
- package/src/domain/shopping/factories/mercado-pago-payment-method.factory.d.ts +11 -0
- package/src/domain/shopping/factories/payment-provider.factory.d.ts +2 -0
- package/src/domain/shopping/models/payment-transaction.d.ts +2 -0
- package/src/domain/shopping/models/payment.d.ts +1 -0
- package/src/domain/shopping/services/antifraud-card.service.d.ts +2 -0
- package/src/domain/shopping/types/checkout-paylod-request.type.d.ts +2 -7
- package/src/domain/shopping/types/index.d.ts +2 -0
- package/src/domain/shopping/types/mercado-pago-card.type.d.ts +14 -0
- package/src/domain/shopping/types/mercado-pago-credentials.type.d.ts +5 -0
- package/src/domain/shopping/types/payment-card-info.type.d.ts +3 -0
- package/src/infra/firebase/firestore/repositories/catalog/category-brand-firestore.repository.d.ts +7 -0
- package/src/infra/firebase/firestore/repositories/catalog/index.d.ts +1 -0
- package/src/infra/index.d.ts +1 -0
- package/src/infra/mercado-pago/adapters/index.d.ts +3 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-boleto-payment-axios.adapter.d.ts +8 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-card-payment-axios.adapter.d.ts +20 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-pix-payment-axios.adapter.d.ts +7 -0
- package/src/infra/mercado-pago/enums/index.d.ts +2 -0
- package/src/infra/mercado-pago/enums/mercado-pago-status-detail.enum.d.ts +33 -0
- package/src/infra/mercado-pago/enums/mercado-pago-status.enum.d.ts +10 -0
- package/src/infra/mercado-pago/helpers/index.d.ts +2 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-request.helper.d.ts +60 -0
- package/src/infra/mercado-pago/helpers/mercado-pago-response.helper.d.ts +10 -0
- package/src/infra/mercado-pago/index.d.ts +4 -0
- package/src/infra/mercado-pago/types/index.d.ts +3 -0
- package/src/infra/mercado-pago/types/mercado-pago-request.type.d.ts +1 -0
- package/src/infra/mercado-pago/types/mercado-pago-response.type.d.ts +188 -0
- package/src/infra/mercado-pago/types/mercado-pago-status-detail.type.d.ts +2 -0
- package/src/infra/mercado-pago/types/mercado-pago-status.type.d.ts +2 -0
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +1 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -62,6 +62,18 @@ exports.OrderBlockedType = void 0;
|
|
|
62
62
|
OrderBlockedType["Boleto"] = "Boleto";
|
|
63
63
|
})(exports.OrderBlockedType || (exports.OrderBlockedType = {}));
|
|
64
64
|
|
|
65
|
+
exports.OrderPaymentStatus = void 0;
|
|
66
|
+
(function (OrderPaymentStatus) {
|
|
67
|
+
OrderPaymentStatus["Em processamento"] = "processing";
|
|
68
|
+
OrderPaymentStatus["Autorizada"] = "authorized";
|
|
69
|
+
OrderPaymentStatus["Pago"] = "paid";
|
|
70
|
+
OrderPaymentStatus["Estornada"] = "refunded";
|
|
71
|
+
OrderPaymentStatus["Aguardando pagamento"] = "waiting_payment";
|
|
72
|
+
OrderPaymentStatus["Aguardando estorno"] = "pending_refund";
|
|
73
|
+
OrderPaymentStatus["Recusada/N\u00E3o autorizada"] = "refused";
|
|
74
|
+
OrderPaymentStatus["Chargedback"] = "chargedback";
|
|
75
|
+
})(exports.OrderPaymentStatus || (exports.OrderPaymentStatus = {}));
|
|
76
|
+
|
|
65
77
|
exports.PagarmePaymentStatus = void 0;
|
|
66
78
|
(function (PagarmePaymentStatus) {
|
|
67
79
|
PagarmePaymentStatus["Em processamento"] = "processing";
|
|
@@ -114,6 +126,7 @@ exports.PaymentProviders = void 0;
|
|
|
114
126
|
PaymentProviders["PAGARME"] = "pagarMe";
|
|
115
127
|
PaymentProviders["ADYEN"] = "adyen";
|
|
116
128
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
129
|
+
PaymentProviders["MERCADOPAGO"] = "mercadoPago";
|
|
117
130
|
})(exports.PaymentProviders || (exports.PaymentProviders = {}));
|
|
118
131
|
|
|
119
132
|
exports.TransactionPaymentMethods = void 0;
|
|
@@ -147,6 +160,9 @@ class AntifraudProviderFactory {
|
|
|
147
160
|
class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
|
|
148
161
|
}
|
|
149
162
|
|
|
163
|
+
class MercadoPagoPaymentMethodFactory extends BasePaymentMethodFactory {
|
|
164
|
+
}
|
|
165
|
+
|
|
150
166
|
class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
|
|
151
167
|
}
|
|
152
168
|
|
|
@@ -757,6 +773,30 @@ tslib.__decorate([
|
|
|
757
773
|
], Category.prototype, "filters", void 0);
|
|
758
774
|
registerClass('Category', Category);
|
|
759
775
|
|
|
776
|
+
class BrandCategory extends BaseModel {
|
|
777
|
+
get glamImages() {
|
|
778
|
+
return this.images?.[exports.Shops.GLAMSHOP]
|
|
779
|
+
? this.images[exports.Shops.GLAMSHOP]
|
|
780
|
+
: {
|
|
781
|
+
brandBanner: null,
|
|
782
|
+
brandBannerMobile: null,
|
|
783
|
+
image: null,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
get mensImages() {
|
|
787
|
+
return this.images?.[exports.Shops.MENSMARKET]
|
|
788
|
+
? this.images[exports.Shops.MENSMARKET]
|
|
789
|
+
: {
|
|
790
|
+
brandBanner: null,
|
|
791
|
+
brandBannerMobile: null,
|
|
792
|
+
image: null,
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
static get identifiersFields() {
|
|
796
|
+
return ['id'];
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
760
800
|
class CategoryCollectionChildren extends BaseModel {
|
|
761
801
|
static get identifiersFields() {
|
|
762
802
|
return ['collectionId', 'categoryId'];
|
|
@@ -832,7 +872,7 @@ class ProductReview extends BaseModel {
|
|
|
832
872
|
}
|
|
833
873
|
tslib.__decorate([
|
|
834
874
|
classTransformer.Type(resolveClass('Product')),
|
|
835
|
-
tslib.__metadata("design:type",
|
|
875
|
+
tslib.__metadata("design:type", Product)
|
|
836
876
|
], ProductReview.prototype, "product", void 0);
|
|
837
877
|
registerClass('ProductReview', ProductReview);
|
|
838
878
|
|
|
@@ -1765,19 +1805,58 @@ class AntifraudCardService {
|
|
|
1765
1805
|
constructor(orderRepository, orderBlockedRepository) {
|
|
1766
1806
|
this.orderRepository = orderRepository;
|
|
1767
1807
|
this.orderBlockedRepository = orderBlockedRepository;
|
|
1768
|
-
this.LIMIT_ORDERS_DAY =
|
|
1769
|
-
this.LIMIT_ORDERS_WEEK =
|
|
1770
|
-
this.LIMIT_BLOCKED_ORDERS_DAY = 5;
|
|
1808
|
+
this.LIMIT_ORDERS_DAY = null;
|
|
1809
|
+
this.LIMIT_ORDERS_WEEK = null;
|
|
1771
1810
|
}
|
|
1772
1811
|
async validate(checkout, card) {
|
|
1812
|
+
this.setLimitsByUserType(checkout.user.isSubscriber);
|
|
1773
1813
|
await this.validateBlockedOrderAttempts(checkout, card);
|
|
1774
1814
|
await this.validateDayAndWeekOrderLimits(checkout, card);
|
|
1775
1815
|
return true;
|
|
1776
1816
|
}
|
|
1817
|
+
setLimitsByUserType(isSubscriber) {
|
|
1818
|
+
this.LIMIT_ORDERS_DAY = {
|
|
1819
|
+
subscriber: {
|
|
1820
|
+
cpf: 4,
|
|
1821
|
+
email: 4,
|
|
1822
|
+
phone: 4,
|
|
1823
|
+
card: 4,
|
|
1824
|
+
zip: 4,
|
|
1825
|
+
},
|
|
1826
|
+
nonSubscriber: {
|
|
1827
|
+
cpf: 2,
|
|
1828
|
+
email: 2,
|
|
1829
|
+
phone: 2,
|
|
1830
|
+
card: 2,
|
|
1831
|
+
zip: 2,
|
|
1832
|
+
},
|
|
1833
|
+
};
|
|
1834
|
+
this.LIMIT_ORDERS_WEEK = {
|
|
1835
|
+
subscriber: {
|
|
1836
|
+
cpf: 12,
|
|
1837
|
+
email: 12,
|
|
1838
|
+
phone: 12,
|
|
1839
|
+
card: 12,
|
|
1840
|
+
zip: Infinity,
|
|
1841
|
+
},
|
|
1842
|
+
nonSubscriber: {
|
|
1843
|
+
cpf: 7,
|
|
1844
|
+
email: 7,
|
|
1845
|
+
phone: 7,
|
|
1846
|
+
card: 7,
|
|
1847
|
+
zip: Infinity,
|
|
1848
|
+
},
|
|
1849
|
+
};
|
|
1850
|
+
this.LIMIT_BLOCKED_ORDERS_DAY = isSubscriber ? 7 : 5;
|
|
1851
|
+
}
|
|
1852
|
+
getLimitsByUserType(type, isSubscriber) {
|
|
1853
|
+
const limits = type === 'day' ? this.LIMIT_ORDERS_DAY : this.LIMIT_ORDERS_WEEK;
|
|
1854
|
+
return isSubscriber ? limits['subscriber'] : limits['nonSubscriber'];
|
|
1855
|
+
}
|
|
1777
1856
|
async validateBlockedOrderAttempts(checkout, card) {
|
|
1778
1857
|
const isValid = await this.verifyBlockedOrderAttempts(checkout, card);
|
|
1779
1858
|
if (!isValid) {
|
|
1780
|
-
throw new FraudValidationError(
|
|
1859
|
+
throw new FraudValidationError(`Cliente com mais de ${this.LIMIT_BLOCKED_ORDERS_DAY} compras negadas/bloqueadas no dia`, {
|
|
1781
1860
|
checkoutId: checkout.id,
|
|
1782
1861
|
userEmail: checkout.user.email,
|
|
1783
1862
|
info: {
|
|
@@ -1791,7 +1870,7 @@ class AntifraudCardService {
|
|
|
1791
1870
|
async validateDayAndWeekOrderLimits(checkout, card) {
|
|
1792
1871
|
const isValid = await this.verifyDayAndWeekOrders(checkout, card);
|
|
1793
1872
|
if (!isValid) {
|
|
1794
|
-
throw new FraudValidationError('Cliente tentando comprar mais
|
|
1873
|
+
throw new FraudValidationError('Cliente tentando comprar mais do que o permitido no dia/semana', {
|
|
1795
1874
|
checkoutId: checkout.id,
|
|
1796
1875
|
userEmail: checkout.user.email,
|
|
1797
1876
|
info: {
|
|
@@ -1810,7 +1889,7 @@ class AntifraudCardService {
|
|
|
1810
1889
|
await this.createBlockedOrderRecord({
|
|
1811
1890
|
checkout,
|
|
1812
1891
|
card,
|
|
1813
|
-
reason:
|
|
1892
|
+
reason: `More than ${this.LIMIT_BLOCKED_ORDERS_DAY} attempts have failed`,
|
|
1814
1893
|
key: 'Failed attempts',
|
|
1815
1894
|
period: 'day',
|
|
1816
1895
|
});
|
|
@@ -1931,26 +2010,28 @@ class AntifraudCardService {
|
|
|
1931
2010
|
}
|
|
1932
2011
|
async validateDayOrderLimits(checkout, params) {
|
|
1933
2012
|
const ordersPerDay = await this.validateOrdersByRange(params, this.getDateRange('day'));
|
|
2013
|
+
const limits = this.getLimitsByUserType('day', checkout.user.isSubscriber);
|
|
1934
2014
|
return this.checkOrderLimitsAndBlock({
|
|
1935
2015
|
checkout,
|
|
1936
2016
|
orderCounts: ordersPerDay,
|
|
1937
|
-
limit:
|
|
2017
|
+
limit: limits,
|
|
1938
2018
|
period: 'day',
|
|
1939
2019
|
});
|
|
1940
2020
|
}
|
|
1941
2021
|
async validateWeekOrderLimits(checkout, params) {
|
|
1942
2022
|
const ordersPerWeek = await this.validateOrdersByRange(params, this.getDateRange('week'));
|
|
2023
|
+
const limits = this.getLimitsByUserType('week', checkout.user.isSubscriber);
|
|
1943
2024
|
return this.checkOrderLimitsAndBlock({
|
|
1944
2025
|
checkout,
|
|
1945
2026
|
orderCounts: ordersPerWeek,
|
|
1946
|
-
limit:
|
|
2027
|
+
limit: limits,
|
|
1947
2028
|
period: 'week',
|
|
1948
2029
|
});
|
|
1949
2030
|
}
|
|
1950
2031
|
async checkOrderLimitsAndBlock(params) {
|
|
1951
2032
|
const { checkout, orderCounts, limit, period } = params;
|
|
1952
2033
|
for (const key in orderCounts) {
|
|
1953
|
-
if (orderCounts[key] >= limit) {
|
|
2034
|
+
if (orderCounts[key] >= limit[key]) {
|
|
1954
2035
|
await this.createBlockedOrderRecord({
|
|
1955
2036
|
checkout,
|
|
1956
2037
|
card: null,
|
|
@@ -4768,6 +4849,17 @@ const withCrudFirestore = (MixinBase) => {
|
|
|
4768
4849
|
};
|
|
4769
4850
|
};
|
|
4770
4851
|
|
|
4852
|
+
class BrandCategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4853
|
+
constructor({ firestore, interceptors, }) {
|
|
4854
|
+
super({
|
|
4855
|
+
firestore,
|
|
4856
|
+
collectionName: 'brandsCategory',
|
|
4857
|
+
model: BrandCategory,
|
|
4858
|
+
interceptors,
|
|
4859
|
+
});
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4771
4863
|
class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
|
|
4772
4864
|
constructor({ firestore, interceptors }) {
|
|
4773
4865
|
super({
|
|
@@ -9249,6 +9341,438 @@ tslib.__decorate([
|
|
|
9249
9341
|
tslib.__metadata("design:returntype", Promise)
|
|
9250
9342
|
], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
|
|
9251
9343
|
|
|
9344
|
+
class MercadoPagoRequestHelper {
|
|
9345
|
+
static build(data) {
|
|
9346
|
+
const { checkout, method, postback, card } = data;
|
|
9347
|
+
return {
|
|
9348
|
+
transaction_amount: +checkout.totalPrice.toFixed(2),
|
|
9349
|
+
notification_url: postback,
|
|
9350
|
+
metadata: {
|
|
9351
|
+
checkoutId: checkout.id,
|
|
9352
|
+
},
|
|
9353
|
+
payer: this.buildPayer(checkout, card),
|
|
9354
|
+
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
|
|
9355
|
+
additional_info: {
|
|
9356
|
+
items: this.buildItems(checkout),
|
|
9357
|
+
},
|
|
9358
|
+
...(method === 'credit_card' && this.buildCardPayment(card)),
|
|
9359
|
+
...(method === 'pix' && this.buildPixPayment()),
|
|
9360
|
+
...(method === 'boleto' && this.buildBoletoPayment(checkout)),
|
|
9361
|
+
};
|
|
9362
|
+
}
|
|
9363
|
+
static buildItems(checkout) {
|
|
9364
|
+
return checkout.lineItems
|
|
9365
|
+
.filter((item) => !item.isGift)
|
|
9366
|
+
.map((item) => {
|
|
9367
|
+
return {
|
|
9368
|
+
id: item.EAN,
|
|
9369
|
+
title: item.name,
|
|
9370
|
+
description: item.name,
|
|
9371
|
+
picture_url: item.image ?? null,
|
|
9372
|
+
category_id: item.category?.id ?? null,
|
|
9373
|
+
quantity: item.quantity,
|
|
9374
|
+
unit_price: +item.pricePaid.toFixed(2),
|
|
9375
|
+
};
|
|
9376
|
+
});
|
|
9377
|
+
}
|
|
9378
|
+
static buildPayer(checkout, card) {
|
|
9379
|
+
return {
|
|
9380
|
+
...(card && { id: card.customerId }),
|
|
9381
|
+
first_name: checkout.user.firstName,
|
|
9382
|
+
last_name: checkout.user.lastName,
|
|
9383
|
+
email: checkout.user.email,
|
|
9384
|
+
identification: {
|
|
9385
|
+
type: 'CPF',
|
|
9386
|
+
number: checkout.user.cpf.replace(/\D/g, ''),
|
|
9387
|
+
},
|
|
9388
|
+
};
|
|
9389
|
+
}
|
|
9390
|
+
static buildFullPayer(checkout) {
|
|
9391
|
+
return {
|
|
9392
|
+
first_name: checkout.user.firstName,
|
|
9393
|
+
last_name: checkout.user.lastName,
|
|
9394
|
+
phone: {
|
|
9395
|
+
area_code: checkout.user.phone.substring(0, 2),
|
|
9396
|
+
number: checkout.user.phone.substring(2),
|
|
9397
|
+
},
|
|
9398
|
+
address: {
|
|
9399
|
+
zip_code: checkout.shippingAddress.zip,
|
|
9400
|
+
street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
9401
|
+
street_number: checkout.shippingAddress.number,
|
|
9402
|
+
neighborhood: checkout.shippingAddress.district,
|
|
9403
|
+
city: checkout.shippingAddress.city,
|
|
9404
|
+
federal_unit: checkout.shippingAddress.state,
|
|
9405
|
+
},
|
|
9406
|
+
};
|
|
9407
|
+
}
|
|
9408
|
+
static buildCardPayment(card) {
|
|
9409
|
+
return {
|
|
9410
|
+
installments: card.installments,
|
|
9411
|
+
token: card.cardId,
|
|
9412
|
+
binary_mode: true,
|
|
9413
|
+
capture: true,
|
|
9414
|
+
};
|
|
9415
|
+
}
|
|
9416
|
+
static buildPixPayment() {
|
|
9417
|
+
return {
|
|
9418
|
+
payment_method_id: 'pix',
|
|
9419
|
+
date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
|
|
9420
|
+
};
|
|
9421
|
+
}
|
|
9422
|
+
static buildBoletoPayment(checkout) {
|
|
9423
|
+
return {
|
|
9424
|
+
payment_method_id: 'bolbradesco',
|
|
9425
|
+
date_of_expiration: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd') + 'T23:59:59.999-03:00',
|
|
9426
|
+
payer: {
|
|
9427
|
+
first_name: checkout.user.firstName,
|
|
9428
|
+
last_name: checkout.user.lastName,
|
|
9429
|
+
email: checkout.user.email,
|
|
9430
|
+
identification: {
|
|
9431
|
+
type: 'CPF',
|
|
9432
|
+
number: checkout.user.cpf.replace(/\D/g, ''),
|
|
9433
|
+
},
|
|
9434
|
+
phone: {
|
|
9435
|
+
area_code: checkout.user.phone.substring(0, 2),
|
|
9436
|
+
number: checkout.user.phone.substring(2),
|
|
9437
|
+
},
|
|
9438
|
+
address: {
|
|
9439
|
+
zip_code: checkout.shippingAddress.zip.replace(/\D/g, ''),
|
|
9440
|
+
street_name: `${checkout.shippingAddress.street}, ${checkout.shippingAddress.district}`,
|
|
9441
|
+
street_number: checkout.shippingAddress.number,
|
|
9442
|
+
neighborhood: checkout.shippingAddress.district,
|
|
9443
|
+
city: checkout.shippingAddress.city,
|
|
9444
|
+
federal_unit: checkout.shippingAddress.state,
|
|
9445
|
+
},
|
|
9446
|
+
},
|
|
9447
|
+
};
|
|
9448
|
+
}
|
|
9449
|
+
}
|
|
9450
|
+
|
|
9451
|
+
class MercadoPagoResponseHelper {
|
|
9452
|
+
static build(method, checkout, response) {
|
|
9453
|
+
return Payment.toInstance({
|
|
9454
|
+
createdAt: new Date(),
|
|
9455
|
+
updatedAt: new Date(),
|
|
9456
|
+
userId: checkout.user.id,
|
|
9457
|
+
checkoutId: checkout.id,
|
|
9458
|
+
totalPrice: checkout.totalPrice,
|
|
9459
|
+
paymentProvider: exports.PaymentProviders.MERCADOPAGO,
|
|
9460
|
+
mercadoPagoId: response.id,
|
|
9461
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
9462
|
+
});
|
|
9463
|
+
}
|
|
9464
|
+
static buildPaymentTransaction(method, response) {
|
|
9465
|
+
return PaymentTransaction.toInstance({
|
|
9466
|
+
id: response.id.toString(),
|
|
9467
|
+
acquirer_name: exports.PaymentProviders.MERCADOPAGO,
|
|
9468
|
+
amount: response.transaction_amount,
|
|
9469
|
+
status: this.statusMapping(response.status),
|
|
9470
|
+
status_reason: response.status_detail?.toString(),
|
|
9471
|
+
payment_method: method,
|
|
9472
|
+
currency: response.currency_id?.toString(),
|
|
9473
|
+
paid_amount: response.transaction_details?.total_paid_amount ?? null,
|
|
9474
|
+
paid_at: response.date_approved ?? null,
|
|
9475
|
+
charger_id: response.charges_details?.at(0)?.id?.toString() ?? null,
|
|
9476
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(response)),
|
|
9477
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(response)),
|
|
9478
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(response)),
|
|
9479
|
+
});
|
|
9480
|
+
}
|
|
9481
|
+
static getBoletoReponse(response) {
|
|
9482
|
+
return {
|
|
9483
|
+
boleto_url: response.transaction_details?.external_resource_url?.toString(),
|
|
9484
|
+
boleto_barcode: response.transaction_details?.barcode?.content?.toString(),
|
|
9485
|
+
boleto_line: response.transaction_details?.digitable_line?.toString(),
|
|
9486
|
+
boleto_expiration_date: response.date_of_expiration?.toString(),
|
|
9487
|
+
boleto_document_number: response.transaction_details?.verification_code?.toString(),
|
|
9488
|
+
};
|
|
9489
|
+
}
|
|
9490
|
+
static getPixReponse(response) {
|
|
9491
|
+
return {
|
|
9492
|
+
pix_qr_code: response.point_of_interaction?.transaction_data?.qr_code,
|
|
9493
|
+
pix_expiration_date: response.date_of_expiration?.toString(),
|
|
9494
|
+
};
|
|
9495
|
+
}
|
|
9496
|
+
static getCardReponse(response) {
|
|
9497
|
+
return {
|
|
9498
|
+
soft_descriptor: response.statement_descriptor?.toString(),
|
|
9499
|
+
installments: response.installments,
|
|
9500
|
+
card_brand: response.payment_method_id?.toString(),
|
|
9501
|
+
card_first_digits: response.card?.first_six_digits?.toString(),
|
|
9502
|
+
card_last_digits: response.card?.last_four_digits?.toString(),
|
|
9503
|
+
card_id: response.card?.id?.toString(),
|
|
9504
|
+
card_holder_name: response.card?.cardholder?.name?.toString(),
|
|
9505
|
+
card_expiration_month: response.card?.expiration_month?.toString(),
|
|
9506
|
+
card_expiration_year: response.card?.expiration_year?.toString(),
|
|
9507
|
+
capture_method: response.payment_type_id?.toString(),
|
|
9508
|
+
authorization_code: response.authorization_code?.toString(),
|
|
9509
|
+
paid_amount: this.statusMapping(response.status) == 'paid' ? response.transaction_details?.total_paid_amount : null,
|
|
9510
|
+
paid_at: this.statusMapping(response.status) == 'paid' ? response.date_approved : null,
|
|
9511
|
+
};
|
|
9512
|
+
}
|
|
9513
|
+
static statusMapping(status) {
|
|
9514
|
+
const statusMap = {
|
|
9515
|
+
approved: 'paid',
|
|
9516
|
+
pending: 'waiting_payment',
|
|
9517
|
+
in_process: 'processing',
|
|
9518
|
+
rejected: 'refused',
|
|
9519
|
+
cancelled: 'refused',
|
|
9520
|
+
refunded: 'refunded',
|
|
9521
|
+
charged_back: 'chargedback',
|
|
9522
|
+
};
|
|
9523
|
+
return statusMap[status] || status;
|
|
9524
|
+
}
|
|
9525
|
+
}
|
|
9526
|
+
|
|
9527
|
+
class MercadoPagoBankSlipAxiosAdapter {
|
|
9528
|
+
constructor(credentials, paymentRepository) {
|
|
9529
|
+
this.credentials = credentials;
|
|
9530
|
+
this.paymentRepository = paymentRepository;
|
|
9531
|
+
}
|
|
9532
|
+
async pay(checkout) {
|
|
9533
|
+
try {
|
|
9534
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
9535
|
+
checkout,
|
|
9536
|
+
method: 'boleto',
|
|
9537
|
+
postback: this.credentials.postback,
|
|
9538
|
+
});
|
|
9539
|
+
console.warn('[MERCADO PAGO BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
9540
|
+
const { data } = await axios__default["default"]({
|
|
9541
|
+
method: 'POST',
|
|
9542
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
9543
|
+
headers: {
|
|
9544
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
9545
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9546
|
+
'Content-Type': 'application/json',
|
|
9547
|
+
},
|
|
9548
|
+
data: payload,
|
|
9549
|
+
});
|
|
9550
|
+
console.warn('[MERCADO PAGO RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9551
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
9552
|
+
return payment;
|
|
9553
|
+
}
|
|
9554
|
+
catch (error) {
|
|
9555
|
+
if (error instanceof axios.AxiosError) {
|
|
9556
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9557
|
+
}
|
|
9558
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9559
|
+
checkoutId: checkout.id,
|
|
9560
|
+
userEmail: checkout.user.email,
|
|
9561
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9562
|
+
});
|
|
9563
|
+
}
|
|
9564
|
+
}
|
|
9565
|
+
getBoletoTransaction(paymentId) {
|
|
9566
|
+
throw new Error('Method not implemented.');
|
|
9567
|
+
}
|
|
9568
|
+
}
|
|
9569
|
+
|
|
9570
|
+
class MercadoPagoCardAxiosAdapter {
|
|
9571
|
+
constructor(credentials, paymentRepository, orderBlockedRepository) {
|
|
9572
|
+
this.credentials = credentials;
|
|
9573
|
+
this.paymentRepository = paymentRepository;
|
|
9574
|
+
this.orderBlockedRepository = orderBlockedRepository;
|
|
9575
|
+
}
|
|
9576
|
+
async pay(checkout, card) {
|
|
9577
|
+
try {
|
|
9578
|
+
const payload = await this.getPaymentPayload(checkout, card);
|
|
9579
|
+
console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
|
|
9580
|
+
const { data } = await axios__default["default"]({
|
|
9581
|
+
method: 'POST',
|
|
9582
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
9583
|
+
headers: {
|
|
9584
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
9585
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9586
|
+
'Content-Type': 'application/json',
|
|
9587
|
+
},
|
|
9588
|
+
data: payload,
|
|
9589
|
+
});
|
|
9590
|
+
console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
|
|
9591
|
+
if (data.status == exports.MercadoPagoStatusEnum.rejected) {
|
|
9592
|
+
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
9593
|
+
checkout,
|
|
9594
|
+
blockType: 'Card not authorized',
|
|
9595
|
+
type: 'Card',
|
|
9596
|
+
limiteRange: 'day',
|
|
9597
|
+
card,
|
|
9598
|
+
});
|
|
9599
|
+
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', {
|
|
9600
|
+
checkoutId: checkout.id,
|
|
9601
|
+
userEmail: checkout.user.email,
|
|
9602
|
+
info: data,
|
|
9603
|
+
});
|
|
9604
|
+
}
|
|
9605
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
9606
|
+
return payment;
|
|
9607
|
+
}
|
|
9608
|
+
catch (error) {
|
|
9609
|
+
if (error instanceof axios.AxiosError) {
|
|
9610
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9611
|
+
}
|
|
9612
|
+
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', {
|
|
9613
|
+
checkoutId: checkout.id,
|
|
9614
|
+
userEmail: checkout.user.email,
|
|
9615
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9616
|
+
});
|
|
9617
|
+
}
|
|
9618
|
+
}
|
|
9619
|
+
async getPaymentPayload(checkout, card) {
|
|
9620
|
+
const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
|
|
9621
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
9622
|
+
checkout,
|
|
9623
|
+
method: 'credit_card',
|
|
9624
|
+
postback: this.credentials.postback,
|
|
9625
|
+
card: {
|
|
9626
|
+
...card,
|
|
9627
|
+
cardId: cardResponse.id,
|
|
9628
|
+
},
|
|
9629
|
+
});
|
|
9630
|
+
return payload;
|
|
9631
|
+
}
|
|
9632
|
+
async addCard(card, customer) {
|
|
9633
|
+
return;
|
|
9634
|
+
}
|
|
9635
|
+
async getCardByToken(customerId, token, cardCvv) {
|
|
9636
|
+
try {
|
|
9637
|
+
const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
|
|
9638
|
+
console.warn('payload getCardByToken', payload);
|
|
9639
|
+
const { data } = await axios__default["default"]({
|
|
9640
|
+
method: 'POST',
|
|
9641
|
+
url: `${this.credentials.url}/v1/card_tokens`,
|
|
9642
|
+
headers: {
|
|
9643
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9644
|
+
'Content-Type': 'application/json',
|
|
9645
|
+
},
|
|
9646
|
+
data: payload,
|
|
9647
|
+
});
|
|
9648
|
+
return data;
|
|
9649
|
+
}
|
|
9650
|
+
catch (error) {
|
|
9651
|
+
if (error instanceof axios.AxiosError) {
|
|
9652
|
+
console.warn(JSON.stringify(error.response.data.cause));
|
|
9653
|
+
}
|
|
9654
|
+
throw error;
|
|
9655
|
+
}
|
|
9656
|
+
}
|
|
9657
|
+
createCardHash(bu, shop, card) {
|
|
9658
|
+
return;
|
|
9659
|
+
}
|
|
9660
|
+
createTransaction(info) {
|
|
9661
|
+
return;
|
|
9662
|
+
}
|
|
9663
|
+
async createOrUpdateCustomer(customer) {
|
|
9664
|
+
const { data } = await axios__default["default"]({
|
|
9665
|
+
method: 'POST',
|
|
9666
|
+
url: `${this.credentials.url}/v1/customers`,
|
|
9667
|
+
headers: {
|
|
9668
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9669
|
+
'Content-Type': 'application/json',
|
|
9670
|
+
},
|
|
9671
|
+
data: {
|
|
9672
|
+
email: customer.email,
|
|
9673
|
+
first_name: customer.firstName,
|
|
9674
|
+
last_name: customer.lastName,
|
|
9675
|
+
phone: {
|
|
9676
|
+
area_code: customer.phone.substring(0, 2),
|
|
9677
|
+
number: customer.phone.substring(2),
|
|
9678
|
+
},
|
|
9679
|
+
identification: {
|
|
9680
|
+
type: 'CPF',
|
|
9681
|
+
number: customer.cpf.replace(/\D/g, ''),
|
|
9682
|
+
},
|
|
9683
|
+
},
|
|
9684
|
+
});
|
|
9685
|
+
return data;
|
|
9686
|
+
}
|
|
9687
|
+
}
|
|
9688
|
+
|
|
9689
|
+
class MercadoPagoPixAxiosAdapter {
|
|
9690
|
+
constructor(credentials, paymentRepository) {
|
|
9691
|
+
this.credentials = credentials;
|
|
9692
|
+
this.paymentRepository = paymentRepository;
|
|
9693
|
+
}
|
|
9694
|
+
async pay(checkout) {
|
|
9695
|
+
try {
|
|
9696
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
9697
|
+
checkout,
|
|
9698
|
+
method: 'pix',
|
|
9699
|
+
postback: this.credentials.postback,
|
|
9700
|
+
});
|
|
9701
|
+
console.warn('[MERCADO PAGO PIX DATA TO SEND]', JSON.stringify(payload));
|
|
9702
|
+
const { data } = await axios__default["default"]({
|
|
9703
|
+
method: 'POST',
|
|
9704
|
+
url: `${this.credentials.url}/v1/payments`,
|
|
9705
|
+
headers: {
|
|
9706
|
+
'X-Idempotency-Key': `${checkout.id}-${new Date().getTime()}`,
|
|
9707
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9708
|
+
'Content-Type': 'application/json',
|
|
9709
|
+
},
|
|
9710
|
+
data: payload,
|
|
9711
|
+
});
|
|
9712
|
+
console.warn('[MERCADO PAGO RESPONSE PIX DATA]', JSON.stringify(data));
|
|
9713
|
+
const payment = await this.paymentRepository.create(MercadoPagoResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
9714
|
+
return payment;
|
|
9715
|
+
}
|
|
9716
|
+
catch (error) {
|
|
9717
|
+
if (error instanceof axios.AxiosError) {
|
|
9718
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9719
|
+
}
|
|
9720
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9721
|
+
checkoutId: checkout.id,
|
|
9722
|
+
userEmail: checkout.user.email,
|
|
9723
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9724
|
+
});
|
|
9725
|
+
}
|
|
9726
|
+
}
|
|
9727
|
+
}
|
|
9728
|
+
|
|
9729
|
+
exports.MercadoPagoStatusDetailEnum = void 0;
|
|
9730
|
+
(function (MercadoPagoStatusDetailEnum) {
|
|
9731
|
+
MercadoPagoStatusDetailEnum["accredited"] = "accredited";
|
|
9732
|
+
MercadoPagoStatusDetailEnum["partially_refunded"] = "partially_refunded";
|
|
9733
|
+
MercadoPagoStatusDetailEnum["pending_capture"] = "pending_capture";
|
|
9734
|
+
MercadoPagoStatusDetailEnum["offline_process"] = "offline_process";
|
|
9735
|
+
MercadoPagoStatusDetailEnum["pending_contingency"] = "pending_contingency";
|
|
9736
|
+
MercadoPagoStatusDetailEnum["pending_review_manual"] = "pending_review_manual";
|
|
9737
|
+
MercadoPagoStatusDetailEnum["pending_waiting_transfer"] = "pending_waiting_transfer";
|
|
9738
|
+
MercadoPagoStatusDetailEnum["pending_waiting_payment"] = "pending_waiting_payment";
|
|
9739
|
+
MercadoPagoStatusDetailEnum["pending_challenge"] = "pending_challenge";
|
|
9740
|
+
MercadoPagoStatusDetailEnum["bank_error"] = "bank_error";
|
|
9741
|
+
MercadoPagoStatusDetailEnum["cc_rejected_3ds_mandatory"] = "cc_rejected_3ds_mandatory";
|
|
9742
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_card_number"] = "cc_rejected_bad_filled_card_number";
|
|
9743
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_date"] = "cc_rejected_bad_filled_date";
|
|
9744
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_other"] = "cc_rejected_bad_filled_other";
|
|
9745
|
+
MercadoPagoStatusDetailEnum["cc_rejected_bad_filled_security_code"] = "cc_rejected_bad_filled_security_code";
|
|
9746
|
+
MercadoPagoStatusDetailEnum["cc_rejected_blacklist"] = "cc_rejected_blacklist";
|
|
9747
|
+
MercadoPagoStatusDetailEnum["cc_rejected_call_for_authorize"] = "cc_rejected_call_for_authorize";
|
|
9748
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_disabled"] = "cc_rejected_card_disabled";
|
|
9749
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_error"] = "cc_rejected_card_error";
|
|
9750
|
+
MercadoPagoStatusDetailEnum["cc_rejected_duplicated_payment"] = "cc_rejected_duplicated_payment";
|
|
9751
|
+
MercadoPagoStatusDetailEnum["cc_rejected_high_risk"] = "cc_rejected_high_risk";
|
|
9752
|
+
MercadoPagoStatusDetailEnum["cc_rejected_insufficient_amount"] = "cc_rejected_insufficient_amount";
|
|
9753
|
+
MercadoPagoStatusDetailEnum["cc_rejected_invalid_installments"] = "cc_rejected_invalid_installments";
|
|
9754
|
+
MercadoPagoStatusDetailEnum["cc_rejected_max_attempts"] = "cc_rejected_max_attempts";
|
|
9755
|
+
MercadoPagoStatusDetailEnum["cc_rejected_other_reason"] = "cc_rejected_other_reason";
|
|
9756
|
+
MercadoPagoStatusDetailEnum["cc_amount_rate_limit_exceeded"] = "cc_amount_rate_limit_exceeded";
|
|
9757
|
+
MercadoPagoStatusDetailEnum["rejected_insufficient_data"] = "rejected_insufficient_data";
|
|
9758
|
+
MercadoPagoStatusDetailEnum["rejected_by_bank"] = "rejected_by_bank";
|
|
9759
|
+
MercadoPagoStatusDetailEnum["rejected_by_regulations"] = "rejected_by_regulations";
|
|
9760
|
+
MercadoPagoStatusDetailEnum["insufficient_amount"] = "insufficient_amount";
|
|
9761
|
+
MercadoPagoStatusDetailEnum["cc_rejected_card_type_not_allowed"] = "cc_rejected_card_type_not_allowed";
|
|
9762
|
+
})(exports.MercadoPagoStatusDetailEnum || (exports.MercadoPagoStatusDetailEnum = {}));
|
|
9763
|
+
|
|
9764
|
+
exports.MercadoPagoStatusEnum = void 0;
|
|
9765
|
+
(function (MercadoPagoStatusEnum) {
|
|
9766
|
+
MercadoPagoStatusEnum["approved"] = "approved";
|
|
9767
|
+
MercadoPagoStatusEnum["authorized"] = "authorized";
|
|
9768
|
+
MercadoPagoStatusEnum["pending"] = "pending";
|
|
9769
|
+
MercadoPagoStatusEnum["in_process"] = "in_process";
|
|
9770
|
+
MercadoPagoStatusEnum["rejected"] = "rejected";
|
|
9771
|
+
MercadoPagoStatusEnum["cancelled"] = "cancelled";
|
|
9772
|
+
MercadoPagoStatusEnum["refunded"] = "refunded";
|
|
9773
|
+
MercadoPagoStatusEnum["charged_back"] = "charged_back";
|
|
9774
|
+
})(exports.MercadoPagoStatusEnum || (exports.MercadoPagoStatusEnum = {}));
|
|
9775
|
+
|
|
9252
9776
|
class PagarmeBankSlipAxiosAdapter {
|
|
9253
9777
|
constructor(credentials, paymentRepository) {
|
|
9254
9778
|
this.credentials = credentials;
|
|
@@ -9396,15 +9920,17 @@ class PagarMeV5RequestHelper {
|
|
|
9396
9920
|
customer: this.buildCustomer(checkout),
|
|
9397
9921
|
shipping: this.buildShipping(checkout),
|
|
9398
9922
|
payments: this.buildPayment(checkout, method, card),
|
|
9923
|
+
...this.buildAdditionalInfo(checkout),
|
|
9399
9924
|
};
|
|
9400
9925
|
}
|
|
9401
9926
|
static buildItems(checkout) {
|
|
9927
|
+
const isSubscriber = checkout.user?.isSubscriber ?? false;
|
|
9402
9928
|
return checkout.lineItems
|
|
9403
9929
|
.filter((item) => !item.isGift)
|
|
9404
9930
|
.map((item) => {
|
|
9405
9931
|
return {
|
|
9406
9932
|
amount: Math.floor(item.pricePaid * 100),
|
|
9407
|
-
description: item.name,
|
|
9933
|
+
description: isSubscriber ? `${item.name} - ASSINANTE` : item.name,
|
|
9408
9934
|
quantity: item.quantity,
|
|
9409
9935
|
code: item.EAN,
|
|
9410
9936
|
};
|
|
@@ -9501,6 +10027,14 @@ class PagarMeV5RequestHelper {
|
|
|
9501
10027
|
},
|
|
9502
10028
|
};
|
|
9503
10029
|
}
|
|
10030
|
+
static buildAdditionalInfo(checkout) {
|
|
10031
|
+
const isSubscriber = checkout.user?.isSubscriber ?? false;
|
|
10032
|
+
if (isSubscriber)
|
|
10033
|
+
return {
|
|
10034
|
+
antifraude_enabled: false,
|
|
10035
|
+
};
|
|
10036
|
+
return {};
|
|
10037
|
+
}
|
|
9504
10038
|
}
|
|
9505
10039
|
|
|
9506
10040
|
class PagarMeV5ResponseHelper {
|
|
@@ -10372,6 +10906,8 @@ exports.Base = Base;
|
|
|
10372
10906
|
exports.BaseModel = BaseModel;
|
|
10373
10907
|
exports.BeautyProfile = BeautyProfile;
|
|
10374
10908
|
exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
|
|
10909
|
+
exports.BrandCategory = BrandCategory;
|
|
10910
|
+
exports.BrandCategoryFirestoreRepository = BrandCategoryFirestoreRepository;
|
|
10375
10911
|
exports.BusinessError = BusinessError;
|
|
10376
10912
|
exports.Buy2Win = Buy2Win;
|
|
10377
10913
|
exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
|
|
@@ -10430,6 +10966,12 @@ exports.Log = Log;
|
|
|
10430
10966
|
exports.LogDocument = LogDocument;
|
|
10431
10967
|
exports.LogFirestoreRepository = LogFirestoreRepository;
|
|
10432
10968
|
exports.Logger = Logger;
|
|
10969
|
+
exports.MercadoPagoBankSlipAxiosAdapter = MercadoPagoBankSlipAxiosAdapter;
|
|
10970
|
+
exports.MercadoPagoCardAxiosAdapter = MercadoPagoCardAxiosAdapter;
|
|
10971
|
+
exports.MercadoPagoPaymentMethodFactory = MercadoPagoPaymentMethodFactory;
|
|
10972
|
+
exports.MercadoPagoPixAxiosAdapter = MercadoPagoPixAxiosAdapter;
|
|
10973
|
+
exports.MercadoPagoRequestHelper = MercadoPagoRequestHelper;
|
|
10974
|
+
exports.MercadoPagoResponseHelper = MercadoPagoResponseHelper;
|
|
10433
10975
|
exports.NotFoundError = NotFoundError;
|
|
10434
10976
|
exports.ObsEmitter = ObsEmitter;
|
|
10435
10977
|
exports.Order = Order;
|