Esempio n. 1
0
 public function __toString()
 {
     $prefix = null;
     if ($this->protocol || $this->domain || $this->port) {
         $protocol = ValueAs::nonempty($this->protocol, 'http');
         $auth = '';
         if (strlen($this->user) && strlen($this->pass)) {
             $auth = SafeHtml::escapeUri($this->user) . ':' . SafeHtml::escapeUri($this->pass) . '@';
         } else {
             if (strlen($this->user)) {
                 $auth = SafeHtml::escapeUri($this->user) . '@';
             }
         }
         if ($protocol != 'javascript') {
             $prefix = $protocol . '://' . $auth . $this->domain;
         } else {
             $prefix = $protocol . ':';
         }
         if ($this->port) {
             $prefix .= ':' . $this->port;
         }
     }
     if ($this->query) {
         $query = '?' . http_build_query($this->query);
     } else {
         $query = null;
     }
     if (strlen($this->getFragment())) {
         $fragment = '#' . $this->getFragment();
     } else {
         $fragment = null;
     }
     return $prefix . $this->getPath() . $query . $fragment;
 }
Esempio n. 2
0
 /**
  * Create a new customer (and trigger a lead)
  *
  * @param string $companyFid
  * @param string $email
  * @param string $firstName
  * @param string $lastName
  * @param string $phoneNumber
  * @param string $reference                   Your internal ID for this
  *                                            customer (e.g. user id)
  * @param string $accountType
  * @param int    $createdTime
  * @param bool   $isImport
  *
  * @return $this
  */
 public function create($companyFid, $email, $firstName, $lastName = null, $phoneNumber = null, $reference = null, $accountType = CustomerAccountType::RESIDENTIAL, $createdTime = null, $isImport = false)
 {
     $exRef = ValueAs::nonempty($reference, $this->_externalReference);
     $createCustomerPayload = new CreateCustomerPayload();
     $createCustomerPayload->externalReference = $exRef;
     $createCustomerPayload->companyFid = $companyFid;
     $createCustomerPayload->email = $email;
     $createCustomerPayload->firstName = $firstName;
     $createCustomerPayload->lastName = $lastName;
     $createCustomerPayload->accountType = $accountType;
     $createCustomerPayload->createdTime = $createdTime;
     $createCustomerPayload->isImport = $isImport;
     $customerEp = $this->_getEndpoint();
     $req = $customerEp->createProspect($createCustomerPayload);
     $customer = $this->_processRequest($req);
     $this->_customerFid = $customer->fid;
     if (!empty($phoneNumber)) {
         try {
             $this->addPhoneNumber($phoneNumber, true);
         } catch (\Exception $e) {
         }
     }
     try {
         $locationPayload = new CustomerSetLocationPayload();
         $locationPayload->fid = $this->_customerFid;
         $locationPayload->userIp = $this->_fortifi->getClientIp();
         $this->_processRequest($this->_getEndpoint()->setLocation($locationPayload));
     } catch (\Exception $e) {
     }
     return $this;
 }
Esempio n. 3
0
 public function testNonempty()
 {
     $this->assertEquals('zebra', ValueAs::nonempty(false, null, 0, '', [], 'zebra'));
     $this->assertEquals(null, ValueAs::nonempty());
     $this->assertEquals(false, ValueAs::nonempty(null, false));
     $this->assertEquals(null, ValueAs::nonempty(false, null));
 }
Esempio n. 4
0
 /**
  * Trigger a visitor action
  *
  * @param        $companyFid
  * @param        $actionKey
  * @param        $transactionId
  * @param int    $transactionValue
  * @param array  $data
  * @param null   $couponCode
  * @param bool   $returnPixels
  * @param string $userReference
  * @param string $campaignHash
  * @param string $sid1
  * @param string $sid2
  * @param string $sid3
  *
  * @return PostActionResponse
  */
 public function triggerAction($companyFid, $actionKey, $transactionId, $transactionValue = 0, array $data = null, $couponCode = null, $returnPixels = true, $userReference = null, $campaignHash = null, $sid1 = null, $sid2 = null, $sid3 = null)
 {
     $endpoint = AffiliateActionEndpoint::bound($this->_getApi());
     $payload = new PostActionPayload();
     $payload->userAgent = $this->_fortifi->getUserAgent();
     $payload->language = $this->_fortifi->getUserLanguage();
     $payload->clientIp = $this->_fortifi->getClientIp();
     $payload->encoding = $this->_fortifi->getUserEncoding();
     $payload->companyFid = $companyFid;
     $payload->actionKey = $actionKey;
     $payload->transactionId = $transactionId;
     $payload->transactionValue = $transactionValue;
     $payload->coupon = $couponCode;
     $payload->data = $data;
     $payload->returnPixels = $returnPixels;
     $payload->visitorId = $this->_visitorId;
     $payload->userReference = ValueAs::nonempty($userReference, $this->_alias);
     $payload->campaignHash = $campaignHash;
     $payload->sid1 = $sid1;
     $payload->sid2 = $sid2;
     $payload->sid3 = $sid3;
     $req = $endpoint->post($payload);
     $result = $this->_processRequest($req);
     if ($returnPixels) {
         /**
          * @var $result PostActionResponse
          */
         $this->_pixels = $result->pixels;
     }
     return $result;
 }
 protected function _dataNodeLink($property, $subProperty = null, $displayName = null)
 {
     $fid = $this->{$property . 'Fid'};
     $response = $this->{$property};
     if ($subProperty) {
         $fid = $response->{$subProperty . 'Fid'};
         $response = $response->{$subProperty};
     }
     $text = ValueAs::nonempty($displayName, Objects::property($response, 'displayName'), $fid);
     return '"{' . $text . '[' . $fid . ']}"';
 }
