Checkout / Payment is being handled entirely by a 3rd Party. What would be the correct process to mark an Order as Paid via a custom Craft plugin?

The Order will already have been converted from a Cart to an Order and assigned an Order Status via a previous step.

The 3rd Party will be calling a series of API endpoints exposed by a custom Craft plugin to process the various steps of the Order.

EDIT: For future reference, base on Luke's answer below, this is the code I got to work...

$orderNumber = "XXXX-XXXX-XXXX-XXXX";

$order = craft()->commerce_orders->getOrderByNumber($orderNumber);

$transaction = craft()->commerce_transactions->createTransaction($order);

$transaction->status = Commerce_TransactionRecord::STATUS_SUCCESS;
$transaction->type = Commerce_TransactionRecord::TYPE_PURCHASE;

craft()->commerce_transactions->saveTransaction($transaction);

craft()->commerce_orders->updateOrderPaidTotal($order);
up vote 2 down vote accepted

Your best bet would be to create a transaction for the full amount:

$transaction = Plugin::getInstance()->transactions->createTransaction($order);
$transaction->status = \craft\commerce\records\Transaction::STATUS_SUCCESS;
$transaction->type = \craft\commerce\records\Transaction::TYPE_PURCHASE;
Plugin::getInstance()->transactions->saveTransaction($transaction);
$order->updateOrderPaidTotal();
  • 1
    Thanks for the answer Luke. Where you say Plugin::getInstance()->transactions->createTransaction($order) does that translate to craft()->commerce_transactions->createTransaction($order)? If so, then it all works fine. – Steve Holland Aug 22 at 7:16
  • Based on your answer, I've updated my question with the working code. Is there anything in there I shouldn't be doing, or does that look about right to you? It all seems to be working as far as I can tell. – Steve Holland Aug 22 at 7:24
  • 1
    Yes looks good! – Luke Holder Aug 22 at 8:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.