Search code examples
braintree

How to check if user subscription is up to date?


  1. I create new customer with credit card using gateway.customer.create
  2. I create new subscription for a customer using gateway.subscription.create

Now when my application starts I have to check if customers subscriptions is still valid. Is there any api endpoint that will allow me to do this?

I am looking for example for a method like this:

isUserSubscribed(customerId)

Maybe also something to get info in which plan user is subscribed (silver,gold,etc)


Solution

  • I work at Braintree. If you have more questions, feel free to reach out to our support team.

    When you get a customer from Braintree, you get all of its credit cards and subscriptions:

    customer = gateway.customer.find(customerId)
    subscriptions = customer.credit_cards.flat_map(&:subscriptions)
    

    You can then look at the customer's subscriptions to find any info you need.