You are here

public function StripePaymentMethodController::__construct in Stripe 7

Public constructor.

File

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

Class

StripePaymentMethodController

Code

public function __construct() {
  static::loadLibrary();
  $cache = cache_get('stripe_payment_currencies');
  if ($cache && !empty($cache->data)) {
    $this->currencies = $cache->data;
  }
  else {
    try {

      // Available payment currencies will vary based on
      // the country in which the Stripe account is located.
      $account = \Stripe\Account::retrieve();
      $country_spec = \Stripe\CountrySpec::retrieve($account->country);
      $currencies = $country_spec->supported_payment_currencies;
      $currencies = array_combine(array_map('strtoupper', $currencies), $currencies);
      cache_set('stripe_payment_currencies', $currencies, 'cache', CACHE_TEMPORARY);
      $this->currencies = $currencies;
    } catch (Exception $e) {
      if ($e
        ->getMessage()) {
        drupal_set_message($e
          ->getMessage(), 'error');
        watchdog('stripe_payment', 'Stripe supported payment currencies load error: @message.', array(
          '@message' => $e
            ->getMessage(),
        ), WATCHDOG_ERROR);
      }
    }
  }
  $this->title = t('Stripe Payment');
}