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;



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;
  • 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. Aug 22 '18 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. Aug 22 '18 at 7:24
  • 1
    Yes looks good! Aug 22 '18 at 8:07

If anyone is interested, here's Commerce 3 version.

$number = 'xxx'; 
$order =  \craft\commerce\elements\Order::find()->number($number)->one();

$transaction = \craft\commerce\Plugin::getInstance()->getTransactions()->createTransaction($order);
$transaction->status = \craft\commerce\records\Transaction::STATUS_SUCCESS;
$transaction->type = \craft\commerce\records\Transaction::TYPE_PURCHASE;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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