每笔付款分别创建一个新客户

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

更新

对于一个相同的客户,我希望在此客户的所有付款中有一行。但是即使有相同的客户,我的每一笔付款也只有一行:enter image description here

if(!empty($_POST)){
        $token = $_POST['tokenID'];
        $name ='dfg' ;
        $email ='[email protected]';
        // Add customer to stripe
        $customer = \Stripe\Customer::create(array(
            'email' => $email,
            'card' => $token,
        ));

        // Unique order ID
        $orderID = strtoupper(str_replace('.', '', uniqid('', true)));

        // Convert price to cents
        $itemPrice = ($_POST['price'] * 100);

        $charge = \Stripe\Charge::create([
            'customer' => $customer->id,
            'amount' => $itemPrice,
            'currency' => 'eur',
            'description' => $_POST['description'],
            'metadata' => array(
                'order_id' => $orderID,
            ),
        ]);

我如何按客户排成一行?

之后的建议:现在我有:

if(gettype($customerAlreadyKnown)=='array'){
            $charge = \Stripe\Charge::create([
                'customer' => $customerAlreadyKnown[0]['user_id'],
                'card'=>$token,
                'amount' => $itemPrice,
                'currency' => 'eur',
                'description' => $_POST['description'],
                'metadata' => array(
                    'order_id' => $orderID,
                ),
            ]);
        }else{

但仍然出现错误:客户cus_GvvCtjg4I1Vdic没有ID为tok_1GO3S8F0S5meJa3hmxe8njSw的链接源

stripe-payments
1个回答
1
投票

您正在为每次付款创建一个新的TokenCustomer。您应该以某种方式(例如,通过其email_addressTokenCard fingerprint)来标识现有的客户(在应用程序本地存储关系表)。然后,代替使用新的Token和新的Customer,在收费之前将现有客户检索为$customer(它们的现有卡将自动使用)。

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