[英]Laravel Cashier Stripe set capture_method to manual
https://stripe.com/docs/payments/capture-later
在上面的條帶文檔中,他們說如果您想捕獲付款暫停,請將 capture_method 設置為手動,然后當您准備好完成收費時,發送帶有最終金額的捕獲請求。
我在 laravel 收銀員的實現中沒有看到任何關於如何執行此操作的文檔。
但是,當我查看代碼時,我看到我可以傳遞合並的選項,我希望可以設置這個嗎?
trait Billable
{
/**
* Make a "one off" charge on the customer for the given amount.
*
* @param int $amount
* @param string $paymentMethod
* @param array $options
* @return \Laravel\Cashier\Payment
*
* @throws \Laravel\Cashier\Exceptions\PaymentActionRequired
* @throws \Laravel\Cashier\Exceptions\PaymentFailure
*/
public function charge($amount, $paymentMethod, array $options = [])
{
$options = array_merge([
'confirmation_method' => 'automatic',
'confirm' => true,
'currency' => $this->preferredCurrency(),
], $options);
$options['amount'] = $amount;
$options['payment_method'] = $paymentMethod;
if ($this->stripe_id) {
$options['customer'] = $this->stripe_id;
}
$payment = new Payment(
StripePaymentIntent::create($options, $this->stripeOptions())
);
$payment->validate();
return $payment;
}
...
/**
* Create a new SetupIntent instance.
*
* @param array $options
* @return \Stripe\SetupIntent
*/
public function createSetupIntent(array $options = [])
{
return StripeSetupIntent::create(
$options, $this->stripeOptions()
);
}
但這似乎設置了 payment_method 而不是 capture_method ......我覺得如果兩者都設置了這會導致問題。
在我寫這篇文章時,我認為答案是使用 createSetupIntent function 和我想要的參數,然后保存響應,以便我稍后可以參考意圖並最終確定收費。
有人做過嗎? 而是有人讀過這篇文章自己做過嗎? 如果是這樣,這是正確的解決方案嗎?
盡管 Laravel Cashier 讓您開始為您的應用程序訂閱基於訂閱的 model 非常棒,但我始終發現 Stripe 的 SDK 方式更有用、直觀且易於使用。 他們的文檔很棒,我建議使用 SDK 本身。
鑒於此,您可以繼續將 Cashier 用於其他所有操作,對於此特定場景,您可以使用 SDK。 對於您的情況,您必須創建一個 PaymentIntent,就像您說的那樣,將 capture_method 設置為手動。
這是一個使用 Stripe SDK 的示例(如果您使用的是 Cashier,則您已經擁有該軟件包):
$stripe = new \Stripe\StripeClient(
'YOUR_SECRET_KEY'
);
$stripe->paymentIntents->create([
'amount' => 2000,
'currency' => 'usd',
'payment_method_types' => ['card'],
'capture_method' => 'manual'
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.