Beispiel #1
0
 /**
  * Validate return from Canada Post merchant registration process
  *
  * @return void
  */
 protected function capostValidateMerchant()
 {
     $token = \XLite\Core\Request::getInstance()->{'token-id'};
     $status = \XLite\Core\Request::getInstance()->{'registration-status'};
     if (\XLite\Module\XC\CanadaPost\Core\Service\Platforms::REG_STATUS_SUCCESS === $status) {
         // Registration is complete
         // Send request to Canada Post server to retrieve merchant details
         $data = \XLite\Module\XC\CanadaPost\Core\Service\Platforms::getInstance()->callGetMerchantRegistrationInfoByToken($token);
         if (isset($data->merchantInfo)) {
             // Update Canada Post settings
             $this->updateCapostMerchantSettings($data->merchantInfo);
             // Disable wizard
             $this->disableCapostWizard();
             \XLite\Core\TopMessage::getInstance()->addInfo('Registration process has been completed successfully.');
         } else {
             foreach ($data->errors as $err) {
                 \XLite\Core\TopMessage::getInstance()->addError('ERROR: [' . $err->code . '] ' . $err->description);
             }
         }
     } else {
         // An error occurred
         if (\XLite\Module\XC\CanadaPost\Core\Service\Platforms::REG_STATUS_CANCELLED === $status) {
             \XLite\Core\TopMessage::getInstance()->addError('Registration process has been canceled.');
         } else {
             \XLite\Core\TopMessage::getInstance()->addError('Failure to finish registration process.');
         }
     }
     // Remove token from the session
     \XLite\Core\Session::getInstance()->capost_token_id = null;
     \XLite\Core\Session::getInstance()->capost_token_ts = null;
     // Redirect back to the Canada Post settings page
     $this->setReturnURL($this->buildURL('capost'));
 }
Beispiel #2
0
 /**
  * Get Canada Post merchant registration token
  *
  * @return string
  */
 public function getTokenId()
 {
     $token = null;
     if (!$this->isTokenValid()) {
         // Send request to Canada Post server to retrieve token
         $data = \XLite\Module\XC\CanadaPost\Core\Service\Platforms::getInstance()->callGetMerchantRegistrationToken();
         if (isset($data->token)) {
             $token = $data->token->tokenId;
             \XLite\Core\Session::getInstance()->capost_token_id = $token;
             \XLite\Core\Session::getInstance()->capost_token_ts = \XLite\Core\Converter::time();
             \XLite\Core\Session::getInstance()->capost_developer_mode = \XLite\Core\Config::getInstance()->XC->CanadaPost->developer_mode;
         } else {
             // TODO: print real error message returned by the request
             \XLite\Core\TopMessage::getInstance()->addError('Failure to get token ID.');
         }
     } else {
         // Get token from the session
         $token = \XLite\Core\Session::getInstance()->capost_token_id;
     }
     return $token;
 }