+ /**
+ * Complete transaction if payment has been processed.
+ *
+ * Check the result for a success outcome & if paid then complete the transaction.
+ *
+ * Completing will trigger update of related entities and emails.
+ *
+ * @param array $result
+ * @param int $contributionID
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function completeTransaction($result, $contributionID) {
+ if (CRM_Utils_Array::value('payment_status_id', $result) == 1) {
+ try {
+ civicrm_api3('contribution', 'completetransaction', array(
+ 'id' => $contributionID,
+ 'trxn_id' => CRM_Utils_Array::value('trxn_id', $result),
+ 'payment_processor_id' => $this->_paymentProcessor['id'],
+ 'is_transactional' => FALSE,
+ 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result),
+ )
+ );
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ if ($e->getErrorCode() != 'contribution_completed') {
+ throw new CRM_Core_Exception('Failed to update contribution in database');
+ }
+ }
+ }
+ }
+