当前位置: 首页>>代码示例>>PHP>>正文


PHP Subscription::save方法代码示例

本文整理汇总了PHP中Subscription::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscription::save方法的具体用法?PHP Subscription::save怎么用?PHP Subscription::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subscription的用法示例。


在下文中一共展示了Subscription::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: subscribe

 public function subscribe()
 {
     $rules = ['email' => 'required|email'];
     $validator = Validator::make(Input::all(), $rules);
     $contents = json_encode(['message' => 'Your subscription was unsuccessful.']);
     $failure = Response::make($contents, 200);
     $failure->header('Content-Type', 'text/json');
     if ($validator->fails()) {
         return $failure;
     }
     $subscription = new Subscription();
     $subscription->email = Input::get('email');
     $subscription->active = 1;
     $subscription->save();
     $email = Input::get('email');
     $subject = "Subscribe {$email} to Newsletter";
     #Shoot email to subscription service
     Mail::send('emails.subscription', array('email' => $email), function ($message) use($subject) {
         $message->to('newsletter@chenenetworks.com')->subject($subject);
     });
     $contents = json_encode(['message' => 'Your subscription was successful.']);
     $success = Response::make($contents, 200);
     $success->header('Content-Type', 'text/json');
     return $success;
 }
开发者ID:RainbowSeven,项目名称:la-chene,代码行数:25,代码来源:SubscriptionController.php

示例2: create

 public function create($data, $save = true)
 {
     $sbc = new Subscription($this, $data);
     if ($save) {
         $sbc->save();
     }
     return $sbc;
 }
开发者ID:bandwidthcom,项目名称:php-bandwidth-iris,代码行数:8,代码来源:SubscriptionsModel.php

示例3: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Subscription();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Subscription'])) {
         $model->attributes = $_POST['Subscription'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->ID));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:Yougmark,项目名称:TiCheck_Server,代码行数:17,代码来源:SubscriptionController.php

示例4: subscribe

 public function subscribe()
 {
     $eventId = Utils::lookupEventId(trim(Input::get('event')));
     if (!$eventId) {
         return Response::json('', 500);
     }
     $subscription = Subscription::where('account_id', '=', Auth::user()->account_id)->where('event_id', '=', $eventId)->first();
     if (!$subscription) {
         $subscription = new Subscription();
         $subscription->account_id = Auth::user()->account_id;
         $subscription->event_id = $eventId;
     }
     $subscription->target_url = trim(Input::get('target_url'));
     $subscription->save();
     return Response::json('{"id":' . $subscription->id . '}', 201);
 }
开发者ID:poseidonjm,项目名称:invoice-ninja,代码行数:16,代码来源:IntegrationController.php

示例5: Subscription

 function __Construct($user, $dictionary)
 {
     parent::__Construct(get_class());
     $success = false;
     $message = '';
     if (HTTP::IsPost()) {
         //inputs
         $subscriptionId = Params::GetLong('subscriptionId');
         $name = Params::Get('name');
         //load subscription
         $subscription = new Subscription($subscriptionId);
         $subscription->setName($name);
         $subscription->save();
         $success = true;
     } else {
         $message = "NO DATA POSTED";
     }
     //done
     $this->jsonData = array('success' => $success, 'message' => $message);
 }
开发者ID:TreatNOW,项目名称:TNfrontend,代码行数:20,代码来源:SubscriptionNameResponse.inc.php

