【问题标题】:How to delete a Customer with Stripe API PHP如何使用 Stripe API PHP 删除客户
【发布时间】:2021-12-31 15:20:33
【问题描述】:

我一直在将 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

有什么建议吗?

【问题讨论】:

  • 你使用的是哪个版本的stripe-php?
  • 嗨亚历克斯 - 7.32.0

标签: php stripe-payments codeigniter-3


【解决方案1】:

对于 7.33 之前的 stripe-php 版本,您必须先检索,然后像这样调用 delete:

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

由于提出了额外的请求,Stripe 引入了一个在 7.33.0 中批准的新客户端/服务,记录在 here 这使得事情变得更容易,因为您可以直接调用 delete,如 API 参考中所述:

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

【讨论】:

  • 谢谢亚历克斯!!!!工作完美。
猜你喜欢
  • 2021-12-27
  • 2014-03-30
  • 2019-04-04
  • 2019-12-31
  • 2017-06-17
  • 1970-01-01
  • 2012-08-30
  • 2020-05-26
  • 2017-02-02
相关资源
最近更新 更多