การหักบัญชีออนไลน์โดยตรง (บิลเบย์)
ยอมรับการชำระเงินซ้ำโดยการหักเบิกจากบัญชีธนาคารของลูกค้าด้วยอนุมัติล่วงหน้า สำหรับการสมัครสมาชิก การเรียกเก็บเงินโดยอัตโนมัติ
ภาพรวม
การหักบัญชีออนไลน์โดยตรง (บิลเบย์) ช่วยให้คุณเรียกเก็บเงินจากบัญชีธนาคารของลูกค้าโดยอัตโนมัติบนพื้นฐานประจำ ลูกค้าให้อนุมัติธุรกิจของคุณเพียงครั้งเดียว แล้วคุณสามารถเรียกเก็บเงินจากบัญชีของตนโดยอัตโนมัติสำหรับการสมัครสมาชิก การจ่ายราคาส่วนหรือบร ิการที่เกิดขึ้นประจำ
คุณลักษณะหลัก:
- ✅ การชำระเงินซ้ำ - การเรียกเก็บเงินอัตโนมัติตามกำหนด
- ✅ ได้รับอนุมัติล่วงหน้า - ลูกค้าให้อนุมัติเพียงครั้งเดียว
- ✅ อัตราความสำเร็จสูง - หักเบิกจากบัญชีธนาคารโดยตรง
- ✅ ขีดจำกัดสูง - ได้ถึง ฿5,000,000+ ต่อธุรกรรม
- ✅ สนับสนุนการคืนเงิน - การคืนเงินเต็มและบางส่วน
- ✅ ธนาคารหลายแห่ง - รองรับธนาคารไทยทั้งหมด
กรณีการใช้งาน
เหมาะสำหรับ:
- การสมัครสมาชิก - SaaS รายเดือน บริการสตรีมมิ่ง สมาช ิก
- การจ่ายราคาส่วน - การชำระเงินกู้ แผนการซื้อ
- บิลสาธารณูปโภค - ค่าบริการที่เกิดขึ้นประจำ
- เบี้ยประกันภัย - การชำระเงินเบี้ยประกันภัยประจำ
- การบริจาค - การบริจาคการกุศลที่เกิดขึ้นประจำ
ไม่เหมาะสำหรับ:
- การชำระเงินครั้งเดียว (ใช้มือถือหรือบิลโดยตรง)
- การชำระเงินของแขก (ต้องตั้งค่าการให้อนุมัติ)
- การชำระเงินทันที (การตั้งค่าเริ่มต้นใช้เวลา)
ภูมิภาคที่รองรับ
| ภูมิภาค | สกุลเงิน | จำนวนขั้นต่ำ | จำนวนสูงสุ ด | สามารถคืนเงินได้ |
|---|---|---|---|---|
| ประเทศไทย | THB | ฿20.00 | ฿5,000,000+ | ✅ ใช่ |
วิธีการทำงาน
การไหลของการตั้งค่าเริ่มต้น
การไหลของการเรียกเก็บเงินซ้ำ
การเพิ่มประสิทธิภาพ
ขั้นตอนที่ 1: สร้างลูกค้า
- Node.js
- PHP
const omise = require('omise')({
secretKey: 'skey_test_YOUR_SECRET_KEY'
});
// สร้างลูกค้า
const customer = await omise.customers.create({
email: 'customer@example.com',
description: 'ลูกค้าสำหรับการสมัครสมาชิก',
metadata: {
user_id: '12345'
}
});
console.log('สร้างลูกค้า:', customer.id);
<?php
$customer = OmiseCustomer::create(array(
'email' => 'customer@example.com',
'description' => 'ลูกค้าสำหรับการสมัครสมาชิก'
));
?>
ขั้นตอนที่ 2: สร้างต้นทาง Direct Debit
// สร้างต้นทาง direct debit (ต้องมีการให้อนุมัติจากลูกค้า)
const source = await omise.sources.create({
type: 'pay_with_bill_payment',
amount: 50000, // จำนวนการให้อนุมัติเริ่มต้น
currency: 'THB',
customer: customer.id
});
// เปลี่ยนเส้นทางลูกค้าเพื่อให้อนุมัติ
res.redirect(source.authorize_uri);
ขั้นตอนที่ 3: จัดการการเรียกกลับการให้อนุมัติ
app.get('/debit/callback', async (req, res) => {
const sourceId = req.query.source_id;
const source = await omise.sources.retrieve(sourceId);
if (source.flow_status === 'successful') {
// ต้นทางได้รับอนุมัติและสามารถเรียกเก็บเงินได้
// แนบไปยังลูกค้า (ถ้ายังไม่ได้)
await omise.customers.update(customer.id, {
default_source: source.id
});
res.redirect('/subscription-success');
} else {
res.redirect('/authorization-failed');
}
});
ขั้นตอนที่ 4: สร้างค่าใช้ซ้ำ
// เรียกเก็บเงินจากลูกค้าบนพื้นฐานประจำ
async function chargeSubscription(customerId, amount) {
try {
const charge = await omise.charges.create({
customer: customerId,
amount: amount,
currency: 'THB',
description: 'การสมัครสมาชิกรายเดือน',
metadata: {
billing_period: '2024-02',
subscription_id: 'sub_12345'
}
});
return charge;
} catch (error) {
console.error('ล้มเหลวในการเรียกเก็บเงิน:', error);
// จัดการความล้มเหลว (ลองใหม่ ผู้เช่าแจ้ง ฯลฯ)
}
}
// กำหนดการเรียกเก็บเงินซ้ำ
setInterval(async () => {
const subscriptions = await getActiveSubscriptions();
for (const sub of subscriptions) {
if (sub.next_billing_date === today()) {
await chargeSubscription(sub.customer_id, sub.amount);
}
}
}, 24 * 60 * 60 * 1000); // ตรวจสอบทุกวัน
ตัวอย่างการเพิ่มประสิทธิภาพที่สมบูรณ์
const express = require('express');
const omise = require('omise')({
secretKey: process.env.OMISE_SECRET_KEY
});
const app = express();
app.use(express.json());
// ขั้นตอนที่ 1: สมัครลูกค้า
app.post('/subscribe', async (req, res) => {
try {
const { email, plan_id, amount } = req.body;
// สร้างลูกค้า
const customer = await omise.customers.create({
email: email,
description: `การสมัครสมาชิก: ${plan_id}`
});
// สร้างต้นทาง direct debit
const source = await omise.sources.create({
type: 'pay_with_bill_payment',
amount: amount,
currency: 'THB',
customer: customer.id
});
// บันทึกการสมัครสมาชิกในฐานข้อมูล
await saveSubscription({
customer_id: customer.id,
source_id: source.id,
plan_id: plan_id,
amount: amount,
status: 'pending_authorization'
});
// เปลี่ยนเส้นทางไปยังการให้อนุมัติธนาคาร
res.json({
authorize_uri: source.authorize_uri,
customer_id: customer.id
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// ขั้นตอนที่ 2: จัดการการเรียกกลับการให้อนุมัติ
app.get('/debit/callback', async (req, res) => {
try {
const sourceId = req.query.source_id;
const source = await omise.sources.retrieve(sourceId);
if (source.flow_status === 'successful') {
// อัปเดตสถานะการสมัครสมาชิก
await updateSubscription(source.id, {
status: 'active',
authorized_at: new Date()
});
// สร้างค่าใช้แรก
const charge = await omise.charges.create({
customer: source.customer,
amount: source.amount,
currency: 'THB',
description: 'การชำระเงินการสมัครสมาชิกเริ่มต้น'
});
res.redirect('/subscription-active');
} else {
await updateSubscription(source.id, {
status: 'authorization_failed'
});
res.redirect('/authorization-failed');
}
} catch (error) {
res.redirect('/error');
}
});
// ขั้นตอนที่ 3: ประมวลผลค่าใช้ซ้ำ (งาน cron)
app.post('/cron/process-subscriptions', async (req, res) => {
try {
const dueSubscriptions = await getDueSubscriptions();
for (const subscription of dueSubscriptions) {
try {
const charge = await omise.charges.create({
customer: subscription.customer_id,
amount: subscription.amount,
currency: 'THB',
description: `ประจำ: ${subscription.plan_id}`,
metadata: {
subscription_id: subscription.id,
billing_period: getCurrentPeriod()
}
});
await recordPayment(subscription.id, charge.id);
} catch (error) {
await handleFailedPayment(subscription.id, error);
}
}
res.sendStatus(200);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// ตัวจัดการ Webhook
app.post('/webhooks/omise', async (req, res) => {
const event = req.body;
if (event.key === 'charge.complete') {
const charge = event.data;
if (charge.status === 'successful') {
await updateSubscriptionPayment(charge.metadata.subscription_id, 'paid');
await sendReceiptEmail(charge);
} else {
await handleFailedPayment(charge.metadata.subscription_id);
await notifyCustomer(charge);
}
}
res.sendStatus(200);
});
app.listen(3000);