#pymon

1 messages · Page 1 of 1 (latest)

sacred stormBOT
ancient nova
#

@cunning bough in here

cunning bough
#

hi.

ancient nova
#

Hello

#

You need to pass line_items to create a checkout session

cunning bough
#

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.
ancient nova
#

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.