定期支払いスケジュール
自動化されたサブスクリプション請求、メンバーシップ、定期請求のための定期支払いスケジュールの作成と管理方法について説明します。スケジュールは手動干渉なしで顧客に定期的に請求するプロセスを自動化します。
概要
Schedules API により、手動干渉なしで定期請求を自動化できます。以下に最適です:
- サブスクリプションサービス(月額、年額)
- メンバーシップ費用
- 分割払い
- 使用量ベースの請求周期
- 定期寄付
- ライセンス更新
主な利点
- 自動請求 - 設定して完了、請求が自動的に発生します
- 柔軟なスケジュール - 毎日、毎週、毎月、またはカスタム期間
- 再試行ロジック - 失敗した支払い処理の組み込み
- 簡単な管理 - スケジュールを一時停止、再開、またはキャンセル
- 包括的な追跡 - すべてのスケジュール請求を監視
- 顧客の維持 - シームレスな更新により離脱を減らします
スケジュールの動作方法
- 顧客と請求の詳細を使用してスケジュールを作成
- スケジュールは指定された日付に自動的に請求を生成
- システムは顧客のデフォルト支払い方法への請求を試みます
- Webhook は成功/失敗した請求について通知します
- スケジュール終了またはキャンセルまで続行します
スケジュールの作成
基本的なスケジュール作成
curl https://api.omise.co/schedules \
-u skey_test_123: \
-d "every=1" \
-d "period=month" \
-d "start_date=2024-02-01" \
-d "end_date=2024-12-31" \
-d "charge[customer]=cust_test_123456" \
-d "charge[amount]=100000" \
-d "charge[currency]=THB" \
-d "charge[description]=Monthly Premium Subscription"
const omise = require('omise')({
secretKey: 'skey_test_123'
});
const schedule = await omise.schedules.create({
every: 1,
period: 'month',
start_date: '2024-02-01',
end_date: '2024-12-31',
charge: {
customer: 'cust_test_123456',
amount: 100000,
currency: 'THB',
description: 'Monthly Premium Subscription'
}
});
console.log('スケジュール ID:', schedule.id);
console.log('ステータス:', schedule.status);
console.log('次の発生:', schedule.next_occurrences_on[0]);
import omise
from datetime import datetime, timedelta
omise.api_secret = 'skey_test_123'
schedule = omise.Schedule.create(
every=1,
period='month',
start_date='2024-02-01',
end_date='2024-12-31',
charge={
'customer': 'cust_test_123456',
'amount': 100000,
'currency': 'THB',
'description': 'Monthly Premium Subscription'
}
)
print(f'スケジュール ID: {schedule.id}')
print(f'ステータス: {schedule.status}')
print(f'次の発生: {schedule.next_occurrences_on[0]}')
スケジュール期間
// 月額請求
const monthly = await omise.schedules.create({
every: 1,
period: 'month',
start_date: '2024-02-01',
charge: { /* ... */ }
});
// 週単位請求
const weekly = await omise.schedules.create({
every: 1,
period: 'week',
start_date: '2024-02-01',
charge: { /* ... */ }
});
// 日単位請求
const daily = await omise.schedules.create({
every: 1,
period: 'day',
start_date: '2024-02-01',
charge: { /* ... */ }
});
// 四半期ごと(3ヶ月ごと)
const quarterly = await omise.schedules.create({
every: 3,
period: 'month',
start_date: '2024-02-01',
charge: { /* ... */ }
});
// 年額請求
const annual = await omise.schedules.create({
every: 1,
period: 'year',
start_date: '2024-02-01',
charge: { /* ... */ }
});
スケジュールの管理
スケジュールの取得
const schedule = await omise.schedules.retrieve('schd_test_123456');
console.log('スケジュール:', schedule.in_words);
console.log('ステータス:', schedule.status);
console.log('次の請求:', schedule.next_occurrences_on);
console.log('完了した請求:', schedule.occurrences.total);
すべてのスケジュールをリストアップ
// フィルター付きでリスト
const schedules = await omise.schedules.list({
limit: 20,
offset: 0,
order: 'reverse_chronological'
});
schedules.data.forEach(schedule => {
console.log(`${schedule.id} - ${schedule.status} - ${schedule.in_words}`);
});
// ステータス別でフィルター
const activeSchedules = schedules.data.filter(
s => s.status === 'active'
);
スケジュールを一時停止
// スケジュール一時停止
await omise.schedules.destroy('schd_test_123456');
// 停止を確認
const schedule = await omise.schedules.retrieve('schd_test_123456');
console.log('ステータス:', schedule.status);
スケジュール発生を表示
const schedule = await omise.schedules.retrieve('schd_test_123456');
const occurrences = schedule.occurrences.data;
occurrences.forEach(occurrence => {
console.log('日付:', occurrence.schedule_date);
console.log('ステータス:', occurrence.status);
console.log('請求:', occurrence.result?.id);
console.log('---');
});