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
File diff suppressed because it is too large.
Load diff
@@ -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.
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Invoice Items Iterator
|
||||
* @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 24 Mar 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 Items Iterator
|
||||
*/
|
||||
class _ItemsIterator extends \ArrayIterator
|
||||
{
|
||||
/**
|
||||
* @brief Currency
|
||||
*/
|
||||
public $currency;
|
||||
|
||||
/**
|
||||
* @brief Class Names
|
||||
*/
|
||||
protected static $classnames = NULL;
|
||||
|
||||
/**
|
||||
* Convert array into object
|
||||
*
|
||||
* @param array $data Data
|
||||
* @return \IPS\nexus\Invoice\Item
|
||||
*/
|
||||
public function arrayToObject( $data )
|
||||
{
|
||||
if ( is_object( $data ) )
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/* Load correct class */
|
||||
if ( $data['act'] === 'renewal' )
|
||||
{
|
||||
$obj = new \IPS\nexus\Invoice\Item\Renewal( $data['itemName'], new \IPS\nexus\Money( $data['cost'], $this->currency ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( static::$classnames === NULL )
|
||||
{
|
||||
static::$classnames = array();
|
||||
foreach ( \IPS\Application::allExtensions( 'nexus', 'Item', TRUE, NULL, NULL, FALSE ) as $ext )
|
||||
{
|
||||
static::$classnames[ $ext::$application ][ $ext::$type ] = $ext;
|
||||
}
|
||||
}
|
||||
if ( $data['app'] === 'nexus' and in_array( $data['type'], array( 'product', 'hosting', 'ad' ) ) )
|
||||
{
|
||||
$data['type'] = 'package';
|
||||
}
|
||||
|
||||
$class = isset( static::$classnames[ $data['app'] ][ $data['type'] ] ) ? static::$classnames[ $data['app'] ][ $data['type'] ] : NULL;
|
||||
if ( !$class )
|
||||
{
|
||||
$class = 'IPS\nexus\extensions\nexus\Item\MiscellaneousCharge';
|
||||
}
|
||||
$obj = new $class( $data['itemName'], new \IPS\nexus\Money( $data['cost'], $this->currency ) );
|
||||
}
|
||||
|
||||
/* Basic information */
|
||||
$obj->quantity = $data['quantity'];
|
||||
$obj->id = $data['itemID'];
|
||||
|
||||
/* Details */
|
||||
if ( isset( $data['cfields'] ) and $data['cfields'] )
|
||||
{
|
||||
$obj->details = $data['cfields'];
|
||||
}
|
||||
|
||||
/* Tax */
|
||||
if ( isset( $data['tax'] ) AND $data['tax'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$obj->tax = \IPS\nexus\Tax::load( $data['tax'] );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
/* Renewal terms */
|
||||
if ( isset( $data['renew_term'] ) and $data['renew_term'] )
|
||||
{
|
||||
$obj->renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $data['renew_cost'], $this->currency ), new \DateInterval( 'P' . $data['renew_term'] . mb_strtoupper( $data['renew_units'] ) ), $obj->tax, FALSE, isset( $data['grace_period'] ) ? new \DateInterval( 'PT' . $data['grace_period'] . 'S' ) : NULL );
|
||||
}
|
||||
|
||||
/* Expire Date */
|
||||
if ( isset( $data['expires'] ) and $data['expires'] )
|
||||
{
|
||||
$obj->expireDate = \IPS\DateTime::ts( $data['expires'] );
|
||||
}
|
||||
|
||||
/* Available methods */
|
||||
if ( isset( $data['methods'] ) and $data['methods'] !== '*' )
|
||||
{
|
||||
$obj->paymentMethodIds = $data['methods'];
|
||||
}
|
||||
|
||||
/* Shipping */
|
||||
if ( isset( $data['physical'] ) AND $data['physical'] )
|
||||
{
|
||||
$obj->physical = TRUE;
|
||||
if ( isset( $data['shipping'] ) and $data['shipping'] !== '*' )
|
||||
{
|
||||
$obj->shippingMethodIds = $data['shipping'];
|
||||
}
|
||||
$obj->weight = new \IPS\nexus\Shipping\Weight( $data['weight'] );
|
||||
$obj->length = new \IPS\nexus\Shipping\Length( $data['length'] );
|
||||
$obj->width = new \IPS\nexus\Shipping\Length( $data['width'] );
|
||||
$obj->height = new \IPS\nexus\Shipping\Length( $data['height'] );
|
||||
|
||||
if ( isset( $data['chosen_shipping'] ) and $data['chosen_shipping'] )
|
||||
{
|
||||
$obj->chosenShippingMethodId = $data['chosen_shipping'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Parent */
|
||||
if ( isset( $data['assoc'] ) )
|
||||
{
|
||||
if ( $data['assocBought'] )
|
||||
{
|
||||
$obj->parent = \IPS\nexus\Purchase::load( $data['assoc'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$obj->parent = $data['assoc'];
|
||||
}
|
||||
|
||||
$obj->groupWithParent = isset( $data['groupParent'] ) ? $data['groupParent'] : FALSE;
|
||||
}
|
||||
|
||||
/* Paying another member? */
|
||||
if ( isset( $data['payTo'] ) and $data['payTo'] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$obj->payTo = \IPS\nexus\Customer::load( $data['payTo'] );
|
||||
if ( isset( $data['commission'] ) )
|
||||
{
|
||||
$obj->commission = ( $data['commission'] <= 100 ) ? $data['commission'] : 100;
|
||||
}
|
||||
if ( isset( $data['fee'] ) )
|
||||
{
|
||||
$obj->fee = new \IPS\nexus\Money( $data['fee'], $this->currency );
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
|
||||
/* URIs? */
|
||||
if ( isset( $data['itemURI'] ) )
|
||||
{
|
||||
$obj->itemURI = $data['itemURI'];
|
||||
}
|
||||
if ( isset( $data['adminURI'] ) )
|
||||
{
|
||||
$obj->adminURI = $data['adminURI'];
|
||||
}
|
||||
|
||||
/* Extra */
|
||||
if ( isset( $data['extra'] ) )
|
||||
{
|
||||
$obj->extra = $data['extra'];
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current
|
||||
*
|
||||
* @return \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return $this->arrayToObject( parent::current() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get offset
|
||||
*
|
||||
* @param string $index Index
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet( $index )
|
||||
{
|
||||
return $this->arrayToObject( parent::offsetGet( $index ) );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user