Stripe オブジェクト

Stripeその他エントリー

目次一覧

 状態:-  閲覧数:798  投稿日:2019-02-13  更新日:2019-04-19  
よく使用するStripe オブジェクト一覧 / Stripe オブジェクト別メソッド比較一覧 /「各Stripeオブジェクト」作成するまでに、作成必要なオブジェクト

\Stripe\Accountオブジェクト / \Stripe\Tokenオブジェクト / \Stripe\Sourceオブジェクト

Cardオブジェクト / \Stripe\Chargeオブジェクト / \Stripe\Productオブジェクト

\Stripe\Planオブジェクト / \Stripe\Customerオブジェクト / \Stripe\Subscriptionオブジェクト

\\Stripe\PaymentIntentオブジェクト / Stripe\PaymentMethodオブジェクト / \Stripe\Checkout\Sessionオブジェクト

よく使用するStripe オブジェクト一覧 / Stripe オブジェクト別メソッド比較一覧 /「各Stripeオブジェクト」作成するまでに、作成必要なオブジェクト

 閲覧数:261 投稿日:2019-02-13 更新日:2019-04-25 

よく使用するStripe オブジェクト一覧


Accountオブジェクト
Tokenオブジェクト
Sourceオブジェクト
Cardオブジェクト
Chargeオブジェクト
Productオブジェクト
SKUオブジェクト
Planオブジェクト
Customerオブジェクト
Subscriptionオブジェクト
PaymentIntentオブジェクト
PaymentMethodオブジェクト
Checkout\Sessionオブジェクト

Stripe オブジェクト別メソッド比較一覧


Cardオブジェクト
・他オブジェクトとは異なりStripeオブジェクトと継承関係がない
→ 他とは異なり、createメソッドがない
→ 他とは異なり、deleteメソッドがない
※Cardオブジェクトは、Customerオブジェクトの「sourcesプロパティ」内にある「dataプロパティ」内に、「リスト構造化されて配置される」仕様

一覧表
オブジェクト名 createメソッド 備考
Accountオブジェクト Accountクラスのcreateメソッド呼出
→ Createトレイトのcreateメソッドが実行される
Tokenオブジェクト -
Sourceオブジェクト -
Cardオブジェクト × CustomerオブジェクトのcreateSourceメソッドを使用
Chargeオブジェクト -
Productオブジェクト -
Planオブジェクト -
Customerオブジェクト -
Subscriptionオブジェクト -
PaymentIntentオブジェクト -
PaymentMethodオブジェクト サーバで直接createメソッド実行するのではなく、「Stripe.js、Stripeモバイルバインディング、Stripe Checkout」の何れかを介した方が良い
Checkout\Sessionオブジェクト -

「各Stripeオブジェクト」作成するまでに、作成必要なオブジェクト


比較一覧表
・横 … 作成対象である「各Stripeオブジェクト」
・縦 … 上記作成のために、事前に作成必要なオブジェクト
- Token Product Plan Customer
Token - - - -
Product - - - -
Plan - - -
Subscription
PaymentIntent - - - -


\Stripe\Accountオブジェクト / \Stripe\Tokenオブジェクト / \Stripe\Sourceオブジェクト

 閲覧数:296 投稿日:2019-02-13 更新日:2019-04-14 

\Stripe\Accountオブジェクト


create()メソッド
・コード例
\Stripe\Stripe::setApiKey("sk_test_●●");

\Stripe\Account::create([
 "type" => "custom",
 "country" => "US",
 "email" => "bob@example.com"
]);


・必須パラメータ一覧表
パラメータ 内容
type 作成するStripeアカウントの種類。 カスタムアカウントのみがAPIを介して作成される場合があるため、現在はcustomである必要がある

\Stripe\Tokenオブジェクト


create()メソッド
・コード例
\Stripe\Stripe::setApiKey("sk_test_●●");

\Stripe\Token::create([
 "card" => [
   "number" => "4242424242424242",
   "exp_month" => 2,
   "exp_year" => 2020,
   "cvc" => "314"
 ]
]);


・必須パラメータ一覧表
パラメータ 内容
card.exp_month カードの有効期限月を表す2桁の番号
card.exp_year カードの有効期限を表す2桁または4桁の番号
card.number 区切り文字なしの文字列としてのカード番号

\Stripe\Sourceオブジェクト


create()メソッド
・コード例
・下記コードは「ACH支払い」なので日本では意味がない
・入力されたカード情報を元にSourceオブジェクト作成するので、通常はこのメソッドを直接呼び出すことはない → Stripeが提供しているライブラリ経由で呼出
\Stripe\Stripe::setApiKey("sk_test_xxxx");

\Stripe\Source::create([
 "type" => "ach_credit_transfer",
 "currency" => "usd",
 "owner" => [
   "email" => "jenny.rosen@example.com"
 ]
]);


・必須パラメータ一覧表
パラメータ 内容
type 作成するソースの種類。 customerとoriginal_sourceが指定されていない場合は必須だ( 『Shared card Sources』ガイドを参照)


