Open owenstrevor opened 7 years ago
I checked the Logs in my Stripe API Test Dashboard, it looks like Stripe is sending the response back fine. I also have the Stripe API set in Koudoku.rb to be compatible with Koudoku (ie. Stripe.api_version = '2015-01-11').
There seems to be a disconnect between Stripe's response and my app.
Here's the response
{
"id": "<removed>",
"object": "token",
"card": {
"id": "<removed>",
"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": 12,
"exp_year": 2019,
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"tokenization_method": null
},
"client_ip": "<removed>",
"created": <removed>,
"livemode": false,
"type": "card",
"used": false
}
Trying to see if changing the JS handling of the response will help. Will update if I figure anything out.
Ok, so by changing the JS handling of the response (function stripeResponseHandler) from:
form$.append("<input type='hidden' name='subscription[last_four]' value='" + response['last4'] + "'/>");
form$.append("<input type='hidden' name='subscription[card_type]' value='" + response['card_type'] + "'/>");
To
form$.append("<input type='hidden' name='subscription[last_four]' value='" + response['card']['last4'] + "'/>");
form$.append("<input type='hidden' name='subscription[card_type]' value='" + response['card']['brand'] + "'/>");
Basically just changing response['last4'] and response['card_type'] to response['card']['last4'] and response['card']['brand'] I am able to get the correct information submitted when I submit the form (it's not longer undefined).
However, SubscriptionsController#create still rollbacks after the commit in terminal.
I've tried changing response['id'] to response['card']['id'] to see if it's an issue with credit_card_token but that doesn't work either.
Note: response['id'] returns "tok_xxxxxxxxxxxxxx" whereas response['card']['id'] returns "card_xxxxxxxxxxxxxx".
Still looking for a solution.
I took out the Koudoku gem and rebuilt it directly into my app.
It appears the problem is that the before_save method was not being called (Rails 5).
I believe this because no subscriptions ever appeared in my Stripe test dashboard while I was using the Koudoku gem. Now I directly call the 'processing!' method from the controller before I save the subscription and the subscriptions are showing up in my Stripe test dashboard.
The only alternative is that something was wrong with setting the customer_attributes before calling Stripe::Customer.create(customer_attributes).
I'm not sure how one would fix this WRT the gem but I hope the maintainers add a fix as I'd love to use the gem for future projects.
Best of luck to anyone else who runs into this problem.
Another thing:
Make sure you add "optional: true" to the belongs_to :coupon in the subscription model file otherwise it will not save (Rails 5).
belongs_to :coupon, optional: true
I had same issue, i'd put information with test fake card 4242 4242 4242 4242 and then submit, but i'd get send back to the page with the card form again without any message. So it turns out it is the coupon thats missing, so i added the optional: true as told above and its fine.
Thanks @owenstrevor
I'm getting a generic error when using a test card in development mode in Rails 5.
When I submit the form, Stripe returns a 200 status but the response appears to be blank or undefined (response['last4'] and response['card_type'] are both undefined).
Then I see the SubscriptionsController#create rollback after the commit in terminal.
Any thoughts?