mollie / laravel-cashier-mollie

Official Mollie integration for Laravel Cashier
https://www.cashiermollie.com/
MIT License
137 stars 45 forks source link

Charges - make sure to complete purchases via the checkout #244

Closed YDBleeker closed 6 months ago

YDBleeker commented 6 months ago

Can I enforce forwarding to a Mollie checkout for charges, similar to subscriptions? I tried newFirstPaymentChargeThroughCheckout for that. But now the amount from the config is being charged instead of the amount from the items.

$item = new \Laravel\Cashier\Charge\ChargeItemBuilder($user);
        $item->unitPrice(money($request->amount/121*100 ,'EUR'));
        $item->taxPercentage($user->tax_percentage);
        $item->description('Phone credits');
        $chargeItem = $item->make();

        $result = $user->newFirstPaymentChargeThroughCheckout()
            ->addItem($chargeItem)
            ->create();

        if(is_a($result, \Laravel\Cashier\Http\RedirectToCheckoutResponse::class)) {
            return $result;
        }
sandervanhooft commented 6 months ago

Hi @YDBleeker,

Thanks for following up here. What is the exact value (incl type) of $request->amount here?

sandervanhooft commented 6 months ago

Same question for $user->tax_percentage

YDBleeker commented 6 months ago

amount: 10 -> string tax_percentage: decimal

Naoray commented 6 months ago

Hi @YDBleeker,

But now the amount from the config is being charged instead

What config value are you referring to in your initial description?

Naoray commented 6 months ago

Can you also help me understand why you divide through 121 to create the Money instance (money($request->amount/121*100 ,'EUR'))? If the $request->amount() is '10', this results in 0.08 €. Not sure if this is what you were going for?!

YDBleeker commented 6 months ago

Hi @Naoray,

Thank you for your time. I've revisited this again and realized I overlooked something. It turned out that the amount charged at checkout was exactly the same as for the first payment in the cashier configuration due to my mistake. I forgot to take into account decimal numbers, but everything is already resolved. Still, thank you.