You are here

public function MiniorangeOAuthCustomer::createCustomer in Drupal OAuth & OpenID Connect Login - OAuth2 Client SSO Login 7

Create Customer.

File

includes/customer_setup.php, line 91
Contains miniOrange Customer class.

Class

MiniorangeOAuthCustomer
@file This class represents configuration for customer.

Code

public function createCustomer() {
  if (!Utilities::isCurlInstalled()) {
    return json_encode(array(
      "statusCode" => 'ERROR',
      "statusMessage" => '. Please check your configuration.',
    ));
  }
  $url = MiniorangeOAuthConstants::BASE_URL . '/moas/rest/customer/add';
  $ch = curl_init($url);
  $fields = array(
    'companyName' => $_SERVER['SERVER_NAME'],
    'areaOfInterest' => 'Drupal 7 OAuth Client Module ',
    'email' => $this->email,
    'phone' => $this->phone,
    'password' => $this->password,
  );
  $field_string = json_encode($fields);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($ch, CURLOPT_ENCODING, "");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'charset: UTF - 8',
    'Authorization: Basic',
  ));
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string);
  $content = curl_exec($ch);
  if (curl_errno($ch)) {
    $error = array(
      '%method' => 'createCustomer',
      '%file' => 'customer_setup.php',
      '%error' => curl_error($ch),
    );
    watchdog('miniorange_oauth', 'Error at %method of %file: %error', $error);
  }
  curl_close($ch);
  return $content;
}