Skip to main content
Quick reference for SDK client session parameters when charging returning customers. The SDK behavior is identical for all scenarios—only the client session payload differs.
For business context and when to use each approach, see Charge Returning Customers.

Use Cases

FlowParametersResult
One-time paymentcustomer.id + plan.idPayment created, no subscription
Change plancustomer.id + plan.id + subscription.idSubscription updated, payment collected
Recover past duecustomer.id + subscription.idSubscription reactivated

One-Time Payment

Charge an existing customer for a one-time purchase (add-on, credits, standalone item).

Create Client Session

curl -X POST https://api.paynext.com/client-session \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "X-API-Version: 1.0.0" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": { "id": "cus_11dfa45f-23b1-40f4-9e9b-c9d485915528" },
    "plan": { "id": "plan_7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d" },
    "payment": { "metadata": { "order_id": "order_12345" } },
    "options": { "payment_methods_mode": "saved_or_new" }
  }'
The plan must have type: one_off. Do not include subscription for one-time payments.

Change Plan

Upgrade or downgrade a subscription with immediate payment.

Create Client Session

curl -X POST https://api.paynext.com/client-session \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "X-API-Version: 1.0.0" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": { "id": "cus_11dfa45f-23b1-40f4-9e9b-c9d485915528" },
    "plan": { "id": "plan_8b9c0d1e-2f3a-4b5c-6d7e-8f9a0b1c2d3e" },
    "subscription": {
      "id": "sub_11dfa45f-23b1-40f4-9e9b-c9d485915528",
      "proration_billing_mode": "prorated_immediately"
    },
    "options": { "payment_methods_mode": "saved_or_new" }
  }'

Proration Modes

ModeBehavior
prorated_immediatelyCharge difference based on remaining time, reset billing cycle
full_immediatelyCharge full new plan price, reset billing cycle
Change Subscription Plan for proration calculations and examples

Recover Past Due

Collect payment for failed renewals to reactivate a subscription.

Create Client Session

curl -X POST https://api.paynext.com/client-session \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "X-API-Version: 1.0.0" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": { "id": "cus_11dfa45f-23b1-40f4-9e9b-c9d485915528" },
    "subscription": { "id": "sub_11dfa45f-23b1-40f4-9e9b-c9d485915528" },
    "options": { "payment_methods_mode": "saved_or_new" }
  }'
Do not include plan.id for recovery—PayNext uses the existing plan from the subscription.
Recover Subscriptions for status handling and workflows

Mount the SDK

Once you have the session id, mount the checkout:
'use client'

import { useEffect } from 'react'
import { PayNextCheckout } from '@paynext/sdk'
import '@paynext/sdk/styles'

export const SavedMethodCheckout = ({ sessionId }: { sessionId: string }) => {
  useEffect(() => {
    const checkout = new PayNextCheckout()

    checkout.mount('paynext-checkout', {
      clientToken: sessionId,
      environment: 'sandbox',
      onCheckoutComplete: (result) => {
        console.log('Payment successful:', result.payment_id)
        // Handle success
      },
      onCheckoutFail: (error) => {
        console.error('Payment failed:', error.status_reason?.decline_code)
        // Customer can switch cards and retry in the SDK
      },
    })

    return () => checkout.unmount()
  }, [sessionId])

  return <div id="paynext-checkout" />
}
Behavior:
  • SDK displays the customer’s saved payment method
  • Customer can switch to a new card if needed
  • On failure, customer retries instantly—no new session required
SDK Getting Started for full configuration options

Payment Method Modes

ModeBehavior
saved_or_new (default)Show saved card, allow switching to new
new_onlyCollect new card only, ignore saved methods

Outcomes

ResultOne-TimeChange PlanRecovery
SuccessPayment createdSubscription updated, billing cycle resetSubscription returns to active
FailureCustomer retries with new cardSubscription stays on old planCustomer retries with new card