0

ストライプをStripe Gemと統合しました。チャージとストライプユーザーを正常に作成できました。私はちょうど2つを関連付けることができません。 :source => params[:stripeToken]を関連付けると請求が終わりますが、ユーザーモデル:source => current_user.stripe_customerと関連付けると、No such token: cus_BX2RXGoOVkpvhL error.Rails5に関連付けられていないストライプエレメントチャージcurrent_user - CheckoutController#InvalidRequestError in checkoutsController#create

私のユーザーモデルに関連付けるときのリクエストパラメータは次のとおりです。

Request 

Parameters: 

{"utf8"=>"✓", 
"authenticity_token"=>"/KI7rzkJsM2uXIynoZkWKa1L+kNgyVcw+UsqfPNOnLYO3t4vfL+R7Yb4XhonyhwTbqlyWTtgYjey71ZroSmoRA==", 
"charge"=>"2200", 
"stripeToken"=>"tok_1B9yneHbiQgBeZWGq78mXM2l", 
"card_brand"=>"Visa", 
"card_exp_month"=>"4", 
"card_exp_year"=>"2024", 
"card_last4"=>"4242"} 

ビュー/寄付/ show.html.erb

... 
<%= link_to 'Confirm Donation', new_checkout_path(charge: @donation.amount), class: 'btn btn-primary' %> 
... 

ビュー/チェックアウト/ new.html.erb

<section> 
    <h1>Secure Payment</h1> 
    <div class="pages-content"> 
    <% if current_user.card_last4? %> 
     <%= form_tag checkout_path, id: 'existing-card' do %> 
      <p>Pay with existing card:</p> 
      <div><strong>Card on file:</strong> 
       <%= current_user.card_brand %> (**** **** **** <%= current_user.card_last4 %>) 
      </div> 
      <div><strong>Expiration:</strong> <%= current_user.card_exp_month %>/<%= current_user.card_exp_year %></div> 
      <p>or <%= link_to 'add a new card', '#', class: 'show-card-form' %></p> 
      <%= hidden_field_tag :charge, params[:charge] %> 
      <input type="submit" class="btn btn-default" value="Submit Payment"> 
     <% end %> 
    <% end %> 
    <%= form_tag checkout_path, id: 'payment-form', style: (current_user.card_last4? ? 'display:none' : nil) do %> 
     <div class="stripe-wrapper"> 
      <div class="form-row"> 
      <label for="card-element"> 
       Enter Your Credit or Debit Card 
      </label> 
      <div id="card-element"> 
       <!-- a Stripe Element will be inserted here. --> 
      </div> 
      <%= hidden_field_tag :charge, params[:charge] %> 
      <!-- Used to display Element errors --> 
      <div id="card-errors" role="alert"></div> 
      </div> 

      <button>Submit</button> 
     </div> 
    <% end %> 
    </div> 
</section> 

モデル/ user.rb

class User < ApplicationRecord 
    ... 

    def stripe_customer 
    if stripe_id? 
     Stripe::Customer.retrieve(stripe_id) 
    else 
     stripe_customer = Stripe::Customer.create(email: email) 
     update(stripe_id: stripe_customer.id) 
     stripe_customer 
    end 
    end 

答えて

1

あなたはIDによって顧客を充電している場合は、代わりにこれを実行する必要があります。

:customer => current_user.stripe_customer 
0

私は同じような問題を一度も抱えていましたが、私のパートナーはテストモードで別の[Publishable key]を使用していたことを覚えています。私は彼に鉱山を与えてくれました。ストライプ上に既に存在します。

私はこれがあなたに役立つことを願っています。

関連する問題