diff --git a/src/Presenter/BillingPresenter.php b/src/Presenter/BillingPresenter.php index cd9a653..e4d136f 100644 --- a/src/Presenter/BillingPresenter.php +++ b/src/Presenter/BillingPresenter.php @@ -29,6 +29,8 @@ class BillingPresenter { + const CONTEXT_VERSION = 2; + /** * @var EnvBuilder */ @@ -83,34 +85,31 @@ public function present($params) return [ 'psBillingContext' => [ 'context' => [ + 'contextVersion' => BillingPresenter::CONTEXT_VERSION, 'billingEnv' => $billingEnv, - 'billingUIUrl' => $this->getUrlBuilder()->buildUIUrl($billingEnv), 'isSandbox' => $this->getBillingContextWrapper()->isSandbox() ? $this->getBillingContextWrapper()->isSandbox() : false, - - 'versionPs' => _PS_VERSION_, - 'versionModule' => $this->getModule()->version, - 'moduleName' => $this->getModule()->name, - 'displayName' => $this->getModule()->displayName, - 'i18n' => [ 'isoCode' => $this->getBillingContextWrapper()->getLanguageIsoCode(), ], - 'refreshToken' => $this->getBillingContextWrapper()->getRefreshToken(), 'shop' => [ 'uuid' => $this->getBillingContextWrapper()->getShopUuid(), + 'domain' => $this->getBillingContextWrapper()->getShopDomain(), ], - 'user' => [ + 'organization' => [ + 'uuid' => $this->getBillingContextWrapper()->getOrganizationUuid(), 'email' => $this->getBillingContextWrapper()->getEmail(), + 'logoSrc' => !empty($params['logo']) ? $this->encodeImage($params['logo']) : '', + ], + 'product' => [ + 'id' => $this->getModule()->name, + 'displayName' => $this->getModule()->displayName, + 'logoSrc' => $this->encodeImage($this->getModuleLogo()), + 'privacyUrl' => !empty($params['privacyUrl']) ? $params['privacyUrl'] : '', + 'tosUrl' => !empty($params['tosUrl']) ? $params['tosUrl'] : '', ], - - 'moduleLogo' => $this->encodeImage($this->getModuleLogo()), - 'partnerLogo' => !empty($params['logo']) ? $this->encodeImage($params['logo']) : '', - 'moduleTosUrl' => !empty($params['tosLink']) ? $params['tosLink'] : '', - 'modulePrivacyUrl' => !empty($params['privacyLink']) ? $params['privacyLink'] : '', - 'emailSupport' => !empty($params['emailSupport']) ? $params['emailSupport'] : '', ], ], ]; @@ -127,20 +126,17 @@ public function present($params) */ private function validateContextArgs($params) { - if (!\Validate::isEmail($params['emailSupport'])) { - throw new BillingContextException('"emailSupport" must be a valid email (value=' . $params['emailSupport'] . ')'); - } - if (empty($params['tosLink'])) { - throw new BillingContextException('"tosLink" must be provided (value=' . $params['tosLink'] . ')'); + if (empty($params['tosUrl'])) { + throw new BillingContextException('"tosUrl" must be provided (value=' . $params['tosUrl'] . ')'); } - if (!\Validate::isAbsoluteUrl($params['tosLink'])) { - throw new BillingContextException('"tosLink" must be a valid url (value=' . $params['tosLink'] . ')'); + if (!\Validate::isAbsoluteUrl($params['tosUrl'])) { + throw new BillingContextException('"tosUrl" must be a valid url (value=' . $params['tosUrl'] . ')'); } - if (empty($params['privacyLink'])) { - throw new BillingContextException('"privacyLink" must be provided (value=' . $params['privacyLink'] . ')'); + if (empty($params['privacyUrl'])) { + throw new BillingContextException('"privacyUrl" must be provided (value=' . $params['privacyUrl'] . ')'); } - if (!\Validate::isAbsoluteUrl($params['privacyLink'])) { - throw new BillingContextException('"privacyLink" must be a valid url (value=' . $params['privacyLink'] . ')'); + if (!\Validate::isAbsoluteUrl($params['privacyUrl'])) { + throw new BillingContextException('"privacyUrl" must be a valid url (value=' . $params['privacyUrl'] . ')'); } } diff --git a/src/Wrappers/BillingContextWrapper.php b/src/Wrappers/BillingContextWrapper.php index 12e2d38..51b7c4e 100644 --- a/src/Wrappers/BillingContextWrapper.php +++ b/src/Wrappers/BillingContextWrapper.php @@ -114,6 +114,26 @@ public function getEmail() return $this->getPsAccountService()->getEmail(); } + /** + * Get the uuid of the organization. + * + * @return string|null + */ + public function getOrganizationUuid() + { + return $this->getPsAccountService()->getUserUuid(); + } + + /** + * Get the domain of the shop. + * + * @return string|null + */ + public function getShopDomain() + { + return \Tools::getShopDomain(); + } + /** * getSandbox *