振込スケジュール
振込スケジュールにより、定期的な支払い、給与処理、およびベンダー支払いを完全に自動化できます。このガイドでは、スケジュールの作成、繰り返しパターンの設定、および自動出金の管理について説明します。
概要
振込スケジュールは以下を可能にします:
- 繰り返し支払い: 毎日、毎週、毎月の出金
- 柔軟なスケジュール: カスタムパターンをサポート
- 自動処理: 手動操作不要
- 完全な制御: スケジュールを一時停止、再開、キャンセル
- エラー処理: 失敗したスケジュール振込の通知
- 監視: スケジュール実行をリアルタイムで追跡
スケジュールの作成
月次給与スケジュール
const omise = require('omise')({
secretKey: 'skey_test_123456789'
});
async function createMonthlyPayrollSchedule(recipientId, monthlyAmount) {
const schedule = await omise.schedules.create({
every: 1,
period: 'month',
recipient: recipientId,
transfer: {
amount: monthlyAmount
},
metadata: {
type: 'monthly_salary',
purpose: '従業員報酬'
}
});
console.log('スケジュール作成:', schedule.id);
console.log('次回予定:', schedule.next_occurrence);
console.log('受取人:', schedule.recipient);
return schedule;
}
// 使用例: 月次給与スケジュールを作成
createMonthlyPayrollSchedule('recp_test_123456', 5000000); // 50,000 THB
週次支払いスケジュール
async function createWeeklyPayoutSchedule(recipientId, weeklyAmount, dayOfWeek = 'monday') {
const schedule = await omise.schedules.create({
every: 1,
period: 'week',
weekdays: [dayOfWeek],
recipient: recipientId,
transfer: {
amount: weeklyAmount
},
metadata: {
type: 'weekly_vendor_payment',
vendor_id: 'VENDOR-001'
}
});
return schedule;
}
隔週支払いスケジュール
async function createBiWeeklySchedule(recipientId, biWeeklyAmount, startDate) {
const schedule = await omise.schedules.create({
every: 2,
period: 'week',
start_date: startDate,
recipient: recipientId,
transfer: {
amount: biWeeklyAmount
},
metadata: {
type: 'bi_weekly_payment'
}
});
return schedule;
}
スケジュール管理
スケジュールを取得
async function getScheduleDetails(scheduleId) {
const schedule = await omise.schedules.retrieve(scheduleId);
console.log('スケジュールID:', schedule.id);
console.log('ステータス:', schedule.status);
console.log('受取人:', schedule.recipient);
console.log('金額:', schedule.transfer.amount / 100, 'THB');
console.log('期間:', schedule.every, schedule.period);
console.log('次回実行:', schedule.next_occurrence);
return schedule;
}
スケジュールを一覧表示
async function listAllSchedules(status = 'active') {
const schedules = await omise.schedules.list({
status: status,
limit: 100
});
schedules.data.forEach(schedule => {
console.log(`${schedule.id}: ${schedule.transfer.amount / 100} THB - ${schedule.status}`);
});
return schedules;
}