Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.monei.cc/llms.txt

Use this file to discover all available pages before exploring further.

Overview

monei.paymentMethod provides methods to save and manage cards or bank accounts for fast repeat deposits.

List Payment Methods

const { paymentMethods } = await monei.paymentMethod.getAll('sub-wallet-id');

console.log(paymentMethods);

Add a Payment Method

const pm = await monei.paymentMethod.create({
  type: 'card',
  cardNumber: '4111111111111111',
  expiryMonth: '12',
  expiryYear: '2027',
  cvv: '123',
  subWalletId: 'sub-wallet-id',
});

console.log(pm);

Get Payment Method Details

const pm = await monei.paymentMethod.get('pm-id');

console.log(pm);

Set Default Payment Method

await monei.paymentMethod.setDefault('pm-id');

Delete a Payment Method

await monei.paymentMethod.delete('pm-id');

Working with Response Objects

All methods return objects with property access:
// List payment methods response
const { paymentMethods } = await monei.paymentMethod.getAll('sub-wallet-id');
paymentMethods.forEach(pm => {
  console.log(pm.id);              // Payment method ID
  console.log(pm.type);            // 'card' | 'bank_account'
  console.log(pm.last4);           // Last 4 digits
  console.log(pm.expiryMonth);     // Expiry month (for cards)
  console.log(pm.expiryYear);      // Expiry year (for cards)
  console.log(pm.bankName);        // Bank name (for bank accounts)
  console.log(pm.isDefault);       // Whether it's the default method
  console.log(pm.createdAt);       // Creation date
});

// Create payment method response
const pm = await monei.paymentMethod.create({
  type: 'card',
  cardNumber: '4111111111111111',
  expiryMonth: '12',
  expiryYear: '2027',
  cvv: '123',
  subWalletId: 'sub-wallet-id',
});
console.log(pm.id);              // Payment method ID
console.log(pm.type);            // Payment method type
console.log(pm.last4);           // Last 4 digits of card
console.log(pm.expiryMonth);     // Expiry month
console.log(pm.expiryYear);      // Expiry year
console.log(pm.isDefault);       // Default status

// Get payment method details response
const pm = await monei.paymentMethod.get('pm-id');
console.log(pm.id);              // Payment method ID
console.log(pm.type);            // Payment method type
console.log(pm.last4);           // Last 4 digits
console.log(pm.expiryMonth);     // Expiry month (for cards)
console.log(pm.expiryYear);      // Expiry year (for cards)
console.log(pm.bankName);        // Bank name (for bank accounts)
console.log(pm.accountName);     // Account name (for bank accounts)
console.log(pm.isDefault);       // Default status
console.log(pm.createdAt);       // Creation date

// Set default response (no data returned, just success)
await monei.paymentMethod.setDefault('pm-id');
console.log('Default payment method updated successfully');

// Delete response (no data returned, just success)
await monei.paymentMethod.delete('pm-id');
console.log('Payment method deleted successfully');

Response Types

PaymentMethodDto

{
  id: string;
  type: 'card' | 'bank_account';
  last4: string;
  expiryMonth?: string;    // For cards
  expiryYear?: string;     // For cards
  bankName?: string;       // For bank accounts
  accountName?: string;    // For bank accounts
  isDefault: boolean;
  createdAt: string;
}

Error Handling

All payment method calls may throw an error if the request fails.
import { MoneiError } from 'monei-sdk';

try {
  const { paymentMethods } = await monei.paymentMethod.getAll('sub-wallet-id');
  console.log(paymentMethods);
} catch (error) {
  if (error instanceof MoneiError) {
    console.error(error.statusCode);  // HTTP status code
    console.error(error.message);     // Error message
    console.error(error.code);        // Error code
  }
}

Service Overview

MethodDescription
getAll(subWalletId)List all payment methods for a wallet
create(data)Add a new payment method
get(paymentMethodId)Get payment method details
setDefault(paymentMethodId)Set a payment method as default
delete(paymentMethodId)Delete a payment method

Notes

  • All methods require a properly configured MoneiClient instance with authentication
  • subWalletId is required for listing payment methods
  • Card details are tokenized and securely stored
  • Only the last 4 digits of card numbers are returned for security
  • Setting a default payment method automatically updates the previous default
  • Deleted payment methods cannot be recovered
  • All responses are strongly typed objects with property access