Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoice Item Class for Charges
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 10 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice Item Class for Charges
|
||||
*/
|
||||
abstract class _Charge extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
/**
|
||||
* @brief Act (new/charge)
|
||||
*/
|
||||
public static $act = 'charge';
|
||||
|
||||
/**
|
||||
* @brief Requires login to purchase?
|
||||
*/
|
||||
public static $requiresAccount = FALSE;
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoice Abstract Item Class
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 10 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Invoice;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice Abstract Item Interface
|
||||
*/
|
||||
abstract class _Item
|
||||
{
|
||||
/**
|
||||
* @brief Can use coupons?
|
||||
*/
|
||||
public static $canUseCoupons = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Can use account credit?
|
||||
*/
|
||||
public static $canUseAccountCredit = TRUE;
|
||||
|
||||
/**
|
||||
* @brief string Name
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @brief int Quantity
|
||||
*/
|
||||
public $quantity = 1;
|
||||
|
||||
/**
|
||||
* @brief \IPS\nexus\Money Price
|
||||
*/
|
||||
public $price;
|
||||
|
||||
/**
|
||||
* @brief int|NULL ID
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @brief \IPS\nexus\Tax Tax Class
|
||||
*/
|
||||
public $tax;
|
||||
|
||||
/**
|
||||
* @brief Payment Methods IDs
|
||||
*/
|
||||
public $paymentMethodIds;
|
||||
|
||||
/**
|
||||
* @brief Key/Value array of extra details
|
||||
*/
|
||||
public $details = array();
|
||||
|
||||
/**
|
||||
* @brief Physical?
|
||||
*/
|
||||
public $physical = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Shipping Methods IDs
|
||||
*/
|
||||
public $shippingMethodIds;
|
||||
|
||||
/**
|
||||
* @brief Chosen Shipping Methods ID
|
||||
*/
|
||||
public $chosenShippingMethodId;
|
||||
|
||||
/**
|
||||
* @brief Weight
|
||||
*/
|
||||
public $weight;
|
||||
|
||||
/**
|
||||
* @brief Length
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* @brief Width
|
||||
*/
|
||||
public $width;
|
||||
|
||||
/**
|
||||
* @brief Height
|
||||
*/
|
||||
public $height;
|
||||
|
||||
/**
|
||||
* @brief Pay To member
|
||||
*/
|
||||
public $payTo;
|
||||
|
||||
/**
|
||||
* @brief Commission percentage
|
||||
*/
|
||||
public $commission = 0;
|
||||
|
||||
/**
|
||||
* @brief Commission fee
|
||||
*/
|
||||
public $fee = 0;
|
||||
|
||||
/**
|
||||
* @brief Extra
|
||||
*/
|
||||
public $extra;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param \IPS\nexus\Money $price Price
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $name, \IPS\nexus\Money $price )
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->price = $price->round();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get (can be used to override static properties like icon and title in an instance)
|
||||
*
|
||||
* @param string $k Property
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get( $k )
|
||||
{
|
||||
$k = mb_substr( $k, 1 );
|
||||
return static::$$k;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line price without tax
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
*/
|
||||
public function linePrice()
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->price->amount * $this->quantity, $this->price->currency );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tax rate
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function taxRate()
|
||||
{
|
||||
return ( $this->tax ? $this->tax->rate( $this->billaddress ) : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line price with tax
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
*/
|
||||
public function grossLinePrice()
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->linePrice()->amount + ( $this->linePrice()->amount * $this->taxRate() ), $this->price->currency );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipient amounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function recipientAmounts()
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( $this->payTo )
|
||||
{
|
||||
$linePrice = $this->linePrice();
|
||||
$currency = $linePrice->currency;
|
||||
|
||||
$commission = ( new \IPS\nexus\Money( ( $this->price->amount / 100 ) * $this->commission, $currency ) );
|
||||
$return['site_commission_unit'] = $commission->round();
|
||||
$return['site_commission_line'] = new \IPS\nexus\Money( $return['site_commission_unit']->amount * $this->quantity, $currency );
|
||||
|
||||
$return['recipient_unit'] = new \IPS\nexus\Money( $this->price->amount - $return['site_commission_unit']->amount, $currency );
|
||||
$return['recipient_line'] = new \IPS\nexus\Money( $linePrice->amount - $return['site_commission_line']->amount, $currency );
|
||||
|
||||
$return['site_total'] = new \IPS\nexus\Money( $return['site_commission_line']->amount + ( $this->fee ? $this->fee->amount : 0 ), $currency );
|
||||
$return['recipient_final'] = new \IPS\nexus\Money( $linePrice->amount - $return['site_total']->amount, $currency );
|
||||
if ( $return['recipient_final']->amount < 0 )
|
||||
{
|
||||
$return['recipient_final']->amount = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$return['site_total'] = $this->linePrice()->amount;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get amount for recipient (on line price)
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function amountForRecipient()
|
||||
{
|
||||
if ( !$this->payTo )
|
||||
{
|
||||
throw new \BadMethodCallException;
|
||||
}
|
||||
|
||||
$linePrice = $this->linePrice();
|
||||
$amountForSite = ( $linePrice->amount / 100 ) * $this->commission;
|
||||
$amountForRecipient = ( new \IPS\nexus\Money( $linePrice->amount - $amountForSite, $linePrice->currency ) );
|
||||
return $amountForRecipient->round();
|
||||
}
|
||||
|
||||
/**
|
||||
* Image
|
||||
*
|
||||
* @return |IPS\File|NULL
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Paid
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @return void
|
||||
*/
|
||||
public function onPaid( \IPS\nexus\Invoice $invoice )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Unpaid description
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @return array
|
||||
*/
|
||||
public function onUnpaidDescription( \IPS\nexus\Invoice $invoice )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* On Unpaid
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @param string $status Status
|
||||
* @return void
|
||||
*/
|
||||
public function onUnpaid( \IPS\nexus\Invoice $invoice, $status )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Invoice Cancel (when unpaid)
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @return void
|
||||
*/
|
||||
public function onInvoiceCancel( \IPS\nexus\Invoice $invoice )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Client Area URL
|
||||
*
|
||||
* @return |IPS\Http\Url|NULL
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP URL
|
||||
*
|
||||
* @return |IPS\Http\Url|NULL
|
||||
*/
|
||||
public function acpUrl()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoice Item Class for Purchases
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 10 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice Item Class for Purchases
|
||||
*/
|
||||
abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
/**
|
||||
* @brief string Act (new/charge)
|
||||
*/
|
||||
public static $act = 'new';
|
||||
|
||||
/**
|
||||
* @brief Requires login to purchase?
|
||||
*/
|
||||
public static $requiresAccount = TRUE;
|
||||
|
||||
/**
|
||||
* @brief \IPS\nexus\Purchase\RenewalTerm Renewal Term
|
||||
*/
|
||||
public $renewalTerm;
|
||||
|
||||
/**
|
||||
* @brief \IPS\DateTime Expiry Date (only if the purchase needs to expire but not renew)
|
||||
*/
|
||||
public $expireDate;
|
||||
|
||||
/**
|
||||
* @brief \IPS\nexus\Purchase|int The parent purchase or item ID
|
||||
*/
|
||||
public $parent = NULL;
|
||||
|
||||
/**
|
||||
* @brief bool Group with parent?
|
||||
*/
|
||||
public $groupWithParent = FALSE;
|
||||
|
||||
/**
|
||||
* Get Icon
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return string
|
||||
*/
|
||||
public static function getIcon( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return static::$icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return string
|
||||
*/
|
||||
public static function getTypeTitle( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return static::$title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return |IPS\File|NULL
|
||||
*/
|
||||
public static function purchaseImage( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get purchases made by a customer of this item
|
||||
*
|
||||
* @param \IPS\nexus\Customer $customer The customer
|
||||
* @param int|array|NULL $id Item ID(s)
|
||||
* @param bool $includeInactive Include expired purchases?
|
||||
* @param bool $includeCanceled Include canceled purchases?
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
*/
|
||||
public static function getPurchases( \IPS\nexus\Customer $customer, $id = NULL, $includeInactive = TRUE, $includeCanceled = FALSE )
|
||||
{
|
||||
$where = array( array( 'ps_app=? AND ps_type=? AND ps_member=?', static::$application, static::$type, $customer->member_id ) );
|
||||
if ( $id !== NULL )
|
||||
{
|
||||
if ( is_array( $id ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'ps_item_id', $id ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'ps_item_id=?', $id );
|
||||
}
|
||||
}
|
||||
if ( !$includeInactive )
|
||||
{
|
||||
$where[] = array( 'ps_active=1' );
|
||||
}
|
||||
if ( !$includeCanceled )
|
||||
{
|
||||
$where[] = array( 'ps_cancelled=0' );
|
||||
}
|
||||
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', $where ), 'IPS\nexus\Purchase' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional name info
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return array
|
||||
*/
|
||||
public static function getPurchaseNameInfo( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ACP Page HTML
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return string
|
||||
*/
|
||||
public static function acpPage( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ACP Page Buttons
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param \IPS\Http\Url $url The page URL
|
||||
* @return array
|
||||
*/
|
||||
public static function acpButtons( \IPS\nexus\Purchase $purchase, \IPS\Http\Url $url )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP Action
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function acpAction( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP Edit Form
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param \IPS\nexus\Purchase\RenewalTerm $renewals The renewal term
|
||||
* @return string
|
||||
*/
|
||||
public static function acpEdit( \IPS\nexus\Purchase $purchase, \IPS\Helpers\Form $form, $renewals )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'ps_name', $purchase->_name, TRUE, array( 'maxLength' => 128 ) ) );
|
||||
|
||||
if ( !$purchase->grouped_renewals )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'ps_expire', $purchase->expire ?: 0, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'does_not_expire', 'disabled' => !$purchase->canChangeExpireDate() ) ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\nexus\Form\RenewalTerm( 'ps_renewals', $renewals, FALSE, array( 'lockTerm' => !$purchase->canChangeExpireDate() ) ) );
|
||||
|
||||
if ( !$purchase->grouped_renewals )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'ps_parent', $purchase->parent(), FALSE, array( 'class' => 'IPS\nexus\Purchase', 'forceOwner' => $purchase->member, 'zeroVal' => 'no_parent' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP Edit Save
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param array $values Values from form
|
||||
* @return string
|
||||
*/
|
||||
public static function acpEditSave( \IPS\nexus\Purchase $purchase, array $values )
|
||||
{
|
||||
$purchase->name = $values['ps_name'];
|
||||
if ( $purchase->grouped_renewals )
|
||||
{
|
||||
$purchase->ungroupFromParent();
|
||||
$purchase->renewals = $values['ps_renewals'];
|
||||
$purchase->save();
|
||||
$purchase->groupWithParent();
|
||||
}
|
||||
else
|
||||
{
|
||||
$purchase->expire = ( $values['ps_expire'] ?: NULL );
|
||||
$purchase->renewals = $values['ps_renewals'];
|
||||
$purchase->parent = $values['ps_parent'] ?: NULL;
|
||||
$purchase->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Client Area Page HTML
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return string
|
||||
*/
|
||||
public static function clientAreaPage( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Client Area Page HTML
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return string
|
||||
*/
|
||||
public static function clientAreaAction( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin can change expire date / renewal term?
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return bool
|
||||
*/
|
||||
public static function canChangeExpireDate( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can Renew Until
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param bool $admin If TRUE, is for ACP. If FALSE, is for front-end.
|
||||
* @return \IPS\DateTime|bool TRUE means can renew as much as they like. FALSE means cannot renew at all. \IPS\DateTime means can renew until that date
|
||||
*/
|
||||
public static function canRenewUntil( \IPS\nexus\Purchase $purchase, $admin )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Severity
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return \IPS\nexus\Support\Severity|NULL
|
||||
*/
|
||||
public static function supportSeverity( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Generated
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @return void
|
||||
*/
|
||||
public static function onPurchaseGenerated( \IPS\nexus\Purchase $purchase, \IPS\nexus\Invoice $invoice )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Renew (Renewal invoice paid. Is not called if expiry data is manually changed)
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param int $cycles Cycles
|
||||
* @return void
|
||||
*/
|
||||
public static function onRenew( \IPS\nexus\Purchase $purchase, $cycles )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Expiration Date Change
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function onExpirationDateChange( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Expired
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function onExpire( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Canceled
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function onCancel( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Deleted
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function onDelete( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Reactivated (renewed after being expired or reactivated after being canceled)
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function onReactivate( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On Transfer (is ran before transferring)
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @param \IPS\Member $newCustomer New Customer
|
||||
* @return void
|
||||
*/
|
||||
public static function onTransfer( \IPS\nexus\Purchase $purchase, \IPS\Member $newCustomer )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Purchase Record?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showPurchaseRecord()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoice Item Class for Renewals
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 01 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice Item Class for Renewals
|
||||
*/
|
||||
class _Renewal extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
/**
|
||||
* @brief Act (new/charge)
|
||||
*/
|
||||
public static $act = 'renewal';
|
||||
|
||||
/**
|
||||
* @brief Icon
|
||||
*/
|
||||
public static $icon = 'refresh';
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'renewal';
|
||||
|
||||
/**
|
||||
* @brief Requires login to purchase?
|
||||
*/
|
||||
public static $requiresAccount = TRUE;
|
||||
|
||||
/**
|
||||
* @brief New expiry date (NULL will cause automatic calculation)
|
||||
*/
|
||||
public $expire = NULL;
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase to renew
|
||||
* @param int $cycles The number of cycles to renew for
|
||||
* @return void
|
||||
*/
|
||||
public static function create( \IPS\nexus\Purchase $purchase, $cycles = 1 )
|
||||
{
|
||||
$obj = new static( sprintf( $purchase->member->language()->get('renew_title'), $purchase->name ), $purchase->renewals->cost );
|
||||
$obj->tax = $purchase->renewals->tax;
|
||||
$obj->quantity = $cycles;
|
||||
$obj->application = $purchase->app;
|
||||
$obj->type = $purchase->type;
|
||||
$obj->id = $purchase->id;
|
||||
|
||||
if ( $purchase->pay_to )
|
||||
{
|
||||
$obj->payTo = $purchase->pay_to;
|
||||
$obj->commission = $purchase->commission;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Paid
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @return void
|
||||
*/
|
||||
public function onPaid( \IPS\nexus\Invoice $invoice )
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::load( $this->id );
|
||||
|
||||
if ( $purchase->renewals and $interval = $purchase->renewals->interval and !$purchase->cancelled and $expire = $purchase->expire )
|
||||
{
|
||||
$_expire = clone $expire;
|
||||
if ( $_expire->add( new \DateInterval( 'PT' . $purchase->grace_period . 'S' ) )->getTimestamp() < time() )
|
||||
{
|
||||
$expire = new \IPS\DateTime;
|
||||
}
|
||||
for ( $i=0; $i<$this->quantity; $i++ )
|
||||
{
|
||||
$expire->add( $interval );
|
||||
}
|
||||
|
||||
$purchase->expire = $expire;
|
||||
$purchase->invoice_pending = NULL;
|
||||
$purchase->save();
|
||||
$purchase->onRenew( $this->quantity );
|
||||
|
||||
$purchase->member->log( 'purchase', array( 'type' => 'renew', 'id' => $purchase->id, 'name' => $purchase->name, 'invoice_id' => $invoice->id, 'invoice_title' => $invoice->title ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On Unpaid description
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @return array
|
||||
*/
|
||||
public function onUnpaidDescription( \IPS\nexus\Invoice $invoice )
|
||||
{
|
||||
$return = parent::onUnpaidDescription( $invoice );
|
||||
|
||||
$purchase = \IPS\nexus\Purchase::load( $this->id );
|
||||
|
||||
if ( $purchase->renewals and $interval = $purchase->renewals->interval and !$purchase->cancelled and $expire = $purchase->expire )
|
||||
{
|
||||
for ( $i=0; $i<$this->quantity; $i++ )
|
||||
{
|
||||
$expire->sub( $interval );
|
||||
}
|
||||
|
||||
$return[] = \IPS\Member::loggedIn()->language()->addToStack( 'renewal_unpaid', FALSE, array( 'sprintf' => array( $purchase->name, $purchase->id, $expire->localeDate() ) ) );
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Unpaid
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice The invoice
|
||||
* @param string $status Status
|
||||
* @return void
|
||||
*/
|
||||
public function onUnpaid( \IPS\nexus\Invoice $invoice, $status )
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::load( $this->id );
|
||||
|
||||
if ( $purchase->renewals and $interval = $purchase->renewals->interval and !$purchase->cancelled and $expire = $purchase->expire )
|
||||
{
|
||||
for ( $i=0; $i<$this->quantity; $i++ )
|
||||
{
|
||||
$expire->sub( $interval );
|
||||
}
|
||||
$purchase->expire = $expire;
|
||||
|
||||
if ( $status === \IPS\nexus\Invoice::STATUS_PENDING )
|
||||
{
|
||||
$purchase->invoice_pending = $invoice;
|
||||
}
|
||||
|
||||
$purchase->save();
|
||||
|
||||
$purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $purchase->id, 'name' => $purchase->name, 'invoice_id' => $invoice->id, 'invoice_title' => $invoice->title, 'system' => TRUE ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Client Area URL
|
||||
*
|
||||
* @return |IPS\Http\Url|NULL
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Purchase::load( $this->id )->url();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ACP URL
|
||||
*
|
||||
* @return |IPS\Http\Url|NULL
|
||||
*/
|
||||
public function acpUrl()
|
||||
{
|
||||
return \IPS\nexus\Purchase::load( $this->id )->acpUrl();
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user