Esempio n. 6
0
 /**
  * Create a new customer (and trigger a lead)
  *
  * @param string $companyFid
  * @param string $email
  * @param string $firstName
  * @param string $lastName
  * @param string $phoneNumber
  * @param string $reference                   Your internal ID for this
  *                                            customer (e.g. user id)
  * @param string $accountType
  * @param string $accountStatus
  * @param string $subscriptionType
  * @param bool   $triggerLeadAction
  * @param int    $createdTime
  *
  * @return $this
  */
 public function create($companyFid, $email, $firstName, $lastName = null, $phoneNumber = null, $reference = null, $accountType = CustomerAccountType::RESIDENTIAL, $accountStatus = CustomerAccountStatus::ACTIVE, $subscriptionType = CustomerSubscriptionType::FREE, $triggerLeadAction = false, $createdTime = null)
 {
     $exRef = ValueAs::nonempty($reference, $this->_externalReference);
     $createCustomerPayload = new CreateCustomerPayload();
     $createCustomerPayload->externalReference = $exRef;
     $createCustomerPayload->companyFid = $companyFid;
     $createCustomerPayload->email = $email;
     $createCustomerPayload->firstName = $firstName;
     $createCustomerPayload->lastName = $lastName;
     $createCustomerPayload->accountType = $accountType;
     $createCustomerPayload->accountStatus = $accountStatus;
     $createCustomerPayload->subscriptionType = $subscriptionType;
     $createCustomerPayload->createdTime = $createdTime;
     $customerEp = $this->_getEndpoint();
     $req = $customerEp->createCustomer($createCustomerPayload);
     $customer = $this->_processRequest($req);
     $this->_customerFid = $customer->fid;
     if (!empty($phoneNumber)) {
         try {
             $this->addPhoneNumber($phoneNumber, true);
         } catch (\Exception $e) {
         }
     }
     if ($triggerLeadAction) {
         $trigger = $this->_fortifi->visitor($this->_visitorId)->triggerAction($companyFid, AffiliateBuiltInAction::LEAD, $reference, 0, ['customerFid' => $this->_customerFid, 'email' => $email, 'first_name' => $firstName, 'last_name' => $lastName, 'phone_number' => $phoneNumber, 'external_reference' => $exRef, 'accountType' => $accountType, 'accountStatus' => $accountStatus, 'subscriptionType' => $subscriptionType]);
         if (!empty($trigger->visitorId)) {
             $this->setVisitorId($trigger->visitorId);
         }
         $affPayload = new CustomerSetAffiliatePayload();
         $affPayload->affiliateFid = $trigger->affiliate;
         $affPayload->fid = $this->_customerFid;
         $affPayload->sid1 = $trigger->sid1;
         $affPayload->sid2 = $trigger->sid2;
         $affPayload->sid3 = $trigger->sid3;
         try {
             $this->_processRequest($this->_getEndpoint()->setAffiliate($affPayload));
         } catch (\Exception $e) {
         }
     }
     try {
         $locationPayload = new CustomerSetLocationPayload();
         $locationPayload->fid = $this->_customerFid;
         $locationPayload->userIp = $this->_fortifi->getClientIp();
         $this->_processRequest($this->_getEndpoint()->setLocation($locationPayload));
     } catch (\Exception $e) {
     }
     return $this;
 }
 /**
  * @param AffiliatePolicyPayload       $payload
  * @param string                       $companyFid
  * @param string                       $resourceFid
  * @param string                       $campaignFid
  * @param string                       $sid1
  * @param string                       $sid2
  * @param string                       $sid3
  * @param string                       $action
  * @param string                       $country
  * @param string                       $platform
  * @param AffiliatePolicyRulePayload[] $rules
  * @param string                       $description
  *
  * @return FidResponse|FortifiApiRequestInterface
  */
 public function set(AffiliatePolicyPayload $payload, $companyFid = null, $resourceFid = null, $campaignFid = null, $sid1 = null, $sid2 = null, $sid3 = null, $action = null, $country = null, $platform = null, $rules = null, $description = null)
 {
     $payload->companyFid = ValueAs::nonempty($companyFid, $payload->companyFid);
     $payload->resourceFid = ValueAs::nonempty($resourceFid, $payload->resourceFid);
     $payload->campaignFid = ValueAs::nonempty($campaignFid, $payload->campaignFid);
     $payload->sid1 = ValueAs::nonempty($sid1, $payload->sid1);
     $payload->sid2 = ValueAs::nonempty($sid2, $payload->sid2);
     $payload->sid3 = ValueAs::nonempty($sid3, $payload->sid3);
     $payload->action = ValueAs::nonempty($action, $payload->action);
     $payload->country = ValueAs::nonempty($country, $payload->country);
     $payload->platform = ValueAs::nonempty($platform, $payload->platform);
     $payload->rules = ValueAs::nonempty($rules, $payload->rules);
     $payload->description = ValueAs::nonempty($description, $payload->description);
     $ep = AffiliatePolicyEndpoint::bound($this->getApi());
     return $ep->set($payload)->get();
 }
