You are here

protected function Payflow::validatePayment in Commerce PayPal 8

Attempt to validate payment information according to a payment state.

Parameters

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

string|null $payment_state: The payment state to validate the payment for.

3 calls to Payflow::validatePayment()
Payflow::capturePayment in src/Plugin/Commerce/PaymentGateway/Payflow.php
Captures the given authorized payment.
Payflow::createPayment in src/Plugin/Commerce/PaymentGateway/Payflow.php
Creates a payment.
Payflow::voidPayment in src/Plugin/Commerce/PaymentGateway/Payflow.php
Voids the given payment.

File

src/Plugin/Commerce/PaymentGateway/Payflow.php, line 324

Class

Payflow
Provides the PayPal Payflow payment gateway.

Namespace

Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway

Code

protected function validatePayment(PaymentInterface $payment, $payment_state = 'new') {
  $this
    ->assertPaymentState($payment, [
    $payment_state,
  ]);
  $payment_method = $payment
    ->getPaymentMethod();
  if (empty($payment_method)) {
    throw new InvalidArgumentException('The provided payment has no payment method referenced.');
  }
  switch ($payment_state) {
    case 'new':
      if ($payment_method
        ->isExpired()) {
        throw new HardDeclineException('The provided payment method has expired.');
      }
      break;
    case 'authorization':
      if ($payment
        ->isExpired()) {
        throw new \InvalidArgumentException('Authorizations are guaranteed for up to 29 days.');
      }
      if (empty($payment
        ->getRemoteId())) {
        throw new \InvalidArgumentException('Could not retrieve the transaction ID.');
      }
      break;
  }
}