You are here

public function CreditCardPaymentMethodBase::processPayment in Ubercart 8.4

Process a payment through the credit card gateway.

Parameters

\Drupal\uc_order\OrderInterface $order: The order that is being processed.

float $amount: The amount of the payment we're attempting to collect.

string $txn_type: The transaction type, one of the UC_CREDIT_* constants.

string $reference: (optional) The payment reference, where needed for specific transaction types.

Return value

bool TRUE or FALSE indicating whether or not the payment was processed.

1 call to CreditCardPaymentMethodBase::processPayment()
CreditCardPaymentMethodBase::orderSubmit in payment/uc_credit/src/CreditCardPaymentMethodBase.php
Called when an order is being submitted with this payment method.

File

payment/uc_credit/src/CreditCardPaymentMethodBase.php, line 614

Class

CreditCardPaymentMethodBase
Defines a base credit card payment method plugin implementation.

Namespace

Drupal\uc_credit

Code

public function processPayment(OrderInterface $order, $amount, $txn_type, $reference = NULL) {

  // Ensure the cached details are loaded.
  // @todo Figure out which parts of this call are strictly necessary.
  $this
    ->orderLoad($order);
  $result = $this
    ->chargeCard($order, $amount, $txn_type, $reference);

  // If the payment processed successfully...
  if ($result['success'] === TRUE) {

    // Log the payment to the order if not disabled.
    if (!isset($result['log_payment']) || $result['log_payment'] !== FALSE) {
      uc_payment_enter($order
        ->id(), $this
        ->getPluginId(), $amount, empty($result['uid']) ? 0 : $result['uid'], empty($result['data']) ? NULL : $result['data'], empty($result['comment']) ? '' : $result['comment']);
    }
  }
  else {

    // Otherwise display the failure message in the logs.
    \Drupal::logger('uc_payment')
      ->warning('Payment failed for order @order_id: @message', [
      '@order_id' => $order
        ->id(),
      '@message' => $result['message'],
      'link' => $order
        ->toLink($this
        ->t('view order'))
        ->toString(),
    ]);
  }
  return $result['success'];
}