Skip to content

Commit

Permalink
Merge pull request #18 from PrestaShopCorp/feat/new-context-format
Browse files Browse the repository at this point in the history
feat: modify the context to better reflect what billing asks for
  • Loading branch information
maximesimoncelli authored Aug 24, 2023
2 parents a7be5d2 + f4999d7 commit e3abaf6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/Presenter/BillingPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

class BillingPresenter
{
const CONTEXT_VERSION = 2;

/**
* @var EnvBuilder
*/
Expand Down Expand Up @@ -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'] : '',
],
],
];
Expand All @@ -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'] . ')');
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/Wrappers/BillingContextWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit e3abaf6

Please sign in to comment.