示例6: cancelSubscription

 public function cancelSubscription($userId, $validateUsersCount = true)
 {
     $result = ['error' => 1, 'message' => "Error canceling subscription. Please contact support about this issue"];
     $ipn = new SubscriptionsIPN();
     $ipn->configureDatabase($userId);
     /* clear subscription plan restrictions */
     unset($_SESSION['subscriptionPlanOptions']);
     /**/
     $gsSubscriptions = Subscription::getActiveSubscriptions();
     if (count($gsSubscriptions) != 1) {
         PayPalIPN::log(['message' => "Error. Can\\'t cancel subscription. User has no active subscriptions", 'level' => PayPalIPN::LOG_LEVEL_ERROR, 'user_id' => $userId]);
     }
     $subscription = $gsSubscriptions[0];
     $subscriptionPlan = new SubscriptionPlan();
     $subscriptionPlan->load($subscription['plan_id']);
     if (!$this->validateUsersCount() && $validateUsersCount) {
         $result = ['error' => 2, 'message' => 'Error, wrong users count'];
     }
     /* free subscription */
     if ($subscriptionPlan->service_provider == 'getscorecard' && $subscriptionPlan->service_name == 'free') {
         $recordId = $subscription['subId'];
         $subscription = new Subscription();
         $subscription->load($recordId);
         $subscription->status = Subscription::STATUS_CANCELED;
         $subscription->save();
         $result = ['error' => 0, 'message' => 'success. Subscription canceling.'];
     } else {
         if (!$subscription['subscription_id']) {
             PayPalIPN::log(['message' => "Error. Can\\'t cancel subscription. Wrong subscription id", 'level' => PayPalIPN::LOG_LEVEL_ERROR, 'user_id' => $userId]);
         }
         $lastTransaction = $ipn->getLastActiveTransactionBySubscription($subscription['subId']);
         $transactionId = $lastTransaction['txn_id'];
         $subscriptionId = $subscription['subscription_id'];
         $refundAmount = $ipn->getTransactionRefundAmount($lastTransaction);
         $cancelSubscriptionResult = $ipn->changeSubscriptionStatus($subscriptionId, 'Cancel');
         $refundTransactionResult = $ipn->refundTransaction($lastTransaction, $refundAmount);
         if ($cancelSubscriptionResult['ACK'] == "Success" && $refundTransactionResult['ACK'] == "Success") {
             $subscription = new Subscription();
             $subscription->loadBySubscriptionId($subscriptionId);
             $subscription->status = Subscription::STATUS_CANCELING;
             $subscription->save();
             $result = ['error' => 0, 'message' => 'success. Subscription canceling.'];
             PayPalIPN::log(['txn_id' => $transactionId, 'subscr_id' => $subscriptionId, 'message' => "Subscription canceling", 'level' => PayPalIPN::LOG_LEVEL_INFO, 'data' => '', 'user_id' => $userId]);
         } else {
             PayPalIPN::log(['txn_id' => $transactionId, 'subscr_id' => $subscriptionId, 'message' => "Error. Can\\'t cancel subscription. Rejected by PayPal", 'level' => PayPalIPN::LOG_LEVEL_ERROR, 'data' => json_encode(['cancelSubscriptionResult' => $cancelSubscriptionResult, 'refundTransactionResult' => $refundTransactionResult]), 'user_id' => $userId]);
         }
     }
     return $result;
 }
开发者ID:antonshell,项目名称:paypal_sample,代码行数:49,代码来源:SubscriptionsManager.php

示例7: json

 public function json($method = null)
 {
     $response = array('result' => 0);
     switch ($method) {
         case 'subscribe':
             if (Request::get('Email')) {
                 $Subscription = new Subscription();
                 if ($Subscription->findSize(array('Email = ' . Request::get('Email')))) {
                     $response['result'] = 1;
                     $response['msg'] = 'Данный E-mail уже есть в базе подписчиков';
                 } else {
                     $Subscription->Email = Request::get('Email');
                     if ($Subscription->save()) {
                         $Email = new Email_Subscription($Subscription);
                         $Email->send();
                         $response['result'] = 1;
                         $response['msg'] = 'Вы успешно подписались на новости';
                     } else {
                         $response['msg'] = 'Ошибка записи данных';
                     }
                 }
             }
             break;
     }
     return $this->outputJSON($response);
 }
开发者ID:vosaan,项目名称:ankor.local,代码行数:26,代码来源:articles.php

示例8: createUser

 /**
  * createUser
  * creates a new User object (and related models)
  * from the POST data
  * --------------------------------------------------
  * @param (array) ($userdata) Array with the user data
  * @return (User) ($user) The new User object
  * --------------------------------------------------
  */
 private function createUser($userdata)
 {
     /* Create new user */
     $user = new User();
     /* Set authentication info */
     $user->email = $userdata['email'];
     $user->password = Hash::make($userdata['password']);
     $user->name = $userdata['name'];
     /* Save the user */
     $user->save();
     /* Create default settings for the user */
     $settings = new Settings();
     $settings->user()->associate($user);
     $settings->newsletter_frequency = 0;
     $settings->background_enabled = true;
     /* Save settings */
     $settings->save();
     /* Create default subscription for the user */
     $plan = Plan::where('name', 'Free')->first();
     $subscription = new Subscription();
     $subscription->user()->associate($user);
     $subscription->plan()->associate($plan);
     $subscription->status = 'active';
     $subscription->current_period_start = Carbon::now();
     $subscription->current_period_end = Carbon::now()->addDays(SiteConstants::getTrialPeriodInDays());
     $subscription->braintree_customer_id = null;
     $subscription->braintree_payment_method_token = null;
     /* Save subscription */
     $subscription->save();
     /* Return */
     return $user;
 }
