Reputation: 15
This is an App code
@app.route("/stripe_pay")
def stripe_pay():
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[{
'price_data': 'my_price_id',
'quantity': 1,
}],
mode='subscription',
success_url=url_for('index', _external=True) + '?session_id={CHECKOUT_SESSION_ID}',
cancel_url=url_for('add_service', _external=True),
)
return {
'checkout_session_id' : session['id'],
'checkout_public_key' : app.config['STRIPE_PUBLIC_KEY']
}
I have tried to make money transactions in my app and watched this [tutorial][1]. I have checked all my secret_keys and imported everything that the app needs.
A debugger argues cancel_url=url_for('add_service', _external=True),
.
This is my a JS code
button.addEventListener('click', event => {
fetch('/stripe_pay')
.then((result) => { return result.json(); })
.then((data) => {
var stripe = Stripe(data.checkout_public_key);
stripe.redirectToCheckout({
sessionId: data.checkout_session_id
}).then(function (result) {
});
})
});```
*Thank you in advance*
[1]: https://www.youtube.com/watch?v=cC9jK3WntR8&t=7s
Upvotes: 1
Views: 1331
Reputation: 1306
If you have a price ID already, you should be using price
in your line_items
, not price_data
which requires some child parameters.
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price
Upvotes: 1