You are here

public static function Utilities::customer_setup_submit in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

2 calls to Utilities::customer_setup_submit()
miniorange_saml_customer_setup_submit in ./miniorange_saml_customer_setup.inc
Handle submit for customer setup.
miniorange_saml_registration in ./miniorange_saml_registration.php

File

includes/Utilities.php, line 333

Class

Utilities
This file is part of miniOrange SAML plugin.

Code

public static function customer_setup_submit($username, $phone, $password, $called_from_popup = false, $payment_plan = NULL) {
  $customer_config = new MiniorangeSAMLCustomer($username, $phone, $password, NULL);
  $check_customer_response = json_decode($customer_config
    ->checkCustomer());
  if ($check_customer_response->status == 'CUSTOMER_NOT_FOUND') {

    // Create customer.
    // Store email and phone.
    variable_set('miniorange_saml_customer_admin_email', $username);
    variable_set('miniorange_saml_customer_admin_phone', $phone);
    variable_set('miniorange_saml_customer_admin_password', $password);
    $send_otp_response = json_decode($customer_config
      ->sendOtp());
    if ($send_otp_response->status == 'SUCCESS') {

      // Store txID.
      variable_set('miniorange_saml_tx_id', $send_otp_response->txId);
      variable_set('miniorange_saml_status', 'VALIDATE_OTP');
      if ($called_from_popup == true) {
        miniorange_otp(false, false, false);
      }
      else {
        drupal_set_message(t('Verify email address by entering the passcode sent to @username', array(
          '@username' => $username,
        )));
      }
    }
    else {
      if ($called_from_popup == true) {
        register_data(true);
      }
      else {
        drupal_set_message(t('An error has been occured. Please try after some time or contact us at <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a>.'), 'error');
      }
    }
  }
  elseif ($check_customer_response->status == 'CURL_ERROR') {
    if ($called_from_popup == true) {
      register_data(true);
    }
    else {
      drupal_set_message(t('cURL is not enabled. Please enable cURL'), 'error');
    }
  }
  else {

    // Customer exists. Retrieve keys.
    $customer_keys_response = json_decode($customer_config
      ->getCustomerKeys());
    if (json_last_error() == JSON_ERROR_NONE) {
      variable_set('miniorange_saml_customer_id', $customer_keys_response->id);
      variable_set('miniorange_saml_customer_admin_token', $customer_keys_response->token);
      variable_set('miniorange_saml_customer_admin_email', $username);
      variable_set('miniorange_saml_customer_admin_phone', $phone);
      variable_set('miniorange_saml_customer_api_key', $customer_keys_response->apiKey);
      variable_set('miniorange_saml_status', 'PLUGIN_CONFIGURATION');
      if ($called_from_popup == true) {
        $payment_page_url = variable_get('redirect_plan_after_registration_' . $payment_plan, '');
        $payment_page_url = str_replace('none', $username, $payment_page_url);
        miniorange_redirect_successful($payment_page_url);
      }
      else {
        drupal_set_message(t('Successfully retrieved your account.'));
        self::redirect_to_licensing();
      }
    }
    else {
      if ($check_customer_response->status == 'TRANSACTION_LIMIT_EXCEEDED') {
        if ($called_from_popup == true) {
          register_data(true);
        }
        else {
          drupal_set_message(t('An error has been occured. Please try after some time or contact us at <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a>..'), 'error');
        }
      }
      else {
        if ($called_from_popup == true) {
          register_data(false, true);
        }
        else {
          drupal_set_message(t('Invalid credentials'), 'error');
        }
      }
    }
  }
}