You are here

function uc_payment_uc_payment_receipt_insert in Ubercart 8.4

Implements hook_uc_payment_receipt_insert().

File

payment/uc_payment/uc_payment.module, line 168
Defines the payment API that lets payment modules interact with Ubercart.

Code

function uc_payment_uc_payment_receipt_insert(PaymentReceiptInterface $payment) {
  $order = $payment
    ->getOrder();

  // Log a message against the order.
  $method_name = $payment
    ->getMethod() ? $payment
    ->getMethod()
    ->cartReviewTitle() : t('Other');
  $log_message = t('@method payment for @amount entered.', [
    '@method' => $method_name,
    '@amount' => uc_currency_format($payment
      ->getAmount()),
  ]);
  $order
    ->logChanges([
    $log_message,
  ]);

  //\Drupal::moduleHandler()->invokeAll('uc_payment_entered', [$order, $method, $amount, $order->getOwner(), $data, $comment]);

  /* rules_invoke_event('uc_payment_entered', $order, $account); */
  $event = new PaymentEnteredEvent($order, $order
    ->getOwner());
  \Drupal::service('event_dispatcher')
    ->dispatch($event::EVENT_NAME, $event);

  // @todo Uncomment this if{} statement when Rules is working.
  // Automatically mark paid orders as "payment received"
  // if Rules is not available.

  //if (!\Drupal::moduleHandler()->moduleExists('rules')) {
  if (uc_payment_balance($order) <= 0) {
    $state = $order
      ->getStateId();
    if ($state == 'in_checkout' || $state == 'post_checkout') {
      $order
        ->setStatusId('payment_received')
        ->save();
    }
  }

  //}
}