开发者ID:neraunzaran,项目名称:fruit-dashboard,代码行数:41,代码来源:SignupWizardController.php

示例9: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($fid = null)
 {
     $model = new Subscription();
     $parms = array();
     if (isset($_POST['Subscription']) and isset($_POST['Subscription']['family_id'])) {
         $fid = $_POST['Subscription']['family_id'];
     }
     if (isset($fid)) {
         $family = Families::model()->findByPk($fid);
         $parms['family'] = $family;
         $dt = $this->getStartDate($family);
         $parms['start_dt'] = $dt;
         Yii::trace("SC.create: fid:" . $family->id . ", dt=" . date_format($dt, 'Y-m-d'), 'application.controllers.SubscriptionController');
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Subscription'])) {
         $till = $_POST['Subscription']['till'];
         $amt = $_POST['Subscription']['amount'];
         $start_dt = new DateTime(date_format($dt, 'Y-m-d'));
         $end_dt = new DateTime(date_format($dt, 'Y-m-d'));
         $end_dt->add(new DateInterval('P' . $till . 'M'));
         $tr = Yii::app()->db->beginTransaction();
         $trans = new Transaction();
         $acct = Account::get('Family Subscriptions');
         $trans->account_id = $acct->id;
         $trans->type = 'credit';
         if ('total' == $_POST['duration']) {
             $total = $amt;
             $amt = $amt / $till;
         } else {
             $total = $till * $amt;
         }
         $trans->amount = $total;
         $trans->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
         $trans->creator = Yii::app()->user->id;
         $trans->descr = "Family #" . $family->id . ' subscription from ' . date_format($start_dt, 'M Y') . ' to ' . date_format($end_dt, 'M Y');
         if ($trans->save()) {
             $model = new Subscription();
             $model->paid_by = $_POST['Subscription']['paid_by'];
             $model->family_id = $family->id;
             $model->start_month = date_format($start_dt, 'n');
             $model->start_year = date_format($start_dt, 'Y');
             $model->end_month = date_format($end_dt, 'n');
             $model->end_year = date_format($end_dt, 'Y');
             $model->amount = $amt;
             $model->trans_id = $trans->id;
             if ($model->save()) {
                 $tr->commit();
                 $this->redirect(array('view', 'id' => $model->id));
                 return;
             }
         }
         $tr->rollback();
     }
     $parms['model'] = $model;
     $this->render('create', $parms);
 }
开发者ID:srinidg,项目名称:stbennos-parish,代码行数:62,代码来源:SubscriptionController.php

