@infrab4a/connect 5.4.0-beta.25 → 5.4.0-beta.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -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,
@@ -9002,12 +9003,7 @@ class MercadoPagoCardAxiosAdapter {
9002
9003
  }
9003
9004
  async pay(checkout, card) {
9004
9005
  try {
9005
- const payload = MercadoPagoRequestHelper.build({
9006
- checkout,
9007
- method: 'credit_card',
9008
- postback: this.credentials.postback,
9009
- card,
9010
- });
9006
+ const payload = await this.getPaymentPayload(checkout, card);
9011
9007
  console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
9012
9008
  const { data } = await axios__default["default"]({
9013
9009
  method: 'POST',
@@ -9020,8 +9016,7 @@ class MercadoPagoCardAxiosAdapter {
9020
9016
  data: payload,
9021
9017
  });
9022
9018
  console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
9023
- if ((data.status !== 'approved' && data.status_detail !== exports.MercadoPagoStatusDetailEnum.accredited) ||
9024
- data.status !== 'authorized') {
9019
+ if (data.status == exports.MercadoPagoStatusEnum.rejected) {
9025
9020
  await this.orderBlockedRepository.createBlockedOrderOrPayment({
9026
9021
  checkout,
9027
9022
  blockType: 'Card not authorized',
@@ -9045,41 +9040,44 @@ class MercadoPagoCardAxiosAdapter {
9045
9040
  throw error;
9046
9041
  }
9047
9042
  }
9048
- async addCard(card, customer) {
9049
- const { data } = await axios__default["default"]({
9050
- method: 'POST',
9051
- url: `${this.credentials.url}/v1/payments`,
9052
- headers: {
9053
- Authorization: `Bearer ${this.credentials.api_key}`,
9054
- 'Content-Type': 'application/json',
9055
- },
9056
- data: {
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
- },
9043
+ async getPaymentPayload(checkout, card) {
9044
+ const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
9045
+ const payload = MercadoPagoRequestHelper.build({
9046
+ checkout,
9047
+ method: 'credit_card',
9048
+ postback: this.credentials.postback,
9049
+ card: {
9050
+ ...card,
9051
+ cardId: cardResponse.id,
9076
9052
  },
9077
9053
  });
9078
- return data;
9054
+ return payload;
9079
9055
  }
9080
- getCardByToken(customerId, token) {
9056
+ async addCard(card, customer) {
9081
9057
  return;
9082
9058
  }
9059
+ async getCardByToken(customerId, token, cardCvv) {
9060
+ try {
9061
+ const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
9062
+ console.warn('payload getCardByToken', payload);
9063
+ const { data } = await axios__default["default"]({
9064
+ method: 'POST',
9065
+ url: `${this.credentials.url}/v1/card_tokens`,
9066
+ headers: {
9067
+ Authorization: `Bearer ${this.credentials.api_key}`,
9068
+ 'Content-Type': 'application/json',
9069
+ },
9070
+ data: payload,
9071
+ });
9072
+ return data;
9073
+ }
9074
+ catch (error) {
9075
+ if (error instanceof axios.AxiosError) {
9076
+ console.warn(JSON.stringify(error.response.data.cause));
9077
+ }
9078
+ throw error;
9079
+ }
9080
+ }
9083
9081
  createCardHash(bu, shop, card) {
9084
9082
  return;
9085
9083
  }
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,
@@ -8978,12 +8979,7 @@ class MercadoPagoCardAxiosAdapter {
8978
8979
  }
8979
8980
  async pay(checkout, card) {
8980
8981
  try {
8981
- const payload = MercadoPagoRequestHelper.build({
8982
- checkout,
8983
- method: 'credit_card',
8984
- postback: this.credentials.postback,
8985
- card,
8986
- });
8982
+ const payload = await this.getPaymentPayload(checkout, card);
8987
8983
  console.warn('[MERCADO PAGO CARD DATA TO SEND]', JSON.stringify(payload));
8988
8984
  const { data } = await axios({
8989
8985
  method: 'POST',
@@ -8996,8 +8992,7 @@ class MercadoPagoCardAxiosAdapter {
8996
8992
  data: payload,
8997
8993
  });
8998
8994
  console.warn('[MERCADO PAGO RESPONSE CARD DATA]', JSON.stringify(data));
8999
- if ((data.status !== 'approved' && data.status_detail !== MercadoPagoStatusDetailEnum.accredited) ||
9000
- data.status !== 'authorized') {
8995
+ if (data.status == MercadoPagoStatusEnum.rejected) {
9001
8996
  await this.orderBlockedRepository.createBlockedOrderOrPayment({
9002
8997
  checkout,
9003
8998
  blockType: 'Card not authorized',
@@ -9021,41 +9016,44 @@ class MercadoPagoCardAxiosAdapter {
9021
9016
  throw error;
9022
9017
  }
9023
9018
  }
9024
- async addCard(card, customer) {
9025
- const { data } = await axios({
9026
- method: 'POST',
9027
- url: `${this.credentials.url}/v1/payments`,
9028
- headers: {
9029
- Authorization: `Bearer ${this.credentials.api_key}`,
9030
- 'Content-Type': 'application/json',
9031
- },
9032
- data: {
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
- },
9019
+ async getPaymentPayload(checkout, card) {
9020
+ const cardResponse = await this.getCardByToken(card.customerId, card.cardId, card.cardCvv);
9021
+ const payload = MercadoPagoRequestHelper.build({
9022
+ checkout,
9023
+ method: 'credit_card',
9024
+ postback: this.credentials.postback,
9025
+ card: {
9026
+ ...card,
9027
+ cardId: cardResponse.id,
9052
9028
  },
9053
9029
  });
9054
- return data;
9030
+ return payload;
9055
9031
  }
9056
- getCardByToken(customerId, token) {
9032
+ async addCard(card, customer) {
9057
9033
  return;
9058
9034
  }
9035
+ async getCardByToken(customerId, token, cardCvv) {
9036
+ try {
9037
+ const payload = { cardId: token, customerId: customerId, securityCode: cardCvv };
9038
+ console.warn('payload getCardByToken', payload);
9039
+ const { data } = await axios({
9040
+ method: 'POST',
9041
+ url: `${this.credentials.url}/v1/card_tokens`,
9042
+ headers: {
9043
+ Authorization: `Bearer ${this.credentials.api_key}`,
9044
+ 'Content-Type': 'application/json',
9045
+ },
9046
+ data: payload,
9047
+ });
9048
+ return data;
9049
+ }
9050
+ catch (error) {
9051
+ if (error instanceof AxiosError) {
9052
+ console.warn(JSON.stringify(error.response.data.cause));
9053
+ }
9054
+ throw error;
9055
+ }
9056
+ }
9059
9057
  createCardHash(bu, shop, card) {
9060
9058
  return;
9061
9059
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "5.4.0-beta.25",
3
+ "version": "5.4.0-beta.26",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -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
+ }
@@ -6,4 +6,5 @@ export type PaymentCardInfo = {
6
6
  cpf?: string;
7
7
  fingerprint?: string;
8
8
  paymentProvider?: PaymentProviders;
9
+ customerId?: string;
9
10
  };
@@ -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<MercadoPagoCard>;
13
- getCardByToken(customerId: string, token: string): Promise<MercadoPagoCard>;
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 & {