【问题标题】:How to add billing details to source Stripe API如何将计费详细信息添加到源 Stripe API
【发布时间】:2021-07-12 14:28:39
【问题描述】:

我正在尝试使用 Stripe API 和 PHP 将表单中的帐单地址插入到 Stripe 源中。

这是我目前正在尝试的:

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  //Get form data and load it into DB and Stripe
  $address = stripslashes($_REQUEST['address']);
  $city    = stripslashes($_REQUEST['city']);
  $state   = stripslashes($_REQUEST['state']);
  $zip     = stripslashes($_REQUEST['zip_code']);

  \Stripe\Stripe::setApiKey("MY-API-KEY");
      
  $customer = \Stripe\Customer::updateSource(
    $ss_customer_id,
    $ss_card_id,
    [
      'billing_address' => [
        'line1' => $address,
      ]
    ]
  );
}

但是,这似乎不起作用,因为 Stripe API 给了我以下响应:

parameter_unknown - billing_address
Received unknown parameter: billing_address

我该如何解决这个问题?

【问题讨论】:

    标签: php api stripe-payments


    【解决方案1】:

    根据 Stripe docs https://stripe.com/docs/api/customers/update,您应该使用参数 address,其中包含 citycountryline1 em>、line2邮政编码

    我猜你的情况

            $customer = \Stripe\Customer::update(
              $ss_customer_id,
              [
                'address' => [
                  'line1' => $address,
                ]
              ]
            );
    

    【讨论】:

    • 好的,我想我试过了,但我会用你的方法再试一次。如果它不起作用,我会发表评论。
    • 我得到了parameter_unknown的API响应 - address Received unknown parameter: address
    • 抱歉,现在我看到“updateSource”与更新客户数据不同。如我所见,您使用的是旧版本的 PHP SDK。地址是客户实体的一部分,所以方法应该是 Customer::update() 代替。我已经澄清了我的答案。
    • 非常感谢,现在我可以添加其他字段了。
    猜你喜欢
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 2019-09-07
    • 2011-04-02
    相关资源
    最近更新 更多