Order

Check if an order exists

// DDPClient is from "Setting up DDP" guide.

const orderId = 'some-order-id';

DDPClient.call('order.exists', [orderId], (error, exists) => {
    if (!exists) {
        throw new Error('Order does not exist!');
    }

    console.log('Order exists!');
});

Fulfill an unpaid order

Handy if you're developing your own payment system for your shop. The below example will mark an order as paid, completing the order and in turn sending the ordered items to the customer. Do note that this method requires administrative privileges over your shop. See the authentication section for more info.

/**
 * The _id field of the order you want to fulfill/mark as paid.
 */
const orderId = '_id of the order you want to fulfill';

/**
 * Amount paid in cents.
 * 200 = $2,00
 */
const amountPaid = 200;

/**
 * (optional) indicator for how the customer paid for the order.
 * Leave as 'alternative-payment' unless you know what you're doing.
 */
const paymentMethod = 'alternative-payment'

DDPClient.call('order.fulfill.alternativePayment', [orderId, amountPaid, paymentMethod], (err, resp) => {
    if (err) {
        return console.error(err);
    }

    console.log('Successfully fulfilled %s!', orderId);
})

Issue a replacement for a fulfilled order

const orderId = '321abc'; // '_id' field of the order you want to issue a replacement for.
const shopId = 'cba123'; // The 'shopId' field of the order you're issuing a replacement for.
const quantity = 5; // Number of items to send to customer as replacements.
const note = 'Products were non-functioning at arrival.'; // (max 255 characters)

DDPClient.call('admin.orders.replace', [shopId, orderId, quantity, note], (err, resp) => {
    if (err) {
        return console.error(err);
    }

    console.log('Successfully issued %d replacement items for order "%s".\nNote: %s', quantity, orderId, note);
});