[javascript] code
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import type { NextApiRequest, NextApiResponse } from 'next'
- import supabase from '../../../../lib/supabase'
- import axios from 'axios'
- const formData = require('form-data');
- // const Mailgun = require('mailgun.js');
- // const mailgun = new Mailgun(formData);
- // const mg = mailgun.client({ username: 'api', key: 'acd9a67295ba96a738a28f3ce060ffe0-054ba6b6-3a70cd77' });
- export default async function handler(
- req: NextApiRequest,
- res: NextApiResponse
- ) {
- try {
- var body = req.body
- if (Object.prototype.toString.call(body) === '[object String]')
- body = JSON.parse(body)
- await supabase.from('logs').insert({ data: body, sender: "Sama alThawaf (Webhook)" })
- var transactionsSnapshot = await supabase.from('transactions').select("*").eq("id", body.transactionId)
- if (transactionsSnapshot.status >= 300 || (transactionsSnapshot.data && transactionsSnapshot.data!.length < 1))
- throw 'Data transaksi tidak ditemukan'
- var transaction = transactionsSnapshot.data![0]
- if (body.status === transaction.status) throw `Data transaksi sudah ${body.status}`
- transactionsSnapshot = await supabase.from('transactions').update({ status: body.status, serialnum: body.sn || "", updatedAt: new Date() }).eq("id", body.transactionId).select("*")
- transaction = transactionsSnapshot.data![0]
- if (body.status != "Success") throw 'Transaksi gagal atau sedang diproses'
- // Send WA
- try {
- if (!(transaction.formatnum)) throw 'Email tidak diset, batalkan pengiriman email'
- const authorization = "ByJ2mp6pzAbmJ9d-wrX0elBsEp_qASEFD-DGIbZC1AE"
- const url = 'https://service-chat.qontak.com/api/open/v1/broadcasts/whatsapp/direct'
- const config = {
- headers: {
- "Authorization": authorization,
- // "api-version": "2022-07-31",
- "Content-Type": "application/json"
- }
- }
- var bodyd = {
- "to_number": transaction.formatnum,
- "to_name": transaction.name,
- "message_template_id": "1b1d72cb-a50b-4e19-93cd-aff1547cdbc9",
- "channel_integration_id": "a71dd2d1-1089-445c-8344-5c6bf173c602",
- "language": {
- "code": "id"
- },
- "parameters": {
- "body": [
- {
- "key": "1",
- "value": "full_name",
- "value_text": transaction.name,
- },
- {
- "key": "2",
- "value": "cust_number",
- "value_text": transaction.customerId + "\n -Serial Number : " + transaction.serialnum,
- },
- {
- "key": "3",
- "value": "package_type",
- "value_text": transaction.detail
- },
- {
- "key": "4",
- "value": "200",
- "value_text": "Pembayaran Berhasil"
- },
- {
- "key": "5",
- "value": "invoice_link",
- "value_text": "https://petugashaji.thawaf.id/"
- },
- ]
- }
- }
- // res.send({ url: url, body: bodyd, config: config })
- const response = await axios.post(url, bodyd, config)
- await supabase.from('logs').insert({ data: response.data, sender: "Qontak (Callback)" })
- } catch (e) {
- await supabase.from('consoles').insert({ summary: `${e}`, severity: 2 })
- }
- // Send Email
- // try {
- // if (!(transaction.email)) throw 'Email tidak diset, batalkan pengiriman email'
- // mg.messages.create('payment-ir.thawaf.id', {
- // from: 'Kuwais Group <[email protected]>',
- // to: [transaction.email],
- // subject: 'TERIMAKASIH UNTUK PEMBELIAN ANDA!',
- // html: `
- // <html>
- // <body style="background-color:#e2e1e0;font-family: Open Sans, sans-serif;font-size:100%;font-weight:400;line-height:1.4;color:#000;">
- // <table style="max-width:670px;margin:50px auto 10px;background-color:#fff;padding:50px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);-moz-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24); border-top: solid 10px green;">
- // <tbody>
- // <tr>
- // <td style="height:35px;"></td>
- // </tr>
- // <tr>
- // <td colspan="2" style="border: solid 1px #ddd; padding:10px 20px;">
- // <p><span style="font-family: Arial, Helvetica, sans-serif;">Assalamu'alaikum ${transaction.name}!<br /><br /><strong><span style="font-size: 20px;">Selamat Pembayaranmu Berhasil!</span></strong></span></p>
- // <p style="font-size:14px;margin:0 0 6px 0;"><span style="font-weight:bold;display:inline-block;min-width:150px">Order status</span><b style="color:green;font-weight:normal;margin:0">${transaction.status}</b></p>
- // <p style="font-size:14px;margin:0 0 6px 0;"><span style="font-weight:bold;display:inline-block;min-width:146px">Serial Number</span> ${transaction.serialnum}</p>
- // </td>
- // </tr>
- // <tr>
- // <td style="height:35px;"></td>
- // </tr>
- // <tr>
- // <td style="width:50%;padding:20px;vertical-align:top">
- // <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px">Name</span> ${transaction.name}</p>
- // <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">Email</span> ${transaction.email}</p>
- // <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">Phone</span> ${transaction.formatnum}</p>
- // </td>
- // <td style="width:50%;padding:20px;vertical-align:top">
- // <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">Date</span> ${transaction.updatedAt}</p>
- // <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">ID</span> TRANSACTION-${transaction.id}</p>
- // </td>
- // </tr>
- // <tr>
- // <td colspan="2" style="font-size:20px;padding:30px 15px 0 15px;">Paket Yang Dibeli</td>
- // </tr>
- // <tr>
- // <td colspan="2" style="padding:15px;">
- // <p style="font-size:14px;margin:0;padding:10px;border:solid 1px #ddd;font-weight:bold;">
- // <span style="display:block;font-size:13px;font-weight:normal;">${transaction.productTitle}</span> Rp. ${transaction.productPrice} <b style="font-size:12px;font-weight:300;">${transaction.productDay}</b>
- // </table>
- // <p> </p>
- // <hr />
- // <p>E-mail ini dibuat otomatis, mohon tidak membalas. Jika butuh bantuan, silakan hubungi<a href="https://api.whatsapp.com/send/?phone=6281224881962&text&type=phone_number&app_absent=0"> <strong>Whatsapp</strong></a></p>
- // <p> </p>
- // <br>
- // <br>
- // </body>
- // </html>
- // `
- // })
- // await supabase.from('consoles').insert({ summary: `Email has sended to ${transaction.email}`, severity: 1 })
- // } catch (e) {
- // await supabase.from('consoles').insert({ summary: `${e}`, severity: 1 })
- // }
- // } catch (e) {
- // await supabase.from('consoles').insert({ summary: `${e}`, severity: 1 })
- // }
- // Send Email using Lamun
- try {
- if (!(transaction.email)) throw 'Email tidak diset, batalkan pengiriman email'
- await axios.post('http://api.lamun.my.id/api/mail/send', {
- to: [transaction.email],
- subject: 'TERIMAKASIH UNTUK PEMBELIAN ANDA!',
- html: `
- <html>
- <body style="background-color:#e2e1e0;font-family: Open Sans, sans-serif;font-size:100%;font-weight:400;line-height:1.4;color:#000;">
- <table style="max-width:670px;margin:50px auto 10px;background-color:#fff;padding:50px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);-moz-box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24);box-shadow:0 1px 3px rgba(0,0,0,.12),0 1px 2px rgba(0,0,0,.24); border-top: solid 10px green;">
- <tbody>
- <tr>
- <td style="height:35px;"></td>
- </tr>
- <tr>
- <td colspan="2" style="border: solid 1px #ddd; padding:10px 20px;">
- <p><span style="font-family: Arial, Helvetica, sans-serif;">Assalamu'alaikum ${transaction.name}!<br /><br /><strong><span style="font-size: 20px;">Selamat Pembayaranmu Berhasil!</span></strong></span></p>
- <p style="font-size:14px;margin:0 0 6px 0;"><span style="font-weight:bold;display:inline-block;min-width:150px">Order status</span><b style="color:green;font-weight:normal;margin:0">${transaction.status}</b></p>
- <p style="font-size:14px;margin:0 0 6px 0;"><span style="font-weight:bold;display:inline-block;min-width:146px">Serial Number</span> ${transaction.serialnum}</p>
- </td>
- </tr>
- <tr>
- <td style="height:35px;"></td>
- </tr>
- <tr>
- <td style="width:50%;padding:20px;vertical-align:top">
- <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px">Name</span> ${transaction.name}</p>
- <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">Email</span> ${transaction.email}</p>
- <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">Phone</span> ${transaction.formatnum}</p>
- </td>
- <td style="width:50%;padding:20px;vertical-align:top">
- <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">Date</span> ${transaction.updatedAt}</p>
- <p style="margin:0 0 10px 0;padding:0;font-size:14px;"><span style="display:block;font-weight:bold;font-size:13px;">ID</span> TRANSACTION-${transaction.id}</p>
- </td>
- </tr>
- <tr>
- <td colspan="2" style="font-size:20px;padding:30px 15px 0 15px;">Paket Yang Dibeli</td>
- </tr>
- <tr>
- <td colspan="2" style="padding:15px;">
- <p style="font-size:14px;margin:0;padding:10px;border:solid 1px #ddd;font-weight:bold;">
- <span style="display:block;font-size:13px;font-weight:normal;">${transaction.productTitle}</span> Rp. ${transaction.productPrice} <b style="font-size:12px;font-weight:300;">${transaction.productDay}</b>
- </table>
- <p> </p>
- <hr />
- <p>E-mail ini dibuat otomatis, mohon tidak membalas. Jika butuh bantuan, silakan hubungi<a href="https://api.whatsapp.com/send/?phone=6281224881962&text&type=phone_number&app_absent=0"> <strong>Whatsapp</strong></a></p>
- <p> </p>
- <br>
- <br>
- </body>
- </html>
- ` // Insert HTML content here
- }, {
- headers: {
- 'Content-Type': 'application/json',
- 'username': 'noreply@payment-ir.thawaf.id',
- 'apikey': 'cd7100dbac059e53da9f2525a933467b'
- }
- });
- await supabase.from('consoles').insert({ summary: `Email has been sent to ${transaction.email}`, severity: 1 })
- } catch (e) {
- await supabase.from('consoles').insert({ summary: `${e}`, severity: 1 })
- }
- } catch (e) {
- await supabase.from('consoles').insert({ summary: `${e}`, severity: 1 })
- }
- res.status(200).send({ body: "Thanks", code: 200, status: "Success" })
- }
Editor
You can edit this paste and save as new: