You are here

Other.php in Ubercart 8.4

File

payment/uc_payment_pack/src/Plugin/Ubercart/PaymentMethod/Other.php
View source
<?php

namespace Drupal\uc_payment_pack\Plugin\Ubercart\PaymentMethod;

use Drupal\uc_order\OrderInterface;
use Drupal\uc_payment\PaymentMethodPluginBase;

/**
 * Defines a generic payment method.
 *
 * @UbercartPaymentMethod(
 *   id = "other",
 *   name = @Translation("Other"),
 * )
 */
class Other extends PaymentMethodPluginBase {

  /**
   * {@inheritdoc}
   */
  public function orderView(OrderInterface $order) {
    $build = [];
    if ($description = $this->database
      ->query('SELECT description FROM {uc_payment_other} WHERE order_id = :id', [
      ':id' => $order
        ->id(),
    ])
      ->fetchField()) {
      $build = [
        '#markup' => $this
          ->t('Description: @desc', [
          '@desc' => $description,
        ]),
      ];
    }
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function orderEditDetails(OrderInterface $order) {
    $build = [];
    $build['description'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Description'),
      '#default_value' => isset($order->payment_details['description']) ? $order->payment_details['description'] : '',
      '#size' => 32,
      '#maxlength' => 64,
    ];
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function orderLoad(OrderInterface $order) {
    $description = $this->database
      ->query('SELECT description FROM {uc_payment_other} WHERE order_id = :id', [
      ':id' => $order
        ->id(),
    ])
      ->fetchField();
    if (isset($description)) {
      $order->payment_details['description'] = $description;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function orderSave(OrderInterface $order) {
    if (empty($order->payment_details['description'])) {
      $this->database
        ->delete('uc_payment_other')
        ->condition('order_id', $order
        ->id())
        ->execute();
    }
    else {
      $this->database
        ->merge('uc_payment_other')
        ->key([
        'order_id' => $order
          ->id(),
      ])
        ->fields([
        'description' => $order->payment_details['description'],
      ])
        ->execute();
    }
  }

}

Classes

Namesort descending Description
Other Defines a generic payment method.