Skip to content

Commit

Permalink
fix(debugs): remove unnecessary debugs
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Jul 16, 2024
1 parent 0e034a0 commit 66545ad
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 39 deletions.
1 change: 0 additions & 1 deletion functions/lib/pagarme/handle-plans.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const discountPlanPayment = (planName, plan, amount) => {
let discount
// console.log('>>Plan ', plan)
if (plan.discount_first_installment &&
plan.discount_first_installment.value
) {
Expand Down
3 changes: 0 additions & 3 deletions functions/lib/pagarme/payment-subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const createSubscription = async (params, appData, storeId, plan, customer) => {
} else {
pagarmeSubscription.installments = intervalPlan.interval_count || 1
}

}
}

Expand Down Expand Up @@ -132,7 +131,6 @@ const createSubscription = async (params, appData, storeId, plan, customer) => {
pagarmeSubscription.items.push(itemFreight)
}

// console.log('>> amount ', JSON.stringify(amount))
// Add once discont, but webhook invoce check discount plan
const discountSubscription = amount.discount && {
value: `${Math.floor((amount.discount).toFixed(2) * 1000) / 10}`,
Expand Down Expand Up @@ -160,7 +158,6 @@ const createPayment = async (params, appData, storeId, customer) => {

const address = parseAddress(params.to || params.billing_address)

console.log('>>Try payment')
let discountEach
if (amount.discount) {
const quantityItems = items.reduce(function (acumulador, item) {
Expand Down
3 changes: 0 additions & 3 deletions functions/lib/store-api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const getOrderIntermediatorTransactionId = async (appSdk, storeId, invoiceId, au
const { response: { data } } = await appSdk
.apiRequest(storeId, `/orders.json${queryString}`, 'GET', null, auth)

// console.log(`>>> ${JSON.stringify(data)}`)

return data?.result.length ? data?.result[0] : null
}

Expand All @@ -38,7 +36,6 @@ const checkItemsAndRecalculeteOrder = (amount, items, plan, itemsPagarme) => {
items.splice(i, 1)
} else {
const itemFound = itemsPagarme.find(itemFind => itemFind.id === `pi_${item.sku}`)
// console.log('>> Item ', JSON.stringify(itemFound))
if (itemFound) {
item.quantity = itemFound.quantity
if (item.final_price) {
Expand Down
9 changes: 2 additions & 7 deletions functions/routes/ecom/modules/create-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ exports.post = async ({ appSdk, admin }, req, res) => {
const orderId = params.order_id
// const { amount, buyer, payer, to, items } = params
const { amount, to, buyer } = params
console.log('> Transaction #', storeId, orderId)
console.log('>> Type transaction', params.type)
console.log('> Transaction #', storeId, orderId, params.type)
const paymentMethod = params.payment_method.code

// https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
Expand Down Expand Up @@ -70,11 +69,9 @@ exports.post = async ({ appSdk, admin }, req, res) => {
subscriptionPagarmeId = subcription.id
// /invoices
const { data: { data: invoices } } = await pagarmeAxios.get(`/invoices?subscription_id=${subscriptionPagarmeId}`)
console.log('>>Invoices: ', JSON.stringify(invoices))

const { data: charge } = await pagarmeAxios.get(`/charges/${invoices[0].charge.id}`)

console.log('>>Charge: ', JSON.stringify(charge))
const transactionPagarme = charge.last_transaction

transaction.status = {
Expand All @@ -97,7 +94,7 @@ exports.post = async ({ appSdk, admin }, req, res) => {
transaction.payment_link = charge.last_transaction.url
redirectToPayment = true
}
// console.log('>> transaction ', JSON.stringify(transaction))

colletionFirebase.doc(orderId)
.set({
storeId,
Expand All @@ -113,8 +110,6 @@ exports.post = async ({ appSdk, admin }, req, res) => {
})
.catch(console.error)

console.log('> Save Firebase')

res.send({
redirect_to_payment: redirectToPayment,
transaction
Expand Down
11 changes: 2 additions & 9 deletions functions/routes/ecom/modules/list-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ exports.post = async ({ appSdk }, req, res) => {
query: {
bool: {
must: [
{ terms: { '_id': items.map((item) => item.product_id) } },
{ terms: { 'categories._id': categoryIds } },
{ terms: { _id: items.map((item) => item.product_id) } },
{ terms: { 'categories._id': categoryIds } }
]
}
}
Expand All @@ -39,9 +39,6 @@ exports.post = async ({ appSdk }, req, res) => {

hasRecurrence = data?.hits.total > 0
isAllRecurring = data?.hits.total === items.length

// console.log(`${JSON.stringify(data?.hits.total)} isAllRecurring: ${isAllRecurring} hasRecurrence: ${hasRecurrence}`)

} catch (err) {
// console.error(err)
}
Expand Down Expand Up @@ -81,7 +78,6 @@ exports.post = async ({ appSdk }, req, res) => {
listPaymentMethod.push('account_deposit')
}

// console.log(`APP: ${JSON.stringify(configApp)}`)
paymentTypes.forEach(type => {
// At first the occurrence only with credit card
const isRecurrence = type === 'recurrence'
Expand All @@ -98,8 +94,6 @@ exports.post = async ({ appSdk }, req, res) => {
methodEnable = methodConfig.enable_recurrence
}

// console.log(`>>list: #${storeId} ${type} - ${paymentMethod} - ${methodEnable} plan: ${JSON.stringify(plan)}`)

// Pix not active in recurrence
methodEnable = isPix && isRecurrence ? false : methodEnable

Expand Down Expand Up @@ -219,6 +213,5 @@ exports.post = async ({ appSdk }, req, res) => {
})
})

// console.log(`Response: ${JSON.stringify(response?.payment_gateways)}`)
res.send(response)
}
14 changes: 4 additions & 10 deletions functions/routes/ecom/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ exports.post = async ({ appSdk, admin }, req, res) => {
throw err
}

console.log(`>> Webhook E-com: #${storeId} ${action} ${resource}: ${resourceId}, ${body && JSON.stringify(body)}`)
if (resource === 'orders') {
if (body?.status === 'cancelled') {
const order = await getOrderById(appSdk, storeId, resourceId, auth)
if (order?.transactions?.length && order?.transactions[0]?.type === 'recurrence') {
const { data: { data: subcriptions } } = await pagarmeAxios.get(`/subscriptions?code=${resourceId}`)
if (subcriptions && subcriptions[0].status !== 'canceled') {
try {
console.log(`>> Webhook E-com: Try cancel subscription Pagar.Me code: #${resourceId}`)
await pagarmeAxios.delete(`/subscriptions/${subcriptions[0].id}`)
console.log('>> Webhook E-com: Successfully canceled')
res.send(ECHO_SUCCESS)
Expand All @@ -74,14 +74,10 @@ exports.post = async ({ appSdk, admin }, req, res) => {
console.log(`>> Webhook E-com: Subscription #${resourceId} already canceled or does not exist`)
res.send(ECHO_SUCCESS)
}
} else {
console.warn(`Warn: Order ${order ? JSON.stringify(order) : ' not found'}`)
}
// edit items order order Original
//
}
} else if (resource === 'products' && action === 'change') {
console.log('> Edit product ', resourceId, 's: ', storeId)
// console.log('> Edit product ', resourceId, 's: ', storeId)

let query = 'status!=cancelled&transactions.type=recurrence'
query += '&transactions.app.intermediator.code=pagarme'
Expand All @@ -94,7 +90,7 @@ exports.post = async ({ appSdk, admin }, req, res) => {
const updateItemPagarme = []
const order = await getOrderById(appSdk, storeId, result[i]._id, auth)
const docSubscription = await getDocFirestore(colletionFirebase, result[i]._id)
console.log('>> order ', JSON.stringify(order), ' ', JSON.stringify(docSubscription))
// console.log('>> order ', JSON.stringify(order), ' ', JSON.stringify(docSubscription))
if (order && docSubscription) {
const itemsUpdate = []
order.items.forEach(orderItem => {
Expand Down Expand Up @@ -143,7 +139,6 @@ exports.post = async ({ appSdk, admin }, req, res) => {
}
// order not found or error
if (updateItemPagarme.length) {
console.log('>> Try update item in Pagar.Me')
try {
//
await Promise.all(updateItemPagarme.map(itemPagarme => {
Expand All @@ -154,7 +149,7 @@ exports.post = async ({ appSdk, admin }, req, res) => {
}
)
}))
console.log('>>> Update SUCESSS')
console.log('> Update item in Pagar.Me SUCESSS')
res.send(ECHO_SUCCESS)
} catch (err) {
console.log('err ', err)
Expand All @@ -164,7 +159,6 @@ exports.post = async ({ appSdk, admin }, req, res) => {
}
}
}
console.log('>> not found ')
}
// More Trigger
} catch (err) {
Expand Down
7 changes: 1 addition & 6 deletions functions/routes/pagarme/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.post = async ({ appSdk, admin }, req, res) => {
if (type === 'subscription.created' && body.data) {
const orderOriginalId = body.data?.code
const subscriptionPagarmeId = body.data?.id
console.log(`>> Check SubcriptionId: ${orderOriginalId}`)
// (`>> Check SubcriptionId: ${orderOriginalId}`)
const documentSnapshot = await colletionFirebase.doc(orderOriginalId).get()
const docSubscription = documentSnapshot.exists && documentSnapshot.data()
if (!docSubscription) {
Expand Down Expand Up @@ -138,13 +138,11 @@ exports.post = async ({ appSdk, admin }, req, res) => {
console.log('>> Charge ', JSON.stringify(charge))
if (charge.invoice) {
const { invoice, status } = charge
console.log('>>Parse status: ', parserChangeStatusToEcom(status))
const order = await getOrderIntermediatorTransactionId(appSdk, storeId, invoice.id, auth)
if (order) {
if (order.financial_status.current !== parserChangeStatusToEcom(status)) {
// updadte status
const transaction = order.transactions.find(transaction => transaction.intermediator.transaction_id === invoice.id)
console.log('>> Try add payment history')
const transactionPagarme = charge.last_transaction
let notificationCode = `${type};${body.id};`
if (transactionPagarme.transaction_type === 'credit_card') {
Expand All @@ -168,7 +166,6 @@ exports.post = async ({ appSdk, admin }, req, res) => {
console.log('>> Status update to paid')
return res.sendStatus(200)
} else {
console.log(`Status is ${parserChangeStatusToEcom(status)}`)
return res.sendStatus(200)
}
} else {
Expand Down Expand Up @@ -209,12 +206,10 @@ exports.post = async ({ appSdk, admin }, req, res) => {
console.log('>> Create new Order')
return res.sendStatus(201)
} else {
console.log('>> Subscription not found')
return res.status(404)
.send({ message: `Subscription code: #${subscription.code} not found` })
}
} else {
console.log('>> Order not found and transaction status is not paid')
return res.status(400)
.send({ message: 'Order not found and status is not paid' })
}
Expand Down

0 comments on commit 66545ad

Please sign in to comment.