php - L4.2 Extend/override Cashier to add Tax feature -
i using laravel 4.2 cashier , need modify protected function buildpayload() don't want directly in vendor file break code when composer update... how should proceed override function own logic ?
i use cashier in 1 of controller doing:
$user->subscription('testplan') ->create(input::get('stripetoken'), [ 'email' => 'email@email.com, ]);
but want add withtax() parameters... so:
$user->subscription('testplan') ->withtax(10) ->create(input::get('stripetoken'), [ 'email' => 'email@email.com, ]);
i know how directly in stripegateway.php
file it's bad practice...
i know need add:
protected $taxpercent = 0; public function withtax($tax) { $this->taxpercent = $tax; return $this; } protected function buildpayload() { $payload = [ 'plan' => $this->plan, 'prorate' => $this->prorate, 'quantity' => $this->quantity, 'trial_end' => $this->gettrialendforupdate(), 'tax_percent' => $this->taxpercent, ]; return $payload; }
what don't know how add code not directly in cashier original file.
you add gettaxpercent
method in user
model , calculate taxes well.laravel docs
sadly there's no option extend stripegateway
class hard coded in billable
trait,what can change functions -
public function charge($amount, array $options = []) { return (new stripegateway($this))->charge($amount, $options); } public function subscription($plan = null) { return new stripegateway($this, $plan); }
in user
class,the problem here can never know change in billable
,they might change name of functions , add few more uses stripegateway
, wouldn't know until bugs arrive.
the first option better wont need mention withtax
method each time.
Comments
Post a Comment