The SuperSubscription Class
Subscription creation and manipulation
Functions
SuperSubscription::addSubscription
Definition
- Name
- addSubscription
- Syntax
- Array|False = SuperSubscription::addSubscription( Array $action );
Description
Add subscription to item for specified user.
Will only add paid subscription if order_id is passed.
Will not add subscription if subscription already exists, but returns existing subscription instead.
/#controller#/addSubscription/
Parameters
- $action
-
Array Action array.
Action parameters
Parameters in $_POST
Return values
Array|false Subscription object. False on error.
Examples
1: Add subscription to free item (without price)
$SuperSubscriptionClass = new SuperSubscription();
$_POST["user_id"] = $user_id;
$_POST["item_id"] = $item_id;
$subscription = $SuperSubscriptionClass->addSubscription($action);
2: Add paid subscription
$SuperSubscriptionClass = new SuperSubscription();
$_POST["user_id"] = $user_id;
$_POST["item_id"] = $item_id;
$_POST["order_id"] = $order_id;
$subscription = $SuperSubscriptionClass->addSubscription($action);
Dependencies
PHP
- count
- unset
Janitor
- Model::getPostedEntities
- Model::validateList
- Model::getProperty
- SuperSubscription::getSubscriptions
- SuperSubscription::updateSubscriptions
- Subscription::calculateSubscriptionExpiry
- SuperMember::getMembership
- Items::getItem
- Items::typeObject
- Type#ItemType#::subscribed
- SuperShop::getOrders
- Query::sql
- Page::addLog
SuperSubscription::getSubscriptions
Definition
- Name
- getSubscriptions
- Syntax
- Array|False = SuperSubscription::getSubscriptions( [ Array $_options ] );
Description
Get subscriptions for specified user.
Passing no parameters in $_options will return all subscriptions.
Parameters
- $_options
-
Array|false Optional parameters.
Options
Return values
Array|false One or several subscription objects. False on error.
Examples
1: Get all subscriptions
$SuperSubscriptionClass = new SuperSubscription();
$subscriptions = $SuperSubscriptionClass->getSubscriptions();
2a: Get all subscriptions for specific user.
$SuperSubscriptionClass = new SuperSubscription();
$subscriptions = $SuperSubscriptionClass->getSubscriptions(["user_id"] => $user_id);
Dependencies
Janitor
- Items::getItem
- SuperMember::getMembership
- SuperShop::getOrders
- Query::sql
- Query::result
- Query::results
- Page::paymentMethods
- Page::addLog
SuperSubscription::updateSubscription
Definition
- Name
- updateSubscription
- Syntax
- Array|False = SuperSubscription::updateSubscription( Array $action );
Description
Update subscription for specified user.
/#controller#/updateSubscription/#subscription_id#
Parameters
- $action
-
Array Action array.
Action parameters
Parameters in $_POST
Return values
Array|false Subscription object. False on error.
Examples
Change subscription item – to free item (without price)
$SubscriptionClass = new Subscription();
$_POST["item_id"] = $item_id;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
This will create a callback to #ItemType#::subscribed
Change subscription item – to paid item
$SubscriptionClass = new Subscription();
$_POST["item_id"] = $item_id;
$_POST["order_id"] = $order_id;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
This will create a callback to #ItemType#::subscribed
Update expiry date
$SubscriptionClass = new Subscription();
$_POST["expires_at"] = "2020-03-02 00:00:00";
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
Update order_id
$SubscriptionClass = new Subscription();
$_POST["order_id"] = $order_id;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
May be used if the order for the subscription were accidentally deleted.
Renew subscription
$SubscriptionClass = new Subscription();
$_POST["subscription_renewal"] = 1;
$subscription = $SubscriptionClass->updateSubscription(["updateSubscription", $subscription_id]);
Used when a cronjob periodically renews subscriptions. A new expiry date is automatically calculated.
Dependencies
PHP
- count
- unset
Janitor
- Model::getPostedEntities
- Model::validateList
- Model::getProperty
- SuperSubscription::getSubscriptions
- SuperSubscription::calculateSubscriptionExpiry
- SuperMember::getMembership
- Items::getItem
- Items::typeObject
- Type#ItemType#::subscribed
- Type#ItemType#::subscription_renewed
- Query::sql
- Page::addLog
SuperSubscription::deleteSubscription
Definition
- Name
- deleteSubscription
- Syntax
- Boolean = SuperSubscription::deleteSubscription( Array $action );
Description
Delete specified subscription for current user.
/#controller#/deleteSubscription/#subscription_id#
Parameters
- $action
-
Array Action array.
Action parameters
Return values
Boolean True on successful deletion. False on error.
Examples
$SuperSubscriptionClass = new SuperSubscription();
$result = $SuperSubscriptionClass->deleteSubscription(["deleteSubscription", $subscription_id]);
Dependencies
PHP
- count
- method_exists
Janitor
- Session::value
- Query::sql
- SuperSubscription::getSubscriptions
- Items::getItem
- Items::typeObject
- Type#ItemType#::unsubscribed
- Page::addLog
SuperSubscription::renewSubscriptions
Definition
- Name
- renewSubscriptions
- Syntax
- Boolean = SuperSubscription::renewSubscriptions( Array $action );
Description
Renew subscription for specified user or all users.
/#controller#/renewSubscriptions[/#user_id#]
Parameters
- $action
-
Array Action array.
Action parameters
Return values
Boolean True on success. False on error.
Examples
1: Renew all subscriptions that are expiring on current date
$SuperSubscriptionClass = new SuperSubscription();
$result = $SuperSubscriptionClass->renewSubscriptions(["renewSubscriptions"]);
2: Renew all of a specific user's subscriptions that are expiring on current date
$SuperSubscriptionClass = new SuperSubscription();
$result = $SuperSubscriptionClass->renewSubscriptions(["renewSubscriptions", $user_id]);
Dependencies
PHP
- count
- unset
Janitor
- Subscription::calculateSubscriptionExpiry
- Items::getItem
- SuperShop::getPrice
- SuperShop::addCart
- SuperShop::addToNewInternalCart
- SuperShop::newOrderFromCart
- Query::sql
- Query::result
- Page::addLog
- MailGateway::send