Skip to main content
The Orders API allows you to retrieve order information and process refunds.

List Orders

Retrieve all orders for your store.
const response = await client.orders.getOrders({
  params: {
    limit: 50,
    after: 'order-id', // Optional: for pagination
    asc: false // Optional: sort order (false = newest first)
  }
});

console.log(response.data); // Array of OrderDto

Parameters

  • limit (optional): Maximum number of orders to return
  • after (optional): Return orders after this ID (cursor-based pagination)
  • before (optional): Return orders before this ID
  • asc (optional): Sort order - true for ascending, false for descending

Response

Returns an array of order objects containing:
  • Order ID and status
  • Customer information
  • Line items (products purchased)
  • Payment details
  • Timestamps (created, updated)
  • Delivery information

Get Order by ID

Retrieve detailed information about a specific order.
const response = await client.orders.getOrderById({
  path: {
    orderId: '1234567890'
  }
});

console.log(response.data); // OrderDto

Parameters

  • orderId (required): The ID of the order to retrieve

Response

Returns a complete order object with full details including:
  • Customer information
  • All purchased items
  • Payment method details
  • Delivery status
  • Applied coupons or discounts
  • Subscription information (if applicable)

Refund Order

Create a refund for an order.
const response = await client.orders.refundOrder({
  path: {
    orderId: '1234567890'
  },
  data: {
    reason: 'Customer requested refund',
    // Optional: specify partial refund amount
    // amount: 1000 // Amount in cents
  }
});

console.log(response.data); // Refund details

Parameters

  • orderId (required): The ID of the order to refund
  • data.reason (optional): Reason for the refund
  • data.amount (optional): Partial refund amount in cents. If not specified, full order amount is refunded.
Refunds are processed through the original payment method. Processing time depends on the payment provider.

Order Delivery Items

Retrieve delivery items associated with an order.
const response = await client.delivery.getOrderDeliveryItems({
  path: {
    orderId: '1234567890'
  }
});

console.log(response.data); // Array of delivery items
Delivery items represent the fulfillment status of products in an order, such as game commands that need to be executed.

Example: Order Management Workflow

import { createManagementClient, isPayNowError } from '@paynow-gg/typescript-sdk';

const client = createManagementClient(
  process.env.STORE_ID!,
  process.env.API_KEY!
);

async function processOrders() {
  try {
    // Get recent orders
    const orders = await client.orders.getOrders({
      params: { 
        limit: 20,
        asc: false // Newest first
      }
    });

    for (const order of orders.data) {
      console.log(`Order ${order.id}:`);
      console.log(`  Customer: ${order.customer?.email || 'Guest'}`);
      console.log(`  Total: $${order.total / 100}`);
      console.log(`  Status: ${order.status}`);

      // Get full order details if needed
      const fullOrder = await client.orders.getOrderById({
        path: { orderId: order.id }
      });

      // Check delivery status
      const deliveryItems = await client.delivery.getOrderDeliveryItems({
        path: { orderId: order.id }
      });

      console.log(`  Delivery items: ${deliveryItems.data.length}`);
    }

  } catch (error) {
    if (isPayNowError(error)) {
      console.error('API Error:', error.response?.data);
    } else {
      throw error;
    }
  }
}

processOrders();

Example: Process Refund

async function refundOrder(orderId: string, reason: string) {
  try {
    // Get order details first
    const order = await client.orders.getOrderById({
      path: { orderId }
    });

    console.log(`Processing refund for order ${orderId}`);
    console.log(`Order total: $${order.data.total / 100}`);

    // Process full refund
    const refund = await client.orders.refundOrder({
      path: { orderId },
      data: { reason }
    });

    console.log('Refund processed successfully');
    console.log(refund.data);

    return refund.data;

  } catch (error) {
    if (isPayNowError(error)) {
      console.error('Refund failed:', error.response?.data);
      throw new Error(`Failed to refund order: ${error.response?.data.message}`);
    } else {
      throw error;
    }
  }
}

// Usage
await refundOrder('1234567890', 'Customer not satisfied with purchase');

Example: Partial Refund

async function partialRefund(orderId: string, refundAmount: number) {
  try {
    const order = await client.orders.getOrderById({
      path: { orderId }
    });

    if (refundAmount > order.data.total) {
      throw new Error('Refund amount exceeds order total');
    }

    const refund = await client.orders.refundOrder({
      path: { orderId },
      data: {
        amount: refundAmount, // Amount in cents
        reason: `Partial refund of $${refundAmount / 100}`
      }
    });

    console.log(`Refunded $${refundAmount / 100} of $${order.data.total / 100}`);
    return refund.data;

  } catch (error) {
    if (isPayNowError(error)) {
      console.error('Partial refund failed:', error.response?.data);
    }
    throw error;
  }
}

// Refund half of the order
await partialRefund('1234567890', 500); // $5.00

Order Status

Orders can have various statuses throughout their lifecycle:
  • pending - Order created but payment not completed
  • completed - Payment successful, order fulfilled
  • refunded - Order has been refunded
  • disputed - Payment is disputed/chargebacked
  • cancelled - Order was cancelled
  • Payments - View payment details and analytics
  • Customers - Manage customer information
  • Products - Manage products and inventory

Build docs developers (and LLMs) love