支払いの作成
Stripe API およびお客様のサーバ側のコードを使用して支払いを処理します。
Checkout のレガシーバージョン または Elements を使用して、顧客のクレジットカード情報を安全に収集してトークン化しておけば、クレジットカードに即時請求することも、保存して後で請求することもできます。 ブラウザで行なわれるトークン化とは異なり、料金請求は通常、Stripe のクライアントライブラリのいずれかを使用してお客様のサーバから行なわれます。 まだライブラリをインストールしていない場合は、必要な言語のライブラリをインストールしてください。
お客様のサーバ上で、お客様のフォームから送信された POST パラメータ内の Stripe トークンを取得します。そこから簡単な API コールを行なうだけで、クレジットカードに請求が行われます。
curl https://api.stripe.com/v1/charges \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d amount=999 \
-d currency=usd \
-d description="Example charge" \
-d source=tok_visa
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = params[:stripeToken]
charge = Stripe::Charge.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
})
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = request.form['stripeToken'] # Using Flask
charge = stripe.Charge.create(
amount=999,
currency='usd',
description='Example charge',
source=token,
)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
]);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
String token = request.getParameter("stripeToken");
Map<String, Object> params = new HashMap<>();
params.put("amount", 999);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
Charge charge = Charge.create(params);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
const token = request.body.stripeToken; // Using Express
(async () => {
const charge = await stripe.charges.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
});
})();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
token := r.FormValue("stripeToken")
params := &stripe.ChargeParams{
Amount: stripe.Int64(999),
Currency: stripe.String(string(stripe.CurrencyUSD)),
Description: stripe.String("Example charge"),
}
params.SetSource(token)
ch, _ := charge.New(params)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token submitted by the form:
var token = model.Token; // Using ASP.NET MVC
var options = new ChargeCreateOptions {
Amount = 999,
Currency = "usd",
Description = "Example charge",
Source = token,
};
var service = new ChargeService();
Charge charge = service.Create(options);
ログインした状態でこのページを読まれている場合、テスト用シークレット API キーが例として自動入力されます。
この値はお客様にのみ表示されます。このキーは Stripe の認証に使用されるため、他の人に知られないように安全な場所に保管してください。
本番環境では、テスト用キーを本番用キーに置き換えることを忘れないでください。ダッシュボードですべてのキーを取得できます。
支払い作成リクエストが成功すれば、クレジットカードへの請求に成功したことになります。 2 日後に自動的に代金が振り込まれます。 支払いが失敗した場合は、エラーが返されます。
トークンは一度しか使用できず、作成されてから数分で失効します。 複数の支払い、今後の支払い、または定期支払いには請求を行わず、クレジットカードのトークンを保存してください。
動的な明細書表記
顧客のクレジットカードに請求を行うたびに、Stripe アカウントに記載されている明細書表記 がデフォルトで顧客の明細書に表示されます。また、Charge オブジェクトの statement_descriptor
引数を指定すると、支払いリクエストごとに明細書表記を動的に設定できます。
curl https://api.stripe.com/v1/charges \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d amount=999 \
-d currency=usd \
-d description="Example charge" \
-d source=tok_visa \
-d statement_descriptor="Custom descriptor"
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = params[:stripeToken]
charge = Stripe::Charge.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
statement_descriptor: 'Custom descriptor',
})
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = request.form['stripeToken'] # Using Flask
charge = stripe.Charge.create(
amount=999,
currency='usd',
description='Example charge',
source=token,
statement_descriptor='Custom descriptor',
)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
'statement_descriptor' => 'Custom descriptor',
]);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
String token = request.getParameter("stripeToken");
Map<String, Object> params = new HashMap<>();
params.put("amount", 999);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
params.put("statement_descriptor", "Custom descriptor");
Charge charge = Charge.create(params);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
const token = request.body.stripeToken; // Using Express
(async () => {
const charge = await stripe.charges.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
statement_descriptor: 'Custom descriptor',
});
})();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
token := r.FormValue("stripeToken")
params := &stripe.ChargeParams{
Amount: stripe.Int64(999),
Currency: stripe.String(string(stripe.CurrencyUSD)),
Description: stripe.String("Example charge"),
StatementDescriptor: stripe.String("Custom descriptor"),
}
params.SetSource(token)
ch, _ := charge.New(params)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token submitted by the form:
var token = model.Token; // Using ASP.NET MVC
var options = new ChargeCreateOptions {
Amount = 999,
Currency = "usd",
Description = "Example charge",
Source = token,
StatementDescriptor = "Custom descriptor",
};
var service = new ChargeService();
Charge charge = service.Create(options);
アカウントの明細書表記が 10 文字を超える場合は、ダッシュボードで短い表記を設定するか、statement_descriptor_prefix
を使用してください。これにより、予想外の形で明細書表記が短縮されることがなくなります。
明細書表記が最終的にどのような形で表示されるかは、Stripe ダッシュボード で確認できます。
別個のオーソリとキャプチャ
最初に支払いのオーソリを行い、後で決済処理 (キャプチャ) を行います。 支払いが承認されると、クレジットカード会社によって資金が確保され、その金額が顧客のクレジットカードに最大 7 日間確保されます。 この期間中に支払いがキャプチャされない場合、オーソリはキャンセルされ、資金がリリースされます。
支払いのオーソリだけを行ない、キャプチャしないようするには、capture
パラメータに false の値を指定して支払いリクエストを行います。
そうすることで、顧客のクレジットカードの金額承認のみをするよう Stripe に指示できます。
オーソリをキャンセルする必要がある場合は、関連する Charge
オブジェクトを返金することで解除できます。
curl https://api.stripe.com/v1/charges \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d amount=999 \
-d currency=usd \
-d description="Example charge" \
-d source=tok_visa \
-d capture=false
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = params[:stripeToken]
charge = Stripe::Charge.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
capture: false,
})
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = request.form['stripeToken'] # Using Flask
charge = stripe.Charge.create(
amount=999,
currency='usd',
description='Example charge',
source=token,
capture=False,
)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
'capture' => false,
]);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
String token = request.getParameter("stripeToken");
Map<String, Object> params = new HashMap<>();
params.put("amount", 999);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
params.put("capture", false);
Charge charge = Charge.create(params);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
const token = request.body.stripeToken; // Using Express
(async () => {
const charge = await stripe.charges.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
capture: false,
});
})();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
token := r.FormValue("stripeToken")
params := &stripe.ChargeParams{
Amount: stripe.Int64(999),
Currency: stripe.String(string(stripe.CurrencyUSD)),
Description: stripe.String("Example charge"),
Capture: stripe.Bool(false),
}
params.SetSource(token)
ch, _ := charge.New(params)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token submitted by the form:
var token = model.Token; // Using ASP.NET MVC
var options = new ChargeCreateOptions {
Amount = 999,
Currency = "usd",
Description = "Example charge",
Source = token,
Capture = false,
};
var service = new ChargeService();
Charge charge = service.Create(options);
承認された支払いの決済処理をするには、支払いのキャプチャリクエストを作成します。
デフォルトでは承認された金額の総額がキャプチャされ、それ以上キャプチャすることはできません。
当初の金額を下回る金額 (たとえば、承認された 10 ドルのうち 8 ドル) をキャプチャするには、amount
パラメータを渡します。
支払いの一部をキャプチャすると、自動的に残りの金額が金額がリリースされます。
curl https://api.stripe.com/v1/charges/ch_61kSUi2u0CR549DPcXAX/capture \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-X POST
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
charge = Stripe::Charge.capture('ch_61kSUi2u0CR549DPcXAX')
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
charge = stripe.Charge.capture('ch_61kSUi2u0CR549DPcXAX')
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
$charge = \Stripe\Charge::retrieve('ch_61kSUi2u0CR549DPcXAX');
$charge->capture();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
Charge charge = Charge.retrieve("ch_61kSUi2u0CR549DPcXAX");
charge.capture();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
const charge = stripe.Charges.capture('ch_61kSUi2u0CR549DPcXAX')
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
ch, _ := charge.Capture("ch_61kSUi2u0CR549DPcXAX", nil)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
var service = new ChargeService();
Charge charge = service.Capture("ch_61kSUi2u0CR549DPcXAX")
クレジットカード会社によっては、カード明細書でオーソリとキャプチャ (決済) 処理を区別しないため、顧客が混乱する原因となることがあります。 さらに、承認された支払いは 1 度しかキャプチャできません。 支払いの一部しかキャプチャしなかった場合、差額のキャプチャはできません。 要件によっては、後で使用するために顧客のクレジットカード情報を保存し、必要に応じて支払いを作成する方が効率的です。
メタデータへの情報格納
Stripe では、最もよく利用するリクエスト (支払いプロセスなど) にメタデータを追加できます。 メタデータは顧客には表示されません。また、不正防止システムによって支払いが拒否またはブロックされるかどうかの判断にも使用されません。
メタデータを使用すると、お客様に役立つその他の情報を Stripe のアクティビティに関連付けることができます。 追加したメタデータはすべて、ダッシュボードに表示されます (たとえば、個々の支払いのページを表示した場合など)。また、 一般的なレポートやエクスポートでも利用できます。たとえば、ストアの注文 ID をその注文の支払いに割り当てることができます。 これにより、お客様、会計士、経理チームが、Stripe での支払いとお客様のシステム内の注文とを簡単に照合できるようになります。
Radar を使用する場合は、追加の顧客情報と注文情報をメタデータとして渡すことを検討してください。 そうすることで、メタデータ属性を使用した Radar ルールを記述でき、ダッシュボード内で支払いについて詳細情報を確認できるようになり、レビュープロセスが迅速化されます。
curl https://api.stripe.com/v1/charges \
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d amount=999 \
-d currency=usd \
-d description="Example charge" \
-d source=tok_visa \
-d metadata[order_id]=6735
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = params[:stripeToken]
charge = Stripe::Charge.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
metadata: {'order_id' => 6735},
})
# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
# Token is created using Checkout or Elements!
# Get the payment token ID submitted by the form:
token = request.form['stripeToken'] # Using Flask
charge = stripe.Charge.create(
amount=999,
currency='usd',
description='Example charge',
source=token,
metadata={'order_id': 6735},
)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => 999,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
'metadata' => ['order_id' => 6735],
]);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
String token = request.getParameter("stripeToken");
Map<String, Object> params = new HashMap<>();
params.put("amount", 999);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
Map<String, String> metadata = new HashMap<>();
metadata.put("order_id", 6735);
params.put("metadata", metadata);
Charge charge = Charge.create(params);
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
const token = request.body.stripeToken; // Using Express
(async () => {
const charge = await stripe.charges.create({
amount: 999,
currency: 'usd',
description: 'Example charge',
source: token,
metadata: {order_id: 6735},
});
})();
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
token := r.FormValue("stripeToken")
params := &stripe.ChargeParams{
Amount: stripe.Int64(999),
Currency: stripe.String(string(stripe.CurrencyUSD)),
Description: stripe.String("Example charge"),
}
params.SetSource(token)
params.AddMetadata("order_id", 6735)
ch, _ := charge.New(params)
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
// Token is created using Checkout or Elements!
// Get the payment token submitted by the form:
var token = model.Token; // Using ASP.NET MVC
var options = new ChargeCreateOptions {
Amount = 999,
Currency = "usd",
Description = "Example charge",
Source = token,
Metadata = new Dictionary<String, String>() {{"OrderId", "6735"}},
};
var service = new ChargeService();
Charge charge = service.Create(options);
次のステップ
これで Stripe を使用して支払いを処理することができました。以下の関連情報を参考に、次のステップにお進みください。