I'm looking to override Cashier's SubscriptionBuilder::buildPayload()
. Which looks like:
protected function buildPayload()
{
return array_filter([
'billing_cycle_anchor' => $this->billingCycleAnchor,
'coupon' => $this->coupon,
'expand' => ['latest_invoice.payment_intent'],
'metadata' => $this->metadata,
'plan' => $this->plan,
'quantity' => $this->quantity,
'tax_percent' => $this->getTaxPercentageForPayload(),
'trial_end' => $this->getTrialEndForPayload(),
'off_session' => true,
]);
}
I'm looking to add 1 param to this which is 'collection_method': 'invoice'
So I'm trying to override this function so I can modify it.
I tried a few things, namely following some of the below answers:
Strategy to override a class in a library installed with Composer
Laravel 5.7 Override vendor class and extend old one
I have added my CustomSubscriptionBuilder
in App\SparkOverrides\
<?php
namespace Laravel\Cashier;
class CustomSubscriptionBuilder extends SubscriptionBuilder
{
protected function buildPayload()
{
dd('here');
}
}
Then in composer.json
I have added:
"autoload": {
...
"files": [
"app/SparkOverrides/CustomSubscriptionBuilder.php"
]
},
I have then run composer dump-autoload
. But then when I try and create a subscription the dd()
never gets hit. To make matters more confusing, I have added a dump and die to the vendor
buildPayload()
and that isn't getting hit either.
I feel like I'm close but am missing something. Thanks for any help.