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 ?
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)
This can also happen if you use the wrong APiKey
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With