Skip to content

Commit

Permalink
New feature for Apigee X monetization phase2 (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-intelli authored Oct 20, 2021
1 parent cac3753 commit 0126eaa
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 28 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"drupal/admin_toolbar": "^3.0",
"drupal/adminimal_admin_toolbar": "^1.9",
"drupal/apigee_api_catalog": "^2.4",
"drupal/apigee_edge": "^1.18",
"drupal/apigee_edge": "^1.18 || ^2.0.0",
"drupal/better_exposed_filters": "^5.0",
"drupal/default_content": "^1.0@alpha",
"drupal/email_registration": "^1.0@RC",
Expand Down
5 changes: 5 additions & 0 deletions config/install/core.entity_view_display.user.user.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ content:
region: content
settings: { }
third_party_settings: { }
billingtype:
weight: 7
region: content
settings: { }
third_party_settings: { }
user_picture:
type: image
weight: 0
Expand Down
19 changes: 19 additions & 0 deletions modules/custom/apigee_kickstart_enhancement/apigee_kickstart_enhancement.module
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ function apigee_kickstart_enhancement_user_view(array &$build, EntityInterface $
'value' => $value,
],
];
if ($field_name == 'billingtype') {
$build[$field_name]['#cache']['max-age'] = 0;
}
}
}
}
Expand Down Expand Up @@ -210,5 +213,21 @@ function _apigee_kickstart_user_extra_fields() {
return $user->getTimeZone();
},
],
'billingtype' => [
'label' => t('Billing Type'),
'value_callback' => function (UserInterface $user) {
if (\Drupal::hasService('apigee_m10n.monetization')) {
$sdk = \Drupal::service('apigee_m10n.monetization');
try {
$billing_type = $sdk->getBillingtype($user);
$developer_billing_type = $billing_type ? $billing_type : 'Not Specified (Defaults to Postpaid)' ;
}
catch (\Exception $e) {
$developer_billing_type = NULL;
}
return $developer_billing_type;
}
},
],
];
}
41 changes: 19 additions & 22 deletions src/Installer/Form/ApigeeMonetizationConfigurationForm.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Apigee\Edge\Api\Management\Controller\OrganizationController;
use Apigee\Edge\Api\Monetization\Controller\OrganizationProfileController;
use Apigee\Edge\Api\Monetization\Controller\SupportedCurrencyController;
use Apigee\Edge\Api\ApigeeX\Controller\SupportedCurrencyController as ApigeeXSupportedCurrencyController;
use CommerceGuys\Addressing\AddressFormat\AddressField;
use CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface;
use CommerceGuys\Intl\Currency\CurrencyRepository;
Expand Down Expand Up @@ -133,6 +134,10 @@ public function __construct(SDKConnectorInterface $sdk_connector, LanguageManage
// Set the organization.
$this->organization = $organization;

// Set supported currencies.
$supported_currency_controller = new ApigeeXSupportedCurrencyController($organization_id, $client);
$this->supportedCurrencies = $supported_currency_controller->getEntities();

$this->isOrgApigeeX = TRUE;
}
}
Expand Down Expand Up @@ -260,20 +265,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#description' => $this->t('Enable monetization for your Apigee Edge organization.'),
];

// 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['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 @@ -315,14 +316,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
],
];

// 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']['default_currency'] = [
'#type' => 'value',
'#value' => $this->isOrgApigeeX ? 'USD' : $this->organization->getCurrencyCode(),
];

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

// Check if ApigeeX and add default address from organization for org other than ApigeeX.
// Check if not ApigeeX and add default address from organization.
if (!$this->isOrgApigeeX && $addresses = $this->organization->getAddresses()) {
/** @var \Apigee\Edge\Api\Monetization\Structure\Address $address */
$address = reset($addresses);
Expand Down
57 changes: 52 additions & 5 deletions themes/custom/apigee_kickstart/templates/apigee/apigee-entity--xrate-plan--full.html.twig
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
'setupFees',
'recurringFees',
'consumptionFee',
'consumptionPricingRates',
'consumptionPricingType',
'revenueShareType',
'revenueShareRates',
'feeFrequency',
'paymentFundingModel',
'purchase'
Expand All @@ -49,11 +52,55 @@
{{ content.paymentFundingModel }}
</div>

<div class="rate-plan__card rate-plan__card--fees bg-lighter p-4 my-5 rounded-lg">
<h2>{{ 'Consumption Fees'|t }}</h2>
{{ content.consumptionFee }}
{{ content.consumptionPricingType }}
</div>
{% if content.consumptionPricingRates|render|striptags|trim is not empty %}
<div class="rate-plan__card rate-plan__card--fees bg-lighter p-4 my-5 rounded-lg">
<h2>{{ 'Consumption Fees'|t }}</h2>
{{ content.consumptionPricingType }}

{% if content.consumptionPricingRates[0]['#singleConsumptionText'] %}
{{ content.consumptionPricingRates }}
{% else %}
<div class="rate-plan-detail__table px-4 py-2 mt-4 bg-white">
<table class="table table-borderless mb-0">
<thead>
<tr>
<th scope="col">{{ 'Volume Bands'|t }}</th>
<th scope="col">{{ 'Cost per API call'|t }}</th>
</tr>
</thead>
<tbody>
{{ content.consumptionPricingRates }}
</tbody>
</table>
</div>
{% endif %}
</div>
{% endif %}

{% if content.revenueShareRates|render|striptags|trim is not empty %}
<div class="rate-plan__card rate-plan__card--fees bg-lighter p-4 my-5 rounded-lg">
<h2>{{ 'Revenue Sharing'|t }}</h2>
{{ content.revenueShareType }}

{% if content.revenueShareRates[0]['#singleShareText'] %}
{{ content.revenueShareRates }}
{% else %}
<div class="rate-plan-detail__table px-4 py-2 mt-4 bg-white">
<table class="table table-borderless mb-0">
<thead>
<tr>
<th scope="col">{{ 'Volume Bands'|t }}</th>
<th scope="col">{{ 'Developer Share Percentage'|t }}</th>
</tr>
</thead>
<tbody>
{{ content.revenueShareRates }}
</tbody>
</table>
</div>
{% endif %}
</div>
{% endif %}

{% if content.purchase %}
<div class="rate-plan__card rate-plan__card--purchase bg-lighter p-4 mt-4 rounded-lg" id="purchase">
Expand Down

0 comments on commit 0126eaa

Please sign in to comment.