@infrab4a/connect 5.1.0-beta.0 → 5.1.0-beta.10
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 +96 -114
- package/index.esm.js +97 -115
- package/package.json +1 -1
- package/src/domain/shopping/enums/index.d.ts +1 -0
- package/src/domain/shopping/enums/transaction-payment-methods.enum.d.ts +5 -0
- package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +3 -1
- package/src/domain/shopping/models/payment-transaction.d.ts +3 -2
- package/src/domain/shopping/models/payment.d.ts +1 -1
- package/src/domain/shopping/types/pagarme-credentials.type.d.ts +9 -3
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-request.helper.d.ts +1 -1
- package/src/infra/pagarme/adapters/helpers/pagarme-v5-response.helper.d.ts +3 -2
- package/src/infra/pagarme/adapters/v4/pagarme-card-payment-axios.adapter.d.ts +2 -1
- package/src/infra/pagarme/adapters/v5/pagarmev5-card-payment-axios.adapter.d.ts +4 -2
- package/src/infra/pagarme/types/v5/pagarmev5-order-request-payload.type.d.ts +1 -0
- package/src/infra/pagarme/types/v5/pagarmev5-order-response.type.d.ts +6 -6
package/index.cjs.js
CHANGED
|
@@ -115,6 +115,13 @@ exports.PaymentProviders = void 0;
|
|
|
115
115
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
116
116
|
})(exports.PaymentProviders || (exports.PaymentProviders = {}));
|
|
117
117
|
|
|
118
|
+
exports.TransactionPaymentMethods = void 0;
|
|
119
|
+
(function (TransactionPaymentMethods) {
|
|
120
|
+
TransactionPaymentMethods["CARD"] = "credit_card";
|
|
121
|
+
TransactionPaymentMethods["BANKSLIP"] = "boleto";
|
|
122
|
+
TransactionPaymentMethods["PIX"] = "pix";
|
|
123
|
+
})(exports.TransactionPaymentMethods || (exports.TransactionPaymentMethods = {}));
|
|
124
|
+
|
|
118
125
|
class BasePaymentMethodFactory {
|
|
119
126
|
constructor(methods) {
|
|
120
127
|
this.methods = methods;
|
|
@@ -8588,20 +8595,23 @@ class PagarmePaymentOperationsHelper {
|
|
|
8588
8595
|
}
|
|
8589
8596
|
|
|
8590
8597
|
class PagarMeV5RequestHelper {
|
|
8591
|
-
static build(checkout,
|
|
8598
|
+
static build(checkout, method, card) {
|
|
8592
8599
|
return {
|
|
8593
8600
|
items: this.buildItems(checkout),
|
|
8594
8601
|
customer: this.buildCustomer(checkout),
|
|
8595
8602
|
shipping: this.buildShipping(checkout),
|
|
8596
|
-
payments: this.buildPayment(checkout,
|
|
8603
|
+
payments: this.buildPayment(checkout, method, card),
|
|
8597
8604
|
};
|
|
8598
8605
|
}
|
|
8599
8606
|
static buildItems(checkout) {
|
|
8600
|
-
return checkout.lineItems
|
|
8607
|
+
return checkout.lineItems
|
|
8608
|
+
.filter((item) => !item.isGift)
|
|
8609
|
+
.map((item) => {
|
|
8601
8610
|
return {
|
|
8602
8611
|
amount: Math.floor(item.pricePaid * 100),
|
|
8603
8612
|
description: item.name,
|
|
8604
8613
|
quantity: item.quantity,
|
|
8614
|
+
code: item.EAN,
|
|
8605
8615
|
};
|
|
8606
8616
|
});
|
|
8607
8617
|
}
|
|
@@ -8612,10 +8622,15 @@ class PagarMeV5RequestHelper {
|
|
|
8612
8622
|
type: 'individual',
|
|
8613
8623
|
document: checkout.user.cpf,
|
|
8614
8624
|
phones: {
|
|
8625
|
+
home_phone: {
|
|
8626
|
+
country_code: '55',
|
|
8627
|
+
number: checkout.user.phone.slice(2),
|
|
8628
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
8629
|
+
},
|
|
8615
8630
|
mobile_phone: {
|
|
8616
8631
|
country_code: '55',
|
|
8617
8632
|
number: checkout.user.phone.slice(2),
|
|
8618
|
-
area_code: checkout.user.phone.slice(0,
|
|
8633
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
8619
8634
|
},
|
|
8620
8635
|
},
|
|
8621
8636
|
address: {
|
|
@@ -8624,14 +8639,14 @@ class PagarMeV5RequestHelper {
|
|
|
8624
8639
|
zip_code: checkout.shippingAddress.zip,
|
|
8625
8640
|
city: checkout.billingAddress.city,
|
|
8626
8641
|
state: checkout.billingAddress.state,
|
|
8627
|
-
country:
|
|
8642
|
+
country: 'BR',
|
|
8628
8643
|
},
|
|
8629
8644
|
};
|
|
8630
8645
|
}
|
|
8631
8646
|
static buildShipping(checkout) {
|
|
8632
8647
|
return {
|
|
8633
|
-
amount: checkout.shipping.ShippingPrice,
|
|
8634
|
-
description:
|
|
8648
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
8649
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
8635
8650
|
recipient_name: checkout.shippingAddress.recipient,
|
|
8636
8651
|
recipient_phone: checkout.user.phone,
|
|
8637
8652
|
address: {
|
|
@@ -8640,22 +8655,22 @@ class PagarMeV5RequestHelper {
|
|
|
8640
8655
|
zip_code: checkout.shippingAddress.zip,
|
|
8641
8656
|
city: checkout.shippingAddress.city,
|
|
8642
8657
|
state: checkout.shippingAddress.state,
|
|
8643
|
-
country:
|
|
8658
|
+
country: 'BR',
|
|
8644
8659
|
},
|
|
8645
8660
|
};
|
|
8646
8661
|
}
|
|
8647
|
-
static buildPayment(checkout,
|
|
8662
|
+
static buildPayment(checkout, method, card) {
|
|
8648
8663
|
return [
|
|
8649
8664
|
{
|
|
8650
|
-
payment_method:
|
|
8665
|
+
payment_method: method,
|
|
8651
8666
|
amount: Math.floor(checkout.totalPrice * 100),
|
|
8652
|
-
...(
|
|
8667
|
+
...(method === 'pix' && {
|
|
8653
8668
|
pix: this.getPixOrder(),
|
|
8654
8669
|
}),
|
|
8655
|
-
...(
|
|
8670
|
+
...(method === 'boleto' && {
|
|
8656
8671
|
boleto: this.getBoletoOrder(),
|
|
8657
8672
|
}),
|
|
8658
|
-
...(
|
|
8673
|
+
...(method === 'credit_card' && {
|
|
8659
8674
|
credit_card: this.getCardOrder(checkout, card),
|
|
8660
8675
|
}),
|
|
8661
8676
|
},
|
|
@@ -8687,7 +8702,7 @@ class PagarMeV5RequestHelper {
|
|
|
8687
8702
|
}
|
|
8688
8703
|
|
|
8689
8704
|
class PagarMeV5ResponseHelper {
|
|
8690
|
-
static build(checkout, response) {
|
|
8705
|
+
static build(method, checkout, response) {
|
|
8691
8706
|
return Payment.toInstance({
|
|
8692
8707
|
createdAt: new Date(),
|
|
8693
8708
|
updatedAt: new Date(),
|
|
@@ -8696,10 +8711,10 @@ class PagarMeV5ResponseHelper {
|
|
|
8696
8711
|
totalPrice: checkout.totalPrice,
|
|
8697
8712
|
paymentProvider: exports.PaymentProviders.PAGARME,
|
|
8698
8713
|
pagarMeOrderId: response.id,
|
|
8699
|
-
transaction: this.buildPaymentTransaction(response),
|
|
8714
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
8700
8715
|
});
|
|
8701
8716
|
}
|
|
8702
|
-
static buildPaymentTransaction(response) {
|
|
8717
|
+
static buildPaymentTransaction(method, response) {
|
|
8703
8718
|
const charger = response.charges.at(0);
|
|
8704
8719
|
const transaction = charger.last_transaction;
|
|
8705
8720
|
return PaymentTransaction.toInstance({
|
|
@@ -8707,20 +8722,28 @@ class PagarMeV5ResponseHelper {
|
|
|
8707
8722
|
amount: charger.amount,
|
|
8708
8723
|
currency: charger.currency,
|
|
8709
8724
|
gateway_id: charger.gateway_id,
|
|
8710
|
-
status:
|
|
8725
|
+
status: this.getPaymentStatus(transaction.status),
|
|
8711
8726
|
payment_method: charger.payment_method,
|
|
8712
8727
|
date_created: charger.created_at,
|
|
8713
8728
|
date_updated: charger.updated_at,
|
|
8714
8729
|
paid_amount: charger.paid_amount,
|
|
8715
8730
|
paid_at: charger.paid_at,
|
|
8716
8731
|
order_id: response.id,
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
...this.
|
|
8721
|
-
...this.
|
|
8732
|
+
charger_id: charger.id,
|
|
8733
|
+
tid: charger.id,
|
|
8734
|
+
id: charger.id,
|
|
8735
|
+
...(method == exports.TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
|
|
8736
|
+
...(method == exports.TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
|
|
8737
|
+
...(method == exports.TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
|
|
8722
8738
|
});
|
|
8723
8739
|
}
|
|
8740
|
+
static getPaymentStatus(status) {
|
|
8741
|
+
if (status == exports.PagarMeV5PaymentStatus.Gerado)
|
|
8742
|
+
return exports.PagarMeV5PaymentStatus['Aguardando pagamento'];
|
|
8743
|
+
if (status == exports.PagarMeV5PaymentStatus.Capturada)
|
|
8744
|
+
return exports.PagarMeV5PaymentStatus.Pago;
|
|
8745
|
+
return status;
|
|
8746
|
+
}
|
|
8724
8747
|
static getBoletoReponse(transaction) {
|
|
8725
8748
|
return {
|
|
8726
8749
|
boleto_url: transaction.url?.toString(),
|
|
@@ -8750,11 +8773,11 @@ class PagarMeV5ResponseHelper {
|
|
|
8750
8773
|
acquirer_message: transaction.acquirer_message?.toString(),
|
|
8751
8774
|
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
8752
8775
|
installments: transaction.installments ?? null,
|
|
8753
|
-
card_holder_name: transaction.card
|
|
8754
|
-
card_last_digits: transaction.card
|
|
8755
|
-
card_first_digits: transaction.card
|
|
8756
|
-
card_brand: transaction.card
|
|
8757
|
-
card_id: transaction.card
|
|
8776
|
+
card_holder_name: transaction.card?.holder_name?.toString(),
|
|
8777
|
+
card_last_digits: transaction.card?.last_four_digits?.toString(),
|
|
8778
|
+
card_first_digits: transaction.card?.first_six_digits?.toString(),
|
|
8779
|
+
card_brand: transaction.card?.brand?.toString(),
|
|
8780
|
+
card_id: transaction.card?.id?.toString(),
|
|
8758
8781
|
};
|
|
8759
8782
|
}
|
|
8760
8783
|
}
|
|
@@ -8815,8 +8838,9 @@ class PagarmeCardAxiosAdapter {
|
|
|
8815
8838
|
});
|
|
8816
8839
|
}
|
|
8817
8840
|
}
|
|
8818
|
-
async createCardHash(bu) {
|
|
8819
|
-
const
|
|
8841
|
+
async createCardHash(bu, shop) {
|
|
8842
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
8843
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
8820
8844
|
try {
|
|
8821
8845
|
const { data } = await axios__default["default"]({
|
|
8822
8846
|
method: 'GET',
|
|
@@ -8979,7 +9003,6 @@ class PagarmePixAxiosAdapter {
|
|
|
8979
9003
|
}
|
|
8980
9004
|
}
|
|
8981
9005
|
|
|
8982
|
-
/* eslint-disable no-console */
|
|
8983
9006
|
class PagarmeV5BankSlipAxiosAdapter {
|
|
8984
9007
|
constructor(credentials, paymentRepository) {
|
|
8985
9008
|
this.credentials = credentials;
|
|
@@ -8999,25 +9022,28 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
8999
9022
|
data: payload,
|
|
9000
9023
|
});
|
|
9001
9024
|
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
9002
|
-
if (data.
|
|
9003
|
-
data.charges.at(0).status
|
|
9025
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha ||
|
|
9026
|
+
data.charges.at(0).status === exports.PagarMeV5OrderStatus.Falha ||
|
|
9027
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Gerado ||
|
|
9028
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus['Em processamento']) {
|
|
9004
9029
|
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9005
9030
|
checkoutId: checkout.id,
|
|
9006
9031
|
userEmail: checkout.user.email,
|
|
9007
|
-
info: data,
|
|
9032
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9008
9033
|
}));
|
|
9009
9034
|
}
|
|
9010
|
-
const
|
|
9011
|
-
const payment = await this.paymentRepository.create(paymentData);
|
|
9035
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
9012
9036
|
return payment;
|
|
9013
9037
|
}
|
|
9014
9038
|
catch (error) {
|
|
9015
|
-
console.
|
|
9016
|
-
|
|
9039
|
+
console.error('Full error: ', JSON.stringify(error));
|
|
9040
|
+
if (error instanceof axios.AxiosError) {
|
|
9041
|
+
console.error('Error response: ', error.response, 'error data: ', error.response?.data);
|
|
9042
|
+
}
|
|
9017
9043
|
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
9018
9044
|
checkoutId: checkout.id,
|
|
9019
9045
|
userEmail: checkout.user.email,
|
|
9020
|
-
info: error.response
|
|
9046
|
+
info: error.response?.data,
|
|
9021
9047
|
});
|
|
9022
9048
|
}
|
|
9023
9049
|
}
|
|
@@ -9032,7 +9058,7 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
9032
9058
|
},
|
|
9033
9059
|
});
|
|
9034
9060
|
const payment = await this.paymentRepository.get({
|
|
9035
|
-
id:
|
|
9061
|
+
id: data.id,
|
|
9036
9062
|
});
|
|
9037
9063
|
return payment.transaction;
|
|
9038
9064
|
}
|
|
@@ -9065,8 +9091,9 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9065
9091
|
data: payload,
|
|
9066
9092
|
});
|
|
9067
9093
|
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
9068
|
-
if (data.
|
|
9069
|
-
data.charges.at(0).status !== exports.
|
|
9094
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha ||
|
|
9095
|
+
data.charges.at(0).status !== exports.PagarMeV5OrderStatus.Pago ||
|
|
9096
|
+
data.charges.at(0).last_transaction.status !== exports.PagarMeV5PaymentStatus.Capturada) {
|
|
9070
9097
|
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
9071
9098
|
checkout,
|
|
9072
9099
|
card,
|
|
@@ -9074,60 +9101,26 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9074
9101
|
});
|
|
9075
9102
|
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
|
|
9076
9103
|
}
|
|
9077
|
-
const
|
|
9078
|
-
const payment = await this.paymentRepository.create(paymentData);
|
|
9104
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.CARD, checkout, data));
|
|
9079
9105
|
return payment;
|
|
9080
9106
|
}
|
|
9081
9107
|
catch (error) {
|
|
9082
9108
|
if (error instanceof PaymentError) {
|
|
9083
9109
|
throw error;
|
|
9084
9110
|
}
|
|
9111
|
+
console.error('Full error: ', JSON.stringify(error));
|
|
9112
|
+
if (error instanceof axios.AxiosError) {
|
|
9113
|
+
console.error('Error response: ', error.response, 'error data: ', error.response?.data);
|
|
9114
|
+
}
|
|
9085
9115
|
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9086
9116
|
}
|
|
9087
9117
|
}
|
|
9088
|
-
// Dúvidas: preciso criar um cliente? como faz na mens?
|
|
9089
9118
|
async addCard(card) {
|
|
9090
|
-
|
|
9091
|
-
const { data } = await axios__default["default"]({
|
|
9092
|
-
method: 'POST',
|
|
9093
|
-
url: `${this.credentials.URL}/cards`,
|
|
9094
|
-
data: {
|
|
9095
|
-
api_key: this.credentials.API_KEY,
|
|
9096
|
-
card_number: card.number,
|
|
9097
|
-
card_expiration_date: card.expirationDate.replace('/', ''),
|
|
9098
|
-
card_holder_name: card.name,
|
|
9099
|
-
card_cvv: card.cvv,
|
|
9100
|
-
// number: '4000000000000010',
|
|
9101
|
-
// holder_name: 'Tony Stark',
|
|
9102
|
-
// holder_document: '93095135270',
|
|
9103
|
-
// exp_month: 1,
|
|
9104
|
-
// exp_year: 30,
|
|
9105
|
-
// cvv: '351',
|
|
9106
|
-
// brand: 'Mastercard',
|
|
9107
|
-
// label: 'Sua bandeira',
|
|
9108
|
-
// billing_address: {
|
|
9109
|
-
// line_1: '375, Av. General Osorio, Centro',
|
|
9110
|
-
// line_2: '7º Andar',
|
|
9111
|
-
// zip_code: '220000111',
|
|
9112
|
-
// city: 'Rio de Janeiro',
|
|
9113
|
-
// state: 'RJ',
|
|
9114
|
-
// country: 'BR',
|
|
9115
|
-
// },
|
|
9116
|
-
// options: {
|
|
9117
|
-
// verify_card: true,
|
|
9118
|
-
// },
|
|
9119
|
-
},
|
|
9120
|
-
});
|
|
9121
|
-
return data;
|
|
9122
|
-
}
|
|
9123
|
-
catch (error) {
|
|
9124
|
-
throw new BusinessError('Houve uma falha adicionar o cartão', {
|
|
9125
|
-
info: error.response.data,
|
|
9126
|
-
});
|
|
9127
|
-
}
|
|
9119
|
+
return;
|
|
9128
9120
|
}
|
|
9129
|
-
async createCardHash(bu) {
|
|
9130
|
-
const
|
|
9121
|
+
async createCardHash(bu, shop) {
|
|
9122
|
+
const credentials = shop && shop == exports.Shops.MENSMARKET ? this.credentials[exports.Shops.MENSMARKET] : this.credentials[exports.Shops.GLAMSHOP];
|
|
9123
|
+
const key = bu === exports.BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
9131
9124
|
try {
|
|
9132
9125
|
const { data } = await axios__default["default"]({
|
|
9133
9126
|
method: 'GET',
|
|
@@ -9147,11 +9140,11 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9147
9140
|
});
|
|
9148
9141
|
}
|
|
9149
9142
|
}
|
|
9150
|
-
async getCardByToken(
|
|
9143
|
+
async getCardByToken(customerId, token) {
|
|
9151
9144
|
try {
|
|
9152
9145
|
const { data } = await axios__default["default"]({
|
|
9153
|
-
method: '
|
|
9154
|
-
url: `${this.credentials.URL}/cards/${
|
|
9146
|
+
method: 'GET',
|
|
9147
|
+
url: `${this.credentials.URL}/cards/${token}`,
|
|
9155
9148
|
data: {
|
|
9156
9149
|
api_key: this.credentials.API_KEY,
|
|
9157
9150
|
},
|
|
@@ -9159,36 +9152,16 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9159
9152
|
return data;
|
|
9160
9153
|
}
|
|
9161
9154
|
catch (error) {
|
|
9162
|
-
throw new BusinessError('Houve uma falha buscar o cartão com id: ' +
|
|
9155
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
|
|
9163
9156
|
info: error.response.data,
|
|
9164
9157
|
});
|
|
9165
9158
|
}
|
|
9166
9159
|
}
|
|
9167
9160
|
async createTransaction(info) {
|
|
9168
|
-
|
|
9169
|
-
const { data } = await axios__default["default"]({
|
|
9170
|
-
method: 'POST',
|
|
9171
|
-
url: `${this.credentials.URL}/transactions`,
|
|
9172
|
-
headers: {
|
|
9173
|
-
Authorization: 'Basic ' + Buffer.from(this.credentials.API_KEY).toString('base64'),
|
|
9174
|
-
'Content-Type': 'application/json',
|
|
9175
|
-
},
|
|
9176
|
-
data: {
|
|
9177
|
-
...info,
|
|
9178
|
-
api_key: this.credentials.API_KEY,
|
|
9179
|
-
},
|
|
9180
|
-
});
|
|
9181
|
-
return data;
|
|
9182
|
-
}
|
|
9183
|
-
catch (error) {
|
|
9184
|
-
throw new BusinessError('Houve uma falha ao criar a transação', {
|
|
9185
|
-
info: error.response.data,
|
|
9186
|
-
});
|
|
9187
|
-
}
|
|
9161
|
+
return;
|
|
9188
9162
|
}
|
|
9189
9163
|
}
|
|
9190
9164
|
|
|
9191
|
-
/* eslint-disable no-console */
|
|
9192
9165
|
class PagarmeV5PixAxiosAdapter {
|
|
9193
9166
|
constructor(credentials, paymentRepository) {
|
|
9194
9167
|
this.credentials = credentials;
|
|
@@ -9197,7 +9170,7 @@ class PagarmeV5PixAxiosAdapter {
|
|
|
9197
9170
|
async pay(checkout) {
|
|
9198
9171
|
try {
|
|
9199
9172
|
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
9200
|
-
console.warn('[PAGARME PIX DATA TO SEND]', payload);
|
|
9173
|
+
console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
|
|
9201
9174
|
const { data } = await axios__default["default"]({
|
|
9202
9175
|
method: 'POST',
|
|
9203
9176
|
url: `${this.credentials.URL}/orders`,
|
|
@@ -9208,13 +9181,22 @@ class PagarmeV5PixAxiosAdapter {
|
|
|
9208
9181
|
data: payload,
|
|
9209
9182
|
});
|
|
9210
9183
|
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
9211
|
-
|
|
9212
|
-
|
|
9184
|
+
if (data.status == exports.PagarMeV5OrderStatus.Falha || data.status == exports.PagarMeV5OrderStatus.Cancelado) {
|
|
9185
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9186
|
+
checkoutId: checkout.id,
|
|
9187
|
+
userEmail: checkout.user.email,
|
|
9188
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9189
|
+
});
|
|
9190
|
+
}
|
|
9191
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(exports.TransactionPaymentMethods.PIX, checkout, data));
|
|
9213
9192
|
return payment;
|
|
9214
9193
|
}
|
|
9215
9194
|
catch (error) {
|
|
9216
|
-
console.
|
|
9217
|
-
|
|
9195
|
+
console.error('Full error: ', JSON.stringify(error));
|
|
9196
|
+
if (error instanceof axios.AxiosError) {
|
|
9197
|
+
console.error('Error: ', error.message);
|
|
9198
|
+
console.error('Error response: ', error.response, 'error data: ', error.response?.data);
|
|
9199
|
+
}
|
|
9218
9200
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9219
9201
|
checkoutId: checkout.id,
|
|
9220
9202
|
userEmail: checkout.user.email,
|
package/index.esm.js
CHANGED
|
@@ -90,6 +90,13 @@ var PaymentProviders;
|
|
|
90
90
|
PaymentProviders["GLAMPOINTS"] = "glampoints";
|
|
91
91
|
})(PaymentProviders || (PaymentProviders = {}));
|
|
92
92
|
|
|
93
|
+
var TransactionPaymentMethods;
|
|
94
|
+
(function (TransactionPaymentMethods) {
|
|
95
|
+
TransactionPaymentMethods["CARD"] = "credit_card";
|
|
96
|
+
TransactionPaymentMethods["BANKSLIP"] = "boleto";
|
|
97
|
+
TransactionPaymentMethods["PIX"] = "pix";
|
|
98
|
+
})(TransactionPaymentMethods || (TransactionPaymentMethods = {}));
|
|
99
|
+
|
|
93
100
|
class BasePaymentMethodFactory {
|
|
94
101
|
constructor(methods) {
|
|
95
102
|
this.methods = methods;
|
|
@@ -8563,20 +8570,23 @@ class PagarmePaymentOperationsHelper {
|
|
|
8563
8570
|
}
|
|
8564
8571
|
|
|
8565
8572
|
class PagarMeV5RequestHelper {
|
|
8566
|
-
static build(checkout,
|
|
8573
|
+
static build(checkout, method, card) {
|
|
8567
8574
|
return {
|
|
8568
8575
|
items: this.buildItems(checkout),
|
|
8569
8576
|
customer: this.buildCustomer(checkout),
|
|
8570
8577
|
shipping: this.buildShipping(checkout),
|
|
8571
|
-
payments: this.buildPayment(checkout,
|
|
8578
|
+
payments: this.buildPayment(checkout, method, card),
|
|
8572
8579
|
};
|
|
8573
8580
|
}
|
|
8574
8581
|
static buildItems(checkout) {
|
|
8575
|
-
return checkout.lineItems
|
|
8582
|
+
return checkout.lineItems
|
|
8583
|
+
.filter((item) => !item.isGift)
|
|
8584
|
+
.map((item) => {
|
|
8576
8585
|
return {
|
|
8577
8586
|
amount: Math.floor(item.pricePaid * 100),
|
|
8578
8587
|
description: item.name,
|
|
8579
8588
|
quantity: item.quantity,
|
|
8589
|
+
code: item.EAN,
|
|
8580
8590
|
};
|
|
8581
8591
|
});
|
|
8582
8592
|
}
|
|
@@ -8587,10 +8597,15 @@ class PagarMeV5RequestHelper {
|
|
|
8587
8597
|
type: 'individual',
|
|
8588
8598
|
document: checkout.user.cpf,
|
|
8589
8599
|
phones: {
|
|
8600
|
+
home_phone: {
|
|
8601
|
+
country_code: '55',
|
|
8602
|
+
number: checkout.user.phone.slice(2),
|
|
8603
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
8604
|
+
},
|
|
8590
8605
|
mobile_phone: {
|
|
8591
8606
|
country_code: '55',
|
|
8592
8607
|
number: checkout.user.phone.slice(2),
|
|
8593
|
-
area_code: checkout.user.phone.slice(0,
|
|
8608
|
+
area_code: checkout.user.phone.slice(0, 2),
|
|
8594
8609
|
},
|
|
8595
8610
|
},
|
|
8596
8611
|
address: {
|
|
@@ -8599,14 +8614,14 @@ class PagarMeV5RequestHelper {
|
|
|
8599
8614
|
zip_code: checkout.shippingAddress.zip,
|
|
8600
8615
|
city: checkout.billingAddress.city,
|
|
8601
8616
|
state: checkout.billingAddress.state,
|
|
8602
|
-
country:
|
|
8617
|
+
country: 'BR',
|
|
8603
8618
|
},
|
|
8604
8619
|
};
|
|
8605
8620
|
}
|
|
8606
8621
|
static buildShipping(checkout) {
|
|
8607
8622
|
return {
|
|
8608
|
-
amount: checkout.shipping.ShippingPrice,
|
|
8609
|
-
description:
|
|
8623
|
+
amount: Math.floor(checkout.shipping.ShippingPrice * 100),
|
|
8624
|
+
description: `${checkout.shipping.ShippingCompanyName} - ${checkout.shipping.description}`,
|
|
8610
8625
|
recipient_name: checkout.shippingAddress.recipient,
|
|
8611
8626
|
recipient_phone: checkout.user.phone,
|
|
8612
8627
|
address: {
|
|
@@ -8615,22 +8630,22 @@ class PagarMeV5RequestHelper {
|
|
|
8615
8630
|
zip_code: checkout.shippingAddress.zip,
|
|
8616
8631
|
city: checkout.shippingAddress.city,
|
|
8617
8632
|
state: checkout.shippingAddress.state,
|
|
8618
|
-
country:
|
|
8633
|
+
country: 'BR',
|
|
8619
8634
|
},
|
|
8620
8635
|
};
|
|
8621
8636
|
}
|
|
8622
|
-
static buildPayment(checkout,
|
|
8637
|
+
static buildPayment(checkout, method, card) {
|
|
8623
8638
|
return [
|
|
8624
8639
|
{
|
|
8625
|
-
payment_method:
|
|
8640
|
+
payment_method: method,
|
|
8626
8641
|
amount: Math.floor(checkout.totalPrice * 100),
|
|
8627
|
-
...(
|
|
8642
|
+
...(method === 'pix' && {
|
|
8628
8643
|
pix: this.getPixOrder(),
|
|
8629
8644
|
}),
|
|
8630
|
-
...(
|
|
8645
|
+
...(method === 'boleto' && {
|
|
8631
8646
|
boleto: this.getBoletoOrder(),
|
|
8632
8647
|
}),
|
|
8633
|
-
...(
|
|
8648
|
+
...(method === 'credit_card' && {
|
|
8634
8649
|
credit_card: this.getCardOrder(checkout, card),
|
|
8635
8650
|
}),
|
|
8636
8651
|
},
|
|
@@ -8662,7 +8677,7 @@ class PagarMeV5RequestHelper {
|
|
|
8662
8677
|
}
|
|
8663
8678
|
|
|
8664
8679
|
class PagarMeV5ResponseHelper {
|
|
8665
|
-
static build(checkout, response) {
|
|
8680
|
+
static build(method, checkout, response) {
|
|
8666
8681
|
return Payment.toInstance({
|
|
8667
8682
|
createdAt: new Date(),
|
|
8668
8683
|
updatedAt: new Date(),
|
|
@@ -8671,10 +8686,10 @@ class PagarMeV5ResponseHelper {
|
|
|
8671
8686
|
totalPrice: checkout.totalPrice,
|
|
8672
8687
|
paymentProvider: PaymentProviders.PAGARME,
|
|
8673
8688
|
pagarMeOrderId: response.id,
|
|
8674
|
-
transaction: this.buildPaymentTransaction(response),
|
|
8689
|
+
transaction: this.buildPaymentTransaction(method, response),
|
|
8675
8690
|
});
|
|
8676
8691
|
}
|
|
8677
|
-
static buildPaymentTransaction(response) {
|
|
8692
|
+
static buildPaymentTransaction(method, response) {
|
|
8678
8693
|
const charger = response.charges.at(0);
|
|
8679
8694
|
const transaction = charger.last_transaction;
|
|
8680
8695
|
return PaymentTransaction.toInstance({
|
|
@@ -8682,20 +8697,28 @@ class PagarMeV5ResponseHelper {
|
|
|
8682
8697
|
amount: charger.amount,
|
|
8683
8698
|
currency: charger.currency,
|
|
8684
8699
|
gateway_id: charger.gateway_id,
|
|
8685
|
-
status:
|
|
8700
|
+
status: this.getPaymentStatus(transaction.status),
|
|
8686
8701
|
payment_method: charger.payment_method,
|
|
8687
8702
|
date_created: charger.created_at,
|
|
8688
8703
|
date_updated: charger.updated_at,
|
|
8689
8704
|
paid_amount: charger.paid_amount,
|
|
8690
8705
|
paid_at: charger.paid_at,
|
|
8691
8706
|
order_id: response.id,
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
...this.
|
|
8696
|
-
...this.
|
|
8707
|
+
charger_id: charger.id,
|
|
8708
|
+
tid: charger.id,
|
|
8709
|
+
id: charger.id,
|
|
8710
|
+
...(method == TransactionPaymentMethods.BANKSLIP && this.getBoletoReponse(transaction)),
|
|
8711
|
+
...(method == TransactionPaymentMethods.PIX && this.getPixReponse(transaction)),
|
|
8712
|
+
...(method == TransactionPaymentMethods.CARD && this.getCardReponse(transaction)),
|
|
8697
8713
|
});
|
|
8698
8714
|
}
|
|
8715
|
+
static getPaymentStatus(status) {
|
|
8716
|
+
if (status == PagarMeV5PaymentStatus.Gerado)
|
|
8717
|
+
return PagarMeV5PaymentStatus['Aguardando pagamento'];
|
|
8718
|
+
if (status == PagarMeV5PaymentStatus.Capturada)
|
|
8719
|
+
return PagarMeV5PaymentStatus.Pago;
|
|
8720
|
+
return status;
|
|
8721
|
+
}
|
|
8699
8722
|
static getBoletoReponse(transaction) {
|
|
8700
8723
|
return {
|
|
8701
8724
|
boleto_url: transaction.url?.toString(),
|
|
@@ -8725,11 +8748,11 @@ class PagarMeV5ResponseHelper {
|
|
|
8725
8748
|
acquirer_message: transaction.acquirer_message?.toString(),
|
|
8726
8749
|
acquirer_return_code: transaction.acquirer_return_code?.toString(),
|
|
8727
8750
|
installments: transaction.installments ?? null,
|
|
8728
|
-
card_holder_name: transaction.card
|
|
8729
|
-
card_last_digits: transaction.card
|
|
8730
|
-
card_first_digits: transaction.card
|
|
8731
|
-
card_brand: transaction.card
|
|
8732
|
-
card_id: transaction.card
|
|
8751
|
+
card_holder_name: transaction.card?.holder_name?.toString(),
|
|
8752
|
+
card_last_digits: transaction.card?.last_four_digits?.toString(),
|
|
8753
|
+
card_first_digits: transaction.card?.first_six_digits?.toString(),
|
|
8754
|
+
card_brand: transaction.card?.brand?.toString(),
|
|
8755
|
+
card_id: transaction.card?.id?.toString(),
|
|
8733
8756
|
};
|
|
8734
8757
|
}
|
|
8735
8758
|
}
|
|
@@ -8790,8 +8813,9 @@ class PagarmeCardAxiosAdapter {
|
|
|
8790
8813
|
});
|
|
8791
8814
|
}
|
|
8792
8815
|
}
|
|
8793
|
-
async createCardHash(bu) {
|
|
8794
|
-
const
|
|
8816
|
+
async createCardHash(bu, shop) {
|
|
8817
|
+
const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
|
|
8818
|
+
const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
8795
8819
|
try {
|
|
8796
8820
|
const { data } = await axios({
|
|
8797
8821
|
method: 'GET',
|
|
@@ -8954,7 +8978,6 @@ class PagarmePixAxiosAdapter {
|
|
|
8954
8978
|
}
|
|
8955
8979
|
}
|
|
8956
8980
|
|
|
8957
|
-
/* eslint-disable no-console */
|
|
8958
8981
|
class PagarmeV5BankSlipAxiosAdapter {
|
|
8959
8982
|
constructor(credentials, paymentRepository) {
|
|
8960
8983
|
this.credentials = credentials;
|
|
@@ -8974,25 +8997,28 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
8974
8997
|
data: payload,
|
|
8975
8998
|
});
|
|
8976
8999
|
console.warn('[PAGARME RESPONSE BOLETO DATA]', JSON.stringify(data));
|
|
8977
|
-
if (data.
|
|
8978
|
-
data.charges.at(0).status
|
|
9000
|
+
if (data.status == PagarMeV5OrderStatus.Falha ||
|
|
9001
|
+
data.charges.at(0).status === PagarMeV5OrderStatus.Falha ||
|
|
9002
|
+
data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Gerado ||
|
|
9003
|
+
data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus['Em processamento']) {
|
|
8979
9004
|
return Promise.reject(new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8980
9005
|
checkoutId: checkout.id,
|
|
8981
9006
|
userEmail: checkout.user.email,
|
|
8982
|
-
info: data,
|
|
9007
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
8983
9008
|
}));
|
|
8984
9009
|
}
|
|
8985
|
-
const
|
|
8986
|
-
const payment = await this.paymentRepository.create(paymentData);
|
|
9010
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.BANKSLIP, checkout, data));
|
|
8987
9011
|
return payment;
|
|
8988
9012
|
}
|
|
8989
9013
|
catch (error) {
|
|
8990
|
-
console.
|
|
8991
|
-
|
|
9014
|
+
console.error('Full error: ', JSON.stringify(error));
|
|
9015
|
+
if (error instanceof AxiosError) {
|
|
9016
|
+
console.error('Error response: ', error.response, 'error data: ', error.response?.data);
|
|
9017
|
+
}
|
|
8992
9018
|
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
8993
9019
|
checkoutId: checkout.id,
|
|
8994
9020
|
userEmail: checkout.user.email,
|
|
8995
|
-
info: error.response
|
|
9021
|
+
info: error.response?.data,
|
|
8996
9022
|
});
|
|
8997
9023
|
}
|
|
8998
9024
|
}
|
|
@@ -9007,7 +9033,7 @@ class PagarmeV5BankSlipAxiosAdapter {
|
|
|
9007
9033
|
},
|
|
9008
9034
|
});
|
|
9009
9035
|
const payment = await this.paymentRepository.get({
|
|
9010
|
-
id:
|
|
9036
|
+
id: data.id,
|
|
9011
9037
|
});
|
|
9012
9038
|
return payment.transaction;
|
|
9013
9039
|
}
|
|
@@ -9040,8 +9066,9 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9040
9066
|
data: payload,
|
|
9041
9067
|
});
|
|
9042
9068
|
console.warn('[RESPONSE PAGARME CARD DATA]', JSON.stringify(data));
|
|
9043
|
-
if (data.
|
|
9044
|
-
data.charges.at(0).status !==
|
|
9069
|
+
if (data.status == PagarMeV5OrderStatus.Falha ||
|
|
9070
|
+
data.charges.at(0).status !== PagarMeV5OrderStatus.Pago ||
|
|
9071
|
+
data.charges.at(0).last_transaction.status !== PagarMeV5PaymentStatus.Capturada) {
|
|
9045
9072
|
await PagarmeBlockedOrderHelper.createBlockedOrderForUnauthorizedCard({
|
|
9046
9073
|
checkout,
|
|
9047
9074
|
card,
|
|
@@ -9049,60 +9076,26 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9049
9076
|
});
|
|
9050
9077
|
throw PagarmeBlockedOrderHelper.createPaymentError(checkout, data);
|
|
9051
9078
|
}
|
|
9052
|
-
const
|
|
9053
|
-
const payment = await this.paymentRepository.create(paymentData);
|
|
9079
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.CARD, checkout, data));
|
|
9054
9080
|
return payment;
|
|
9055
9081
|
}
|
|
9056
9082
|
catch (error) {
|
|
9057
9083
|
if (error instanceof PaymentError) {
|
|
9058
9084
|
throw error;
|
|
9059
9085
|
}
|
|
9086
|
+
console.error('Full error: ', JSON.stringify(error));
|
|
9087
|
+
if (error instanceof AxiosError) {
|
|
9088
|
+
console.error('Error response: ', error.response, 'error data: ', error.response?.data);
|
|
9089
|
+
}
|
|
9060
9090
|
throw PagarmeBlockedOrderHelper.createGenericPaymentError(checkout, error.response?.data);
|
|
9061
9091
|
}
|
|
9062
9092
|
}
|
|
9063
|
-
// Dúvidas: preciso criar um cliente? como faz na mens?
|
|
9064
9093
|
async addCard(card) {
|
|
9065
|
-
|
|
9066
|
-
const { data } = await axios({
|
|
9067
|
-
method: 'POST',
|
|
9068
|
-
url: `${this.credentials.URL}/cards`,
|
|
9069
|
-
data: {
|
|
9070
|
-
api_key: this.credentials.API_KEY,
|
|
9071
|
-
card_number: card.number,
|
|
9072
|
-
card_expiration_date: card.expirationDate.replace('/', ''),
|
|
9073
|
-
card_holder_name: card.name,
|
|
9074
|
-
card_cvv: card.cvv,
|
|
9075
|
-
// number: '4000000000000010',
|
|
9076
|
-
// holder_name: 'Tony Stark',
|
|
9077
|
-
// holder_document: '93095135270',
|
|
9078
|
-
// exp_month: 1,
|
|
9079
|
-
// exp_year: 30,
|
|
9080
|
-
// cvv: '351',
|
|
9081
|
-
// brand: 'Mastercard',
|
|
9082
|
-
// label: 'Sua bandeira',
|
|
9083
|
-
// billing_address: {
|
|
9084
|
-
// line_1: '375, Av. General Osorio, Centro',
|
|
9085
|
-
// line_2: '7º Andar',
|
|
9086
|
-
// zip_code: '220000111',
|
|
9087
|
-
// city: 'Rio de Janeiro',
|
|
9088
|
-
// state: 'RJ',
|
|
9089
|
-
// country: 'BR',
|
|
9090
|
-
// },
|
|
9091
|
-
// options: {
|
|
9092
|
-
// verify_card: true,
|
|
9093
|
-
// },
|
|
9094
|
-
},
|
|
9095
|
-
});
|
|
9096
|
-
return data;
|
|
9097
|
-
}
|
|
9098
|
-
catch (error) {
|
|
9099
|
-
throw new BusinessError('Houve uma falha adicionar o cartão', {
|
|
9100
|
-
info: error.response.data,
|
|
9101
|
-
});
|
|
9102
|
-
}
|
|
9094
|
+
return;
|
|
9103
9095
|
}
|
|
9104
|
-
async createCardHash(bu) {
|
|
9105
|
-
const
|
|
9096
|
+
async createCardHash(bu, shop) {
|
|
9097
|
+
const credentials = shop && shop == Shops.MENSMARKET ? this.credentials[Shops.MENSMARKET] : this.credentials[Shops.GLAMSHOP];
|
|
9098
|
+
const key = bu === BusinessUnitEnum.SHOP ? credentials.SHOP_API_KEY : credentials.SUBSCRIPTION_API_KEY;
|
|
9106
9099
|
try {
|
|
9107
9100
|
const { data } = await axios({
|
|
9108
9101
|
method: 'GET',
|
|
@@ -9122,11 +9115,11 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9122
9115
|
});
|
|
9123
9116
|
}
|
|
9124
9117
|
}
|
|
9125
|
-
async getCardByToken(
|
|
9118
|
+
async getCardByToken(customerId, token) {
|
|
9126
9119
|
try {
|
|
9127
9120
|
const { data } = await axios({
|
|
9128
|
-
method: '
|
|
9129
|
-
url: `${this.credentials.URL}/cards/${
|
|
9121
|
+
method: 'GET',
|
|
9122
|
+
url: `${this.credentials.URL}/cards/${token}`,
|
|
9130
9123
|
data: {
|
|
9131
9124
|
api_key: this.credentials.API_KEY,
|
|
9132
9125
|
},
|
|
@@ -9134,36 +9127,16 @@ class PagarmeV5CardAxiosAdapter {
|
|
|
9134
9127
|
return data;
|
|
9135
9128
|
}
|
|
9136
9129
|
catch (error) {
|
|
9137
|
-
throw new BusinessError('Houve uma falha buscar o cartão com id: ' +
|
|
9130
|
+
throw new BusinessError('Houve uma falha buscar o cartão com id: ' + token, {
|
|
9138
9131
|
info: error.response.data,
|
|
9139
9132
|
});
|
|
9140
9133
|
}
|
|
9141
9134
|
}
|
|
9142
9135
|
async createTransaction(info) {
|
|
9143
|
-
|
|
9144
|
-
const { data } = await axios({
|
|
9145
|
-
method: 'POST',
|
|
9146
|
-
url: `${this.credentials.URL}/transactions`,
|
|
9147
|
-
headers: {
|
|
9148
|
-
Authorization: 'Basic ' + Buffer.from(this.credentials.API_KEY).toString('base64'),
|
|
9149
|
-
'Content-Type': 'application/json',
|
|
9150
|
-
},
|
|
9151
|
-
data: {
|
|
9152
|
-
...info,
|
|
9153
|
-
api_key: this.credentials.API_KEY,
|
|
9154
|
-
},
|
|
9155
|
-
});
|
|
9156
|
-
return data;
|
|
9157
|
-
}
|
|
9158
|
-
catch (error) {
|
|
9159
|
-
throw new BusinessError('Houve uma falha ao criar a transação', {
|
|
9160
|
-
info: error.response.data,
|
|
9161
|
-
});
|
|
9162
|
-
}
|
|
9136
|
+
return;
|
|
9163
9137
|
}
|
|
9164
9138
|
}
|
|
9165
9139
|
|
|
9166
|
-
/* eslint-disable no-console */
|
|
9167
9140
|
class PagarmeV5PixAxiosAdapter {
|
|
9168
9141
|
constructor(credentials, paymentRepository) {
|
|
9169
9142
|
this.credentials = credentials;
|
|
@@ -9172,7 +9145,7 @@ class PagarmeV5PixAxiosAdapter {
|
|
|
9172
9145
|
async pay(checkout) {
|
|
9173
9146
|
try {
|
|
9174
9147
|
const payload = PagarMeV5RequestHelper.build(checkout, 'pix');
|
|
9175
|
-
console.warn('[PAGARME PIX DATA TO SEND]', payload);
|
|
9148
|
+
console.warn('[PAGARME PIX DATA TO SEND]', JSON.stringify(payload));
|
|
9176
9149
|
const { data } = await axios({
|
|
9177
9150
|
method: 'POST',
|
|
9178
9151
|
url: `${this.credentials.URL}/orders`,
|
|
@@ -9183,13 +9156,22 @@ class PagarmeV5PixAxiosAdapter {
|
|
|
9183
9156
|
data: payload,
|
|
9184
9157
|
});
|
|
9185
9158
|
console.warn('[RESPONSE PAGARME PIX DATA]', JSON.stringify(data));
|
|
9186
|
-
|
|
9187
|
-
|
|
9159
|
+
if (data.status == PagarMeV5OrderStatus.Falha || data.status == PagarMeV5OrderStatus.Cancelado) {
|
|
9160
|
+
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9161
|
+
checkoutId: checkout.id,
|
|
9162
|
+
userEmail: checkout.user.email,
|
|
9163
|
+
info: data.charges.at(0).last_transaction?.gateway_response,
|
|
9164
|
+
});
|
|
9165
|
+
}
|
|
9166
|
+
const payment = await this.paymentRepository.create(PagarMeV5ResponseHelper.build(TransactionPaymentMethods.PIX, checkout, data));
|
|
9188
9167
|
return payment;
|
|
9189
9168
|
}
|
|
9190
9169
|
catch (error) {
|
|
9191
|
-
console.
|
|
9192
|
-
|
|
9170
|
+
console.error('Full error: ', JSON.stringify(error));
|
|
9171
|
+
if (error instanceof AxiosError) {
|
|
9172
|
+
console.error('Error: ', error.message);
|
|
9173
|
+
console.error('Error response: ', error.response, 'error data: ', error.response?.data);
|
|
9174
|
+
}
|
|
9193
9175
|
throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
|
|
9194
9176
|
checkoutId: checkout.id,
|
|
9195
9177
|
userEmail: checkout.user.email,
|
|
@@ -9352,4 +9334,4 @@ class ProductsVertexSearch {
|
|
|
9352
9334
|
}
|
|
9353
9335
|
}
|
|
9354
9336
|
|
|
9355
|
-
export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
|
9337
|
+
export { AccessoryImportances, Address, AdyenCardAxiosAdapter, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BrandEquityOptions, BusinessError, BusinessUnitEnum, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, CategoryProduct, CategoryProductHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategories, CouponCategory, CouponChannels, CouponFirestoreRepository, CouponOldCategories, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, Group, GroupFirestoreRepository, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, ObsEmitter, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderBlockedType, OrderFirestoreRepository, OrderStatus, PagarMeV5OrderStatus, PagarMeV5PaymentStatus, PagarmeBankSlipAxiosAdapter, PagarmeCardAxiosAdapter, PagarmePaymentMethodFactory, PagarmePaymentStatus, PagarmePixAxiosAdapter, PagarmeV5BankSlipAxiosAdapter, PagarmeV5CardAxiosAdapter, PagarmeV5PixAxiosAdapter, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductErrors, ProductErrorsHasuraGraphQL, ProductErrorsHasuraGraphQLRepository, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductLabelEnum, ProductReview, ProductReviewHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RestCacheAdapter, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, TransactionPaymentMethods, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, deserialize, getClass, is, isDebuggable, isUUID, parseDateTime, registerClass, resolveClass, serialize, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Shops } from '../../catalog';
|
|
1
2
|
import { BusinessUnitEnum } from '../enums';
|
|
2
3
|
import { PaymentTransaction } from '../models';
|
|
3
4
|
import { Checkout } from '../models/checkout';
|
|
@@ -8,6 +9,7 @@ export interface PaymentProviderCard<Card extends BaseCard = BaseCard> {
|
|
|
8
9
|
pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
|
|
9
10
|
addCard(card: CardInfo): Promise<Card>;
|
|
10
11
|
getCardByToken(token: string): Promise<Card>;
|
|
11
|
-
|
|
12
|
+
getCardByToken(customerId: string, token: string): Promise<Card>;
|
|
13
|
+
createCardHash<T>(bu: BusinessUnitEnum, shop: Shops, card?: CardInfo): Promise<string | T>;
|
|
12
14
|
createTransaction(info: any): Promise<PaymentTransaction>;
|
|
13
15
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseModel } from '../../generic/model/base.model';
|
|
2
2
|
import { PaymentBilling, PaymentCard, PaymentCustomer, PaymentItem, PaymentShipping } from './types';
|
|
3
3
|
export declare class PaymentTransaction extends BaseModel<PaymentTransaction> {
|
|
4
|
-
id?:
|
|
4
|
+
id?: string;
|
|
5
5
|
object?: string;
|
|
6
6
|
status?: string;
|
|
7
|
-
tid?:
|
|
7
|
+
tid?: string;
|
|
8
8
|
gateway_id?: string;
|
|
9
9
|
nsu?: number;
|
|
10
10
|
amount: number;
|
|
@@ -72,6 +72,7 @@ export declare class PaymentTransaction extends BaseModel<PaymentTransaction> {
|
|
|
72
72
|
fraudCovered?: boolean;
|
|
73
73
|
fraud_reimbursed?: string;
|
|
74
74
|
order_id?: string;
|
|
75
|
+
charger_id?: string;
|
|
75
76
|
risk_level?: string;
|
|
76
77
|
receipt_url?: string;
|
|
77
78
|
private_label?: string;
|
|
@@ -2,7 +2,7 @@ import { BaseModel, GenericIdentifier } from '../../generic/model/base.model';
|
|
|
2
2
|
import { PaymentProvider } from '../types';
|
|
3
3
|
import { PaymentTransaction } from './payment-transaction';
|
|
4
4
|
export declare class Payment extends BaseModel<Payment> {
|
|
5
|
-
id: number;
|
|
5
|
+
id: string | number;
|
|
6
6
|
checkoutId: string;
|
|
7
7
|
orderId?: string;
|
|
8
8
|
pagarMeOrderId?: string;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export type PagarmeCredentials = {
|
|
2
2
|
URL: string;
|
|
3
|
-
URL_POSTBACK
|
|
3
|
+
URL_POSTBACK?: string;
|
|
4
4
|
API_KEY: string;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Glamshop: {
|
|
6
|
+
SUBSCRIPTION_API_KEY: string;
|
|
7
|
+
SHOP_API_KEY: string;
|
|
8
|
+
};
|
|
9
|
+
mensmarket: {
|
|
10
|
+
SUBSCRIPTION_API_KEY: string;
|
|
11
|
+
SHOP_API_KEY: string;
|
|
12
|
+
};
|
|
7
13
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Checkout, PaymentCardInfo } from '../../../../domain';
|
|
2
2
|
import { PagarMeV5RequestPayload } from '../../types';
|
|
3
3
|
export declare class PagarMeV5RequestHelper {
|
|
4
|
-
static build(checkout: Checkout,
|
|
4
|
+
static build(checkout: Checkout, method: 'pix' | 'boleto' | 'credit_card', card?: PaymentCardInfo): PagarMeV5RequestPayload;
|
|
5
5
|
private static buildItems;
|
|
6
6
|
private static buildCustomer;
|
|
7
7
|
private static buildShipping;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Checkout, Payment } from '../../../../domain';
|
|
1
|
+
import { Checkout, Payment, TransactionPaymentMethods } from '../../../../domain';
|
|
2
2
|
import { PagarMeV5Response } from '../../types';
|
|
3
3
|
export declare class PagarMeV5ResponseHelper {
|
|
4
|
-
static build(checkout: Checkout, response: PagarMeV5Response): Payment;
|
|
4
|
+
static build(method: TransactionPaymentMethods, checkout: Checkout, response: PagarMeV5Response): Payment;
|
|
5
5
|
private static buildPaymentTransaction;
|
|
6
|
+
private static getPaymentStatus;
|
|
6
7
|
private static getBoletoReponse;
|
|
7
8
|
private static getPixReponse;
|
|
8
9
|
private static getCardReponse;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Shops } from '../../../../domain/catalog';
|
|
1
2
|
import { BusinessUnitEnum } from '../../../../domain/shopping/enums';
|
|
2
3
|
import { PaymentProviderCard } from '../../../../domain/shopping/interfaces';
|
|
3
4
|
import { Checkout, Payment, PaymentTransaction } from '../../../../domain/shopping/models';
|
|
@@ -10,7 +11,7 @@ export declare class PagarmeCardAxiosAdapter implements PaymentProviderCard<Paga
|
|
|
10
11
|
constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
|
|
11
12
|
pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
|
|
12
13
|
addCard(card: CardInfo): Promise<PagarMeCard>;
|
|
13
|
-
createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum): Promise<PagarMeCardManualHash>;
|
|
14
|
+
createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum, shop?: Shops): Promise<PagarMeCardManualHash>;
|
|
14
15
|
getCardByToken(id: string): Promise<PagarMeCard>;
|
|
15
16
|
createTransaction(info: any): Promise<PaymentTransaction>;
|
|
16
17
|
private createCardPayment;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Shops } from '../../../../domain';
|
|
1
2
|
import { BusinessUnitEnum } from '../../../../domain/shopping/enums';
|
|
2
3
|
import { PaymentProviderCard } from '../../../../domain/shopping/interfaces';
|
|
3
4
|
import { Checkout, Payment, PaymentTransaction } from '../../../../domain/shopping/models';
|
|
@@ -10,7 +11,8 @@ export declare class PagarmeV5CardAxiosAdapter implements PaymentProviderCard<Pa
|
|
|
10
11
|
constructor(credentials: PagarmeCredentials, paymentRepository: PaymentRepository, orderBlockedRepository: OrderBlockedRepository);
|
|
11
12
|
pay(checkout: Checkout, card: PaymentCardInfo): Promise<Payment>;
|
|
12
13
|
addCard(card: CardInfo): Promise<PagarMeCard>;
|
|
13
|
-
createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum): Promise<PagarMeCardManualHash>;
|
|
14
|
-
getCardByToken(
|
|
14
|
+
createCardHash<PagarMeCardManualHash>(bu: BusinessUnitEnum, shop?: Shops): Promise<PagarMeCardManualHash>;
|
|
15
|
+
getCardByToken(token: string): Promise<PagarMeCard>;
|
|
16
|
+
getCardByToken(customerId: string, token: string): Promise<PagarMeCard>;
|
|
15
17
|
createTransaction(info: any): Promise<PaymentTransaction>;
|
|
16
18
|
}
|
|
@@ -41,7 +41,7 @@ export type PagarMeV5Charger = {
|
|
|
41
41
|
code: string;
|
|
42
42
|
gateway_id: string;
|
|
43
43
|
amount: number;
|
|
44
|
-
status:
|
|
44
|
+
status: PagarMeV5OrderStatus;
|
|
45
45
|
currency: string;
|
|
46
46
|
payment_method: string;
|
|
47
47
|
paid_amount: number;
|
|
@@ -65,7 +65,7 @@ export type PagarMeV5Transaction = {
|
|
|
65
65
|
transaction_type?: string;
|
|
66
66
|
gateway_id?: string;
|
|
67
67
|
amount: number;
|
|
68
|
-
status?:
|
|
68
|
+
status?: PagarMeV5PaymentStatus;
|
|
69
69
|
success: boolean;
|
|
70
70
|
installments: number;
|
|
71
71
|
installment_type?: string;
|
|
@@ -103,7 +103,7 @@ export type PagarMeV5Transaction = {
|
|
|
103
103
|
type: string;
|
|
104
104
|
created_at: string;
|
|
105
105
|
updated_at: string;
|
|
106
|
-
billing_address
|
|
106
|
+
billing_address?: {
|
|
107
107
|
zip_code: string;
|
|
108
108
|
city: string;
|
|
109
109
|
state: string;
|
|
@@ -112,10 +112,10 @@ export type PagarMeV5Transaction = {
|
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
114
|
gateway_response?: {
|
|
115
|
-
code:
|
|
116
|
-
errors
|
|
115
|
+
code: string;
|
|
116
|
+
errors?: [
|
|
117
117
|
{
|
|
118
|
-
message
|
|
118
|
+
message?: string;
|
|
119
119
|
}
|
|
120
120
|
];
|
|
121
121
|
};
|