@infrab4a/connect 5.1.0-beta.1 → 5.1.0-beta.2
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
|
@@ -8597,7 +8597,9 @@ class PagarMeV5RequestHelper {
|
|
|
8597
8597
|
};
|
|
8598
8598
|
}
|
|
8599
8599
|
static buildItems(checkout) {
|
|
8600
|
-
return checkout.lineItems
|
|
8600
|
+
return checkout.lineItems
|
|
8601
|
+
.filter((item) => !item.isGift)
|
|
8602
|
+
.map((item) => {
|
|
8601
8603
|
return {
|
|
8602
8604
|
amount: Math.floor(item.pricePaid * 100),
|
|
8603
8605
|
description: item.name,
|
|
@@ -8624,14 +8626,14 @@ class PagarMeV5RequestHelper {
|
|
|
8624
8626
|
zip_code: checkout.shippingAddress.zip,
|
|
8625
8627
|
city: checkout.billingAddress.city,
|
|
8626
8628
|
state: checkout.billingAddress.state,
|
|
8627
|
-
country:
|
|
8629
|
+
country: 'BR',
|
|
8628
8630
|
},
|
|
8629
8631
|
};
|
|
8630
8632
|
}
|
|
8631
8633
|
static buildShipping(checkout) {
|
|
8632
8634
|
return {
|
|
8633
|
-
amount: checkout.shipping.ShippingPrice,
|
|
8634
|
-
description:
|
|
8635
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
8636
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
8635
8637
|
recipient_name: checkout.shippingAddress.recipient,
|
|
8636
8638
|
recipient_phone: checkout.user.phone,
|
|
8637
8639
|
address: {
|
|
@@ -8640,7 +8642,7 @@ class PagarMeV5RequestHelper {
|
|
|
8640
8642
|
zip_code: checkout.shippingAddress.zip,
|
|
8641
8643
|
city: checkout.shippingAddress.city,
|
|
8642
8644
|
state: checkout.shippingAddress.state,
|
|
8643
|
-
country:
|
|
8645
|
+
country: 'BR',
|
|
8644
8646
|
},
|
|
8645
8647
|
};
|
|
8646
8648
|
}
|
|
@@ -8984,6 +8986,43 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
8984
8986
|
this.credentials = credentials;
|
|
8985
8987
|
this.paymentRepository = paymentRepository;
|
|
8986
8988
|
}
|
|
8989
|
+
async pay2(payload) {
|
|
8990
|
+
try {
|
|
8991
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
8992
|
+
const { data } = await axios__default["default"]({
|
|
8993
|
+
method: 'POST',
|
|
8994
|
+
url: `${this.credentials.URL}/orders`,
|
|
8995
|
+
headers: {
|
|
8996
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
8997
|
+
'Content-Type': 'application/json',
|
|
8998
|
+
},
|
|
8999
|
+
data: payload,
|
|
9000
|
+
});
|
|
9001
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9002
|
+
if (data.charges.at(0).status !== exports.PagarMeV5OrderStatus['Em processamento'] ||
|
|
9003
|
+
data.charges.at(0).status !== exports.PagarMeV5PaymentStatus['Falha']) {
|
|
9004
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9005
|
+
// checkoutId: checkout.id,
|
|
9006
|
+
// userEmail: checkout.user.email,
|
|
9007
|
+
info: data,
|
|
9008
|
+
}));
|
|
9009
|
+
}
|
|
9010
|
+
// const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
|
|
9011
|
+
// const payment = await this.paymentRepository.create(paymentData)
|
|
9012
|
+
return data;
|
|
9013
|
+
}
|
|
9014
|
+
catch (error) {
|
|
9015
|
+
if (error instanceof axios.AxiosError) {
|
|
9016
|
+
console.error(error.message);
|
|
9017
|
+
console.error(error.response.data);
|
|
9018
|
+
}
|
|
9019
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9020
|
+
// checkoutId: checkout.id,
|
|
9021
|
+
// userEmail: checkout.user.email,
|
|
9022
|
+
info: error.response.data,
|
|
9023
|
+
});
|
|
9024
|
+
}
|
|
9025
|
+
}
|
|
8987
9026
|
async pay(checkout) {
|
|
8988
9027
|
try {
|
|
8989
9028
|
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
@@ -9011,9 +9050,10 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
9011
9050
|
return payment;
|
|
9012
9051
|
}
|
|
9013
9052
|
catch (error) {
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
|
|
9053
|
+
if (error instanceof axios.AxiosError) {
|
|
9054
|
+
console.error(error.message);
|
|
9055
|
+
console.error(error.response.data);
|
|
9056
|
+
}
|
|
9017
9057
|
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9018
9058
|
checkoutId: checkout.id,
|
|
9019
9059
|
userEmail: checkout.user.email,
|
|
@@ -9082,9 +9122,10 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9082
9122
|
if (error instanceof PaymentError) {
|
|
9083
9123
|
throw error;
|
|
9084
9124
|
}
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9125
|
+
if (error instanceof axios.AxiosError) {
|
|
9126
|
+
console.error(error.message);
|
|
9127
|
+
console.error(error.response.data);
|
|
9128
|
+
}
|
|
9088
9129
|
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9089
9130
|
}
|
|
9090
9131
|
}
|
|
@@ -9215,9 +9256,10 @@ class PagarmeV5PixAxiosAdapter {
|
|
|
9215
9256
|
return payment;
|
|
9216
9257
|
}
|
|
9217
9258
|
catch (error) {
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9259
|
+
if (error instanceof axios.AxiosError) {
|
|
9260
|
+
console.error(error.message);
|
|
9261
|
+
console.error(error.response.data);
|
|
9262
|
+
}
|
|
9221
9263
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9222
9264
|
checkoutId: checkout.id,
|
|
9223
9265
|
userEmail: checkout.user.email,
|
package/index.esm.js
CHANGED
|
@@ -8572,7 +8572,9 @@ class PagarMeV5RequestHelper {
|
|
|
8572
8572
|
};
|
|
8573
8573
|
}
|
|
8574
8574
|
static buildItems(checkout) {
|
|
8575
|
-
return checkout.lineItems
|
|
8575
|
+
return checkout.lineItems
|
|
8576
|
+
.filter((item) => !item.isGift)
|
|
8577
|
+
.map((item) => {
|
|
8576
8578
|
return {
|
|
8577
8579
|
amount: Math.floor(item.pricePaid * 100),
|
|
8578
8580
|
description: item.name,
|
|
@@ -8599,14 +8601,14 @@ class PagarMeV5RequestHelper {
|
|
|
8599
8601
|
zip_code: checkout.shippingAddress.zip,
|
|
8600
8602
|
city: checkout.billingAddress.city,
|
|
8601
8603
|
state: checkout.billingAddress.state,
|
|
8602
|
-
country:
|
|
8604
|
+
country: 'BR',
|
|
8603
8605
|
},
|
|
8604
8606
|
};
|
|
8605
8607
|
}
|
|
8606
8608
|
static buildShipping(checkout) {
|
|
8607
8609
|
return {
|
|
8608
|
-
amount: checkout.shipping.ShippingPrice,
|
|
8609
|
-
description:
|
|
8610
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
8611
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
8610
8612
|
recipient_name: checkout.shippingAddress.recipient,
|
|
8611
8613
|
recipient_phone: checkout.user.phone,
|
|
8612
8614
|
address: {
|
|
@@ -8615,7 +8617,7 @@ class PagarMeV5RequestHelper {
|
|
|
8615
8617
|
zip_code: checkout.shippingAddress.zip,
|
|
8616
8618
|
city: checkout.shippingAddress.city,
|
|
8617
8619
|
state: checkout.shippingAddress.state,
|
|
8618
|
-
country:
|
|
8620
|
+
country: 'BR',
|
|
8619
8621
|
},
|
|
8620
8622
|
};
|
|
8621
8623
|
}
|
|
@@ -8959,6 +8961,43 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
8959
8961
|
this.credentials = credentials;
|
|
8960
8962
|
this.paymentRepository = paymentRepository;
|
|
8961
8963
|
}
|
|
8964
|
+
async pay2(payload) {
|
|
8965
|
+
try {
|
|
8966
|
+
console.warn('[PAGARME BOLETO DATA TO SEND]', JSON.stringify(payload));
|
|
8967
|
+
const { data } = await axios({
|
|
8968
|
+
method: 'POST',
|
|
8969
|
+
url: `${this.credentials.URL}/orders`,
|
|
8970
|
+
headers: {
|
|
8971
|
+
Authorization: 'Basic ' + Buffer.from(`${this.credentials.API_KEY}:`).toString('base64'),
|
|
8972
|
+
'Content-Type': 'application/json',
|
|
8973
|
+
},
|
|
8974
|
+
data: payload,
|
|
8975
|
+
});
|
|
8976
|
+
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
8977
|
+
if (data.charges.at(0).status !== PagarMeV5OrderStatus['Em processamento'] ||
|
|
8978
|
+
data.charges.at(0).status !== PagarMeV5PaymentStatus['Falha']) {
|
|
8979
|
+
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8980
|
+
// checkoutId: checkout.id,
|
|
8981
|
+
// userEmail: checkout.user.email,
|
|
8982
|
+
info: data,
|
|
8983
|
+
}));
|
|
8984
|
+
}
|
|
8985
|
+
// const paymentData = PagarMeV5ResponseHelper.build(checkout, data)
|
|
8986
|
+
// const payment = await this.paymentRepository.create(paymentData)
|
|
8987
|
+
return data;
|
|
8988
|
+
}
|
|
8989
|
+
catch (error) {
|
|
8990
|
+
if (error instanceof AxiosError) {
|
|
8991
|
+
console.error(error.message);
|
|
8992
|
+
console.error(error.response.data);
|
|
8993
|
+
}
|
|
8994
|
+
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8995
|
+
// checkoutId: checkout.id,
|
|
8996
|
+
// userEmail: checkout.user.email,
|
|
8997
|
+
info: error.response.data,
|
|
8998
|
+
});
|
|
8999
|
+
}
|
|
9000
|
+
}
|
|
8962
9001
|
async pay(checkout) {
|
|
8963
9002
|
try {
|
|
8964
9003
|
const payload = PagarMeV5RequestHelper.build(checkout, 'boleto');
|
|
@@ -8986,9 +9025,10 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
8986
9025
|
return payment;
|
|
8987
9026
|
}
|
|
8988
9027
|
catch (error) {
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
9028
|
+
if (error instanceof AxiosError) {
|
|
9029
|
+
console.error(error.message);
|
|
9030
|
+
console.error(error.response.data);
|
|
9031
|
+
}
|
|
8992
9032
|
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8993
9033
|
checkoutId: checkout.id,
|
|
8994
9034
|
userEmail: checkout.user.email,
|
|
@@ -9057,9 +9097,10 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9057
9097
|
if (error instanceof PaymentError) {
|
|
9058
9098
|
throw error;
|
|
9059
9099
|
}
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9100
|
+
if (error instanceof AxiosError) {
|
|
9101
|
+
console.error(error.message);
|
|
9102
|
+
console.error(error.response.data);
|
|
9103
|
+
}
|
|
9063
9104
|
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9064
9105
|
}
|
|
9065
9106
|
}
|
|
@@ -9190,9 +9231,10 @@ class PagarmeV5PixAxiosAdapter {
|
|
|
9190
9231
|
return payment;
|
|
9191
9232
|
}
|
|
9192
9233
|
catch (error) {
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9234
|
+
if (error instanceof AxiosError) {
|
|
9235
|
+
console.error(error.message);
|
|
9236
|
+
console.error(error.response.data);
|
|
9237
|
+
}
|
|
9196
9238
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9197
9239
|
checkoutId: checkout.id,
|
|
9198
9240
|
userEmail: checkout.user.email,
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ export declare class PagarmeV5BankSlipAxiosAdapter implements PaymentProviderBan
|
|
|
6
6
|
private credentials;
|
|
7
7
|
private paymentRepository;
|
|
8
8
|
constructor(credentials: PagarmeCredentialsV5, paymentRepository: PaymentRepository);
|
|
9
|
+
pay2(payload: any): Promise<any>;
|
|
9
10
|
pay(checkout: Checkout): Promise<Payment>;
|
|
10
11
|
getBoletoTransaction(paymentId: number): Promise<PaymentTransaction>;
|
|
11
12
|
}
|