0
我正在嘗試實現客戶創建新卡的功能。Stripe - 爲客戶創建新卡
我已經創造了一種客戶創建一個新的卡片形式:
<table class="table">
<%= simple_form_for(@user, :url => billing_path, html: {class: 'form-horizontal' }) do |f| %>
<tr>
<td>Country</td>
<td><%= f.text_field :saddress_country, value: card1.address_country %> </td>
</tr>
<tr>
<td>Billing Address</td>
<td><%= f.text_field :sbilling_address1, value: card1.address_line1 %> </td>
<td><%= f.text_field :sbilling_address2, value: card1.address_line2 %> </td>
</tr>
<tr>
<td>City/State/Zip</td>
<td><%= f.text_field :saddress_city, value: card1.address_city %> </td>
<td><%= f.text_field :saddress_state, value: card1.address_state %> </td>
<td><%= f.text_field :saddress_zip, value: card1.address_zip %> </td>
</tr>
<tr>
<td>Credit Card Number </td>
<td><%= f.text_field :scardnumber, placeholder: card1.last4, value: cardnumberempty %></td>
<td><%= f.text_field :scvc, placeholder: "CVC", value: cvcempty %></td>
</tr>
<tr>
<td>Card's Info</td>
<td><%= f.text_field :sname, value: card1.name %> </td>
<td><%= f.text_field :sexp_month, value: card1.exp_month %> </td>
<td><%= f.text_field :sexp_year, value: card1.exp_year %> </td>
</tr>
<tr><td><%= f.submit %></td></tr>
<% end %>
</table>
然後在控制器我搶的信息,並創建新卡:
def create_card_stripe
@user = current_user
customer = Stripe::Customer.retrieve(current_user.stripe_customer_token)
customer.cards.create({
:card => current_user.stripe_card_token,
:number => params[:user][:scardnumber],
:exp_month => params[:user][:sexp_month],
:exp_year => params[:user][:sexp_year],
:cvc => params[:user][:scvc],
:name => params[:user][:sname],
:address_line1 => params[:user][:saddress_line1],
:address_line2 => params[:user][:saddress_line2],
:address_city => params[:user][:saddress_city],
:address_zip => params[:user][:saddress_zip],
:address_state => params[:user][:saddress_state],
:address_country => params[:user][:saddress_country]
})
@user.update_attribute(:stripe_card_id, customer.active_card.id)
if customer.save
flash.alert = "Billing information updated successfully!"
redirect_to edit_user_registration_path
else
flash.alert = "Stripe error"
redirect_to edit_user_registration_path
end
end
當我提交我收到以下來自Stripe的錯誤: 「收到未知參數:number,exp_month,exp_year,cvc,name,address_city,address_zip,address_state,address_country」。
所以它說的是我發送錯誤的參數。但是,如果您檢查here那些參數(兒童參數)。
任何線索我做錯了什麼?任何有關如何使用Stripe API創建新卡的指導都將非常有幫助。謝謝。
哦,我錯過了。非常感謝你。 –
嗨,它是否允許重複卡?因爲我用兩次相同的卡片細節嘗試了兩次,因爲它將兩張卡片保存了兩次。 –
我想在按照標記創建新卡之前檢查該客戶已有的卡。可能嗎?如果是這樣,我怎麼可以檢查存在與令牌卡?請分享你的想法。 –