【发布时间】:2015-11-24 18:00:02
【问题描述】:
我将 Laravel 4.2 与 Cashier 一起使用,我需要修改其受保护的函数 buildPayload() 但我不想直接在供应商文件中执行此操作,因为我在编写 Update 时可能会破坏代码...应该如何我继续用我自己的逻辑覆盖这个函数?
我目前在我的一个控制器中使用 Cashier,方法是:
$user->subscription('testplan')
->create(Input::get('stripeToken'), [
'email' => 'email@email.com,
]);
但我想添加一个 withTax() 参数... 像这样:
$user->subscription('testplan')
->withTax(10)
->create(Input::get('stripeToken'), [
'email' => 'email@email.com,
]);
我已经知道如何直接在 StripeGateway.php 文件中执行此操作,但这是不好的做法...
我知道我需要补充:
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;
}
我不知道如何不直接在 Cashier Original 文件中添加此代码。
【问题讨论】:
标签: php laravel laravel-4 laravel-cashier