Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -98,22 +98,22 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$table->parsers = array(
|
||||
'i_status' => function( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('invoices')->status( $val );
|
||||
return \IPS\Theme::i()->getTemplate( 'invoices', 'nexus' )->status( $val );
|
||||
},
|
||||
'i_member' => function ( $val, $row )
|
||||
{
|
||||
if ( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('global')->userLink( \IPS\Member::load( $val ) );
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'nexus' )->userLink( \IPS\Member::load( $val ) );
|
||||
}
|
||||
elseif ( $row['i_guest_data'] )
|
||||
{
|
||||
$data = json_decode( $row['i_guest_data'], TRUE );
|
||||
return \IPS\nexus\Customer::constructFromData( $data['member'] )->cm_name;
|
||||
return htmlspecialchars( \IPS\nexus\Customer::constructFromData( $data['member'] )->cm_name, ENT_DISALLOWED, 'UTF-8', FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('global')->userLink( \IPS\Member::load( 0 ) );
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'nexus' )->userLink( \IPS\Member::load( 0 ) );
|
||||
}
|
||||
},
|
||||
'i_total' => function( $val, $row )
|
||||
@@ -1408,6 +1408,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string title Title
|
||||
@@ -1433,14 +1434,14 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
* @apiresponse string viewUrl The URL to where the customer can view this invoice
|
||||
* @apiresponse string checkoutUrl The URL to where the customer can pay this invoice
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
$summary = $this->summary();
|
||||
|
||||
$tax = array();
|
||||
foreach ( $summary['tax'] as $classId => $data )
|
||||
{
|
||||
$tax[] = ( new \IPS\nexus\Invoice\Item\TaxItem( $classId, $data ) )->apiOutput();
|
||||
$tax[] = ( new \IPS\nexus\Invoice\Item\TaxItem( $classId, $data ) )->apiOutput( $authorizedMember );
|
||||
}
|
||||
|
||||
return array(
|
||||
@@ -1449,31 +1450,31 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
'status' => $this->status,
|
||||
'issueDate' => $this->date->rfc3339(),
|
||||
'paidDate' => $this->paid ? $this->paid->rfc3339() : null,
|
||||
'customer' => $this->member->apiOutput(),
|
||||
'items' => array_map( function( $item ){
|
||||
return $item->apiOutput();
|
||||
'customer' => $this->member->apiOutput( $authorizedMember ),
|
||||
'items' => array_map( function( $item ) use ( $authorizedMember ) {
|
||||
return $item->apiOutput( $authorizedMember );
|
||||
}, $summary['items'] ),
|
||||
'subTotal' => $summary['subtotal']->apiOutput(),
|
||||
'shippingCharges' => array_map( function( $item ){
|
||||
return $item->apiOutput();
|
||||
'subTotal' => $summary['subtotal']->apiOutput( $authorizedMember ),
|
||||
'shippingCharges' => array_map( function( $item ) use ( $authorizedMember ) {
|
||||
return $item->apiOutput( $authorizedMember );
|
||||
}, $summary['shipping'] ),
|
||||
'shippingTotal' => $summary['shippingTotal']->apiOutput(),
|
||||
'shippingTotal' => $summary['shippingTotal']->apiOutput( $authorizedMember ),
|
||||
'tax' => $tax,
|
||||
'taxTotal' => $summary['taxTotal']->apiOutput(),
|
||||
'total' => $summary['total']->apiOutput(),
|
||||
'outstanding' => $this->amountToPay()->apiOutput(),
|
||||
'billingAddress' => $this->billaddress ? $this->billaddress->apiOutput() : null,
|
||||
'shippingAddress' => $this->shipaddress ? $this->shipaddress->apiOutput() : null,
|
||||
'taxTotal' => $summary['taxTotal']->apiOutput( $authorizedMember ),
|
||||
'total' => $summary['total']->apiOutput( $authorizedMember ),
|
||||
'outstanding' => $this->amountToPay()->apiOutput( $authorizedMember ),
|
||||
'billingAddress' => $this->billaddress ? $this->billaddress->apiOutput( $authorizedMember ) : null,
|
||||
'shippingAddress' => $this->shipaddress ? $this->shipaddress->apiOutput( $authorizedMember ) : null,
|
||||
'poNumber' => $this->po,
|
||||
'notes' => $this->notes,
|
||||
'transactions' => array_map( function( $transaction ){
|
||||
return $transaction->apiOutput();
|
||||
'transactions' => array_map( function( $transaction ) use ( $authorizedMember ) {
|
||||
return $transaction->apiOutput( $authorizedMember );
|
||||
}, iterator_to_array( $this->transactions() ) ),
|
||||
'shipments' => array_map( function( $shipment ){
|
||||
return $shipment->apiOutput();
|
||||
'shipments' => array_map( function( $shipment ) use ( $authorizedMember ) {
|
||||
return $shipment->apiOutput( $authorizedMember );
|
||||
}, iterator_to_array( $this->shipments() ) ),
|
||||
'purchases' => array_map( function( $purchase ){
|
||||
return $purchase->apiOutput();
|
||||
'purchases' => array_map( function( $purchase ) use ( $authorizedMember ) {
|
||||
return $purchase->apiOutput( $authorizedMember );
|
||||
}, iterator_to_array( $this->purchasesCreated() ) ),
|
||||
'viewUrl' => (string) $this->url(),
|
||||
'checkoutUrl' => (string) $this->checkoutUrl(),
|
||||
@@ -1539,6 +1540,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$profileFields = $this->guest_data['profileFields'];
|
||||
$securityAnswers = isset( $this->guest_data['securityAnswers'] ) ? $this->guest_data['securityAnswers'] : array();
|
||||
$spamData = $this->guest_data['spamData'];
|
||||
|
||||
/* If the member has already been created (the user made two separate purchases with the same data), use that, otherwise create one */
|
||||
try
|
||||
@@ -1554,6 +1556,8 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$memberToSave->changed[ $k ] = $v;
|
||||
}
|
||||
$memberToSave->save();
|
||||
|
||||
$memberToSave->logHistory( 'core', 'account', array( 'type' => 'register_checkout', 'spamCode' => $spamData['code'], 'spamAction' => $spamData['action'], 'invoice' => $this->id ), FALSE );
|
||||
}
|
||||
$this->member = $memberToSave;
|
||||
$this->guest_data = NULL;
|
||||
@@ -1719,12 +1723,14 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$purchase->app = $item::$application;
|
||||
$purchase->type = $item::$type;
|
||||
$purchase->item_id = intval( $item->id );
|
||||
$purchase->custom_fields = $item->details;
|
||||
$purchase->custom_fields = $item->purchaseDetails;
|
||||
$purchase->original_invoice = $this;
|
||||
$purchase->tax = $item->tax ? $item->tax->id : 0;
|
||||
if ( $item->payTo )
|
||||
{
|
||||
$purchase->pay_to = $item->payTo;
|
||||
$purchase->commission = $item->commission;
|
||||
$purchase->fee = $item->fee ?: NULL;
|
||||
}
|
||||
if ( $item->parent !== NULL )
|
||||
{
|
||||
@@ -2095,7 +2101,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$return['purchases'] = array();
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$return['purchases'][] = \IPS\Theme::i()->getTemplate('purchases')->link( $purchase );
|
||||
$return['purchases'][] = \IPS\Theme::i()->getTemplate( 'purchases', 'nexus' )->link( $purchase );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2107,12 +2113,12 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if ( $shipment->status === \IPS\nexus\Shipping\Order::STATUS_SHIPPED )
|
||||
{
|
||||
$return['shipments'][] = \IPS\Theme::i()->getTemplate('shiporders')->link( $shipment );
|
||||
$return['shipments'][] = \IPS\Theme::i()->getTemplate( 'shiporders', 'nexus' )->link( $shipment );
|
||||
}
|
||||
else
|
||||
{
|
||||
$return['shipments'][] = array(
|
||||
'message' => \IPS\Theme::i()->getTemplate('shiporders')->link( $shipment ),
|
||||
'message' => \IPS\Theme::i()->getTemplate( 'shiporders', 'nexus' )->link( $shipment ),
|
||||
'warning' => \IPS\Member::loggedIn()->language()->addToStack('invoice_unpaid_shipments_shipped'),
|
||||
);
|
||||
}
|
||||
@@ -2184,7 +2190,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return \IPS\Http\Url::internal( 'app=nexus&module=checkout&controller=checkout&id=' . $this->id, 'front', 'nexus_checkout', array(), \IPS\Settings::i()->nexus_https );
|
||||
return \IPS\Http\Url::internal( 'app=nexus&module=checkout&controller=checkout&id=' . $this->id, 'front', 'nexus_checkout' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,10 +64,15 @@ abstract class _Item
|
||||
public $paymentMethodIds;
|
||||
|
||||
/**
|
||||
* @brief Key/Value array of extra details
|
||||
* @brief Key/Value array of extra details to display on the invoice
|
||||
*/
|
||||
public $details = array();
|
||||
|
||||
/**
|
||||
* @brief Key/Value array of extra details to store on the purchase
|
||||
*/
|
||||
public $purchaseDetails = array();
|
||||
|
||||
/**
|
||||
* @brief Physical?
|
||||
*/
|
||||
@@ -359,6 +364,7 @@ abstract class _Item
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse string name Item name
|
||||
* @apiresponse string itemApp Key for application. For example, 'nexus' for products and renewals; 'downloads' for Downloads files
|
||||
@@ -385,7 +391,7 @@ abstract class _Item
|
||||
* @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()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return array(
|
||||
'name' => $this->name,
|
||||
@@ -395,23 +401,23 @@ abstract class _Item
|
||||
'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,
|
||||
'itemPrice' => $this->price->apiOutput( $authorizedMember ),
|
||||
'linePrice' => $this->linePrice()->apiOutput( $authorizedMember ),
|
||||
'taxClass' => $this->tax ? $this->tax->apiOutput( $authorizedMember ) : 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,
|
||||
'renewalTerm' => isset( $this->renewalTerm ) ? $this->renewalTerm->apiOutput( $authorizedMember ) : 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,
|
||||
'parentPurchase' => ( isset( $this->parent ) and $this->parent instanceof \IPS\nexus\Purchase ) ? $this->parent->apiOutput( $authorizedMember ) : 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,
|
||||
'payTo' => $this->payTo ? $this->payTo->apiOutput( $authorizedMember ) : null,
|
||||
'commission' => $this->commission,
|
||||
'fee' => $this->fee ? $this->fee->apiOutput() : null,
|
||||
'fee' => $this->fee ? $this->fee->apiOutput( $authorizedMember ) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
$where[] = array( 'ps_cancelled=0' );
|
||||
}
|
||||
|
||||
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', $where ), 'IPS\nexus\Purchase' );
|
||||
}
|
||||
|
||||
@@ -260,6 +260,17 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchase can be renewed?
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return boolean
|
||||
*/
|
||||
public static function canBeRenewed( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can Renew Until
|
||||
@@ -341,6 +352,18 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* On expire soon
|
||||
* If returns TRUE, the normal expire warning email will not be sent
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public static function onExpireWarning( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* On Purchase Expired
|
||||
*
|
||||
|
||||
@@ -68,6 +68,7 @@ class _Renewal extends \IPS\nexus\Invoice\Item
|
||||
{
|
||||
$obj->payTo = $purchase->pay_to;
|
||||
$obj->commission = $purchase->commission;
|
||||
$obj->fee = $purchase->fee;
|
||||
}
|
||||
|
||||
if ( $renewalPaymentMethodIds = $purchase->renewalPaymentMethodIds() )
|
||||
|
||||
@@ -49,15 +49,16 @@ class _TaxItem
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse \IPS\nexus\Tax class The tax class
|
||||
* @apiresponse float rate The rate (for example 0.2 means 20%)
|
||||
* @apiresponse \IPS\nexus\Money amount Amount to pay
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return array(
|
||||
'class' => \IPS\nexus\Tax::load( $this->class )->apiOutput(),
|
||||
'class' => \IPS\nexus\Tax::load( $this->class )->apiOutput( $authorizedMember ),
|
||||
'rate' => $this->data['rate'],
|
||||
'amount' => $this->data['amount']
|
||||
);
|
||||
|
||||
@@ -82,10 +82,12 @@ class _ItemsIterator extends \ArrayIterator
|
||||
|
||||
/* Details */
|
||||
$details = array();
|
||||
$purchaseDetails = array();
|
||||
if ( isset( $data['cfields'] ) and $data['cfields'] )
|
||||
{
|
||||
foreach( $data['cfields'] AS $key => $value )
|
||||
{
|
||||
$purchaseDetails[ $key ] = $value;
|
||||
try
|
||||
{
|
||||
$field = \IPS\nexus\Package\CustomField::load( $key );
|
||||
@@ -133,6 +135,7 @@ class _ItemsIterator extends \ArrayIterator
|
||||
}
|
||||
|
||||
$obj->details = $details;
|
||||
$obj->purchaseDetails = $purchaseDetails;
|
||||
|
||||
/* Tax */
|
||||
if ( isset( $data['tax'] ) AND $data['tax'] )
|
||||
|
||||
Reference in new issue
Block a user