Answers.Body: <p>Your best bet would be to create a transaction for the full amount:</p>
  
  <pre><code>$transaction = Plugin::getInstance()-&gt;transactions-&gt;createTransaction($order);
  $transaction-&gt;status = \craft\commerce\records\Transaction::STATUS_SUCCESS;
  $transaction-&gt;type = \craft\commerce\records\Transaction::TYPE_PURCHASE;
  Plugin::getInstance()-&gt;transactions-&gt;saveTransaction($transaction);
  $order-&gt;updateOrderPaidTotal();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-22T07:16:22.633Z
Answers.Text: 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.
Answers.UserDisplayName: Steve Holland
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-22T07:24:10.913Z
Answers.Text: 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.
Answers.UserDisplayName: Steve Holland
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-22T08:07:33.957Z
Answers.Text: Yes looks good!
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-22T05:38:01.090Z
Answers.LastActivityDate: 2018-08-22T05:38:01.090Z
Answers.UserDisplayName: Luke Holder
Answers.Body: <p>If anyone is interested, here's Commerce 3 version.</p>
  <pre><code>$number = 'xxx'; 
  $order =  \craft\commerce\elements\Order::find()-&gt;number($number)-&gt;one();
  
  $transaction = \craft\commerce\Plugin::getInstance()-&gt;getTransactions()-&gt;createTransaction($order);
  $transaction-&gt;status = \craft\commerce\records\Transaction::STATUS_SUCCESS;
  $transaction-&gt;type = \craft\commerce\records\Transaction::TYPE_PURCHASE;
  \craft\commerce\Plugin::getInstance()-&gt;getTransactions()-&gt;saveTransaction($transaction);
  
  $order-&gt;updateOrderPaidInformation();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-25T16:27:08.423Z
Answers.LastActivityDate: 2020-10-25T16:27:08.423Z
Answers.UserDisplayName: Piotr Pogorzelski
Body: <p>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? </p>
  
  <p>The Order will already have been converted from a Cart to an Order and assigned an Order Status via a previous step.</p>
  
  <p>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. </p>
  
  <p>EDIT: For future reference, base on Luke's answer below, this is the code I got to work...</p>
  
  <pre><code>$orderNumber = "XXXX-XXXX-XXXX-XXXX";
  
  $order = craft()-&gt;commerce_orders-&gt;getOrderByNumber($orderNumber);
  
  $transaction = craft()-&gt;commerce_transactions-&gt;createTransaction($order);
  
  $transaction-&gt;status = Commerce_TransactionRecord::STATUS_SUCCESS;
  $transaction-&gt;type = Commerce_TransactionRecord::TYPE_PURCHASE;
  
  craft()-&gt;commerce_transactions-&gt;saveTransaction($transaction);
  
  craft()-&gt;commerce_orders-&gt;updateOrderPaidTotal($order);
  </code></pre>
  
Tags: <plugin-craftcommerce><payment>
Title: Mark a Commerce Order as Paid, via a custom plugin
ThreadText: # Mark a Commerce Order as Paid, via a custom plugin
  
  (Asked by: username_0 on 2018-08-21)
  
  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 username_1'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);
  
  ```
  
  **Tags:** plugin-craftcommerce, payment
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-08-22. Score: 3 | Accepted answer
  
  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();
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for the answer username_1. Where you say `Plugin::getInstance()->transactions->createTransaction($order)` does that translate to `craft()->commerce_transactions->createTransaction($order)`? If so, then it all works fine.  
  > **username_0**: 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.  
  > **username_1**: Yes looks good!  
  
  ---
  
  ### Answer by username_2 on 2020-10-25. Score: 1
  
  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;
  \craft\commerce\Plugin::getInstance()->getTransactions()->saveTransaction($transaction);
  
  $order->updateOrderPaidInformation();
  
  ```
  
  
  ---
  
  