當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Subscription::retrieve方法代碼示例

本文整理匯總了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);
 }
開發者ID:wp-premium,項目名稱:gravityformsstripe,代碼行數:26,代碼來源:SubscriptionTest.php

示例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);
 }
開發者ID:payjp,項目名稱:payjp-php,代碼行數:41,代碼來源:SubscriptionTest.php


注:本文中的Subscription::retrieve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。