You are here

public function StripePaymentMethodController::validate in Stripe 7

Validate a payment against a payment method and this controller.

Don't call directly. Use PaymentMethod::validate() instead.

Parameters

Payment $payment: The validated payment.

PaymentMethod $payment_method: The payment method for the validated payment.

boolean $strict: Whether to validate everything a payment method needs or to validate the most important things only. Useful when finding available payment methods, for instance, which does not require unimportant things to be a 100% valid.

Throws

PaymentValidationException

Overrides PaymentMethodController::validate

See also

PaymentMethod::validate()

File

stripe_payment/includes/StripePaymentMethodController.inc, line 112
Stripe Payment controller class and helper code (classes and function).

Class

StripePaymentMethodController

Code

public function validate(Payment $payment, PaymentMethod $payment_method, $strict) {
  parent::validate($payment, $payment_method, $strict);

  // Confirm the payment's currency is supported (for the Stripe account).
  if ($stripe_account = $this
    ->retrieveAccount($payment_method)) {
    if (!in_array($payment->currency_code, array_keys($this->currencies))) {
      throw new PaymentValidationUnsupportedCurrencyException(t('The currency is not supported by this payment method.'));
    }
  }

  // Confirm we have a token, a customer or a card information.
  if ($strict && !isset($payment->method_data['token']) && !isset($payment->method_data['card']) && !isset($payment->method_data['customer'])) {
    throw new StripePaymentValidationException("A Stripe payment must have card or a customer to charge.");
  }
}