David Kimura PRO
Joined 7/18/2015
Drifting Ruby Owner
David Kimura PRO said over 5 years ago on Payment Gateway Basics with Stripe :
   I prefer Stripe Checkout now since it handles a lot of things out of the box that you don't have to think about like the 3D Secure credit cards and any other security practices. I do have recent episodes on that topic.

However, if you still want to go this route, check your browser's dev console to see if there are any javascript errors on the page and let us know.

David Kimura PRO said over 5 years ago on Payment Gateway Basics with Stripe :
  The Stripe API 2020-08-27 and later no longer have the customer.subscriptions option by default. Instead to get the user's subscription you can do this.

Stripe::Subscription.retrieve(user.stripe_subscription_id)

or

Stripe::Subscription.list(customer: user.stripe_id).first

David Kimura PRO said over 5 years ago on Payment Gateway Basics with Stripe :
In the stripe_customer method, You wouldn't need to search the subscriptions with customer: user.stripe_id since you're in the user model already. Just use stripe_id
On the create action, You should create a Subscription and pass in the stripe customer id.

David Kimura PRO said over 5 years ago on Payment Gateway Basics with Stripe :
I'm not sure why the stripe_customer is nil. Are you getting any errors from the stripe_customer method in the user model. The guard clause that you have may be problematic as you're likely returning nil since the user has a stripe_id (assuming). If the stripe_id exists, but you're getting nil returned when looking up the customer, you may have some other kind of problem going on. Looking a bit closer at it. you're trying to return a subscription on the stripe_customer method. You should be retrieving the customer (https://stripe.com/docs/api/customers/create?lang=ruby and also see the retrieve customer section) 

The second issue you'll run into is the customer.subscriptions. Once you do have a customer object, you'll get the undefined method subscriptions for the stripe customer. You'll need to look up the subscription based on the subscription_id. https://stripe.com/docs/api/subscriptions/retrieve?lang=ruby

David Kimura PRO said over 5 years ago on Payment Gateway Basics with Stripe :
The stripe_customer method returns nil?

Did you change your stripe_customer method to pull the customer instead of the subscription (i.e., return Stripe::Customer.retrieve(stripe_id) if stripe_id?
)