Esempio n. 8
0
 public function getDisplayText()
 {
     return ValueAs::nonempty($this->displayName, implode(' ', array_filter([$this->firstName, $this->lastName])), 'Employee');
 }
Esempio n. 9
0
 /**
  * Trigger a visitor action
  *
  * @param        $companyFid
  * @param        $actionKey
  * @param        $transactionId
  * @param Carbon $time,
  * @param int    $transactionValue
  * @param array  $data
  * @param null   $couponCode
  * @param bool   $returnPixels
  * @param string $userReference
  * @param string $campaignHash
  * @param string $sid1
  * @param string $sid2
  * @param string $sid3
  *
  * @return PostActionPayload
  */
 public function preparePayload($companyFid, $actionKey, $transactionId, Carbon $time, $transactionValue = 0, array $data = null, $couponCode = null, $returnPixels = true, $userReference = null, $campaignHash = null, $sid1 = null, $sid2 = null, $sid3 = null)
 {
     $payload = new PostActionPayload();
     $payload->userAgent = $this->_fortifi->getUserAgent();
     $payload->language = $this->_fortifi->getUserLanguage();
     $payload->clientIp = $this->_fortifi->getClientIp();
     $payload->encoding = $this->_fortifi->getUserEncoding();
     $payload->companyFid = $companyFid;
     $payload->actionKey = $actionKey;
     $payload->transactionId = $transactionId;
     $payload->timestamp = $time->getTimestamp();
     $payload->transactionValue = $transactionValue;
     $payload->coupon = $couponCode;
     $payload->data = $data;
     $payload->returnPixels = $returnPixels;
     $payload->visitorId = $this->_visitorId;
     $payload->userReference = ValueAs::nonempty($userReference, $this->_alias);
     $payload->campaignHash = $campaignHash;
     $payload->sid1 = $sid1;
     $payload->sid2 = $sid2;
     $payload->sid3 = $sid3;
     return $payload;
 }
Esempio n. 10
0
 public static function generate($time = null)
 {
     return (ValueAs::nonempty($time, time()) << 32) + Arrays::first(unpack('L', Strings::randomString(4)));
 }
Esempio n. 11
0
 /**
  * @param             $response
  * @param AccessToken $token
  *
  * @return OAuthUser
  */
 public function userDetails($response, AccessToken $token)
 {
     $user = new OAuthUser();
     $result = Objects::property($response, 'result', $response);
     /**
      * @var $result AuthUserDetailsResponse
      */
     if (!$result instanceof AuthUserDetailsResponse) {
         $result = AuthUserDetailsResponse::make($result);
     }
     $user->setAuthUserDetails($result);
     $user->exchangeArray(['uid' => $result->userFid, 'nickname' => ValueAs::nonempty($result->displayName, $result->firstName, $result->lastName, $result->username, $result->userFid), 'locale' => $result->language, 'location' => $result->timezone, 'name' => $result->displayName, 'imageUrl' => $result->avatarUrl, 'firstName' => $result->firstName, 'lastName' => $result->lastName, 'description' => $result->description, 'email' => $result->username]);
     return $user;
 }