示例10: postPayment

 public function postPayment()
 {
     if (Auth::check()) {
         $rules = array('paylane_token' => 'required', 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'address' => 'required', 'zip' => 'required', 'city' => 'required', 'state' => 'required', 'company_name' => 'required_with:faktura', 'company_id' => 'required_with:faktura', 'company_address' => 'required_with:faktura', 'company_zip' => 'required_with:faktura', 'company_city' => 'required_with:faktura', 'company_state' => 'required_with:faktura');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             $messages = $validator->messages();
             return Redirect::to('/konto/pro/platnosci')->withInput(Input::flash())->withErrors($validator)->with('alert', array('type' => 'error', 'content' => 'Błąd! Sprawdź wszystkie pola.'));
         } else {
             $user = Auth::user();
             $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2');
             $card_params = array('sale' => array('amount' => 189.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'), 'customer' => array('name' => Input::get('first_name') . ' ' . Input::get('last_name'), 'email' => Input::get('email'), 'ip' => '127.0.0.1', 'address' => array('street_house' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'), 'country_code' => 'PL')), 'card' => array('token' => Input::get('paylane_token')));
             $status = $client->cardSaleByToken($card_params);
             if ($client->isSuccess()) {
                 $subscription = Subscription::where('user_id', '=', $user->id);
                 $faktura = false;
                 if ($subscription->count() > 0) {
                     $subscription = $subscription->first();
                     $subscription->user_id = $user->id;
                     $subscription->is_active = 1;
                     $subscription->first_name = Input::get('first_name');
                     $subscription->last_name = Input::get('last_name');
                     $subscription->email = Input::get('email');
                     $subscription->address = Input::get('address');
                     $subscription->zip = Input::get('zip');
                     $subscription->city = Input::get('city');
                     $subscription->state = Input::get('state');
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     if (Input::has('faktura')) {
                         $faktura = true;
                         $subscription->is_active = 1;
                         $subscription->company_name = Input::get('company_name');
                         $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id'));
                         $subscription->company_address = Input::get('company_address');
                         $subscription->company_city = Input::get('company_city');
                         $subscription->company_state = Input::get('company_state');
                         $subscription->company_zip = Input::get('company_zip');
                     }
                     $subscription->save();
                 } else {
                     $subscription = new Subscription();
                     $subscription->user_id = $user->id;
                     $subscription->first_name = Input::get('first_name');
                     $subscription->last_name = Input::get('last_name');
                     $subscription->email = Input::get('email');
                     $subscription->address = Input::get('address');
                     $subscription->zip = Input::get('zip');
                     $subscription->city = Input::get('city');
                     $subscription->state = Input::get('state');
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     if (Input::has('faktura')) {
                         $faktura = true;
                         $subscription->company_name = Input::get('company_name');
                         $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id'));
                         $subscription->company_address = Input::get('company_address');
                         $subscription->company_city = Input::get('company_city');
                         $subscription->company_state = Input::get('company_state');
                         $subscription->company_zip = Input::get('company_zip');
                     }
                     $subscription->save();
                 }
                 $payment = Payment::create(array('user_id' => $user->id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale'], 'is_success' => 1));
                 Event::fire('invoice.email', array($user->id, $subscription->id, $payment->id, $faktura));
                 EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                 //here
                 $user->level = 2;
                 $user->save();
                 return Redirect::to('/konto/pro/subskrypcja')->with('alert', array('type' => 'success', 'content' => 'Dziękujemy! Płatność zaakceptowana.'));
             } else {
                 if (isset($status['error'])) {
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['error_description']));
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['description']));
                 } else {
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak!'));
                 }
             }
         }
     }
 }
开发者ID:itsfamestudio,项目名称:hashtag,代码行数:79,代码来源:UserController.php

