Stripe 收款流程

huangapple go评论166阅读模式
英文:

Stripe checkout flow

问题

尝试使用Stripe实现购物车,但它应该是什么样子?

//checkout.php

$checkout_session = $stripe->checkout->sessions->create([
   'line_items' => [

    // 针对在POST数据中列出的每个项目,
    //  [],[],[],...

   ],
   'mode' => 'payment',
   'success_url' => $YOUR_DOMAIN . '/success.html',
   'cancel_url' => $YOUR_DOMAIN . '/cancel.html'
]);

我是否应该将客户想要的所有内容都发送到checkout.php中的$_POST
所以在我的域名上我正在创建一个表单吗?

是否有另一种方法可以实现这一点,使客户可以添加到购物车并继续在我的网站上购物,然后进行结账?

感谢任何建议。

英文:

Trying to implement a cart with Stripe, but how should it look?

//checkout.php

$checkout_session = $stripe->checkout->sessions->create([
   'line_items' => [

    // foreach item listed in POST data,
    //  [],[],[],...

   ]
   'mode' => 'payment'
   'success_url' => $YOUR_DOMAIN . '/success.html',
   'cancel_url' => $YOUR_DOMAIN . '/cancel.html'
]);

Do I send checkout.php everything the customer wants in $_POST?
So on my domain I'm making a form?

Is there another way to do this, where the customer can add-to-cart and keep shopping on my site, then checkout?

Any words appreciated.

答案1

得分: 1

根据我理解,您不希望用户每次选择产品时都进行结账?也许您可以在本地存储中保存购物车的信息,包括来自Stripe的价格ID和单个数量。然后,当用户决定付款时,您可以使用结账表单(Stripe为此提供了一个现成的实现),并发送客户购物车中所有产品的所有信息。

根据您编写的代码,您可能已经检查过了,但是仔细查看这里,您会发现可以在list_items中添加多个项目,因此您可以将它们从前端传递给结账集成,然后从后端发送请求到Stripe,正如您在这里写的那样。

如果我对问题的理解有误,请告诉我更多,我将很乐意帮助您。

英文:

For what I understood you don't want to checkout every time the user selects a product? Maybe you could memorize in local storage the information for the cart, with the pricesID from Stripe and the single quantities. Then when the user decides to pay you can use the checkout form ( Stripe gives you a ready implementation for this ) and send all the informations of all the products the customer has in his/her own cart.

From the code you wrote probably you already checked it out, but giving a close look here you can see that you can add multiple items in list_items, so you can pass them from the front with the checkout integration and then send the request from the backend to sripe, exactly the way you wrote here.

If I misunderstood the problem here please tell me more, I'll be glad to help

huangapple
  • 本文由 发表于 2023年6月29日 12:00:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定