0

I am trying to implement a simple view in Flask to test Stripe payments. But it is not connecting to my subscription plan and there is no error to trouble shoot. Publishable key is set in Ubuntu environment properly as I checked in shell. Following is my View and Form:

Flask:

stripe_keys = {
  'secret_key': os.environ['SECRET_KEY'],
  'publishable_key': os.environ['PUBLISHABLE_KEY']
}
stripe.api_key = stripe_keys['secret_key']

@app.route('/payments/subscribe', methods=['GET', 'POST'])
def chagrges(self):
    stripe.api_key = stripe_keys['secret_key']

    amount = 500

    customer = stripe.Customer.create(
        email='[email protected]',
        source=request.form.get['stripeToken']
    )

    charge = stripe.Charge.create(
        customer=customer.id,
        amount=amount,
        currency='usd',
        description='Standard Student Package $5'
        )

    return render_template('charge.html', amount=amount)

My form:

<form action="/charge" method="POST">
        <article>
        <label>
            <span>$ 5.00 Standard Package</span>
            </label>
            </article>

            <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"

            data-key=pk_test_0edgLiaV6OlWvDzipIkAC5G7
            data-description="Student Standard Package"
            data-amount="500"
            data-locale="auto">
            </script>
        </form>

My subscription plan I've created at stripe account is:

ID:standard
Name: standard
Price: $5.00 USD/year
Trial period:No trial

Please advise.

3
  • Are there any errors in your server logging? Do you get any errors from Stripe? If you look in your Stripe Dashboard Logs do you see any errors there? Looking at your code I'd also suggest adding some try-except statements to your backend code to catch errors, stripe.com/docs/api/python#errors Commented Feb 6, 2017 at 0:10
  • It shows 200Ok for all of the logs. This is what confuses me Commented Feb 6, 2017 at 23:43
  • If you want to subscribe a user to a plan you need to create a subscription object stripe.com/docs/subscriptions/quickstart#create-subscription the charge object you are creating is for one time payments Commented Feb 8, 2017 at 9:41

2 Answers 2

3

Log in to stripe.com and go to dashboard. Select test mode from left bottom. Click on "Subscriptions" and go to plan in opened window. Create a plan with same information that you provided in your view. Subscribe again and go to stripe dashboard. Click "home" and you will see your first purchase there.

Sign up to request clarification or add additional context in comments.

Comments

1

You are creating one time charge to a customer, this charge will not be linked to any subscription or create a subscription.

For enabling subscription, you need create plans through API or from stripe dashboard. then subscribe that customer to a plan using API

stripe.Subscription.create(
  customer="<customer_id>",
  plan="plan_name"
)

As soon as you create a subscription, customer is automatically charged,i. e. a charge object is created for subscribed amount specified in plan.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.