我使用以下方式检索客户:
$customer = Stripe_Customer::retrieve( $customer_id );
当我使用$customer->subscriptions->create($array)
时,收到错误消息:
Fatal error: Call to undefined method Stripe_Object::create()
我可以使用$customer->updateSubscription($array)
添加订阅,但工作正常,但这并不允许我向同一个客户添加同一计划的多个订阅。知道我做错了吗?
编辑:
这是$ customer的打印件:
object(Stripe_Customer)[135]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=14)
'id' => string 'cus_...' (length=18)
'object' => string 'customer' (length=8)
'created' => int 1415377515
'livemode' => boolean false
'description' => null
'email' => string 'email' (length=25)
'delinquent' => boolean false
'metadata' =>
object(Stripe_Object)[333]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=1)
'user_id' => string '107' (length=3)
protected '_unsavedValues' =>
object(Stripe_Util_Set)[334]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[335]
private '_elts' =>
array (size=0)
empty
'subscriptions' =>
object(Stripe_Object)[336]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=5)
'object' => string 'list' (length=4)
'total_count' => int 1
'has_more' => boolean false
'url' => string '/v1/customers/cus_.../subscriptions' (length=46)
'data' =>
array (size=1)
0 =>
object(Stripe_Object)[358]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=17)
'id' => string 'sub_...' (length=18)
'plan' =>
object(Stripe_Object)[219]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=12)
'id' => string 'standard' (length=8)
'interval' => string 'month' (length=5)
'name' => string 'Standard' (length=8)
'created' => int 1414519701
'amount' => int 9900
'currency' => string 'usd' (length=3)
'object' => string 'plan' (length=4)
'livemode' => boolean false
'interval_count' => int 1
'trial_period_days' => int 30
'metadata' =>
array (size=0)
empty
'statement_description' => string 'Charge' (length=9)
protected '_unsavedValues' =>
object(Stripe_Util_Set)[340]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[249]
private '_elts' =>
array (size=0)
empty
'object' => string 'subscription' (length=12)
'start' => int 1415381678
'status' => string 'trialing' (length=8)
'customer' => string 'cus_...' (length=18)
'cancel_at_period_end' => boolean false
'current_period_start' => int 1415381678
'current_period_end' => int 1417973678
'ended_at' => null
'trial_start' => int 1415381678
'trial_end' => int 1417973678
'canceled_at' => null
'quantity' => int 1
'application_fee_percent' => null
'discount' => null
'metadata' =>
array (size=0)
empty
protected '_unsavedValues' =>
object(Stripe_Util_Set)[357]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[343]
private '_elts' =>
array (size=0)
empty
protected '_unsavedValues' =>
object(Stripe_Util_Set)[337]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[359]
private '_elts' =>
array (size=0)
empty
'discount' => null
'account_balance' => int 0
'currency' => string 'usd' (length=3)
'cards' =>
object(Stripe_Object)[107]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=5)
'object' => string 'list' (length=4)
'total_count' => int 1
'has_more' => boolean false
'url' => string '/v1/customers/cus_.../cards' (length=38)
'data' =>
array (size=1)
0 =>
object(Stripe_Object)[356]
protected '_apiKey' => string 'sk_test_...' (length=32)
protected '_values' =>
array (size=21)
'id' => string 'card_...' (length=29)
'object' => string 'card' (length=4)
'last4' => string '4242' (length=4)
'brand' => string 'Visa' (length=4)
'funding' => string 'credit' (length=6)
'exp_month' => int 12
'exp_year' => int 2014
'fingerprint' => string '...' (length=16)
'country' => string 'US' (length=2)
'name' => string 'email' (length=25)
'address_line1' => null
'address_line2' => null
'address_city' => null
'address_state' => null
'address_zip' => null
'address_country' => null
'cvc_check' => string 'pass' (length=4)
'address_line1_check' => null
'address_zip_check' => null
'dynamic_last4' => null
'customer' => string 'cus_...' (length=18)
protected '_unsavedValues' =>
object(Stripe_Util_Set)[355]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[64]
private '_elts' =>
array (size=0)
empty
protected '_unsavedValues' =>
object(Stripe_Util_Set)[106]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[354]
private '_elts' =>
array (size=0)
empty
'default_card' => string 'card_...' (length=29)
protected '_unsavedValues' =>
object(Stripe_Util_Set)[230]
private '_elts' =>
array (size=0)
empty
protected '_transientValues' =>
object(Stripe_Util_Set)[138]
private '_elts' =>
array (size=0)
empty
答案 0 :(得分:12)
嗯,通常我是这样做的。
更新客户订阅:
$customer = Stripe_Customer::retrieve($customerStripeID);
$customer -> description = "Plan Change";
$customer -> updateSubscription(array('plan' => $planID);
$customer -> save();
OR
$customer = Stripe_Customer::retrieve($customerStripeID);
$subscription = $customer -> subscriptions -> retrieve($customerStripePlanID);
$subscription -> plan = $newPlan;
$subscription -> save();
新客户:
$customer = Stripe_Customer::create(array(
'card' => $token,
'description' => 'New Customer')
);
$customer->subscriptions->create(array('plan' => $planID));
我记得当我更新我的Stripe版本时,我使用的旧代码突然停止工作。也许,如果你得到最新版本,你的代码将完美运行。
编辑不确定我为何被拒绝投票。我最近一直在使用Stripe,这些解决方案对我来说一直很好。