cashier-mollie icon indicating copy to clipboard operation
cashier-mollie copied to clipboard

Tax inclusive plan prices

Open salmanhijazi opened this issue 4 years ago • 0 comments

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')) );
    }

salmanhijazi avatar Feb 01 '21 23:02 salmanhijazi