I am working on an E-Commerce market place called foodsy. I am using stripe connect for the purpose. Connected accounts are created using stripe-connect-omniauth. And foodsy has several customers. An order for an Sku is created in rails controller by

 Stripe.api_key = "sk_test_o9YlLXk88Df4N2dmsdQtPEqZ"
    Stripe::Order.create(
      {:currency => 'usd',
      :items => [
        {
          :type => 'sku',
          :parent => "sku_7QKrhZJcqcuWBN"
        }
      ] },
    {  :stripe_account => "acct_17BTxDCioT3wKMvR" }
    )

It creates an order with id or_17BUNHCioT3wKMvREWdDBagG .

The customer who exist on the foodsy platform buys it ,

order=Stripe::Order.retrieve("or_17BUNHCioT3wKMvREWdDBagG",stripe_account: "acct_17BTxDCioT3wKMvR")
order.pay(customer: "cus_7QLGXg0dkUYWmK")

But this code returns an error No such customer: cus_7QLGXg0dkUYWmK (Stripe::InvalidRequestError).

The customer exist as I can see him on dashboard and source attribute is set on stripe. So why is it going wrong ?

up vote 6 down vote accepted

The problem is that the customer exists on the platform's account, but not on the connected account you're trying to create the charge on.

You need to share the customer from the platform account to the connected account:

# Create a token from the customer on the platform account
token = Stripe::Token.create(
  {:customer => "cus_7QLGXg0dkUYWmK"},
  {:stripe_account => "acct_17BTxDCioT3wKMvR"}
)

# Retrieve the order on the connected account and pay it using the token
order = Stripe::Order.retrieve("or_17BUNHCioT3wKMvREWdDBagG",
  stripe_account: "acct_17BTxDCioT3wKMvR"
)
order.pay(source: token.id)
  • Ok.. That solved the problem. The documentation is quite messed up. It seems they had documented it.. But I couldnt find the links in the stripe-connect documentation, but its their in the stripe-api documentation. [stripe.com/docs/connect/shared-customers] – raj Nov 26 '15 at 22:14

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.