【发布时间】:2021-11-20 15:15:38
【问题描述】:
我正在尝试自定义条带结帐以从我的购物车中获取动态价格。为了测试这一点,我只是尝试在条形配置中创建产品和价格,然后将该价格传递给订单项。
我正在尝试的代码一直告诉我没有这样的产品。我不知道我是在犯语法错误还是我正在尝试的只是错误的。谁能给点建议?
include './stripe/init.php';
\Stripe\Stripe::setApiKey('API KEY GOES HERE');
header('Content-Type: application/json');
$YOUR_DOMAIN = 'https://www.XXXXX.XX.XX';
$product = \Stripe\Product::create([
'name' => 'Elearn Product',
]);
$price = \Stripe\Price::create([
'product' => '{{$product}}',
'unit_amount' => 1100,
'currency' => 'usd',
'recurring' => [
'interval' => 'month',
],
]);
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
'price' => '{{$price}}',
'quantity' => 1,
]],
'payment_method_types' => [
'card',
],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/enrolment-success',
'cancel_url' => $YOUR_DOMAIN . '/enrolment-failure',
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
【问题讨论】:
标签: php stripe-payments