New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One-Time charge: order items orderable_id / model #122
Comments
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 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:
|
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! |
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.The text was updated successfully, but these errors were encountered: