【问题标题】:stripe charge with existing consumer与现有消费者一起收费
【发布时间】:2020-04-07 22:29:46
【问题描述】:

我使用此代码进行付款并在我的条纹仪表板上创建一个新客户。

            $customer = \Stripe\Customer::create([
                "name" => $utente,
                "source"  => $_POST['stripeToken'],
                "email" => $row['mail'],
            ]);
            $charge = \Stripe\Charge::create([
                "customer" => $customer->id,
                "amount" => $amount_cents,
                "currency" => "eur",
                "description" => $description
            ]);

用于创建新客户的姓名或电子邮件等信息是在用户注册并连接到我的网站时从我的网站的仪表板中获取的。

这关系到用户的第一个付款.php 文件。 在第二个用户付款时,网站重定向到第二个 .php 文件,我需要在其中向先前创建的客户添加第二个付款。问题是,如果我保留相同的代码,在条带仪表板上我会发现自己是两个平等的客户。我不知道如何获取客户 ID,当我重定向到第二个付款页面时,作为用户信息我只有邮件和姓名.. 我该怎么办?

我将通过搜索条带 api 参考来尝试类似的方法:

        $customer = \Stripe\Customer::all([
            'email' => $row['mail']
        ]);
        $charge = \Stripe\Charge::create([
            "customer" => $customer['data']->id,
            "amount" => $amount_cents,
            "currency" => "eur",
            "description" => $description
        ]);

但它给了我错误

Must provide source or customer..

【问题讨论】:

  • 我怀疑你只想要$customer->id,而不是$customer['data']->id。我怀疑Customer::all 返回一个array 客户,而不仅仅是一个。
  • 我也试过了,但给了我同样的错误。无论如何,这是 $customer 值:pastebin.com/PKEMADwN
  • 我尝试使用 $customer->data->id,$customer['data']->id 和 $customer->id 但它给了我同样的错误
  • 您需要print_r($customer) 才能查看其中的内容。同样,我怀疑这将是一个数组,这意味着您尝试过的任何方法都不起作用。
  • 我使用 print_r 查看输出(是我放在 pastebin 上的),是的,它是一个多维数组,但是我知道如何只取这个数组的一个子值,也是因为我不知道它是否是一个特定的条带输出,因此有自己的精确调用值的方式,在参考上它什么也没说

标签: php stripe-payments


【解决方案1】:

列出客户将返回一个带有数据属性的对象。 data 是一个客户列表,因此您需要在该列表中建立索引并在查看他们的 ID 之前抓取其中一位客户。它应该类似于:

$customer = \Stripe\Customer::all([
    'email' => $row['mail']
]);
$charge = \Stripe\Charge::create([
    'customer' => $customer->data[0]->id,
    'amount' => $amount_cents,
    'currency' => 'eur',
    'description' => $description
]);

【讨论】:

    猜你喜欢
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多