尝试通过条带转移到收件人

时间:2014-08-30 03:00:06

标签: ruby-on-rails stripe-payments

我试图传递订单并将钱转移到创建列表的收件人。 每次我尝试传递订单时都会收到错误消息"无法转移到没有默认付款帐户的收件人"。当用户进行新的列表时,他们必须仅提供国家,路由号码和帐号等信息。我将展示我的代码,如果有人能看到错误我做了它会帮助很多。

当我在控制台中尝试这个时,这就是我得到的

 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": "perez@mezarina.me",
"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
}

这是我的列表控制器     class ListingsController&lt; 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

这是我的订单控制器     class OrdersController&lt; 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>

1 个答案:

答案 0 :(得分:0)

您显示的控制台代码也反映了收件人没有帐户设置(我们转移资金)。因此,错误消息。我没有在您的代码中看到您创建目标帐户的任何位置(例如银行卡或借记卡)。

此外,为了清楚起见,如果您今天处理费用,这些资金将在X天之后才能转移(X =取决于您的帐户)。

希望有所帮助, 拉里

PS我在Stripe的支持工作。