Reputation: 333
I retrieve a customer using:
$customer = Stripe_Customer::retrieve( $customer_id );
When I use $customer->subscriptions->create($array)
, I get an error message saying:
Fatal error: Call to undefined method Stripe_Object::create()
I can add a subscription using $customer->updateSubscription($array)
and that works fine, but that doesn't allow me to add multiple subscriptions of the same plan to one customer. Any idea what I'm doing wrong?
EDIT:
Here's a print out of $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
Upvotes: 2
Views: 5171
Reputation: 1925
Well, this is usually how I do it.
Updating the subscription of a customer:
$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();
New customer:
$customer = Stripe_Customer::create(array(
'card' => $token,
'description' => 'New Customer')
);
$customer->subscriptions->create(array('plan' => $planID));
I remember that older code I used suddenly stopped working when I updated my Stripe version. Maybe, if you get the latest one your code will run flawless.
Edit not sure why I got voted down. I've been using Stripe a lot lately, and these solutions have been working fine for me.
Upvotes: 13