Pay.jpを利用した課金の実装をしたいのですが、invalid_api_keyが出てきます。
ググってもよくわからなかったので、お力貸していただけると嬉しいです。
ルーティング
purchase_products POST /products/purchase(.:format) products#purchase products GET /products(.:format) products#index POST /products(.:format) products#create new_product GET /products/new(.:format) products#new edit_product GET /products/:id/edit(.:format) products#edit product GET /products/:id(.:format) products#show PATCH /products/:id(.:format) products#update PUT /products/:id(.:format) products#update DELETE /products/:id(.:format) products#destroy
コントローラー
class ProductsController < ApplicationController def index end def new end def show end def create end def purchase Payjp.api_key = ENV["PAYJP_SECRET_KEY"] Payjp::Charge.create( :amount => 9800, :card => params['payjp-token'], :currency => 'jpy' ) end end
products/index.html.erb
<%= form_tag(action: :purchase, method: :post) do %> <script type="text/javascript" src="https://checkout.pay.jp" class="payjp-button" data-key="<%= ENV["PAYJP_PUBLIC_KEY"] %>"></script> <% end %>
products/purchase.html.erb
支払いが完了しました
ちなみにボタンは表示されていて、本来ならばモーダルが出てクレジットのサンプル番号を入力するのですが、そこで無効なAPIkeyと出てしまい、途方に暮れています><
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/30 13:50