预填 Stripe 送货地址字段?

问题描述 投票:0回答:1

我正在尝试预填写送货地址部分,但我不能,我已经传递了多个不同的参数来指定送货地址,但每个参数都会抛出一个错误,提示未知参数,帮助!

现在我添加这些行是因为我在发布这个问题时遇到错误,说它看起来像你的帖子主要是代码添加一些行。

这是相关代码

<?php
if (isset($_SESSION['billing_details'])) {
  $billing_details = $_SESSION['billing_details'];
  $name = $billing_details['name'];
  $email = $billing_details['email'];
  $number = $billing_details['number'];
  $city = $billing_details['city'];
  $country = $billing_details['country'];
  $addressl1 = $billing_details['addressl1'];
  $addressl2 = $billing_details['addressl2'];
  $postalcode = $billing_details['postalcode'];
  $state = $billing_details['state'];
}
require __DIR__ . "/vendor/autoload.php";
$user_email = $_SESSION['email'];
$stripe_secret_key = "";

\Stripe\Stripe::setApiKey($stripe_secret_key);

// Fetch cart items from the database
$query = $query = "SELECT cart.qty, products.product_price, products.product_title 
FROM cart 
INNER JOIN products ON cart.p_id = products.product_id 
WHERE cart.user_email = '$user_email'";
$result = mysqli_query($conn, $query);

$line_items = [];

while ($row = mysqli_fetch_assoc($result)) {
  $line_item = [
    "quantity" => $row['qty'],
    "price_data" => [
      "currency" => "inr", // Assuming your prices are in USD, change if necessary
      "unit_amount" => $row['product_price'] * 100, // Convert to cents
      "product_data" => [
        "name" => $row['product_title']
      ]
    ]
  ];

  $line_items[] = $line_item;
}

$checkout_session = \Stripe\Checkout\Session::create([
  "mode" => "payment",
  "locale" => "auto",
  "customer_email" => $email,
  "line_items" => $line_items,
  "billing_address_collection" => "required",
  "shipping_address_collection" => [
    "allowed_countries" => ["IN"],
  ],
  "metadata" => [
    "name" => $name,
    "email" => $user_email,
    "phone" => $number,
  ]
]);


http_response_code(303);
header("Location: " . $checkout_session->url);
php stripe-payments stripes
1个回答
0
投票

如果启用了

billing_address_collection
shipping_address_collection
,您将无法执行此操作,因为您的结账会话将为客户添加字段以添加其地址,而您无法预先填写它们。

如果您已经知道客户的地址,则首先使用其 address

shipping
信息
创建客户
,然后使用
customer => customer->id
创建结帐会话。
您的会话仍将显示帐单国家/地区字段,因为这是付款方式(卡)所必需的,但它不会提示客户输入他们的地址。

© www.soinside.com 2019 - 2024. All rights reserved.