質問するログイン新規登録

Q&A

0回答

1200閲覧

Payjp の Errorを解決したい

yuki-natori

総合スコア7

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/06/04 09:56

編集2020/06/05 11:41

0

0

前提・実現したいこと

現在RailsにてPayjpを実装している最中のです。

クレジットカード入力後に出てくる
Payjp::AuthenticationErrorを解決したいです。

発生している問題・エラーメッセージ

イメージ説明

該当のソースコード

new.html.haml = form_tag(pay_credit_index_path, method: :post, id: 'charge-form', name: "inputForm") do %label カード番号 = text_field_tag "number", "", class: "number", placeholder: "半角数字のみ" ,maxlength: "16", type: "text", id: "credit_number" %br %label 有効期限 %select#exp_month{name: "exp_month", type: "text"} %option{value: ""} -- %option{value: "1"}01 %option{value: "2"}02 %option{value: "3"}03 %option{value: "4"}04 %option{value: "5"}05 %option{value: "6"}06 %option{value: "7"}07 %option{value: "8"}08 %option{value: "9"}09 %option{value: "10"}10 %option{value: "11"}11 %option{value: "12"}12 %span 月/ %select#exp_year{name: "exp_year", type: "text"} %option{value: ""} -- %option{value: "2019"}19 %option{value: "2020"}20 %option{value: "2021"}21 %option{value: "2022"}22 %option{value: "2023"}23 %option{value: "2024"}24 %option{value: "2025"}25 %option{value: "2026"}26 %option{value: "2027"}27 %option{value: "2028"}28 %option{value: "2029"}29 %span 年 %br %label セキュリティコード = text_field_tag "cvc", "", class: "cvc", placeholder: "カード背面3~4桁の番号", maxlength: "4", id: "cvc" #credit_token = submit_tag "追加する", id: "token_submit"
credit_controller.rb class CreditController < ApplicationController require "payjp" def new credit = Credit.where(user_id: current_user.id) redirect_to action: "show" if credit.exists? end def pay #payjpとcreditのデータベース作成を実施します。 Payjp.api_key = ENV["PAYJP_PRIVATE_KEY"] if params['payjp_token'].blank? redirect_to action: "new" else customer = Payjp::Customer.create( credit: params['payjp_token'], metadata: {user_id: current_user.id} ) #念の為metadataにuser_idを入れましたがなくてもOK @credit = Credit.new(user_id: current_user.id, customer_id: customer.id, credit_id: customer.default_credit) if @credit.save redirect_to action: "show" else redirect_to action: "pay" end end end def delete #Payjpとcreditデータベースを削除します credit = Credit.where(user_id: current_user.id).first if credit.blank? else Payjp.api_key = ENV["PAYJP_PRIVATE_KEY"] customer = Payjp::Customer.retrieve(credit.customer_id) customer.delete credit.delete end redirect_to action: "new" end def show #creditのデータpayjpに送り情報を取り出します credit = Credit.where(user_id: current_user.id).first if credit.blank? redirect_to action: "new" else Payjp.api_key = ENV["PAYJP_PRIVATE_KEY"] customer = Payjp::Customer.retrieve(credit.customer_id) @default_credit_information = customer.credits.retrieve(credit.credit_id) end end end

試したこと

エラーメッセージを調べたところ、”APIキーが設定されていません”と書いてあったので、

vim ~/.bash_profileにて

export PAYJP_ACCESS_KEY='sk_test_'
export PAYJP_PUBLIC_KEY='pk_test_
'
※APIキーは取得しています

ターミナルにてAPIキーを入力し

source ~/.bash_profile

で保存は確認できましたが、エラー内容は変わらずでした。

エラーに関する記事が少なく、苦戦しています。

環境変数を置く場所が違っているのでは?と考えてますが、他に考えられる要因はありますか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.29%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問