#pymon
1 messages · Page 1 of 1 (latest)
You didn't include line_items in the request. That's a required param. See: https://stripe.com/docs/api/checkout/sessions/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
@cunning bough in here
hi.
can you check my view ?. class StripeCheckoutView(View):
def post(self, request, *args, **kwargs):
plan_ids = request.POST.getlist('plan_ids')
plans = Plan.objects.filter(id__in=plan_ids)
stripe.api_key = settings.STRIPE_SECRET_KEY
line_items = []
for plan in plans:
line_item = {
'price': plan.price_id,
'quantity': 1,
}
line_items.append(line_item)
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=line_items,
mode='payment',
success_url=request.build_absolute_uri(reverse('payment:subscription_success')),
cancel_url=request.build_absolute_uri(reverse('payment:subscription_cancel')),
)
# Save the Stripe Checkout Session ID to the subscription objects
subscriptions = []
for plan in plans:
subscription = Subscription.objects.create(
user=request.user,
plan=plan,
stripe_session_id=session.id,
)
subscriptions.append(subscription)
# Redirect the user to the Stripe checkout page
return redirect(session.url). what changes need in the view to resolve the `line_items` parameter is required in payment mode error.
That looks ok on the surface. But based on the request you shared earlier, no line items are being added to the request. So, you need to debug this code either with a debugger or print statements. Make sure that the for loop that adds line items to the request is being executed. Print out line_items prior to issuing the request too.