Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Tax inclusive plan prices #301

Open
salmanhijazi opened this issue Feb 1, 2021 · 0 comments
Open

Tax inclusive plan prices #301

salmanhijazi opened this issue Feb 1, 2021 · 0 comments

Comments

@salmanhijazi
Copy link

Hello,

Just wanted to ask if we can have a feature to toggle whether tax is to be included in the plan price or added on top? I'm working on an app where the tax is to be included in the price. I'm using a database repository so I was able to make it work by manually calculating it. Is there a better way/place to do this?

I have a global helper to fetch the tax_percentage from a settings file.

/**
     * Builds a Cashier plan from the current model.
     *
     * @returns \Laravel\Cashier\Plan\Plan
     */
    public function buildCashierPlan(): CashierPlan
    {
        $plan = new CashierPlan($this->name);

        $withTax = $this->amount['value'];
        $taxPercentage = settings('tax_percentage') * 0.01;
        $tax = $withTax / (1 + $taxPercentage) * $taxPercentage;
        $preTax = $withTax - $tax;

        $amount['value'] = $preTax;
        $amount['currency'] = $this->amount['currency'];

        if(request()->is('api/*')) {
            $redirect_url = '#####-app://mollie/callback';
        } else {
            $redirect_url = url()->full() .'/callback';
        }

        return $plan->setAmount(mollie_array_to_money($amount))
            ->setInterval( $this->interval )
            ->setDescription( $this->description )
            ->setFirstPaymentMethod( config('cashier.first_payment.method') )
            ->setFirstPaymentAmount( mollie_array_to_money(config('cashier.first_payment.amount')) )
            ->setFirstPaymentDescription( config('cashier.first_payment.description') )
            ->setFirstPaymentRedirectUrl( $redirect_url )
            ->setFirstPaymentWebhookUrl( config('cashier.first_payment.webhook_url') )
            ->setOrderItemPreprocessors( Preprocessors::fromArray( config('cashier.order_item_preprocessors')) );
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant