Skip to content

Commit

Permalink
Checks if ApigeeX and gives option to install m10 module (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-intelli authored Jul 21, 2021
1 parent 43558a7 commit e5a10a4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/Installer/ApigeeDevportalKickstartMonetization.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ public static function isMonetizable() {
$sdk_connector = \Drupal::service('apigee_edge.sdk_connector');
$organization_controller = new OrganizationController($sdk_connector->getClient());
$organization = $organization_controller->load($sdk_connector->getOrganization());
return ($organization->getPropertyValue('features.isMonetizationEnabled') === 'true');
// Check if org is Hybrid or ApigeeX.
if ($organization && ('CLOUD' === $organization->getRuntimeType() || 'HYBRID' === $organization->getRuntimeType()) && $organization->getAddonsConfig()) {
return (TRUE === $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled());
}
else {
return ($organization->getPropertyValue('features.isMonetizationEnabled') === 'true');
}
}
catch (\Exception $exception) {
// Do not log the exception here. This litters the logs since this is run
Expand Down
55 changes: 39 additions & 16 deletions src/Installer/Form/ApigeeMonetizationConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class ApigeeMonetizationConfigurationForm extends FormBase {
*/
protected $missingDependencies;

/**
* TRUE if organization is monetizable ApigeeX.
*
* @var bool
*/
protected $isOrgApigeeX;

/**
* ApigeeM10nConfigurationForm constructor.
*
Expand All @@ -121,8 +128,16 @@ public function __construct(SDKConnectorInterface $sdk_connector, LanguageManage
// cache these values?
$organization_controller = new OrganizationController($client);
$organization = $organization_controller->load($organization_id);
if ($organization && ('CLOUD' === $organization->getRuntimeType() || 'HYBRID' === $organization->getRuntimeType())) {
if ($this->isMonetizable = $organization->getAddonsConfig()->getMonetizationConfig()->getEnabled() === TRUE) {
// Set the organization.
$this->organization = $organization;

$this->isOrgApigeeX = TRUE;
}
}
/** @var \Apigee\Edge\Api\Management\Entity\OrganizationInterface $organization */
if ($this->isMonetizable = $organization->getPropertyValue('features.isMonetizationEnabled') === 'true') {
elseif ($this->isMonetizable = $organization->getPropertyValue('features.isMonetizationEnabled') === 'true') {
// Set the organization.
$organization_profile_controller = new OrganizationProfileController($organization_id, $client);
$this->organization = $organization_profile_controller->load($organization_id);
Expand Down Expand Up @@ -245,16 +260,20 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#description' => $this->t('Enable monetization for your Apigee Edge organization.'),
];

$form['modules']['apigee_m10n_add_credit'] = [
'#title' => $this->t('Enable Add Credit module'),
'#type' => 'checkbox',
'#description' => $this->t('Allow users to add credit to their prepaid balances.'),
'#states' => [
'visible' => [
'input[name="modules[apigee_m10n]"]' => ['checked' => TRUE],
// Don't show add credit checkbox as for now ApigeeX does not support prepaid functionality.
// TODO: remove this restriction when ApigeeX supports prepaid functionality.
if (!$this->isOrgApigeeX) {
$form['modules']['apigee_m10n_add_credit'] = [
'#title' => $this->t('Enable Add Credit module'),
'#type' => 'checkbox',
'#description' => $this->t('Allow users to add credit to their prepaid balances.'),
'#states' => [
'visible' => [
'input[name="modules[apigee_m10n]"]' => ['checked' => TRUE],
],
],
],
];
];
}

$form['store'] = [
'#type' => 'details',
Expand Down Expand Up @@ -296,10 +315,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
],
];

$form['store']['default_currency'] = [
'#type' => 'value',
'#value' => $this->organization->getCurrencyCode(),
];
// Hide for now as ApigeeX does not support add credit.
// TODO: remove this restriction when ApigeeX supports prepaid functionality.
if (!$this->isOrgApigeeX) {
$form['store']['default_currency'] = [
'#type' => 'value',
'#value' => $this->organization->getCurrencyCode(),
];
}

$form['store']['type'] = [
'#type' => 'value',
Expand Down Expand Up @@ -351,8 +374,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];
}

// Add default address from organization.
if ($addresses = $this->organization->getAddresses()) {
// Check if ApigeeX and add default address from organization for org other than ApigeeX.
if (!$this->isOrgApigeeX && $addresses = $this->organization->getAddresses()) {
/** @var \Apigee\Edge\Api\Monetization\Structure\Address $address */
$address = reset($addresses);

Expand Down

0 comments on commit e5a10a4

Please sign in to comment.