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
$action[0]
String "addSubscription"
Parameters in $_POST
user_id
Integer Id for the user that will subscribe to the item (Required)
item_id
Integer Id for the item to which the user will be subscribed (Required)
order_id
Integer Must be passed to create a paid subscription.

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
user_id
Get all subscriptions for specified user. If combined with item_id: get specific subscription for specific user.
item_id
Get all subscriptions for specified item.
subscription_id
Get subscription by subscription_id.

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
$action[0]
String "updateSubscription"
$action[1]
Integer #subscription_id#
Parameters in $_POST
item_id
Integer Id for the new item to which the user will be subscribed. Item must have a subscription_method. If passed without an order_id, it will create an orderless subscription.
expires_at
String Expiry date.
subscription_renewal
Boolean, indicating whether the function call is a periodical renewal of the subscription. If passed, the subscription's expiry date will be recalculated (if it had an expiry date in the first place).
switch_membership
Boolean, indicating whether the function call comes from the Member::switchMembership or SuperMember::switchMembership. If passed, the subscription's expiry date will be recalculated.
order_id
Integer If passed without an item_id, the existing item must have price, and the existing subscription may not have an existing order – or the function returns false.

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
$action[0]
String "deleteSubscription"
$action[1]
Integer #subscription_id#

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
$action[0]
String "renewSubscriptions"
$action[1]
Integer #user_id# (Optional) Include to renew subscription for specific user. Omit to renew subscription for all users.

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