如何使用 Stripe API PHP 删除客户

How to delete a Customer with Stripe API PHP

我一直在将 Stripe 集成到我的平台中,并且一切正常。我可以创建关联帐户、客户、产品、价格、创建和更新订阅,一切正常。我需要做的最后一件事是允许客户删除他们的帐户。这是我的代码:

public function remove_member()  //DELETES MEMBER ACCOUNT
        {  
            $this->api_error = '';
            $this->CI =& get_instance();
            $this->CI->load->config('stripe');
            require APPPATH .'third_party/stripe-php/init.php'; // Include the Stripe PHP bindings library
            \Stripe\Stripe::setApiKey($this->CI->config->item('stripe_api_key')); // Set API key
                        
            $customer = \Stripe\Customer::delete(
                'stripeCustomerID',
                []); 
        }

但是它会抛出此错误:“您必须将数组作为第一个参数传递给 Stripe API 方法调用。”

但我相信我正在关注 Stripe Docs...这里:https://stripe.com/docs/api/customers/delete?lang=php

有什么建议吗?

对于 7.33 之前的 stripe-php 版本,您必须先检索然后调用删除,如下所示:

$customer = \Stripe\Customer::retrieve('cus_xxx');
$customer->delete();

由于提出了一个额外的请求,Stripe 引入了一个新的 client/service 在 7.33.0 中获得批准 here 这使得事情变得更容易,因为您可以直接调用删除 API 参考这里:

$stripe = new \Stripe\StripeClient(
  'sk_test_...'
);
$stripe->customers->delete(
  'cus_...',
  []
);