プログラミング初心者です。どうしても解決できず困っています。
これまで普通に保存できていたユーザーカード情報が保存できなくなりました。登録が完了しましたというアラートが表示されるのでステータスコードは200で返ってきているのですが、データベースに保存されていない状態です。
親切な方いらっしゃいましたら是非コメントよろしくお願い致します。
**Indicate whether to send a cookie in a cross-site request by specifying its SameSite attribute
Because a cookie's SameSite attribute was not set or is invalid, it defaults to SameSite=Lax, which prevents the cookie from being sent in a cross-site request. This behavior protects user data from accidentally leaking to third parties and cross-site request forgery.
Resolve this issue by updating the attributes of the cookie:
Specify SameSite=None and Secure if the cookie should be sent in cross-site requests. This enables third-party use.
Specify SameSite=Strict or SameSite=Lax if the cookie should not be sent in cross-site requests
1 cookie
Name Domain & Path
_ga .pay.jp/
2 requests
**
ブラウザの検証で確認すると、このようなエラーが出ています。
ruby
1cards.controller.rb 2 3def create 4 5 # 環境変数を読み込む 6 Payjp.api_key = ENV["PAYJP_SECRET_KEY"] 7 8 customer = Payjp::Customer.create( 9 description: 'test', # テストカードであることを説明 10 card: params[:card_token] # 登録しようとしているカード情報 11 ) 12 13 @card = Card.new( # トークン化されたカード情報を保存する 14 card_token: params[:card_token], # カードトークン 15 customer_token: customer.id, # 顧客トークン 16 user_id: current_user.id # ログインしているユーザー 17 ) 18 19 redirect_to user_path(current_user.id) 20 21 end
ruby
1 2card.js 3 4if (document.URL.match( /card/ ) && document.URL.match( /new/ )) { 5 document.addEventListener('DOMContentLoaded', function(){ 6 7 // 環境変数を読み込む 8 Payjp.setPublicKey(process.env.PAYJP_PUBLIC_KEY); 9 const form = document.getElementById("charge-form"); 10 form.addEventListener("submit", (e) => { 11 e.preventDefault(); 12 13 // カード情報の取得先 14 const formResult = document.getElementById("charge-form"); 15 const formData = new FormData(formResult); 16 17 const card = { 18 number: formData.get("number"), // カード番号 19 cvc: formData.get("cvc"), // カード裏面の3桁の数字 20 exp_month: formData.get("exp_month"), // 有効期限の月 21 exp_year: `20${formData.get("exp_year")}`, // 有効期限の年 22 }; 23 24 Payjp.createToken(card, (status, response) => { 25 if (status === 200) { 26 const token = response.id; 27 const renderDom = document.getElementById("charge-form"); 28 29 //paramsの中にトークンを含める 30 const tokenObj = `<input value=${token} type="hidden" name='card_token'>`; 31 32 //フォームの一番最後に要素を追加 33 renderDom.insertAdjacentHTML("beforeend", tokenObj); 34 35 document.getElementById("number").removeAttribute("name"); 36 document.getElementById("cvc").removeAttribute("name"); 37 document.getElementById("exp_month").removeAttribute("name"); 38 document.getElementById("exp_year").removeAttribute("name"); 39 40 document.getElementById("charge-form").submit(); 41 document.getElementById("charge-form").reset(); 42 alert("登録が完了しました") 43 } else { 44 alert("カード情報が正しくありません") 45 } 46 }); 47 }); 48 }); 49} 50 51
追記
pay.jpを使用したクレジット決済機能です。
データベースに保存しようとしているカラムは、card_token, customer_token, user_idです。
あなたの回答
tips
プレビュー