plugins {id("com.android.application")}
android {...}
dependencies {// ...// Stripe Android SDKimplementation("com.stripe:stripe-android:21.22.0")// Include the financial connections SDK to support US bank account as a payment methodimplementation("com.stripe:financial-connections:21.22.0")}
また、SDK が Stripe への API コールを実行できるように、公開可能キーを設定する必要もあります。すぐに開始するには、導入中にクライアント側でこれをハードコード化できますが、本番環境ではサーバーから公開可能キーを取得します。
// Set your publishable key: remember to change this to your live publishable key in production// See your keys here: https://dashboard.stripe.com/apikeys
PaymentConfiguration.init(context, publishableKey =
class MyCheckoutActivity :AppCompatActivity(){privatelateinitvar paymentSheet: PaymentSheet
overridefunonCreate(savedInstanceState: Bundle?){super.onCreate(savedInstanceState)// ...
paymentSheet = PaymentSheet.Builder(::onPaymentSheetResult).createIntentCallback{ _, _ ->// Make a request to your server to create a SetupIntent and return its client secretval networkResult = myNetworkClient.createIntent()if(networkResult.isSuccess){
CreateIntentResult.Success(networkResult.clientSecret)}else{
CreateIntentResult.Failure(networkResult.exception)}}.build(this)}funonPaymentSheetResult(paymentSheetResult: PaymentSheetResult){// You'll implement this later}}
class MyCheckoutActivity :AppCompatActivity(){// ...funonPaymentSheetResult(paymentSheetResult: PaymentSheetResult){when(paymentSheetResult){is PaymentSheetResult.Canceled ->{// Customer canceled - you should probably do nothing.}is PaymentSheetResult.Failed ->{print("Error: ${paymentSheetResult.error}")// PaymentSheet encountered an unrecoverable error. You can display the error to the user, log it, etc.}is PaymentSheetResult.Completed ->{// Display, for example, an order confirmation screenprint("Completed")}}}}
post '/create-intent'do
data =JSON.parse request.body.read
params ={
customer:...,# The Customer ID you previously created# In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
automatic_payment_methods:{enabled:true},}begin
intent =Stripe::SetupIntent.create(params){client_secret: intent.client_secret}.to_json
rescueStripe::StripeError=> e
{error: e.error.message}.to_json
endend
購入者にオフセッションで請求する準備ができたら、Customer ID と PaymentMethod ID を使用して、PaymentIntent を作成します。請求する決済手段を見つけるには、顧客に関連付けられた決済手段を一覧表示します。この例ではカードが一覧表示されますが、サポートされているすべてのタイプを一覧表示できます。
: \ -damount=1099\ -dcurrency=usd \# In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default. -d"automatic_payment_methods[enabled]"=true \ -dcustomer="{{CUSTOMER_ID}}"\ -dpayment_method="{{PAYMENT_METHOD_ID}}"\ -dreturn_url="https://example.com/order/123/complete"\ -doff_session=true \ -dconfirm=true