Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No such customer: cus_************ (Stripe::InvalidRequestError) when customer exists

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_************"
    Stripe::Order.create(
      {:currency => 'usd',
      :items => [
        {
          :type => 'sku',
          :parent => "sku_************"
        }
      ] },
    {  :stripe_account => "acct_************" }
    )

It creates an order with id or_************ .

The customer who exist on the foodsy platform buys it ,

order=Stripe::Order.retrieve("or_************",stripe_account: "acct_************")
order.pay(customer: "cus_************")

But this code returns an error No such customer: cus_************ (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 ?

like image 890
raj Avatar asked Nov 26 '15 20:11

raj


2 Answers

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)
like image 192
Ywain Avatar answered Sep 19 '22 03:09

Ywain


This can also happen if you use the wrong APiKey

like image 21
Sabel Avatar answered Sep 18 '22 03:09

Sabel