チェーン付き課金を作成
destinationパラメータを使用して課金を作成し、マーケットプレイスの支払い分割を有効にします。これにより、課金と受取人への自動送金をリンクするチェーンが作成されます。
API認証情報
リクエストパラメータ
必須 - 3 フィールド必須パラメータ
`amount`INTEGER(required)
最小通貨単位での金額(THBはサタン、USDはセント、JPYは円)。例: 100000サタン = 1,000 THB。
`currency`STRING(required)
ISO 4217の3文字の通貨コード(小文字)。
`destination`STRING(required)
課金成功後に自動送金を受け取る受取人ID。マーケットプレイスの支払い分割に必須です。
必須 - 3 フィールドのうち1つ支払い方法(1つ必須)
`card`STRING(optional)
Omise.jsからのトークンID(例: tokn_test_...)または顧客のカードID(例: card_test_...)。customerとsourceが指定されていない場合に必須。
`source`STRING(optional)
PromptPay、モバイルバンキング、QRコードなどの代替支払い方法のソースID。cardとcustomerが指定されていない場合に必須。
`customer`STRING(optional)
顧客ID。顧客のデフォルトカードに課金します。cardと組み合わせて特定のカードを指定できます。cardとsourceが指定されていない場合に必須。
推奨 - 2 フィールド推奨パラメータ
追加 - 1 フィールド追加パラメータ
レスポンス
200
トランザクション成功チェーン付き課金の作成に成功しました。課金成功後、送金先の受取人への自動送金が作成されます。
レスポンスに含まれる情報:
destination- 自動送金の受取人IDchain- 課金と送金をリンクするチェーンIDplatform_fee- プラットフォーム手数料の詳細status- 課金ステータス(successful、pending、failedなど)
400
不正なリクエストリクエストの検証に失敗しました。詳細はエラーメッセージを確認してください。
一般的な原因:
- 必須フィールドの欠落(
amount、currency、destination) - 無効な通貨コード
- 支払い方法が指定されていない(
card、source、またはcustomer) - 無効な送金先受取人ID
401
認証エラー認証に失敗しました。APIキーが無効または不足しています。
一般的な原因:
- Authorizationヘッダーの欠落
- 無効なシークレットキー
- シークレットキーの代わりにパブリックキーを使用
- HTTP Basic Auth形式の誤り
5xx
サーバーエラーサーバー側でエラーが発生しました。稀ですが、適切に処理する必要があります。
対処方法:
- 指数バックオフでリクエストを再試行
- status.omise.coでサービスインシデントを確認
- 詳細なガイダンスはエラー処理を参照
コードサンプル
- cURL
- Ruby
- Python
- Node.js
- PHP
- Java
- C#
- Go
curl https://api.omise.co/charges \
-u skey_test_5xuy4w91xqz7d1w9u0t: \
-d "amount=100000" \
-d "currency=thb" \
-d "card=tokn_test_5xuy4w91xqz7d1w9u0t" \
-d "destination=recp_test_5xuy4w91xqz7d1w9u0t"
require 'omise'
Omise.api_key = 'skey_test_5xuy4w91xqz7d1w9u0t'
charge = Omise::Charge.create({
amount: 100000,
currency: 'thb',
card: 'tokn_test_5xuy4w91xqz7d1w9u0t',
destination: 'recp_test_5xuy4w91xqz7d1w9u0t'
})
import omise
omise.api_secret = 'skey_test_5xuy4w91xqz7d1w9u0t'
charge = omise.Charge.create(
amount=100000,
currency='thb',
card='tokn_test_5xuy4w91xqz7d1w9u0t',
destination='recp_test_5xuy4w91xqz7d1w9u0t'
)
const omise = require('omise')({
secretKey: 'skey_test_5xuy4w91xqz7d1w9u0t'
});
const charge = await omise.charges.create({
amount: 100000,
currency: 'thb',
card: 'tokn_test_5xuy4w91xqz7d1w9u0t',
destination: 'recp_test_5xuy4w91xqz7d1w9u0t'
});
<?php
define('OMISE_SECRET_KEY', 'skey_test_5xuy4w91xqz7d1w9u0t');
$charge = OmiseCharge::create([
'amount' => 100000,
'currency' => 'thb',
'card' => 'tokn_test_5xuy4w91xqz7d1w9u0t',
'destination' => 'recp_test_5xuy4w91xqz7d1w9u0t'
]);
Client client = new Client.Builder()
.secretKey("skey_test_5xuy4w91xqz7d1w9u0t")
.build();
Charge charge = client.charges().create()
.amount(100000L)
.currency("thb")
.card("tokn_test_5xuy4w91xqz7d1w9u0t")
.destination("recp_test_5xuy4w91xqz7d1w9u0t")
.send();
var client = new Client("skey_test_5xuy4w91xqz7d1w9u0t");
var charge = await client.Charges.Create(new CreateChargeRequest
{
Amount = 100000,
Currency = "thb",
Card = "tokn_test_5xuy4w91xqz7d1w9u0t",
Destination = "recp_test_5xuy4w91xqz7d1w9u0t"
});
client, _ := omise.NewClient(
"pkey_test_5xuy4w91xqz7d1w9u0t",
"skey_test_5xuy4w91xqz7d1w9u0t",
)
charge, _ := client.Charges().Create(&operations.CreateCharge{
Amount: 100000,
Currency: "thb",
Card: "tokn_test_5xuy4w91xqz7d1w9u0t",
Destination: "recp_test_5xuy4w91xqz7d1w9u0t",
})
エラーと結果コード
一般的なエラーコード
| コード | 説明 | 解決策 |
|---|---|---|
bad_request | パラメータの欠落または無効 | すべての必須フィールドが指定されているか確認 |
authentication_failure | 無効なAPIキー | シークレットキーが正しいか確認 |
invalid_recipient | 無効な送金先受取人ID | 受取人が存在しアクティブであるか確認 |
recipient_not_verified | 受取人が認証されていない | 送金を受け取る前に受取人の認証が必要です |
課金ステータスコード
| ステータス | 説明 |
|---|---|
successful | 支払いが正常に完了 |
pending | 顧客のアクションを待機中(例: QRコードのスキャン) |
failed | 支払いに失敗(failure_codeを参照) |
reversed | 課金がキャンセル/取り消し |
expired | 支払い前に課金の有効期限切れ |