Skip to main content

charge Method

Overview

The charge method processes a recurring payment using an existing mandate. Once a customer has authorized recurring billing, use this to charge their stored payment method without requiring their interaction.

Business Use Case: Your SaaS subscription renews monthly. The customer already authorized recurring payments during signup. On the renewal date, you call charge to process their subscription payment.

Purpose

ScenarioBenefit
Subscription billingAutomate monthly/yearly charges
Membership duesProcess club/organization fees
Installment plansCollect scheduled payments automatically

Request Fields

FieldTypeRequiredDescription
merchantTransactionIdstringYesYour unique transaction reference
amountMoneyYesAmount to charge (minor units)
mandateIdstringYesThe mandate ID from setupRecurring
descriptionstringNoDescription on customer's statement
metadataobjectNoAdditional data (max 20 keys)

Response Fields

FieldTypeDescription
merchantTransactionIdstringYour transaction reference
connectorTransactionIdstringConnector's transaction ID
statusPaymentStatusSUCCEEDED, PENDING, FAILED
errorErrorInfoError details if failed
statusCodenumberHTTP status code

Example

SDK Setup

const { RecurringPaymentClient } = require('hyperswitch-prism');

const recurringClient = new RecurringPaymentClient({
connector: 'stripe',
apiKey: 'YOUR_API_KEY',
environment: 'SANDBOX'
});

Request

const request = {
merchantTransactionId: "txn_sub_monthly_001",
amount: {
minorAmount: 2900,
currency: "USD"
},
mandateId: "mandate_xxx",
description: "Monthly Pro Plan Subscription"
};

const response = await recurringClient.charge(request);

Response

{
merchantTransactionId: "txn_sub_monthly_001",
connectorTransactionId: "pi_3Oxxx...",
status: "SUCCEEDED",
statusCode: 200
}

Subscription Renewal Flow

sequenceDiagram
participant App as Your App
participant CS as Prism
participant PP as Payment Provider

Note over App: Renewal date reached
App->>CS: charge with mandateId
CS->>PP: Process recurring payment
PP-->>CS: Return: SUCCEEDED
CS-->>App: Return status

Error Handling

Error CodeMeaningAction
402Payment failedInsufficient funds, expired card
404Mandate not foundVerify mandateId
409DuplicateUse unique merchantTransactionId

Next Steps