Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate a plan ID using bitmasks #50

Open
Aerendir opened this issue Sep 3, 2020 · 0 comments
Open

Calculate a plan ID using bitmasks #50

Aerendir opened this issue Sep 3, 2020 · 0 comments

Comments

@Aerendir
Copy link
Owner

Aerendir commented Sep 3, 2020

    /**
     * Calculates the bitmask of the boolean features selected
     * by the merchant and returns the corresponding value in binary format.
     *
     * @return int
     */
    protected function calculatePlanId(PremiumStoreEmbeddable $features, array $options)
    {
        // No feature is selected
        $booleanBitmask = 0;
        $amount = 0;

        if ($features->hasAds()) {
            $amount += $this->plans['boolean']['ads']['price'][$options['currency']][$options['interval']];
            $booleanBitmask += PremiumStoreEmbeddable::ADS;
        }

        if ($features->hasSeo()) {
            $amount += $this->plans['boolean']['seo']['price'][$options['currency']][$options['interval']];
            $booleanBitmask += PremiumStoreEmbeddable::SEO;
        }

        if ($features->hasSocial()) {
            $amount += $this->plans['boolean']['social']['price'][$options['currency']][$options['interval']];
            $booleanBitmask += PremiumStoreEmbeddable::SOCIAL;
        }

        $booleanBitmask = decbin($booleanBitmask);

        return
            $booleanBitmask
            . '_' . $options['interval']
            . '_' . $options['trial_period_days']
            . '_' . $options['currency']
            . '_' . $amount;
    }

    /**
     * Sets the general configurations (as prices, for examples) in the FeatureInterface objects loaded from a
     * SubscriptionInterface object.
     */
    private function configurePricesInSubscriptionFeatures(SubscriptionInterface $subscription)
    {
        /** @var FeatureInterface $feature *
        foreach ($subscription->getFeatures() as $feature) {
            $prices = $this->getConfiguredFeatures()->get($feature->getName())->getPrices();
            $feature->setPrices($prices);
        }
    }

This code once was in SerendipityHQ\Bundle\FeaturesBundle\Service\FeaturesManager.
Removed because it causes troubles when applying Rector and PHP CS Fixer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant