php - Stripe 客户门户 PHP 实施 - 将客户重定向到 URL
问题描述
我正在探索使用 Stripe PHP API(https://stripe.com/docs/billing/subscriptions/)实现 Stripe 客户门户(https://stripe.com/docs/billing/subscriptions/customer-portal)的可能性集成客户门户)。
一旦用户通过身份验证,门户调用将在按钮上可用,以便可以使用会话的登录凭据从外部数据库检索客户 ID。
form method="POST" action="/customer_portal.php"
操作将运行嵌套在 PHP 文件中的以下命令。此代码段向 Stripe 服务器发送 POST 请求并触发来自 Stripe 服务器的响应,其中包含 7 个属性:
POST 请求
\Stripe\Stripe::setApiKey('secret_key');
\Stripe\BillingPortal\Session::create([
'customer' => 'customer_id'
]);
响应体
{
"id": "portal_session_X",
"object": "billing_portal.session",
"created": 2569878511,
"customer": "customer_id",
"livemode": false,
"return_url": "https://example.com/account",
"url": "https://billing.stripe.com/session/{SESSION_SECRET}"
}
下一步是获取响应正文中包含的“URL”属性,并使用它将用户重定向到他/她的自定义客户门户。我在这一步遇到问题。
任何帮助将不胜感激!非常感谢。
解决方案
创建客户门户会话后:
$stripe = new \Stripe\StripeClient(
'sk_test_123'
);
$customer_portal = $stripe->billingPortal->sessions->create([
'customer' => 'cus_123',
'return_url' => 'https://example.com/account',
]);
这将是一种将您的用户重定向到该会话中返回的 URL 的情况。例如:
header('Location: ' . $customer_portal->url);
如何实现最后一步取决于您以及如何设置 Web 服务器。
推荐阅读
- python - Pyrebase:从第二个 get().val() 返回 None
- ssis - 打开 Biml 解决方案崩溃 VS2019
- android - 调试正常时无法构建发布 APK
- c++ - 尝试使用 Emscripten 构建 C++ SDL2 项目时未定义的符号
- r - 从单独的数据框列表中的列表中的数据框中提取列
- android - Kotlin - 与 Recyclerview 滚动同步移动视图
- javascript - 如何更改下面的 javascript 代码,以便我的 div 样式切换从显示无开始到显示网格?
- charts - 条形图方向的折线图
- mysql - 当外连接的主表为空时如何获取值?
- c# - C# - 如何将 4 位和 12 位放入 2 个字节