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


PHP Subscription::getActiveSubscriptions方法代码示例

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


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

示例1: 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

示例2: PaypalSubscription

<?php

$config = Config::get();
$payPal = new PaypalSubscription($config);
$userService = new UserService();
//get selected user
$userId = $userService->getSelectedUserId();
$service_provider = 'getscorecard';
$activeSubscription = Subscription::getActiveSubscriptions($userId, $service_provider);
$subscriptionsArchive = Subscription::getSubscriptionsArchive($userId, $service_provider);
//$subscriptionPlan = new GetscorecardSubscriptionPlanPro();
$subscriptionPlan = new SubscriptionPlan();
//@TODO remake
//$service_provider = 'getscorecard';
//$plans = SubscriptionPlan::getGetscorecardSubscriptionPlans($service_provider);
$plans = SubscriptionPlan::getSubscriptionPlans($service_provider);
//$subscriptionsTempStatus = Subscription::getSubscriptionTemporaryStatus();
$usersCountDefault = 2;
$usersCount = $activeSubscription != null ? $activeSubscription['items_count'] : $usersCountDefault;
?>


<script type="text/javascript">
var subscriptionPlans = <?php 
echo json_encode($plans);
?>
;
var serviceProvider = '<?php 
echo $service_provider;
?>
';
开发者ID:antonshell,项目名称:paypal_sample,代码行数:31,代码来源:subscription.php

示例3: getOptions

 public function getOptions()
 {
     $gsSubscriptions = Subscription::getActiveSubscriptions();
     $sessionManager = new SessionManager();
     $userInfo = $sessionManager->getUserInfo($_SESSION['user_id']);
     $subscriptionsTempStatus = Subscription::getSubscriptionTemporaryStatus();
     $result = [];
     if (count($gsSubscriptions)) {
         $planId = $gsSubscriptions[0]['plan_id'];
         $subscriptionPlan = new SubscriptionPlan();
         $subscriptionPlan->load($planId);
         $subscriptionPlanOptions = $subscriptionPlan->getSubscriptionPlanOptions();
         $result['subscription_status'] = Subscription::STATUS_ACTIVE;
         $result['options'] = $subscriptionPlanOptions;
     } elseif ($subscriptionsTempStatus == Subscription::STATUS_PROCESSING) {
         $result['subscription_status'] = Subscription::STATUS_PROCESSING;
         $result['options'] = [];
     } elseif ($subscriptionsTempStatus == Subscription::STATUS_UPDATING) {
         $gsSubscriptions = Subscription::getGetScorecardSubscriptions();
         if (isset($gsSubscriptions[0])) {
             $planId = $gsSubscriptions[0]['plan_id'];
             $subscriptionPlan = new SubscriptionPlan();
             $subscriptionPlan->load($planId);
             $subscriptionPlanOptions = $subscriptionPlan->getSubscriptionPlanOptions();
             $result['subscription_status'] = Subscription::STATUS_UPDATING;
             $result['options'] = $subscriptionPlanOptions;
         } else {
             $result['subscription_status'] = Subscription::STATUS_NOT_EXIST;
             $result['options'] = [];
         }
     } elseif ($userInfo['dummy_data_live']) {
         $result['subscription_status'] = Subscription::STATUS_TRIAL;
         $result['options'] = [];
     } else {
         $result['subscription_status'] = Subscription::STATUS_NOT_EXIST;
         $result['options'] = [];
     }
     return $result;
 }
开发者ID:antonshell,项目名称:paypal_sample,代码行数:39,代码来源:SubscriptionsManager.php

示例4: 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


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