Better Payment 0.11.1 API
    Preparing search index...

    Class MockProvider

    In-memory payment provider for tests.

    import { betterPayment } from 'better-payment';
    import { MockProvider, MOCK_CARDS } from 'better-payment/testing';

    const payment = betterPayment({ providers: { mock: new MockProvider() } });

    const result = await payment.mock.createPayment({
    ...order,
    paymentCard: { ...card, cardNumber: MOCK_CARDS.INSUFFICIENT_FUNDS },
    });
    // result.status === 'failure', result.code === 'INSUFFICIENT_FUNDS'

    Hierarchy (View Summary)

    Index
    • Pre-authorization: blocks the amount on the card without charging it. Charge it later with capture(), or release it with voidAuthorization(). A success result means the amount is blocked.

      Parameters

      Returns Promise<PaymentResponse>

    • Charges (all or part of) a pre-authorized amount

      Parameters

      • request: CaptureRequest

      Returns Promise<PaymentResponse>

    • Deletes a saved card

      Parameters

      • request: DeleteCardRequest

      Returns Promise<DeleteCardResponse>

    • The next operation fails with code (default CARD_DECLINED), whatever the card

      Parameters

      Returns this

    • The mock bank's record of a payment, for assertions

      Parameters

      • paymentId: string

      Returns MockPaymentRecord | undefined

    • A customer's saved cards

      Parameters

      • request: { customerToken: string }

      Returns Promise<ListCardsResponse>

    • The next operation is processed but its response is lost: it returns PENDING with NETWORK_ERROR, and getPayment() shows the real outcome.

      Parameters

      Returns this

    • Clears payments, saved cards and queued outcomes

      Returns void

    • Saves a card with the provider without charging it

      Parameters

      • request: SaveCardRequest

      Returns Promise<SaveCardResponse>

    • The signed callback the mock bank posts to callbackUrl after the 3D Secure page. Post it to the handler (/mock/payment/complete-3ds) or pass it to completeThreeDSPayment(). approve: false simulates a failed or abandoned authentication.

      Parameters

      • paymentId: string
      • options: { approve?: boolean } = {}

      Returns Promise<Record<string, string>>

    • Releases a pre-authorization; nothing is charged

      Parameters

      • request: VoidAuthorizationRequest

      Returns Promise<CancelResponse>