You are here

public function PurchaseOrderGateway::buildPaymentOperations in Commerce Purchase Order 8

Builds the available operations for the given payment.

Parameters

\Drupal\commerce_payment\Entity\PaymentInterface $payment: The payment.

Return value

array The operations. Keyed by operation ID, each value is an array with the following keys:

  • title: The operation title.
  • page_title: The operation page title.
  • plugin_form: The plugin form ID.
  • access: Whether the operation is allowed for the given payment.

Overrides PaymentGatewayBase::buildPaymentOperations

File

src/Plugin/Commerce/PaymentGateway/PurchaseOrderGateway.php, line 105

Class

PurchaseOrderGateway
Provides the On-site payment gateway.

Namespace

Drupal\commerce_purchase_order\Plugin\Commerce\PaymentGateway

Code

public function buildPaymentOperations(PaymentInterface $payment) {
  $payment_state = $payment
    ->getState()->value;
  $operations = [];
  $operations['receive'] = [
    'title' => $this
      ->t('Receive'),
    'page_title' => $this
      ->t('Receive payment'),
    'plugin_form' => 'receive-payment',
    'weight' => -99,
    'access' => $payment_state == 'completed',
  ];
  $operations['void'] = [
    'title' => $this
      ->t('Void'),
    'page_title' => $this
      ->t('Void payment'),
    'plugin_form' => 'void-payment',
    'access' => $payment_state == 'completed',
    'weight' => 90,
  ];
  $operations['refund'] = [
    'title' => $this
      ->t('Refund'),
    'page_title' => $this
      ->t('Refund payment'),
    'plugin_form' => 'refund-payment',
    'access' => in_array($payment_state, [
      'completed',
      'partially_refunded',
    ]),
  ];
  return $operations;
}