本文整理汇总了PHP中Subscription::loadBySubscriptionId方法的典型用法代码示例。如果您正苦于以下问题:PHP Subscription::loadBySubscriptionId方法的具体用法?PHP Subscription::loadBySubscriptionId怎么用?PHP Subscription::loadBySubscriptionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription::loadBySubscriptionId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
}
}
示例3: 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') {
//.........这里部分代码省略.........