laravel-cashier-mollie
laravel-cashier-mollie copied to clipboard
One-Time charge: order items orderable_id / model
It would be great we could set the orderable
morph relationship for one time charges like so:
$product = App\Models\SomethingOrderable::find(1);
$result = $user->newCharge();
$item = new ChargeItemBuilder($user);
$item->quantity($data->qty);
$item->unitPrice(money($data->price*100,'EUR'));
$item->description($data->name);
$item->taxPercentage(19);
$tiem->orderableModel($product); // <---------- new method
$result->addItem($item->make());
$result = $result->create();
Currently orderable_id
& oderable_type
in table order_items
is always empty.
How about this?
$item = new \Laravel\Cashier\Charge\ChargeItemBuilder($user, $orderable);
@sandervanhooft yeah... much better! :)
Would be even cooler to do something like this and fill everything automatically:
class ChargeItemBuilder
{
// ...
public static function forChargeable(Chargeable $chargeable, Model $billable)
{
$result = new static($billable);
$result->orderable = $chargeable->orderable();
$result->unitPrice($chargeable->unitPrice());
$result->description($chargeable->description());
$result->taxPercentage($billable->taxPercentage());
return $result;
}
}
interface Chargeable
{
public function orderable(): Model;
public function unitPrice(): Money;
public function description(): string;
}
This would require some additional modifications around handlePaymentFailed/Paid on the orderable model (also see InteractsWithOrderItems
. 🤔
Need to investigate if this is possible without breaking change.
For clarity, this would allow you to do stuff like
$itemA = ChargeItemBuilder::forChargeable($chargeableA, $billable)->make();
$itemB = ChargeItemBuilder::forChargeable($chargeableB, $billable)
->taxPercentage(5.5) // overrides allowed
->description('Some other description') // overrides allowed
->quantity(3)
->make();
$result = $user->newCharge()
->addItem($itemA)
->addItem($itemB)
->setRedirectUrl('https://www.example.com')
->create();
This is awesome! 😍
Thanks @divdax .
This is going to involve several steps, need to be careful to not break any existing installations. First impressions:
-
Split
InteractsWithOrderItems
into the following interfaces and apply as such:-
HandlesPaymentStatusUpdates
-
ProcessesOrderItem
-
PreprocessesOrderItems
(already exists)
-
-
Add checks to
Order.handlePaymentPaid
etc to check if thehandlePaymentFailed
method exists on the item before calling it. -
Add
Chargeable
interface. -
Add
ChargeItemBuilder::forChargeable()
Do you think it's possible?
We have put the first steps towards this on our backlog 🤞
First of all happy new year! 🎉 Sorry for asking, but do you have any news here?
Hey, this would help a lot! Is there currently any way to get all one-time charges for a user?