@nevermined-io/payments
    Preparing search index...

    Interface SettlePermissionsResult

    x402 Settle Response - per x402 facilitator spec

    https://github.com/coinbase/x402/blob/main/specs/x402-specification-v2.md

    success alone tells you the settle worked. What to check in addition depends on SettlePermissionsResult.billingModel:

    • creditssuccess === true && Number(creditsRedeemed) > 0.
    • pay-as-you-gosuccess === true plus a non-empty orderTx (fiat rails) or transaction (crypto rails). creditsRedeemed and remainingBalance are always the string '0' on this billing model and carry no information.

    Do not gate on creditsRedeemed without reading billingModel first: on a pay-as-you-go plan creditsRedeemed > 0 can never hold, so a real charge reads as a decline — and retrying a card charge that already succeeded is the one thing to avoid, because repeated attempts feed issuer fraud scoring.

    Mind the type as well: these fields are strings. '0' is truthy while Number('0') > 0 is false, so two plausible-looking checks disagree.

    If billingModel is absent, you are talking to a Nevermined API that predates the discriminator: apply the credits rule, and never read a missing discriminator as pay-as-you-go.

    const settled =
    settlement.success &&
    (settlement.billingModel === 'pay-as-you-go'
    ? Boolean(settlement.orderTx || settlement.transaction)
    : Number(settlement.creditsRedeemed ?? '0') > 0)
    interface SettlePermissionsResult {
        billingModel?: X402BillingModel;
        creditsRedeemed?: string;
        errorReason?: string;
        network: string;
        orderTx?: string;
        payer?: string;
        remainingBalance?: string;
        success: boolean;
        transaction: string;
    }
    Index

    Properties

    billingModel?: X402BillingModel

    Which billing model this settle was priced under (Nevermined extension).

    Reported whether or not the settle succeeded — so check success before treating it as evidence of a charge. It is absent entirely against a Nevermined API that predates the discriminator, which is why it is optional; treat that case as credits. Read it before creditsRedeemed / remainingBalance: see the interface docs above for the per-model criterion.

    creditsRedeemed?: string

    Number of credits redeemed (Nevermined extension). Always the string '0' for billingModel: 'pay-as-you-go' plans, which hold no credit balance — including on a settle that charged the buyer successfully.

    errorReason?: string

    Reason for settlement failure (only present if success is false)

    network: string

    Network identifier. The discriminator is the rail, not the billing model: for crypto rails (nvm:erc4337) it is the CAIP-2 chain id (eip155:84532) under both billing models; for fiat card-delegation rails it is the settling payment provider (stripe, braintree, visa), not a CAIP-2 value.

    orderTx?: string

    Reference for the order or per-request charge, if one occurred (Nevermined extension). On fiat pay-as-you-go this is the per-request charge — the PSP transaction id (a Stripe PaymentIntent pi_…, a Braintree transaction id); crypto pay-as-you-go reports its on-chain order in transaction instead. On credits plans it is set only when the settle had to order credits first (auto top-up). Treat it as an opaque string and disambiguate by prefix if you need to.

    payer?: string

    Address of the payer's wallet

    remainingBalance?: string

    Subscriber's remaining credit balance (Nevermined extension). Always the string '0' for billingModel: 'pay-as-you-go' plans — the per-request charge is referenced by orderTx (fiat) or transaction (crypto), not here.

    success: boolean

    Whether settlement was successful

    transaction: string

    Blockchain transaction hash (empty string if settlement failed). On crypto pay-as-you-go plans this is also the reference for the per-request charge.