Closed divdax closed 4 months ago
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 the handlePaymentFailed
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?
Any updates on this?
Hi @valerius21,
this will likely included within the next major release of this package. There is currently no ETA for the next major release, but I expect it to happen within this year.
It would be great we could set the
orderable
morph relationship for one time charges like so:Currently
orderable_id
&oderable_type
in tableorder_items
is always empty.