Skip to content

Payment Processing API

github-actions[bot] edited this page Nov 14, 2025 · 1 revision

Payment Processing API

Last updated: 2025-11-14 23:42:14

payment-processor.ts

Auto-generated from payment-processor.ts

Payment Processing Module

Overview

The payment processing module handles all payment transactions and billing operations. It provides functions to process payments, refund transactions, and retrieve user transactions.

Exports

The module exports the following interfaces and functions:

  • PaymentMethod interface: Represents a payment method with id, type, last4, and expiryDate properties.
  • Transaction interface: Represents a transaction with id, amount, currency, status, timestamp, and paymentMethod properties.
  • processPayment function: Processes a payment transaction and returns a Transaction object.
  • refundTransaction function: Refunds a completed transaction and returns the updated Transaction object.
  • getUserTransactions function: Retrieves all transactions for a user and returns an array of Transaction objects.

Usage Examples

Process Payment

const paymentMethod: PaymentMethod = {
  id: 'pm_123',
  type: 'card',
  last4: '1234',
  expiryDate: '12/2025'
};

const amount = 100; // Amount in cents
const transaction = await processPayment(amount, paymentMethod);
console.log(transaction);

Refund Transaction

const transactionId = 'txn_123';
const refundedTransaction = await refundTransaction(transactionId);
console.log(refundedTransaction);

Get User Transactions

const userId = 'user_123';
const transactions = await getUserTransactions(userId);
console.log(transactions);

Parameters

processPayment

  • amount: The amount to charge in cents. Required.
  • method: The payment method to use. Required.

refundTransaction

  • transactionId: The ID of the transaction to refund. Required.

getUserTransactions

  • userId: The ID of the user to fetch transactions for. Required.

Return Values

processPayment

  • A Transaction object with the status of the payment transaction.

refundTransaction

  • The updated Transaction object with the refunded status.

getUserTransactions

  • An array of Transaction objects for the specified user.

Interfaces

PaymentMethod

  • id: A unique identifier for the payment method. string.
  • type: The type of payment method (card, bank, or paypal). 'card' | 'bank' | 'paypal'.
  • last4: The last four digits of the payment method. string.
  • expiryDate: The expiry date of the payment method. string.

Transaction

  • id: A unique identifier for the transaction. string.
  • amount: The amount of the transaction in cents. number.
  • currency: The currency of the transaction. string.
  • status: The status of the transaction (pending, completed, or failed). 'pending' | 'completed' | 'failed'.
  • timestamp: The timestamp of the transaction. Date.
  • paymentMethod: The payment method used for the transaction. PaymentMethod.

Clone this wiki locally