本文整理汇总了PHP中AuthUser::SetPlan方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthUser::SetPlan方法的具体用法?PHP AuthUser::SetPlan怎么用?PHP AuthUser::SetPlan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthUser
的用法示例。
在下文中一共展示了AuthUser::SetPlan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pay
/**
* @method POST
*/
function pay()
{
// parse request
parse_str($this->request->data, $request);
$token = $request['token'];
$plan = $request['plan'];
// get an authuser
$authUser = new AuthUser();
if (isset($authUser->UserUniqId)) {
// check if authorized
Stripe::setApiKey(STRIPE_API_KEY);
// create a new customer and subscribe them to the plan
$customer = Stripe_Customer::create(array("card" => $token, "plan" => $plan, "email" => $authUser->Email));
// get back the id and the end period for the plan
$id = $customer->id;
$end = $customer->subscription->current_period_end;
// #debug print 'end='.$end;
date_default_timezone_set('UTC');
// create a date from the timestamp returned by Stripe
$renewalDate = gmdate("Y-m-d H:i:s", intval($end));
// #debug print ' renewalDate='.$renewalDate;
// by default, you should not have to update a payment
$updatePayment = 0;
// update the db and session
Site::SetSubscription($authUser->SiteUniqId, $plan, $id, $renewalDate, $updatePayment);
AuthUser::SetPlan($plan, $renewalDate, $updatePayment);
// return a json response
return new Tonic\Response(Tonic\Response::OK);
} else {
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
}