Checking a Stripe Subscription

I’m trying to look up a subscription on Stripe. Normally, I’d do

stripe.subscription.retrieve(subscription_id)

but the Stripe object returned by require('stripe')(restrictedKey) does not have a subscription property. The closest is customerSubscriptions, which does not seem to be documented anywhere that I can see.

What version of the Stripe library is used by Auth0? Where can I find out more about it?

Hey there!

Can you say what part of our stack you use to integrate Stripe with Auth0?

Thanks!

It’s in a rule.

function(user, context, callback) {

  // copy user metadata value in ID Token
  console.log("setting subscription id");
  console.log(user);
  context.idToken['http://mynamespace/subscription_id'] = user.app_metadata.stripe_subscription_id;
  const subscription_id = user.app_metadata.stripe_subscription_id;
  const restrictedKey = "rk_live_NtDUBQUfQNKcvQmITDYtEArT00Pz44rweH";
  const stripe = require('stripe')(restrictedKey);
  console.log(stripe); // so I can see the properties of stripe
  
  stripe.customerSubscriptions.retrieve(
    subscription_id,
  )
  .then(subscription => {
    console.log(subscription);
    let date = new Date(subscription.current_period_end);
    console.log("PlanID is " + subscription.plan.id + "<br>Expiring on " + date);
  })
  .catch(error => {
    console.error("stripe error", error);
  });

  callback(null, user, context);
}

I cannot find it in the rules editor. How is this called? Have you created it yourself? Based on the context you provided it’s more a question for Stripe developer community forum I think.

It’s called “Get Subscription ID”. Yes, I created it myself - it will be in my own account.

Gotchya! I would love to help you but it’s definitely a question towards Stripe engineers or simply for their docs instead of us. Can you try reaching out to them and discuss it?

Thanks. If I get an answer, I’ll post it here.

1 Like

Perfect! Thanks a lot!

Here’s the official answer:

Unfortunately, we do not support an integration with Stripe. However, you can try using the rule to create stripe user and persist the stripe ID in the user_metadata or app_metadata object. Then, you can add the stripe ID in the ID token as the custom claim. The following community thread has got an example.
Using Stripe as payment platform and link account to an Auth0 user. - #3 by md.reeves. But keep in mind this would be entirely custom and not supported by Auth0.

1 Like

Gotchya! Thanks for sharing that!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.