Cardオブジェクト / \Stripe\Chargeオブジェクト / \Stripe\Productオブジェクト

 閲覧数:308 投稿日:2019-02-14 更新日:2019-04-16 

Cardオブジェクト


Stripeオブジェクトと継承関係がない
・他とは異なり、このオブジェクトだけは「Stripeオブジェクト」と継承関係がない
→ 他とは異なり、createメソッドがない
→ 他とは異なり、deleteメソッドがない

階層
・Customerオブジェクトのsourcesプロパティ内にあるdataプロパティ内にリスト構造化されて配置される仕様

Link
Stripe API Reference
stripe-php/Card.php

既存Customerオブジェクトに"source"パラメータとして、トークンID(tok_xxxx)を追加
\Stripe\Stripe::setApiKey("sk_test_xxxx");

$customer = \Stripe\Customer::retrieve("cus_EiZRT8YsFHonSq");
$customer->sources->create(["source" => "tok_mastercard"]);



(新規作成直後の)既存Customerオブジェクトに"source"パラメータとして、ソースID(src_xxxx)を追加
\Stripe\Stripe::setApiKey("sk_test_xxxx");

$customer1 = \Stripe\Customer::create([
   "description" => "Customer 「Stripe.js and Elements」→ ソースID(src_xxxx)指定。4.既存Customerオブジェクトに'source'パラメータとして、ソースID(src_xxxx)を追加",
   'email' => '20190316@example.com',
]);

$customer = \Stripe\Customer::retrieve($customer1->id);
$sourceObj = $customer->sources->create(["source" => $sourceId]);


新規Customerオブジェクト作成時に'source'パラメータとして、ソースID(src_xxxx)を指定
\Stripe\Stripe::setApiKey("sk_xxxx");

$customer = \Stripe\Customer::create([
   "description" => "Customer 「Stripe.js and Elements」→ ソースID(src_xxxx)指定。3.新規Customerオブジェクト作成時に'source'パラメータとして、ソースID(src_xxxx)を指定",
   'email' => '20190316@example.com',
   'source' => $sourceId,
]);


\Stripe\Chargeオブジェクト


create()メソッド
\Stripe\Stripe::setApiKey("sk_test_●●");

\Stripe\Charge::create([
 "amount" => 2000,
 "currency" => "jpy",
 "source" => "tok_visa", // obtained with Stripe.js
 "description" => "Charge for jenny.rosen@example.com"
]);


\Stripe\Productオブジェクト


製品やサービス
・その配下に料金や通貨などが異なる Plan を複数紐付けることができる

一つの Product へ対して出来ること
・複数の料金プランを持つことができる
・毎月、毎年など異なる請求間隔プランを持つことができる。月額500円のプラン。年額5,000円のプラン
・複数の通貨プランを持つことができる。日本円の料金プラン。USドルの料金プラン。ユーロの料金プラン

create()メソッド
・次のコードは、'type'が'good'タイプのProductを作成する方法を示している
\Stripe\Stripe::setApiKey("sk_test_●●");

\Stripe\Product::create([
 "name" => 'T-shirt',
 "type" => "good",
 "description" => "Comfortable cotton t-shirt",
 "attributes" => ["size", "gender"]
]);


・次のコードは、'type'が'service'タイプのProductを作成する方法を示している
\Stripe\Stripe::setApiKey("'sk_test_●●");

$product = \Stripe\Product::create([
   'name' => 'My SaaS Platform',
   'type' => 'service',
]);

Managing Plans

\Stripe\Planオブジェクト / \Stripe\Customerオブジェクト / \Stripe\Subscriptionオブジェクト

 閲覧数:288 投稿日:2019-03-07 更新日:2019-03-18 

\Stripe\Planオブジェクト


create()メソッド
・ 'product'パラメータ値として「サービス製品の作成に使用されるフィールド、を含む辞書型データ」を指定
\Stripe\Stripe::setApiKey("sk_test_●●");

\Stripe\Plan::create([
 "amount" => 5000,
 "interval" => "month",
 "product" => [
   "name" => "Gold special"
 ],
 "currency" => "jpy",
 "id" => "gold-special"
]);

Managing Plans
・ 'product'パラメータ値として「既存の製品のID」を指定
\Stripe\Stripe::setApiKey("sk_test_●●");

$plan = \Stripe\Plan::create([
   'currency' => 'usd',
   'interval' => 'month',
   'product' => 'prod_CHxGUqw1dyKsDM',
   'nickname' => 'Pro Plan',
   'amount' => 3000,
]);


\Stripe\Customerオブジェクト


create()メソッド
\Stripe\Stripe::setApiKey("'sk_test_●●");

\Stripe\Customer::create([
 "description" => "Customer for jenny.rosen@example.com",
 "source" => "tok_mastercard" // obtained with Stripe.js
]);


\Stripe\Subscriptionオブジェクト


create()メソッド
\Stripe\Stripe::setApiKey("sk_test_●●");

\Stripe\Subscription::create([
 "customer" => "cus_EWcle5LgHORJY6",
 "items" => [
   [
     "plan" => "sample-monthly",
   ],
 ]
]);