示例11: processPayment

 /**
  * @param $myPost
  * @throws Exception
  */
 public function processPayment($myPost)
 {
     $customData = $this->getCustomData($myPost);
     $userId = $customData['user_id'];
     $userService = new UserService();
     $userInfo = $userService->getUserData($userId);
     $userEmail = $userInfo['email'];
     $subscriptionPlan = $this->getSubscriptionPlan($myPost);
     if ($this->validateSubscription($subscriptionPlan, $myPost)) {
         $subscription = new Subscription();
         $subscription->loadBySubscriptionId($myPost['subscr_id']);
         $transactionService = new PaypalTransaction();
         $transaction = $transactionService->getTransactionById($myPost['txn_id']);
         if ($subscription->id) {
             //subscription exists
             if ($myPost['txn_type'] == 'subscr_payment') {
                 if (!$transaction) {
                     $subscription->status = Subscription::STATUS_ACTIVE;
                     $subscription->payment_date = $myPost['payment_date'];
                     $subscription->updated_date = date('Y-m-d H:i:s');
                     $subscription->save();
                     self::log(['message' => self::INFO_SUBSCRIPTION_PAYMENT, 'data' => '', 'level' => self::LOG_LEVEL_INFO], $myPost);
                     $myPost['relation_id'] = $subscription->id;
                     //@TODO remake it
                     $transactionService = new PaypalTransaction();
                     $myPost['relation_type'] = PaypalTransaction::TRANSACTION_RELATION_SUBSCRIPTION;
                     $transactionService->createTransaction($myPost);
                     self::log(['message' => self::INFO_TRANSACTION_CREATED, 'data' => '', 'level' => self::LOG_LEVEL_INFO], $myPost);
                 } else {
                     self::log(['message' => self::WARNING_DUPLICATE_TRANSACTION_IPN, 'data' => '', 'level' => self::LOG_LEVEL_WARNING], $myPost);
                 }
             }
             if ($myPost['txn_type'] == 'subscr_cancel') {
                 $subscription->status = Subscription::STATUS_CANCELED;
                 $subscription->updated_date = date('Y-m-d H:i:s');
                 $subscription->save();
                 self::log(['message' => self::INFO_SUBSCRIPTION_CANCELED, 'data' => '', 'level' => self::LOG_LEVEL_INFO], $myPost);
             }
             if ($myPost['txn_type'] == 'subscr_eot') {
                 $subscription->status = Subscription::STATUS_CANCELED;
                 $subscription->updated_date = date('Y-m-d H:i:s');
                 $subscription->save();
                 self::log(['message' => self::INFO_SUBSCRIPTION_EXPIRED, 'level' => self::LOG_LEVEL_WARNING], $myPost);
             }
             if ($myPost['txn_type'] == 'subscr_signup') {
                 self::log(['message' => self::INFO_SUBSCRIPTION_SIGNUP, 'data' => '', 'level' => self::LOG_LEVEL_INFO], $myPost);
             }
             if ($myPost['txn_type'] == 'subscr_modify') {
                 $subscription->status = Subscription::STATUS_CANCELED;
                 $subscription->updated_date = date('Y-m-d H:i:s');
                 $subscription->save();
                 self::log(['message' => self::INFO_SUBSCRIPTION_MODIFIED, 'level' => self::LOG_LEVEL_WARNING], $myPost);
             }
             if ($myPost['payment_status'] == 'Refunded' && $myPost['reason_code'] == 'refund') {
                 //refund transaction
                 $transactionService = new PaypalTransaction();
                 $transactionService->updateTransaction($myPost['parent_txn_id'], ['payment_status' => 'Refunded']);
                 $myPost['txn_type'] = self::TXN_TYPE_SUBSCR_REFUND;
                 $myPost['relation_id'] = $subscription->id;
                 //@TODO refactor this
                 $myPost['relation_type'] = PaypalTransaction::TRANSACTION_RELATION_SUBSCRIPTION;
                 $transactionService = new PaypalTransaction();
                 $transactionService->createTransaction($myPost);
                 self::log(['message' => self::INFO_PAYMENT_REFUND, 'level' => self::LOG_LEVEL_INFO], $myPost);
             }
         } else {
             if ($myPost['txn_type'] == 'subscr_payment') {
                 //@TODO remake it
                 $serviceProvider = $subscriptionPlan->service_provider;
                 $activeSubscriptions = Subscription::getActiveSubscriptions($userId, $serviceProvider);
                 /* check duplicate subscriptions*/
                 if (count($activeSubscriptions) > 0) {
                     self::log(['message' => self::ERROR_ACTIVE_SUBSCRIPTION_DUPLICATE, 'level' => self::LOG_LEVEL_ERROR], $myPost);
                 } elseif (!$transaction) {
                     $subscription = new Subscription();
                     $subscription->user_id = $userId;
                     $subscription->plan_id = $subscriptionPlan->id;
                     $subscription->subscription_id = $myPost['subscr_id'];
                     $subscription->created_date = date("Y-m-d H:i:s");
                     $subscription->updated_date = date('Y-m-d H:i:s');
                     $subscription->payment_date = $myPost['payment_date'];
                     $subscription->items_count = $customData['items_count'];
                     $subscription->status = Subscription::STATUS_ACTIVE;
                     $subscriptionId = $subscription->save();
                     self::log(['message' => self::INFO_SUBSCRIPTION_CREATED, 'data' => '', 'level' => self::LOG_LEVEL_INFO], $myPost);
                     $myPost['relation_id'] = $subscriptionId;
                     //@TODO refactor this
                     $myPost['relation_type'] = PaypalTransaction::TRANSACTION_RELATION_SUBSCRIPTION;
                     $transactionService = new PaypalTransaction();
                     $transactionService->createTransaction($myPost);
                     self::log(['message' => self::INFO_TRANSACTION_CREATED, 'data' => '', 'level' => self::LOG_LEVEL_INFO], $myPost);
                 } else {
                     self::log(['message' => self::WARNING_DUPLICATE_TRANSACTION_IPN, 'data' => '', 'level' => self::LOG_LEVEL_WARNING], $myPost);
                 }
             }
             if ($myPost['txn_type'] == 'subscr_signup') {
//.........这里部分代码省略.........
开发者ID:antonshell,项目名称:paypal_sample,代码行数:101,代码来源:PaypalSubscription.php

示例12: subscribe

 /**
  * Subscribe $user to a given $object
  *
  * @param User $user
  * @param ProjectObject $object
  * @return boolean
  */
 function subscribe($user, $object)
 {
     if (!$object->can_have_subscribers) {
         return new InvalidParamError('$object', $object, '$object does not support subscribers', true);
     }
     // if
     if (Subscriptions::isSubscribed($user, $object, false)) {
         return true;
     }
     // if
     $subscription = new Subscription();
     $subscription->setUserId($user->getId());
     $subscription->setParentId($object->getId());
     $save = $subscription->save();
     if ($save && !is_error($save)) {
         Subscriptions::dropUserCache($user);
         return true;
     }
     // if
     return $save;
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:28,代码来源:Subscriptions.class.php

示例13: addSubscription

 protected function addSubscription($transaction)
 {
     $package = Package::first(array("id = ?" => $transaction->property_id));
     $items = json_decode($package->item);
     $user = User::first(array("id = ?" => $transaction->user_id));
     $user->live = 1;
     $user->save();
     $days = (int) $package->period;
     foreach ($items as $key => $value) {
         $s = new Subscription(array("user_id" => $user->id, "item_id" => $value, "period" => $days, "expiry" => strftime("%Y-%m-%d", strtotime("+" . ($days + 1) . " Day")), "is_promo" => false));
         $s->save();
     }
     $this->session($user);
     $this->redirect('/member/index.html');
 }
开发者ID:SwiftDeal,项目名称:detectr,代码行数:15,代码来源:plan.php

示例14: modifySubscription

 private function modifySubscription(Subscription $subs, $price)
 {
     $old_price = (int) $subs->CurrentPrice;
     if ($price != $old_price) {
         $subs->CurrentPrice = $price;
         if (!$subs->save()) {
             throw new CDbException("save new subs failed");
         }
         return true;
     }
     return false;
 }
开发者ID:Yougmark,项目名称:TiCheck_Server,代码行数:12,代码来源:DefaultController.php

示例15: cancelSubscription

 /**
  * @param $userId
  * @param $serviceProvider
  * @return array|bool
  * @throws Exception
  */
 public function cancelSubscription($userId, $serviceProvider)
 {
     $activeSubscription = Subscription::getActiveSubscriptions($userId, $serviceProvider);
     if (!$activeSubscription) {
         PaypalSubscription::log(['message' => "Error. Can\\'t cancel subscription. User has no active subscriptions", 'level' => PaypalSubscription::LOG_LEVEL_ERROR, 'user_id' => $userId]);
         return false;
     }
     /* free subscription */
     if ((int) $activeSubscription['price'] == 0) {
         $recordId = $activeSubscription['subId'];
         $subscription = new Subscription();
         $subscription->load($recordId);
         $subscription->status = Subscription::STATUS_CANCELED;
         $subscription->save();
         $result = ['error' => 0, 'message' => 'success. Subscription canceled.'];
         return $result;
     } else {
         if (!$activeSubscription['subscription_id']) {
             PaypalSubscription::log(['message' => "Error. Can\\'t cancel subscription. Wrong subscription id", 'level' => PaypalSubscription::LOG_LEVEL_ERROR, 'user_id' => $userId]);
             return false;
         }
         $config = Config::get();
         $paypalService = new PaypalSubscription($config);
         $lastTransaction = $paypalService->getLastActiveTransactionBySubscription($activeSubscription['subId']);
         $transactionId = $lastTransaction['txn_id'];
         $subscriptionId = $activeSubscription['subscription_id'];
         $refundAmount = $paypalService->getTransactionRefundAmount($lastTransaction);
         $cancelSubscriptionResult = $paypalService->changeSubscriptionStatus($subscriptionId, 'Cancel');
         $refundTransactionResult = $paypalService->refundTransaction($lastTransaction, $refundAmount);
         if ($cancelSubscriptionResult['ACK'] == "Success" && $refundTransactionResult['ACK'] == "Success") {
             $subscription = new Subscription();
             $subscription->loadBySubscriptionId($subscriptionId);
             $subscription->status = Subscription::STATUS_CANCELING;
             $subscription->save();
             $result = ['error' => 0, 'message' => 'success. Subscription canceling.'];
             PaypalSubscription::log(['txn_id' => $transactionId, 'subscr_id' => $subscriptionId, 'message' => "Subscription canceling", 'level' => PaypalSubscription::LOG_LEVEL_INFO, 'data' => '', 'user_id' => $userId]);
             return $result;
         } else {
             PaypalSubscription::log(['txn_id' => $transactionId, 'subscr_id' => $subscriptionId, 'message' => "Error. Can\\'t cancel subscription. Rejected by PayPal", 'level' => PaypalSubscription::LOG_LEVEL_ERROR, 'data' => json_encode(['cancelSubscriptionResult' => $cancelSubscriptionResult, 'refundTransactionResult' => $refundTransactionResult]), 'user_id' => $userId]);
             return false;
         }
     }
 }
开发者ID:antonshell,项目名称:paypal_sample,代码行数:49,代码来源:Subscription.php


注:本文中的Subscription::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。