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 },
)