本文整理汇总了PHP中Subscription::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscription::retrieve方法的具体用法?PHP Subscription::retrieve怎么用?PHP Subscription::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription::retrieve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateUpdateListCancel
public function testCreateUpdateListCancel()
{
$planID = 'gold-' . self::generateRandomString(20);
self::retrieveOrCreatePlan($planID);
$customer = self::createTestCustomer();
$sub = Subscription::create(array('plan' => $planID, 'customer' => $customer->id));
$this->assertSame($sub->status, 'active');
$this->assertSame($sub->plan->id, $planID);
$sub->quantity = 2;
$sub->save();
$sub = Subscription::retrieve($sub->id);
$this->assertSame($sub->status, 'active');
$this->assertSame($sub->plan->id, $planID);
$this->assertSame($sub->quantity, 2);
// Update the quantity parameter one more time
$sub = Subscription::update($sub->id, array("quantity" => 3));
$this->assertSame($sub->status, 'active');
$this->assertSame($sub->plan->id, $planID);
$this->assertSame($sub->quantity, 3);
$subs = Subscription::all(array('customer' => $customer->id, 'plan' => $planID, 'limit' => 3));
$this->assertSame(get_class($subs->data[0]), 'Stripe\\Subscription');
$sub->cancel(array('at_period_end' => true));
$sub = Subscription::retrieve($sub->id);
$this->assertSame($sub->status, 'active');
$this->assertTrue($sub->cancel_at_period_end);
}
示例2: testCreateRetrieveUpdatePauseResumeCancelDelete
public function testCreateRetrieveUpdatePauseResumeCancelDelete()
{
$planID = 'gold-' . self::randomString();
self::retrieveOrCreatePlan($planID);
$customer = self::createTestCustomer();
$sub = Subscription::create(array('customer' => $customer->id, 'plan' => $planID));
$this->assertSame($sub->status, 'active');
$this->assertSame($sub->trial_end, null);
$this->assertSame($sub->plan->id, $planID);
$sub_retrieve = Subscription::retrieve($sub->id);
$sub->pause();
$sub_pause = Subscription::retrieve($sub->id);
$this->assertSame($sub_pause->status, 'paused');
$sub->resume();
$sub_resume = Subscription::retrieve($sub->id);
$this->assertSame($sub_resume->status, 'active');
$resuumed_at = $sub->created + 10000;
$sub->pause();
$sub_pause = Subscription::retrieve($sub->id);
$this->assertSame($sub_pause->status, 'paused');
$this->assertSame(null, $sub->resumed_at);
$trial_end = $sub->created + 5000;
$sub->resume(array('trial_end' => $trial_end));
$sub_resume = Subscription::retrieve($sub->id);
$this->assertSame($sub_resume->status, 'trial');
$this->assertSame(500, $sub->plan->amount);
$this->assertSame($trial_end, $sub->trial_end);
try {
$sub->cancel(array('foo' => "bar"));
} catch (Error\InvalidRequest $e) {
$actual = $e->getJsonBody();
$this->assertSame('Invalid param key to subscription.', $actual['error']['message']);
}
$sub->cancel();
$sub_cancel = Subscription::retrieve($sub->id);
$this->assertSame($sub_cancel->status, 'canceled');
$sub_id = $sub->id;
$sub->delete();
$this->assertSame($sub_id, $sub->id);
$this->assertTrue($sub->deleted);
}