\Stripe\PaymentIntentオブジェクト / Stripe\PaymentMethodオブジェクト / \Stripe\Checkout\Sessionオブジェクト

 閲覧数:313 投稿日:2019-03-18 更新日:2019-04-25 

\Stripe\PaymentIntentオブジェクト


顧客から支払いを集めるというあなたの意図を表し、各段階を通して支払いプロセスのライフサイクルを追跡するオブジェクト

チェックアウトフローの開始時に PaymentIntent を作成すると
・「注文に対する支払いの試行」をすべて追跡できる

create()メソッド
// 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_●●");

$paymentintent = \Stripe\PaymentIntent::create([
 "amount" => 1099,
 "currency" => "eur",
 "payment_method_types" => ["card"],
]);


Stripe\PaymentMethodオブジェクト


顧客の支払い方法を表す
・PaymentIntentsと共に支払いを収集するために使用することも、将来の支払いのために商品の詳細を保存するためにCustomerオブジェクトに保存することもできる

create()メソッド
・非推奨
・サーバで直接createメソッド実行するのではなく、「Stripe.js、Stripeモバイルバインディング、Stripe Checkout」の何れかを介した方が(一般的には)良い
// 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_xxxx");

$paymentMethod = \Stripe\PaymentMethod::create([
 'type' => 'card',
 'card' => [
   'number' => '4000003920000003',
   'exp_month' => 4,
   'exp_year' => 2020,
   'cvc' => '314'
 ]
]);


stripe.createPaymentMethod(type, element[, data])
// 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_xxxx");

$paymentintent = \Stripe\PaymentIntent::create([
// "amount" => 1099,
"currency" => "jpy",
// "payment_method_types" => ["card"],
]);
?>


<input id="cardholder-name" type="text">
<!-- placeholder for Elements -->
<div id="card-element"></div>
<button id="card-button" data-secret="<?php echo $paymentintent->client_secret; ?>">
Submit Payment
</button>

<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('pk_test_sodaTzCycoslfNFDdujc9U5r');

const elements = stripe.elements();
const cardElement = elements.create('card');
cardElement.mount('#card-element');

const cardholderName = document.getElementById('cardholder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;

cardButton.addEventListener('click', async (ev) => {
// const {paymentIntent, error} = await stripe.handleCardPayment(
// clientSecret, cardElement, {
// payment_method_data: {
// billing_details: {name: cardholderName.value}
// }
// }
// );
const {paymentMethod, error} = await stripe.createPaymentMethod('card', cardElement, {
billing_details: {
name: cardholderName.value,
},
});

if (error) {
// Display error.message in your UI.
console.log(error)
} else {
// The payment has succeeded. Display a success message.
console.log("成功")
console.log(paymentMethod.id)
console.log(paymentMethod)
}
});
</script>



\Stripe\Checkout\Sessionオブジェクト


checkout.session.completed Webhookに含まれている


Stripe への問い合わせ方

旧 Stripe 学習の流れを体系化

コメント投稿(ログインが必要)



週間人気ページランキング / 4-18 → 4-24
順位 ページタイトル抜粋 アクセス数
1 YouTube | 動画サービス(課金販売できるプラットフォーム) 8
2 EMVレベル1 / EMVレベル2 / EMVCo とは? 6
3 EMVCo | クレジットカード仕様(仕様) 5
4 クレジットカード決済 | 課金 3
4 pixivFANBOX | クリエイター支援プラットフォーム(課金販売できるプラットフォーム) 3
5 Stripe webhook 配信の問題 / 実際に受け取った警告メールの受信例 2
5 Stripe Q73.CheckoutのSessionオブジェクトをcreateする際、'payment_intent_data'内の'metadata'として渡したデータを、webhookで受け取る件について | QA(Stripe) 2
5 Stripe Q55.Checkout\Session::createする際の、'client_reference_id'パラメータと'payment_intent_data.metadata'パラメータの違いについて | QA(Stripe) 2
5 ログイン 2
5 Stripeアカウントへログインする際、モバイル端末で受信したコード入力を求められる理由は? | その他エントリー(Stripe) 2
5 Off-session Payments with Payment Intents / Payment Intents を使用したオフセッション支払 2
5 Stripe Q32。Webhook のエンドポイントから適切な値を返さなかったときの停止措置について | QA(Stripe) 2
5 Stripe Q16。PaymentIntentの支払いで郵便番号入力を求められる。Radar rules の ZIP code を無効にしているのに | QA(Stripe) 2
5 プリペイドカード | カード 2
5 Squareは、デジタルコンテンツ(デジタル情報)の配信利用が認められないサービス | 「支払」機能を有する決済系サービス(決済サービス) 2
6 Twitchとは?/ Cheeringとは?/ Cheerとは? 1
6 ほしい物リスト | 投げ銭サービス(課金販売できるプラットフォーム) 1
6 Omise | 「支払」機能を有する決済系サービス(決済サービス) 1
6 決済用語 1
6 振込 | 送金 1
2024/4/25 1:02 更新