1
1

More than 3 years have passed since last update.

シンプルにRailsでStripeを動かす(コンソールで決済してみる)

Posted at

RailsでStripe gemをinstall

gem 'stripe'

RailsでStripe設定ファイルを手動で作る

config/initializers/stripe.rb

RailsでStripeを鍵をセット

stripe.rb
Rails.configuration.stripe = {
    :publishable_key => "あなたのPublishable key",
    :secret_key => "あなたのSecret key"
 }

 Stripe.api_key = Rails.configuration.stripe[:secret_key]

RailsでStripe決済する

% rails c

> amount = 500
> token = 'tok_jp'
> order_id = 'sample_order_id'
> charge = Stripe::Charge.create(
    amount: amount,
    currency: 'jpy',
    source: token,
    metadata: { order_id: order_id },
  )
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1