Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+131 -24
View File
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -109,6 +109,11 @@ abstract class _Item
*/
public $payTo;
/**
* @brief Application
*/
public static $application;
/**
* @brief Commission percentage
*/
@@ -124,6 +129,11 @@ abstract class _Item
*/
public $extra;
/**
* @brief Group With Parent
*/
public $groupWithParent = FALSE;
/**
* Constructor
*
@@ -134,7 +144,7 @@ abstract class _Item
public function __construct( $name, \IPS\nexus\Money $price )
{
$this->name = $name;
$this->price = $price->round();
$this->price = $price;
}
/**
@@ -156,27 +166,40 @@ abstract class _Item
*/
public function linePrice()
{
return new \IPS\nexus\Money( $this->price->amount * $this->quantity, $this->price->currency );
return new \IPS\nexus\Money( $this->price->amount->multiply( new \IPS\Math\Number("{$this->quantity}") ), $this->price->currency );
}
/**
* Get tax rate
*
* @return float
* @param \IPS\GeoLocation|NULL $location Location to use for tax rate or NULL to use specified billing address
* @return \IPS\Math\Number
*/
public function taxRate()
public function taxRate( \IPS\GeoLocation $location = NULL )
{
return ( $this->tax ? $this->tax->rate( $this->billaddress ) : 0 );
return new \IPS\Math\Number( $this->tax ? $this->tax->rate( $location ?: $this->billaddress ) : '0' );
}
/**
* Get item price with tax
*
* @param \IPS\GeoLocation|NULL $location Location to use for tax rate or NULL to use specified billing address
* @return \IPS\nexus\Money
*/
public function grossPrice( \IPS\GeoLocation $location = NULL )
{
return new \IPS\nexus\Money( $this->price->amount->add( $this->price->amount->multiply( $this->taxRate( $location ) ) ), $this->price->currency );
}
/**
* Get line price with tax
*
* @param \IPS\GeoLocation|NULL $location Location to use for tax rate or NULL to use specified billing address
* @return \IPS\nexus\Money
*/
public function grossLinePrice()
public function grossLinePrice( \IPS\GeoLocation $location = NULL )
{
return new \IPS\nexus\Money( $this->linePrice()->amount + ( $this->linePrice()->amount * $this->taxRate() ), $this->price->currency );
return new \IPS\nexus\Money( $this->linePrice()->amount->add( $this->linePrice()->amount->multiply( $this->taxRate( $location ) ) ), $this->price->currency );
}
/**
@@ -192,20 +215,21 @@ abstract class _Item
{
$linePrice = $this->linePrice();
$currency = $linePrice->currency;
$commission = $this->price->amount->percentage( $this->commission );
$lineComission = $commission->multiply( new \IPS\Math\Number("{$this->quantity}") );
$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['site_commission_unit'] = new \IPS\nexus\Money( $commission, $currency );
$return['site_commission_line'] = new \IPS\nexus\Money( $lineComission, $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['recipient_unit'] = new \IPS\nexus\Money( $this->price->amount->subtract( $return['site_commission_unit']->amount ), $currency );
$return['recipient_line'] = new \IPS\nexus\Money( $linePrice->amount->subtract( $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;
}
$fee = $this->fee ? $this->fee->amount : new \IPS\Math\Number('0');
$siteTotal = $return['site_commission_line']->amount->add( $fee );
$recipientTotal = $linePrice->amount->subtract( $siteTotal );
$return['site_total'] = new \IPS\nexus\Money( $siteTotal, $currency );
$return['recipient_final'] = new \IPS\nexus\Money( $recipientTotal->isGreaterThanZero() ? $recipientTotal : 0, $currency );
}
else
{
@@ -228,10 +252,8 @@ abstract class _Item
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();
$recipientAmount = $this->recipientAmounts();
return $recipientAmount['recipient_final'];
}
/**
@@ -289,6 +311,32 @@ abstract class _Item
}
/**
* Check for member
* If a user initially checks out as a guest and then logs in during checkout, this method
* is ran to check the items they are purchasing can be bought.
* Is expected to throw a DomainException with an error message to display to the user if not valid
*
* @param \IPS\Member $member The new member
* @return void
* @throws \DomainException
*/
public function memberCanPurchase( \IPS\Member $member )
{
}
/**
* Requires Billing Address
*
* @return bool
* @throws \DomainException
*/
public function requiresBillingAddress()
{
return in_array( 'other', explode( ',', \IPS\Settings::i()->nexus_require_billing ) );
}
/**
* Client Area URL
*
@@ -308,4 +356,63 @@ abstract class _Item
{
return NULL;
}
/**
* Get output for API
*
* @return array
* @apiresponse string name Item name
* @apiresponse string itemApp Key for application. For example, 'nexus' for products and renewals; 'downloads' for Downloads files
* @apiresponse string itemType Key for item type. For example, 'package' for products; 'file' for Downloads files.
* @apiresponse int itemId The ID for the item. For example, the product ID or the file ID.
* @apiresponse string itemUrl Any relevant URL (for example, for Downloads files, this will be the URL to view the file)
* @apiresponse string itemImage If the item has a relevant image (for exmaple, product image, Downloads file screenshot), the URL to it
* @apiresponse int quantity The quantity being purchased
* @apiresponse \IPS\nexus\Money itemPrice Item price, before tax
* @apiresponse \IPS\nexus\Money linePrice Line price, before tax
* @apiresponse \IPS\nexus\Tax taxClassId If the item should be taxed, the Tax Class that applies
* @apiresponse bool physical If the item is physical
* @apiresponse float weight If the item is physical, the weight in kilograms
* @apiresponse float length If the item is physical, the length in metres
* @apiresponse float width If the item is physical, the width in metres
* @apiresponse float height If the item is physical, the height in metres
* @apiresponse \IPS\nexus\Purchase\RenewalTerm renewalTerm If the item renews, the renewal term
* @apiresponse datetime expireDate If the item has been set to expire at a certain date but not automatically renew, the dare it will expire
* @apiresponse object details The values for any custom package fields
* @apiresponse \IPS\nexus\Purchase parentPurchase If when the item has been purchased it will be a child of an existing purchase, the parent purchase
* @apiresponse int parentItem If when the item has been purchased it will be a child of another item on the same invoice, the ID number of the item that will be the parent
* @apiresponse bool groupWithParent If when the item has been purchased it will have its renewals grouped with its parent
* @apiresponse \IPS\nexus\Customer payTo If the payment for this item goes to another user (for example for Downloads files), the user who will receive the payment
* @apiresonse float commission If the payment for this item goes to another user (for example for Downloads files), the percentage of the price that will be retained by the site (in addition to fee)
* @apiresonse \IPS\nexus\Money fee If the payment for this item goes to another user (for example for Downloads files), the fee that will be deducted by the site (in addition to commission)
*/
public function apiOutput()
{
return array(
'name' => $this->name,
'itemApp' => $this->appKey,
'itemType' => $this->typeKey,
'itemId' => $this->id,
'itemUrl' => $this->url() ? ( (string) $this->url() ) : null,
'itemImage' => $this->image() ? ( (string) $this->image()->url ) : null,
'quantity' => $this->quantity,
'itemPrice' => $this->price->apiOutput(),
'linePrice' => $this->linePrice()->apiOutput(),
'taxClass' => $this->tax ? $this->tax->apiOutput() : null,
'physical' => $this->physical,
'weight' => isset( $this->weight ) ? $this->weight->kilograms : null,
'length' => isset( $this->length ) ? $this->length->metres : null,
'width' => isset( $this->width ) ? $this->width->metres : null,
'height' => isset( $this->height ) ? $this->height->metres : null,
'renewalTerm' => isset( $this->renewalTerm ) ? $this->renewalTerm->apiOutput() : null,
'expireDate' => isset( $this->expireDate ) ? $this->expireDate->rfc3339() : null,
'details' => $this->details,
'parentPurchase' => ( isset( $this->parent ) and $this->parent instanceof \IPS\nexus\Purchase ) ? $this->parent->apiOutput() : null,
'parentItem' => ( isset( $this->parent ) and is_int( $this->parent ) ) ? $this->parent : null,
'groupWithParent' => isset( $this->groupWithParent ) ? $this->groupWithParent : false,
'payTo' => $this->payTo ? $this->payTo->apiOutput() : null,
'commission' => $this->commission,
'fee' => $this->fee ? $this->fee->apiOutput() : null,
);
}
}