【问题标题】:Laravel stripe (customers and invoice)Laravel 条纹(客户和发票)
【发布时间】:2022-06-10 19:24:57
【问题描述】:

我创建了条带状的客户和产品。 我为这个客户创建了 paymentIntent、invoiceItems 和 invoice。我如何连接发票和付款? 我的控制器:

        //check user in stripe
        $stripeCustomer = $this->stripe->customers->search([
            'query' => "email:'$user->email'",
        ]);

        if (isset($stripeCustomer['data']) && !count($stripeCustomer['data']) ) {
            //create new user
            $stripeCustomer = $this->stripe->customers->create([
                'email' => $user->email,
                'name'  => $user->name
            ]);

            $stripeCustomerId = $stripeCustomer->id ?: 0;
        } else {
            $stripeCustomerId = $stripeCustomer['data'][0]->id;
        }

        $invoiceItems = $this->stripe->invoiceItems->create([
            'customer' => $stripeCustomerId,
            'price' => $product ? $product->stripe_price_id : null,
        ]);

        //create draft invoice
        $invoice = $this->stripe->invoices->create([
            'customer' => $stripeCustomerId,
        ]);

        //create payment
        $paymentIntent = $this->stripe->paymentIntents->create([
            'customer' => $stripeCustomerId,
            'amount' => $invoiceItems->amount,
            'currency' => Payment::CURRENCY_EUR,
            'payment_method_types' => ['card']
        ]);

        $clientSecret = $paymentIntent->client_secret;

提交表单(号码卡等...)后,我正在确认付款:

            const { error } = await stripe.confirmPayment({
                elements,
                confirmParams: {
                    // Make sure to change this to your payment completion page
                    return_url: "{{route('payment-success'), [ 'token' => $token ])}}",
                },
            });

我的paymentSuccess方法:

public function paymentSuccess($token)
    {
    $data = json_decode(base64_decode($token));
    //$data->paymentId
    // maybe here i must pay invoice  for my paymentId???

    
}

【问题讨论】:

  • Stripe invoicepayment 都是不同的东西,你为什么要混合这两个?
  • Invoices 用于通过电子邮件向客户发送一次性付款。
  • 请说明您想在这里实现什么?也许有人建议你一个更好的解决方案。

标签: laravel stripe-payments


【解决方案1】:

可以通过两种方式支付发票

Stripe 会自动创建并尝试在 根据您的订阅为客户开具发票 订阅设置。但是,如果您想尝试付款 超出正常收款计划的发票或其他一些发票 原因,您可以这样做。

$this->stripe->invoices->finalizeInvoice(
  $invoice->id,
  []
);
$this->stripe->invoices->pay(
   $invoice->id,
   []
);

您可以通过电子邮件手动将发票发送给您的客户 支付。您可以按照以下方式进行操作

$this->stripe->invoices->finalizeInvoice(
  $invoice->id,
  []
);
$this->stripe->invoices->sendInvoice(
   $invoice->id,
   []
);

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 2019-12-25
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2017-12-03
    • 2021-12-12
    相关资源
    最近更新 更多