1
我試圖通過訂單並將錢轉移到創建列表的收件人。 每次嘗試傳遞訂單時,我都會收到錯誤「無法轉移到沒有默認付款帳戶的收件人」。當用戶創建新的列表時,他們必須提供諸如國家,路由號碼和唯一帳號的信息。我將顯示我的代碼,如果有人可以看到一個錯誤,我做了它會有很大幫助。試圖通過條紋轉移到收件人
當我嘗試這在這個控制檯是我得到
rp = Stripe::Recipient.retrieve(user.recipient)
=> #<Stripe::Recipient:0x8333f120 id=rp_14X1Sz4SnElBeDRiOQWxitGL> JSON: {
"id": "rp_14X1Sz4SnElBeDRiOQWxitGL",
"object": "recipient",
"created": 1409365189,
"livemode": false,
"type": "individual",
"description": null,
"email": "[email protected]",
"name": "Andy Perez",
"verified": false,
"metadata": {},
"active_account": null,
"cards": {"object":"list","total_count":0,"has_more":false,"url":"/v1/recipients/rp_14X1Sz4SnElBeDRiOQWxitGL/cards","data":[]},
"default_card": null
}
這是我的房源控制器 類ListingsController < ApplicationController的
def index
if params[:query].present?
@listings = Listing.search(params[:query], page: params[:page])
else
@listings = Listing.all.order("created_at desc").limit(12)
end
end
def show
@listing = Listing.find(params[:id])
end
def new
@listing = Listing.new
end
def create
@listing = Listing.new(listing_params)
@listing.user_id = current_user.id
if current_user.recipient.blank?
Stripe.api_key = ENV["STRIPE_API_KEY"]
token = params[:stripeToken]
recipient = Stripe::Recipient.create(
:name => @listing.user.name,
:email => @listing.user.email,
:type => "individual",
:bank_account => token
)
current_user.recipient = recipient.id
current_user.save
end
if @listing.save
redirect_to @listing
else
render :new
end
end
def seller
@listing = Listing.where(user: current_user)
end
def favorite
if @listing = Listing.find(params[:id])
current_user.mark_as_favorite @listing
redirect_to @listing
end
end
def unfavorite
@listing = Listing.find(params[:id])
@listing.unmark :favorite, :by => current_user
redirect_to @listing = :back
end
private
def listing_params
listing_params = params.require(:listing).permit(:name, :description, :price, :image, :anime_id).merge(:user_id => current_user.id)
end
end
這是我的命令控制器 類OrdersController < ApplicationController的
def sales
@orders = Order.all.where(seller: current_user)
end
def purchases
@orders = Order.all.where(buyer: current_user)
end
def new
@order = Order.new
@listing = Listing.find(params[:listing_id])
end
def create
@order = Order.new(order_params)
@listing = Listing.find(params[:listing_id])
@seller = @listing.user
@order.listing_id = @listing.id
@order.buyer_id = current_user.id
@order.seller_id = @seller.id
recipient_id = @listing.user.recipient
Stripe.api_key = ENV["STRIPE_API_KEY"]
token = params[:stripeToken]
begin
charge = Stripe::Charge.create(
:amount => (@listing.price * 100).floor,
:currency => "usd",
:card => token
)
flash[:notice] = "Thanks for ordering!"
rescue Stripe::CardError => e
flash[:danger] = e.message
end
transfer = Stripe::Transfer.create(
:amount => (@listing.price * 95).floor,
:currency => "usd",
:bank_account => token,
:recipient => @seller.recipient
)
if @order.save
redirect_to root_path
else
render :new
end
end
private
def set_order
@order = Order.find(params[:id])
end
def order_params
order_params = params.require(:order).permit(:address, :city, :state, :buyer_id, :seller_id)
end
end
新上市形式
<section class="new-listing">
<div class="row">
<div class="medium-3 medium-centered columns end">
<%= simple_form_for @listing do |f| %>
<%= f.file_field :image %>
<%= f.input :name, placeholder: 'Name',label: false %>
<%= f.input :price, placeholder: 'Price in USD',label: false %>
<%= f.association :anime, prompt: 'Pick anime',label: false %>
</div>
<div class="medium-12 columns description">
<%= f.input :description, :input_html => { :cols => 50, :rows => 10 }, label: false, placeholder: 'Write the product description here......' %>
<% if current_user.recipient.blank? %>
<br>
<h1>Bank Account Information</h1>
<div class="form-group">
<%= label_tag :country %>
<%= text_field_tag :country, nil, { :name => nil, :'data-stripe' => "country" } %>
</div>
<div class="form-group">
<%= label_tag :routing_number %>
<%= text_field_tag :routing_number, nil, { :name => nil, :'data-stripe' => "routingNumber"} %>
</div>
<div class="form-group">
<%= label_tag :account_number %>
<%= text_field_tag :account_number, nil, { :name => nil, :'data-stripe' => "accountNumber"} %>
</div>
<% end %>
<div class="medium-1 medium-centered columns end">
<%= f.submit 'Done', class: 'button tiny' %>
</div>
<% end %>
</div>
@Larry_Ullman你的答案在這裏,你將如何設置轉移延遲了5天。我們可以在創建轉移時設置延遲參數嗎?是否有一些示例代碼或過程如何設置?我的問題發佈在這裏 - http://stackoverflow.com/questions/26901100/stripe-delaying-transfers-in-a-marketplace-app/26951809#26951809 – Moosa 2014-11-19 14:10:47