diff --git a/functions/lib/pagarme/handle-plans.js b/functions/lib/pagarme/handle-plans.js index 42354af..295d3dc 100644 --- a/functions/lib/pagarme/handle-plans.js +++ b/functions/lib/pagarme/handle-plans.js @@ -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 ) { diff --git a/functions/lib/pagarme/payment-subscriptions.js b/functions/lib/pagarme/payment-subscriptions.js index 52518ab..27f83f0 100644 --- a/functions/lib/pagarme/payment-subscriptions.js +++ b/functions/lib/pagarme/payment-subscriptions.js @@ -85,7 +85,6 @@ const createSubscription = async (params, appData, storeId, plan, customer) => { } else { pagarmeSubscription.installments = intervalPlan.interval_count || 1 } - } } @@ -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}`, @@ -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) { diff --git a/functions/lib/store-api/utils.js b/functions/lib/store-api/utils.js index 58ea995..c5b895e 100644 --- a/functions/lib/store-api/utils.js +++ b/functions/lib/store-api/utils.js @@ -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 } @@ -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) { diff --git a/functions/routes/ecom/modules/create-transaction.js b/functions/routes/ecom/modules/create-transaction.js index 0936385..6d0b896 100644 --- a/functions/routes/ecom/modules/create-transaction.js +++ b/functions/routes/ecom/modules/create-transaction.js @@ -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 @@ -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 = { @@ -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, @@ -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 diff --git a/functions/routes/ecom/modules/list-payments.js b/functions/routes/ecom/modules/list-payments.js index d0b57f3..313ba30 100644 --- a/functions/routes/ecom/modules/list-payments.js +++ b/functions/routes/ecom/modules/list-payments.js @@ -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 } } ] } } @@ -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) } @@ -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' @@ -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 @@ -219,6 +213,5 @@ exports.post = async ({ appSdk }, req, res) => { }) }) - // console.log(`Response: ${JSON.stringify(response?.payment_gateways)}`) res.send(response) } diff --git a/functions/routes/ecom/webhook.js b/functions/routes/ecom/webhook.js index 8746220..03ca8d7 100644 --- a/functions/routes/ecom/webhook.js +++ b/functions/routes/ecom/webhook.js @@ -48,6 +48,7 @@ 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) @@ -55,7 +56,6 @@ exports.post = async ({ appSdk, admin }, req, res) => { 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) @@ -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' @@ -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 => { @@ -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 => { @@ -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) @@ -164,7 +159,6 @@ exports.post = async ({ appSdk, admin }, req, res) => { } } } - console.log('>> not found ') } // More Trigger } catch (err) { diff --git a/functions/routes/pagarme/webhooks.js b/functions/routes/pagarme/webhooks.js index 1a1d875..1747e01 100644 --- a/functions/routes/pagarme/webhooks.js +++ b/functions/routes/pagarme/webhooks.js @@ -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) { @@ -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') { @@ -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 { @@ -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' }) }