2

Laravel Cashier 使得使用订阅税创建订阅变得非常简单,但我发现在交换订阅时,它无法在这种情况下处理税收。

你遇到过这个问题吗?你是如何解决它的?

4

1 回答 1

1

我找到了解决方案,可能有点晚了,但它应该可以帮助其他人。

因此,您需要在您的 User(或任何 Billable)模型上覆盖 Laravel\Cashier\Billable::invoice() 方法以获取"tax_percent" => $this->taxPercentage(). 换句话说,将以下代码添加到您的用户(或任何其他可计费)模型类中。

public function invoice()
{
    if ($this->stripe_id) {
        try {
            return StripeInvoice::create(['customer' => $this->stripe_id, "tax_percent" => $this->taxPercentage()], $this->getStripeKey())->pay();
        } catch (StripeErrorInvalidRequest $e) {
            return false;
        }
    }

    return true;
}

还记得将此新要求添加到您的课程中

use Stripe\Invoice as StripeInvoice;
use Stripe\Error\InvalidRequest as StripeErrorInvalidRequest;
于 2016-07-08T16:09:34.233 回答