@infrab4a/connect 5.1.0-beta.10 → 5.1.0-beta.12
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 +93 -6
- package/index.esm.js +93 -6
- package/package.json +1 -1
- package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +4 -1
- package/src/domain/shopping/types/card-info.type.d.ts +1 -0
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +10 -4
- package/src/infra/pagarme/types/v5/index.d.ts +1 -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 +31 -28
- package/src/infra/pagarme/types/v5/pagarmev5-postback-response.type.d.ts +1 -1
package/index.cjs.js
CHANGED
|
@@ -8696,6 +8696,13 @@ class PagarMeV5RequestHelper {
|
|
|
8696
8696
|
card_id: card.cardId,
|
|
8697
8697
|
card: {
|
|
8698
8698
|
cvv: card.cardCvv,
|
|
8699
|
+
billing_address: {
|
|
8700
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8701
|
+
zip_code: checkout.billingAddress.zip,
|
|
8702
|
+
city: checkout.billingAddress.city,
|
|
8703
|
+
state: checkout.billingAddress.state,
|
|
8704
|
+
country: 'BR',
|
|
8705
|
+
},
|
|
8699
8706
|
},
|
|
8700
8707
|
};
|
|
8701
8708
|
}
|
|
@@ -9022,10 +9029,10 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
9022
9029
|
data: payload,
|
|
9023
9030
|
});
|
|
9024
9031
|
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9025
|
-
if (data.status
|
|
9032
|
+
if (data.status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9026
9033
|
data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9027
|
-
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado
|
|
9028
|
-
|
|
9034
|
+
(data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado &&
|
|
9035
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento'])) {
|
|
9029
9036
|
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9030
9037
|
checkoutId: checkout.id,
|
|
9031
9038
|
userEmail: checkout.user.email,
|
|
@@ -9115,8 +9122,35 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9115
9122
|
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9116
9123
|
}
|
|
9117
9124
|
}
|
|
9118
|
-
async addCard(card) {
|
|
9119
|
-
|
|
9125
|
+
async addCard(card, customer) {
|
|
9126
|
+
const { id } = await this.createOrUpdateCustomer(customer);
|
|
9127
|
+
const { data } = await axios__default["default"]({
|
|
9128
|
+
method: 'POST',
|
|
9129
|
+
url: `${this.credentials.URL}/customers/${id}/cards`,
|
|
9130
|
+
headers: {
|
|
9131
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9132
|
+
'Content-Type': 'application/json',
|
|
9133
|
+
},
|
|
9134
|
+
data: {
|
|
9135
|
+
number: card.number,
|
|
9136
|
+
holder_name: card.name,
|
|
9137
|
+
holder_document: card.cpf,
|
|
9138
|
+
exp_month: card.expirationDate.split('/').at(0),
|
|
9139
|
+
exp_year: card.expirationDate.split('/').at(1),
|
|
9140
|
+
cvv: card.cvv,
|
|
9141
|
+
brand: card.flag,
|
|
9142
|
+
label: card.flag,
|
|
9143
|
+
billing_address: {
|
|
9144
|
+
line_1: `${customer.billindAddress.number}, ${customer.billindAddress.street}, ${customer.billindAddress.district}`,
|
|
9145
|
+
line_2: `${customer.billindAddress.extension}`,
|
|
9146
|
+
zip_code: customer.billindAddress.zip,
|
|
9147
|
+
city: customer.billindAddress.city,
|
|
9148
|
+
state: customer.billindAddress.state,
|
|
9149
|
+
country: 'BR',
|
|
9150
|
+
},
|
|
9151
|
+
},
|
|
9152
|
+
});
|
|
9153
|
+
return data;
|
|
9120
9154
|
}
|
|
9121
9155
|
async createCardHash(bu, shop) {
|
|
9122
9156
|
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
@@ -9158,7 +9192,60 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9158
9192
|
}
|
|
9159
9193
|
}
|
|
9160
9194
|
async createTransaction(info) {
|
|
9161
|
-
return;
|
|
9195
|
+
return info;
|
|
9196
|
+
}
|
|
9197
|
+
// async getCustomerByCpf(cpf: string) {
|
|
9198
|
+
// const { data }: { data: any } = await axios({
|
|
9199
|
+
// method: 'GET',
|
|
9200
|
+
// url: `${this.credentials.URL}/customers`,
|
|
9201
|
+
// headers: {
|
|
9202
|
+
// Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9203
|
+
// 'Content-Type': 'application/json',
|
|
9204
|
+
// },
|
|
9205
|
+
// params: {
|
|
9206
|
+
// document: cpf,
|
|
9207
|
+
// },
|
|
9208
|
+
// })
|
|
9209
|
+
// return data
|
|
9210
|
+
// }
|
|
9211
|
+
async createOrUpdateCustomer(customer) {
|
|
9212
|
+
const { data } = await axios__default["default"]({
|
|
9213
|
+
method: 'POST',
|
|
9214
|
+
url: `${this.credentials.URL}/customers`,
|
|
9215
|
+
headers: {
|
|
9216
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9217
|
+
'Content-Type': 'application/json',
|
|
9218
|
+
},
|
|
9219
|
+
data: {
|
|
9220
|
+
name: customer.displayName,
|
|
9221
|
+
email: customer.email,
|
|
9222
|
+
document: customer.cpf,
|
|
9223
|
+
type: 'individual',
|
|
9224
|
+
document_type: 'CPF',
|
|
9225
|
+
address: {
|
|
9226
|
+
line_1: `${customer.billindAddress.number}, ${customer.billindAddress.street}, ${customer.billindAddress.district}`,
|
|
9227
|
+
line_2: `${customer.billindAddress.extension}`,
|
|
9228
|
+
zip_code: customer.billindAddress.zip,
|
|
9229
|
+
city: customer.billindAddress.city,
|
|
9230
|
+
state: customer.billindAddress.state,
|
|
9231
|
+
country: 'BR',
|
|
9232
|
+
},
|
|
9233
|
+
birthdate: dateFns.format(customer.birthday, 'mm/dd/AAAA'),
|
|
9234
|
+
phones: {
|
|
9235
|
+
home_phone: {
|
|
9236
|
+
country_code: '55',
|
|
9237
|
+
number: customer.phone.slice(2),
|
|
9238
|
+
area_code: customer.phone.slice(0, 2),
|
|
9239
|
+
},
|
|
9240
|
+
mobile_phone: {
|
|
9241
|
+
country_code: '55',
|
|
9242
|
+
number: customer.phone.slice(2),
|
|
9243
|
+
area_code: customer.phone.slice(0, 2),
|
|
9244
|
+
},
|
|
9245
|
+
},
|
|
9246
|
+
},
|
|
9247
|
+
});
|
|
9248
|
+
return data;
|
|
9162
9249
|
}
|
|
9163
9250
|
}
|
|
9164
9251
|
|
package/index.esm.js
CHANGED
|
@@ -8671,6 +8671,13 @@ class PagarMeV5RequestHelper {
|
|
|
8671
8671
|
card_id: card.cardId,
|
|
8672
8672
|
card: {
|
|
8673
8673
|
cvv: card.cardCvv,
|
|
8674
|
+
billing_address: {
|
|
8675
|
+
line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
|
|
8676
|
+
zip_code: checkout.billingAddress.zip,
|
|
8677
|
+
city: checkout.billingAddress.city,
|
|
8678
|
+
state: checkout.billingAddress.state,
|
|
8679
|
+
country: 'BR',
|
|
8680
|
+
},
|
|
8674
8681
|
},
|
|
8675
8682
|
};
|
|
8676
8683
|
}
|
|
@@ -8997,10 +9004,10 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
8997
9004
|
data: payload,
|
|
8998
9005
|
});
|
|
8999
9006
|
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9000
|
-
if (data.status
|
|
9007
|
+
if (data.status === PagarMeV5OrderStatus.Falha ||
|
|
9001
9008
|
data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
|
|
9002
|
-
data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado
|
|
9003
|
-
|
|
9009
|
+
(data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado &&
|
|
9010
|
+
data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus['Em processamento'])) {
|
|
9004
9011
|
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9005
9012
|
checkoutId: checkout.id,
|
|
9006
9013
|
userEmail: checkout.user.email,
|
|
@@ -9090,8 +9097,35 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9090
9097
|
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9091
9098
|
}
|
|
9092
9099
|
}
|
|
9093
|
-
async addCard(card) {
|
|
9094
|
-
|
|
9100
|
+
async addCard(card, customer) {
|
|
9101
|
+
const { id } = await this.createOrUpdateCustomer(customer);
|
|
9102
|
+
const { data } = await axios({
|
|
9103
|
+
method: 'POST',
|
|
9104
|
+
url: `${this.credentials.URL}/customers/${id}/cards`,
|
|
9105
|
+
headers: {
|
|
9106
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9107
|
+
'Content-Type': 'application/json',
|
|
9108
|
+
},
|
|
9109
|
+
data: {
|
|
9110
|
+
number: card.number,
|
|
9111
|
+
holder_name: card.name,
|
|
9112
|
+
holder_document: card.cpf,
|
|
9113
|
+
exp_month: card.expirationDate.split('/').at(0),
|
|
9114
|
+
exp_year: card.expirationDate.split('/').at(1),
|
|
9115
|
+
cvv: card.cvv,
|
|
9116
|
+
brand: card.flag,
|
|
9117
|
+
label: card.flag,
|
|
9118
|
+
billing_address: {
|
|
9119
|
+
line_1: `${customer.billindAddress.number}, ${customer.billindAddress.street}, ${customer.billindAddress.district}`,
|
|
9120
|
+
line_2: `${customer.billindAddress.extension}`,
|
|
9121
|
+
zip_code: customer.billindAddress.zip,
|
|
9122
|
+
city: customer.billindAddress.city,
|
|
9123
|
+
state: customer.billindAddress.state,
|
|
9124
|
+
country: 'BR',
|
|
9125
|
+
},
|
|
9126
|
+
},
|
|
9127
|
+
});
|
|
9128
|
+
return data;
|
|
9095
9129
|
}
|
|
9096
9130
|
async createCardHash(bu, shop) {
|
|
9097
9131
|
const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
|
|
@@ -9133,7 +9167,60 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9133
9167
|
}
|
|
9134
9168
|
}
|
|
9135
9169
|
async createTransaction(info) {
|
|
9136
|
-
return;
|
|
9170
|
+
return info;
|
|
9171
|
+
}
|
|
9172
|
+
// async getCustomerByCpf(cpf: string) {
|
|
9173
|
+
// const { data }: { data: any } = await axios({
|
|
9174
|
+
// method: 'GET',
|
|
9175
|
+
// url: `${this.credentials.URL}/customers`,
|
|
9176
|
+
// headers: {
|
|
9177
|
+
// Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9178
|
+
// 'Content-Type': 'application/json',
|
|
9179
|
+
// },
|
|
9180
|
+
// params: {
|
|
9181
|
+
// document: cpf,
|
|
9182
|
+
// },
|
|
9183
|
+
// })
|
|
9184
|
+
// return data
|
|
9185
|
+
// }
|
|
9186
|
+
async createOrUpdateCustomer(customer) {
|
|
9187
|
+
const { data } = await axios({
|
|
9188
|
+
method: 'POST',
|
|
9189
|
+
url: `${this.credentials.URL}/customers`,
|
|
9190
|
+
headers: {
|
|
9191
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
9192
|
+
'Content-Type': 'application/json',
|
|
9193
|
+
},
|
|
9194
|
+
data: {
|
|
9195
|
+
name: customer.displayName,
|
|
9196
|
+
email: customer.email,
|
|
9197
|
+
document: customer.cpf,
|
|
9198
|
+
type: 'individual',
|
|
9199
|
+
document_type: 'CPF',
|
|
9200
|
+
address: {
|
|
9201
|
+
line_1: `${customer.billindAddress.number}, ${customer.billindAddress.street}, ${customer.billindAddress.district}`,
|
|
9202
|
+
line_2: `${customer.billindAddress.extension}`,
|
|
9203
|
+
zip_code: customer.billindAddress.zip,
|
|
9204
|
+
city: customer.billindAddress.city,
|
|
9205
|
+
state: customer.billindAddress.state,
|
|
9206
|
+
country: 'BR',
|
|
9207
|
+
},
|
|
9208
|
+
birthdate: format(customer.birthday, 'mm/dd/AAAA'),
|
|
9209
|
+
phones: {
|
|
9210
|
+
home_phone: {
|
|
9211
|
+
country_code: '55',
|
|
9212
|
+
number: customer.phone.slice(2),
|
|
9213
|
+
area_code: customer.phone.slice(0, 2),
|
|
9214
|
+
},
|
|
9215
|
+
mobile_phone: {
|
|
9216
|
+
country_code: '55',
|
|
9217
|
+
number: customer.phone.slice(2),
|
|
9218
|
+
area_code: customer.phone.slice(0, 2),
|
|
9219
|
+
},
|
|
9220
|
+
},
|
|
9221
|
+
},
|
|
9222
|
+
});
|
|
9223
|
+
return data;
|
|
9137
9224
|
}
|
|
9138
9225
|
}
|
|
9139
9226
|
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Shops } from '../../catalog';
|
|
2
|
+
import { User, UserAddress } from '../../users';
|
|
2
3
|
import { BusinessUnitEnum } from '../enums';
|
|
3
4
|
import { PaymentTransaction } from '../models';
|
|
4
5
|
import { Checkout } from '../models/checkout';
|
|
@@ -7,7 +8,9 @@ import { CardInfo, PaymentCardInfo } from '../types';
|
|
|
7
8
|
import { BaseCard } from '../types/base-card.type';
|
|
8
9
|
export interface PaymentProviderCard<Card extends BaseCard = BaseCard> {
|
|
9
10
|
pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
|
|
10
|
-
addCard(card: CardInfo
|
|
11
|
+
addCard?(card: CardInfo, customer: User & {
|
|
12
|
+
billindAddress: Partial<UserAddress>;
|
|
13
|
+
}): Promise<Card>;
|
|
11
14
|
getCardByToken(token: string): Promise<Card>;
|
|
12
15
|
getCardByToken(customerId: string, token: string): Promise<Card>;
|
|
13
16
|
createCardHash<T>(bu: BusinessUnitEnum, shop: Shops, card?: CardInfo): Promise<string | T>;
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { Shops } from '../../../../domain';
|
|
1
|
+
import { Shops, User, UserAddress } from '../../../../domain';
|
|
2
2
|
import { BusinessUnitEnum } from '../../../../domain/shopping/enums';
|
|
3
3
|
import { PaymentProviderCard } from '../../../../domain/shopping/interfaces';
|
|
4
4
|
import { Checkout, Payment, PaymentTransaction } from '../../../../domain/shopping/models';
|
|
5
5
|
import { OrderBlockedRepository, PaymentRepository } from '../../../../domain/shopping/repositories';
|
|
6
|
-
import { CardInfo, PagarMeCard,
|
|
6
|
+
import { CardInfo, PagarMeCard, PagarmeCredentialsV5, PaymentCardInfo } from '../../../../domain/shopping/types';
|
|
7
|
+
import { PagarMeV5Customer } from '../../types';
|
|
7
8
|
export declare class PagarmeV5CardAxiosAdapter implements PaymentProviderCard<PagarMeCard> {
|
|
8
9
|
private credentials;
|
|
9
10
|
private paymentRepository;
|
|
10
11
|
private orderBlockedRepository;
|
|
11
|
-
constructor(credentials:
|
|
12
|
+
constructor(credentials: PagarmeCredentialsV5, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
|
|
12
13
|
pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
|
|
13
|
-
addCard(card: CardInfo
|
|
14
|
+
addCard(card: CardInfo, customer: User & {
|
|
15
|
+
billindAddress: Partial<UserAddress>;
|
|
16
|
+
}): Promise<PagarMeCard>;
|
|
14
17
|
createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum, shop?: Shops): Promise<PagarMeCardManualHash>;
|
|
15
18
|
getCardByToken(token: string): Promise<PagarMeCard>;
|
|
16
19
|
getCardByToken(customerId: string, token: string): Promise<PagarMeCard>;
|
|
17
20
|
createTransaction(info: any): Promise<PaymentTransaction>;
|
|
21
|
+
createOrUpdateCustomer(customer: User & {
|
|
22
|
+
billindAddress: Partial<UserAddress>;
|
|
23
|
+
}): Promise<PagarMeV5Customer>;
|
|
18
24
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type PagarMeV5Customer = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
code: string;
|
|
6
|
+
document: string;
|
|
7
|
+
document_type: string;
|
|
8
|
+
type: string;
|
|
9
|
+
gender: string;
|
|
10
|
+
delinquent: boolean;
|
|
11
|
+
address: {
|
|
12
|
+
line_1: string;
|
|
13
|
+
line_2: string;
|
|
14
|
+
zip_code: string;
|
|
15
|
+
city: string;
|
|
16
|
+
state: string;
|
|
17
|
+
country: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -39,34 +39,37 @@ export type PagarMeV5Orderitems = {
|
|
|
39
39
|
export type PagarMeV5OrderPaymentInfo = {
|
|
40
40
|
payment_method: 'boleto' | 'pix' | 'credit_card';
|
|
41
41
|
amount: number;
|
|
42
|
-
pix?:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
pix?: PagarMeV5OrderPaymentPixInfo;
|
|
43
|
+
boleto?: PagarMeV5OrderPaymentBoletoInfo;
|
|
44
|
+
credit_card?: PagarMeV5OrderPaymentCardInfo;
|
|
45
|
+
};
|
|
46
|
+
export type PagarMeV5OrderPaymentPixInfo = {
|
|
47
|
+
expires_at: string;
|
|
48
|
+
additional_information?: [
|
|
49
|
+
{
|
|
50
|
+
name: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
};
|
|
55
|
+
export type PagarMeV5OrderPaymentBoletoInfo = {
|
|
56
|
+
instructions: string;
|
|
57
|
+
due_at: string;
|
|
58
|
+
type: 'DM' | 'BDP';
|
|
59
|
+
document_number?: string;
|
|
60
|
+
};
|
|
61
|
+
export type PagarMeV5OrderPaymentCardInfo = {
|
|
62
|
+
installments: number;
|
|
63
|
+
statement_descriptor: string;
|
|
64
|
+
card_id: string;
|
|
65
|
+
card: {
|
|
66
|
+
cvv: string;
|
|
67
|
+
billing_address?: {
|
|
68
|
+
line_1: string;
|
|
69
|
+
zip_code: string;
|
|
70
|
+
city: string;
|
|
71
|
+
state: string;
|
|
72
|
+
country: string;
|
|
70
73
|
};
|
|
71
74
|
};
|
|
72
75
|
};
|