Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do i get the API Key in the Authorization header ? #2022

Closed
Ockham-Byron opened this issue Jan 18, 2024 · 1 comment
Closed

How do i get the API Key in the Authorization header ? #2022

Ockham-Byron opened this issue Jan 18, 2024 · 1 comment
Labels
question How To or Usage questions

Comments

@Ockham-Byron
Copy link

Ockham-Byron commented Jan 18, 2024

What are you trying to accomplish?
Hi, I'm trying to redirect the customer on a custom subscription confirmation page of my app, with this code :

@login_required 
def subscription_confirm(request):
    # set our stripe keys up
    stripe.api_key = djstripe_settings.STRIPE_SECRET_KEY

    # get the session id from the URL and retrieve the session object from Stripe
    session_id = request.GET.get("session_id")
    session = stripe.checkout.Session.retrieve(session_id)

    # get the subscribing user from the client_reference_id we passed in above
    client_reference_id = int(session.client_reference_id)
    subscription_holder = get_user_model().objects.get(id=client_reference_id)
    # sanity check that the logged in user is the one being updated
    assert subscription_holder == request.user

    # get the subscription object form Stripe and sync to djstripe
    subscription = stripe.Subscription.retrieve(session.subscription)
    djstripe_subscription = Subscription.sync_from_stripe_data(subscription)

    # set the subscription and customer on our user
    subscription_holder.subscription = djstripe_subscription
    subscription_holder.customer = djstripe_subscription.customer
    subscription_holder.save()

    # show a message to the user and redirect
    messages.success(request, f"You've successfully signed up. Thanks for the support!")
    return render(request, 'dashboard/subscription-complete.html')

But I have an error : You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY').

How can I do that ?

Thanks !

@Ockham-Byron Ockham-Byron added the question How To or Usage questions label Jan 18, 2024
@arnav13081994
Copy link
Contributor

@Ockham-Byron You can pass the api_key to any stripe api call like so stripe.checkout.Session.retrieve(session_id, api_key=...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question How To or Usage questions
Projects
None yet
Development

No branches or pull requests

2 participants