调用未定义的方法Stripe \ Subscription :: retrieve()

时间:2016-05-08 02:04:11

标签: php stripe-payments

我在CodeIgniter中使用Stripe,以下是我设置它的方法:

在我的Stripe控制器中,我通过以下方式调用库:

require_once(APPPATH.'libraries/stripe/init.php');

这是Stripe - PHP Fatal error: Class 'Stripe\Charge' not found

失败的功能是:

function cancelSubscription($stripeaccount){

    $customer = \Stripe\Customer::retrieve($stripeaccount);
    $sub_id = $customer->subscriptions->data[0]->id;    
    echo $sub_id;
    $subscription = \Stripe\Subscription::retrieve($sub_id);
    $subscription->cancel();

}

我通过回声确认第一行的\ Stripe \ Customer呼叫实际上正在工作并撤回订阅ID。但是,当我尝试在第4行检索订阅时,它失败了:

Fatal error: Call to undefined method Stripe\Subscription::retrieve()

Stripe的文档提供了以下示例:

$sub = \Stripe\Subscription::retrieve("sub_8PVEGdSaepQU26");
$sub->cancel();

正如您所看到的,除了我的变量名称,它是相同的。我在这个问题上空白,任何帮助都将不胜感激。

结果:

  

的print_r(get_class_method(0函数' \条纹\订阅'));

[0] => instanceUrl [1] => cancel [2] => save [3] => deleteDiscount [4] => baseUrl [5] => refresh [6] => className [7] => classUrl [8] => init [9] => __construct [10] => __set [11] => __isset [12] => __unset [13] => __get [14] => offsetSet [15] => offsetExists [16] => offsetUnset [17] => offsetGet [18] => keys [19] => constructFrom [20] => refreshFrom [21] => serializeParameters [22] => __toJSON [23] => __toString [24] => __toArray

2 个答案:

答案 0 :(得分:8)

\ Stripe \ Subscription :: retrieve api非常新,需要最新版本的stripe-php库(3.13.0),你应该尝试更新你的Stripe库。

答案 1 :(得分:0)

如果您不想更新条带,只需使用此功能cancel subscription

function cancelSubscription($stripeaccount){
      //$stripeaccount will be customer_id
    $customer = \Stripe\Customer::retrieve($stripeaccount);
    $sub_id->cancelSubscription(); 
      // cancelSubscription() is a function in Stripe_Customer Class,
      // So without getting subscription detail direct cancel the subscription 

 }

有关详细说明,请查看此处:Can't cancel the subscription on stripe in cakephp