@infrab4a/connect 5.4.0-beta.25 → 5.4.0-beta.27
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 +58 -46
- package/index.esm.js +58 -46
- package/package.json +1 -1
- package/src/domain/shopping/types/mercado-pago-card.type.d.ts +11 -0
- package/src/domain/shopping/types/payment-card-info.type.d.ts +1 -0
- package/src/infra/mercado-pago/adapters/mercado-pago-card-payment-axios.adapter.d.ts +4 -3
- package/src/infra/mercado-pago/helpers/mercado-pago-request.helper.d.ts +2 -0
package/index.cjs.js
CHANGED
|
@@ -8784,7 +8784,7 @@ class MercadoPagoRequestHelper {
|
|
|
8784
8784
|
metadata: {
|
|
8785
8785
|
checkoutId: checkout.id,
|
|
8786
8786
|
},
|
|
8787
|
-
payer: this.buildPayer(checkout),
|
|
8787
|
+
payer: this.buildPayer(checkout, card),
|
|
8788
8788
|
statement_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
|
|
8789
8789
|
additional_info: {
|
|
8790
8790
|
items: this.buildItems(checkout),
|
|
@@ -8809,8 +8809,9 @@ class MercadoPagoRequestHelper {
|
|
|
8809
8809
|
};
|
|
8810
8810
|
});
|
|
8811
8811
|
}
|
|
8812
|
-
static buildPayer(checkout) {
|
|
8812
|
+
static buildPayer(checkout, card) {
|
|
8813
8813
|
return {
|
|
8814
|
+
...(card && { id: card.customerId }),
|
|
8814
8815
|
first_name: checkout.user.firstName,
|
|
8815
8816
|
last_name: checkout.user.lastName,
|
|
8816
8817
|
email: checkout.user.email,
|
|
@@ -8842,6 +8843,8 @@ class MercadoPagoRequestHelper {
|
|
|
8842
8843
|
return {
|
|
8843
8844
|
installments: card.installments,
|
|
8844
8845
|
token: card.cardId,
|
|
8846
|
+
binary_mode: true,
|
|
8847
|
+
capture: true,
|
|
8845
8848
|
};
|
|
8846
8849
|
}
|
|
8847
8850
|
static buildPixPayment() {
|
|
@@ -8984,9 +8987,13 @@ class MercadoPagoBankSlipAxiosAdapter {
|
|
|
8984
8987
|
}
|
|
8985
8988
|
catch (error) {
|
|
8986
8989
|
if (error instanceof axios.AxiosError) {
|
|
8987
|
-
console.warn(JSON.stringify(error.response.data.
|
|
8990
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
8988
8991
|
}
|
|
8989
|
-
throw
|
|
8992
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8993
|
+
checkoutId: checkout.id,
|
|
8994
|
+
userEmail: checkout.user.email,
|
|
8995
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
8996
|
+
});
|
|
8990
8997
|
}
|
|
8991
8998
|
}
|
|
8992
8999
|
getBoletoTransaction(paymentId) {
|
|
@@ -9002,12 +9009,7 @@ class MercadoPagoCardAxiosAdapter {
|
|
|
9002
9009
|
}
|
|
9003
9010
|
async pay(checkout, card) {
|
|
9004
9011
|
try {
|
|
9005
|
-
const payload =
|
|
9006
|
-
checkout,
|
|
9007
|
-
method: 'credit_card',
|
|
9008
|
-
postback: this.credentials.postback,
|
|
9009
|
-
card,
|
|
9010
|
-
});
|
|
9012
|
+
const payload = await this.getPaymentPayload(checkout, card);
|
|
9011
9013
|
console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
|
|
9012
9014
|
const { data } = await axios__default["default"]({
|
|
9013
9015
|
method: 'POST',
|
|
@@ -9020,8 +9022,7 @@ class MercadoPagoCardAxiosAdapter {
|
|
|
9020
9022
|
data: payload,
|
|
9021
9023
|
});
|
|
9022
9024
|
console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
|
|
9023
|
-
if (
|
|
9024
|
-
data.status !== 'authorized') {
|
|
9025
|
+
if (data.status == exports.MercadoPagoStatusEnum.rejected) {
|
|
9025
9026
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
9026
9027
|
checkout,
|
|
9027
9028
|
blockType: 'Card not authorized',
|
|
@@ -9040,46 +9041,53 @@ class MercadoPagoCardAxiosAdapter {
|
|
|
9040
9041
|
}
|
|
9041
9042
|
catch (error) {
|
|
9042
9043
|
if (error instanceof axios.AxiosError) {
|
|
9043
|
-
console.warn(JSON.stringify(error.response.data.
|
|
9044
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9044
9045
|
}
|
|
9045
|
-
throw
|
|
9046
|
+
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', {
|
|
9047
|
+
checkoutId: checkout.id,
|
|
9048
|
+
userEmail: checkout.user.email,
|
|
9049
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9050
|
+
});
|
|
9046
9051
|
}
|
|
9047
9052
|
}
|
|
9048
|
-
async
|
|
9049
|
-
const
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
email: customer.email,
|
|
9058
|
-
first_name: customer.firstName,
|
|
9059
|
-
last_name: customer.lastName,
|
|
9060
|
-
phone: {
|
|
9061
|
-
area_code: '55',
|
|
9062
|
-
number: '991234567',
|
|
9063
|
-
},
|
|
9064
|
-
identification: {
|
|
9065
|
-
type: 'CPF',
|
|
9066
|
-
number: '12345678900',
|
|
9067
|
-
},
|
|
9068
|
-
default_address: 'Home',
|
|
9069
|
-
address: {
|
|
9070
|
-
id: '123123',
|
|
9071
|
-
zip_code: '01234567',
|
|
9072
|
-
street_name: 'Rua Exemplo',
|
|
9073
|
-
street_number: 123,
|
|
9074
|
-
city: {},
|
|
9075
|
-
},
|
|
9053
|
+
async getPaymentPayload(checkout, card) {
|
|
9054
|
+
const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
|
|
9055
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
9056
|
+
checkout,
|
|
9057
|
+
method: 'credit_card',
|
|
9058
|
+
postback: this.credentials.postback,
|
|
9059
|
+
card: {
|
|
9060
|
+
...card,
|
|
9061
|
+
cardId: cardResponse.id,
|
|
9076
9062
|
},
|
|
9077
9063
|
});
|
|
9078
|
-
return
|
|
9064
|
+
return payload;
|
|
9079
9065
|
}
|
|
9080
|
-
|
|
9066
|
+
async addCard(card, customer) {
|
|
9081
9067
|
return;
|
|
9082
9068
|
}
|
|
9069
|
+
async getCardByToken(customerId, token, cardCvv) {
|
|
9070
|
+
try {
|
|
9071
|
+
const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
|
|
9072
|
+
console.warn('payload getCardByToken', payload);
|
|
9073
|
+
const { data } = await axios__default["default"]({
|
|
9074
|
+
method: 'POST',
|
|
9075
|
+
url: `${this.credentials.url}/v1/card_tokens`,
|
|
9076
|
+
headers: {
|
|
9077
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9078
|
+
'Content-Type': 'application/json',
|
|
9079
|
+
},
|
|
9080
|
+
data: payload,
|
|
9081
|
+
});
|
|
9082
|
+
return data;
|
|
9083
|
+
}
|
|
9084
|
+
catch (error) {
|
|
9085
|
+
if (error instanceof axios.AxiosError) {
|
|
9086
|
+
console.warn(JSON.stringify(error.response.data.cause));
|
|
9087
|
+
}
|
|
9088
|
+
throw error;
|
|
9089
|
+
}
|
|
9090
|
+
}
|
|
9083
9091
|
createCardHash(bu, shop, card) {
|
|
9084
9092
|
return;
|
|
9085
9093
|
}
|
|
@@ -9141,9 +9149,13 @@ class MercadoPagoPixAxiosAdapter {
|
|
|
9141
9149
|
}
|
|
9142
9150
|
catch (error) {
|
|
9143
9151
|
if (error instanceof axios.AxiosError) {
|
|
9144
|
-
console.warn(JSON.stringify(error.response.data.
|
|
9152
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9145
9153
|
}
|
|
9146
|
-
throw
|
|
9154
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9155
|
+
checkoutId: checkout.id,
|
|
9156
|
+
userEmail: checkout.user.email,
|
|
9157
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9158
|
+
});
|
|
9147
9159
|
}
|
|
9148
9160
|
}
|
|
9149
9161
|
}
|
package/index.esm.js
CHANGED
|
@@ -8760,7 +8760,7 @@ class MercadoPagoRequestHelper {
|
|
|
8760
8760
|
metadata: {
|
|
8761
8761
|
checkoutId: checkout.id,
|
|
8762
8762
|
},
|
|
8763
|
-
payer: this.buildPayer(checkout),
|
|
8763
|
+
payer: this.buildPayer(checkout, card),
|
|
8764
8764
|
statement_descriptor: checkout.shop === Shops.GLAMSHOP ? 'Glam' : 'Mens Market',
|
|
8765
8765
|
additional_info: {
|
|
8766
8766
|
items: this.buildItems(checkout),
|
|
@@ -8785,8 +8785,9 @@ class MercadoPagoRequestHelper {
|
|
|
8785
8785
|
};
|
|
8786
8786
|
});
|
|
8787
8787
|
}
|
|
8788
|
-
static buildPayer(checkout) {
|
|
8788
|
+
static buildPayer(checkout, card) {
|
|
8789
8789
|
return {
|
|
8790
|
+
...(card && { id: card.customerId }),
|
|
8790
8791
|
first_name: checkout.user.firstName,
|
|
8791
8792
|
last_name: checkout.user.lastName,
|
|
8792
8793
|
email: checkout.user.email,
|
|
@@ -8818,6 +8819,8 @@ class MercadoPagoRequestHelper {
|
|
|
8818
8819
|
return {
|
|
8819
8820
|
installments: card.installments,
|
|
8820
8821
|
token: card.cardId,
|
|
8822
|
+
binary_mode: true,
|
|
8823
|
+
capture: true,
|
|
8821
8824
|
};
|
|
8822
8825
|
}
|
|
8823
8826
|
static buildPixPayment() {
|
|
@@ -8960,9 +8963,13 @@ class MercadoPagoBankSlipAxiosAdapter {
|
|
|
8960
8963
|
}
|
|
8961
8964
|
catch (error) {
|
|
8962
8965
|
if (error instanceof AxiosError) {
|
|
8963
|
-
console.warn(JSON.stringify(error.response.data.
|
|
8966
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
8964
8967
|
}
|
|
8965
|
-
throw
|
|
8968
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8969
|
+
checkoutId: checkout.id,
|
|
8970
|
+
userEmail: checkout.user.email,
|
|
8971
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
8972
|
+
});
|
|
8966
8973
|
}
|
|
8967
8974
|
}
|
|
8968
8975
|
getBoletoTransaction(paymentId) {
|
|
@@ -8978,12 +8985,7 @@ class MercadoPagoCardAxiosAdapter {
|
|
|
8978
8985
|
}
|
|
8979
8986
|
async pay(checkout, card) {
|
|
8980
8987
|
try {
|
|
8981
|
-
const payload =
|
|
8982
|
-
checkout,
|
|
8983
|
-
method: 'credit_card',
|
|
8984
|
-
postback: this.credentials.postback,
|
|
8985
|
-
card,
|
|
8986
|
-
});
|
|
8988
|
+
const payload = await this.getPaymentPayload(checkout, card);
|
|
8987
8989
|
console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
|
|
8988
8990
|
const { data } = await axios({
|
|
8989
8991
|
method: 'POST',
|
|
@@ -8996,8 +8998,7 @@ class MercadoPagoCardAxiosAdapter {
|
|
|
8996
8998
|
data: payload,
|
|
8997
8999
|
});
|
|
8998
9000
|
console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
|
|
8999
|
-
if (
|
|
9000
|
-
data.status !== 'authorized') {
|
|
9001
|
+
if (data.status == MercadoPagoStatusEnum.rejected) {
|
|
9001
9002
|
await this.orderBlockedRepository.createBlockedOrderOrPayment({
|
|
9002
9003
|
checkout,
|
|
9003
9004
|
blockType: 'Card not authorized',
|
|
@@ -9016,46 +9017,53 @@ class MercadoPagoCardAxiosAdapter {
|
|
|
9016
9017
|
}
|
|
9017
9018
|
catch (error) {
|
|
9018
9019
|
if (error instanceof AxiosError) {
|
|
9019
|
-
console.warn(JSON.stringify(error.response.data.
|
|
9020
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9020
9021
|
}
|
|
9021
|
-
throw
|
|
9022
|
+
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', {
|
|
9023
|
+
checkoutId: checkout.id,
|
|
9024
|
+
userEmail: checkout.user.email,
|
|
9025
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9026
|
+
});
|
|
9022
9027
|
}
|
|
9023
9028
|
}
|
|
9024
|
-
async
|
|
9025
|
-
const
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
email: customer.email,
|
|
9034
|
-
first_name: customer.firstName,
|
|
9035
|
-
last_name: customer.lastName,
|
|
9036
|
-
phone: {
|
|
9037
|
-
area_code: '55',
|
|
9038
|
-
number: '991234567',
|
|
9039
|
-
},
|
|
9040
|
-
identification: {
|
|
9041
|
-
type: 'CPF',
|
|
9042
|
-
number: '12345678900',
|
|
9043
|
-
},
|
|
9044
|
-
default_address: 'Home',
|
|
9045
|
-
address: {
|
|
9046
|
-
id: '123123',
|
|
9047
|
-
zip_code: '01234567',
|
|
9048
|
-
street_name: 'Rua Exemplo',
|
|
9049
|
-
street_number: 123,
|
|
9050
|
-
city: {},
|
|
9051
|
-
},
|
|
9029
|
+
async getPaymentPayload(checkout, card) {
|
|
9030
|
+
const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
|
|
9031
|
+
const payload = MercadoPagoRequestHelper.build({
|
|
9032
|
+
checkout,
|
|
9033
|
+
method: 'credit_card',
|
|
9034
|
+
postback: this.credentials.postback,
|
|
9035
|
+
card: {
|
|
9036
|
+
...card,
|
|
9037
|
+
cardId: cardResponse.id,
|
|
9052
9038
|
},
|
|
9053
9039
|
});
|
|
9054
|
-
return
|
|
9040
|
+
return payload;
|
|
9055
9041
|
}
|
|
9056
|
-
|
|
9042
|
+
async addCard(card, customer) {
|
|
9057
9043
|
return;
|
|
9058
9044
|
}
|
|
9045
|
+
async getCardByToken(customerId, token, cardCvv) {
|
|
9046
|
+
try {
|
|
9047
|
+
const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
|
|
9048
|
+
console.warn('payload getCardByToken', payload);
|
|
9049
|
+
const { data } = await axios({
|
|
9050
|
+
method: 'POST',
|
|
9051
|
+
url: `${this.credentials.url}/v1/card_tokens`,
|
|
9052
|
+
headers: {
|
|
9053
|
+
Authorization: `Bearer ${this.credentials.api_key}`,
|
|
9054
|
+
'Content-Type': 'application/json',
|
|
9055
|
+
},
|
|
9056
|
+
data: payload,
|
|
9057
|
+
});
|
|
9058
|
+
return data;
|
|
9059
|
+
}
|
|
9060
|
+
catch (error) {
|
|
9061
|
+
if (error instanceof AxiosError) {
|
|
9062
|
+
console.warn(JSON.stringify(error.response.data.cause));
|
|
9063
|
+
}
|
|
9064
|
+
throw error;
|
|
9065
|
+
}
|
|
9066
|
+
}
|
|
9059
9067
|
createCardHash(bu, shop, card) {
|
|
9060
9068
|
return;
|
|
9061
9069
|
}
|
|
@@ -9117,9 +9125,13 @@ class MercadoPagoPixAxiosAdapter {
|
|
|
9117
9125
|
}
|
|
9118
9126
|
catch (error) {
|
|
9119
9127
|
if (error instanceof AxiosError) {
|
|
9120
|
-
console.warn(JSON.stringify(error.response.data.
|
|
9128
|
+
console.warn(JSON.stringify(error.response.data.message));
|
|
9121
9129
|
}
|
|
9122
|
-
throw
|
|
9130
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9131
|
+
checkoutId: checkout.id,
|
|
9132
|
+
userEmail: checkout.user.email,
|
|
9133
|
+
info: error.response.data?.message || error.message?.toString(),
|
|
9134
|
+
});
|
|
9123
9135
|
}
|
|
9124
9136
|
}
|
|
9125
9137
|
}
|
package/package.json
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { BaseCard } from './base-card.type';
|
|
2
2
|
export interface MercadoPagoCard extends BaseCard {
|
|
3
3
|
}
|
|
4
|
+
export interface MercadoPagoCardTokenResponse {
|
|
5
|
+
id: string;
|
|
6
|
+
card_id: string;
|
|
7
|
+
status: boolean;
|
|
8
|
+
date_created: string;
|
|
9
|
+
date_last_updated: string;
|
|
10
|
+
date_due: string;
|
|
11
|
+
luhn_validation: boolean;
|
|
12
|
+
live_mode: boolean;
|
|
13
|
+
require_esc: boolean;
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BusinessUnitEnum, CardInfo, Checkout, MercadoPagoCard, MercadoPagoCredentials, OrderBlockedRepository, Payment, PaymentCardInfo, PaymentProviderCard, PaymentRepository, PaymentTransaction, Shops, User, UserAddress } from '../../../domain';
|
|
1
|
+
import { BusinessUnitEnum, CardInfo, Checkout, MercadoPagoCard, MercadoPagoCardTokenResponse, MercadoPagoCredentials, OrderBlockedRepository, Payment, PaymentCardInfo, PaymentProviderCard, PaymentRepository, PaymentTransaction, Shops, User, UserAddress } from '../../../domain';
|
|
2
2
|
import { MercadoPagoResponse } from '../types';
|
|
3
3
|
export declare class MercadoPagoCardAxiosAdapter implements PaymentProviderCard<MercadoPagoCard> {
|
|
4
4
|
private credentials;
|
|
@@ -6,11 +6,12 @@ export declare class MercadoPagoCardAxiosAdapter implements PaymentProviderCard<
|
|
|
6
6
|
private orderBlockedRepository;
|
|
7
7
|
constructor(credentials: MercadoPagoCredentials, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
|
|
8
8
|
pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
|
|
9
|
+
private getPaymentPayload;
|
|
9
10
|
addCard?(card: CardInfo, customer: User & {
|
|
10
11
|
billingAddress: Partial<UserAddress>;
|
|
11
12
|
}): Promise<MercadoPagoCard>;
|
|
12
|
-
getCardByToken(token: string): Promise<
|
|
13
|
-
getCardByToken(customerId: string, token: string): Promise<
|
|
13
|
+
getCardByToken(token: string): Promise<MercadoPagoCardTokenResponse>;
|
|
14
|
+
getCardByToken(customerId: string, token: string, cardCvv: string): Promise<MercadoPagoCardTokenResponse>;
|
|
14
15
|
createCardHash<T>(bu: BusinessUnitEnum, shop: Shops, card?: CardInfo): Promise<string | T>;
|
|
15
16
|
createTransaction(info: any): Promise<PaymentTransaction>;
|
|
16
17
|
createOrUpdateCustomer?(customer: User & {
|