Reputation: 363
I am creating a rails app with Stripe. I can only use the standalone accounts because Managed Accounts are not available in France. I use shared customers because people earning money on my app are sharing their customers.
Of course, What I am showing to you uses my Test Stripe environment.
To charge a customer to a user, I create a token :
tok = Stripe::Token.create(
{:customer => customer.id, :card => customer.cards.last.stripe_id},
{:stripe_account => user.stripe_user_id}
)
=> #<Stripe::Token:0x3fd9c3830900 id=tok_19fYblIUbyeToO5BfgwmLR9Y> JSON: {
"id": "tok_19fYblIUbyeToO5BfgwmLR9Y",
"object": "token",
"card": {"id":"card_19fYblIUbyeToO5BwRTTlJ1x","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":null,"address_zip_check":null,"brand":"Visa","country":"US","cvc_check":"pass","dynamic_last4":null,"exp_month":12,"exp_year":2020,"fingerprint":"xxsPLKbXK7swE7It","funding":"credit","last4":"4242","metadata":{},"name":null,"tokenization_method":null},
"client_ip": "31.33.230.61",
"created": 1485280889,
"livemode": false,
"type": "card",
"used": false
}
After that, I want to charge the customer using that token but unfortunately, the token doesn't exist on Stripe Servers:
Stripe::Token.retrieve(tok.id)
Stripe::InvalidRequestError: No such token: tok_19fYk2IUbyeToO5Bo4thhjn7
from /usr/local/var/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/stripe-1.58.0/lib/stripe.rb:326:in `handle_api_error'
When I try to charge the customer or save the token as a customer source, it gives me the same error. I tried to create a basic charge to see if it was an error from a larger scale:
tok = Stripe::Token.create(
:card => {
:number => "4242424242424242",
:exp_month => 1,
:exp_year => 2018,
:cvc => "314"
},
)
=> #<Stripe::Token:0x3fd9c71b002c id=tok_19fYWGLTk1qRIoGhSApzxo8u> JSON: {
"id": "tok_19fYWGLTk1qRIoGhSApzxo8u",
"object": "token",
"card": {"id":"card_19fYWGLTk1qRIoGhBpLf7sFp","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":null,"address_zip_check":null,"brand":"Visa","country":"US","cvc_check":"unchecked","dynamic_last4":null,"exp_month":1,"exp_year":2018,"fingerprint":"D6Dfg1vPHxjxX2XI","funding":"credit","last4":"4242","metadata":{},"name":null,"tokenization_method":null},
"client_ip": "31.33.230.61",
"created": 1485280548,
"livemode": false,
"type": "card",
"used": false
}
but then I'm able to retrieve the token :
Stripe::Token.retrieve(tok.id)
=> #<Stripe::Token:0x3fd9c2726b3c id=tok_19fYWGLTk1qRIoGhSApzxo8u> JSON: {
"id": "tok_19fYWGLTk1qRIoGhSApzxo8u",
"object": "token",
"card": {"id":"card_19fYWGLTk1qRIoGhBpLf7sFp","object":"card","address_city":null,"address_country":null,"address_line1":null,"address_line1_check":null,"address_line2":null,"address_state":null,"address_zip":null,"address_zip_check":null,"brand":"Visa","country":"US","cvc_check":"unchecked","dynamic_last4":null,"exp_month":1,"exp_year":2018,"fingerprint":"D6Dfg1vPHxjxX2XI","funding":"credit","last4":"4242","metadata":{},"name":null,"tokenization_method":null},
"client_ip": "31.33.230.61",
"created": 1485280548,
"livemode": false,
"type": "card",
"used": false
}
It simply doesn't work when I pass a customer as a parameter, why? I don't know since I did it because the documentation told me to.
Upvotes: 1
Views: 1345
Reputation: 17505
The token was created with the Stripe-Account
header, so the resulting token object exists on the destination account.
So in order to retrieve the token or use it in an API request, the request must also use the Stripe-Account
header with the same account ID.
Upvotes: 3