Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -69,7 +69,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
public static function statuses()
|
||||
{
|
||||
$options = array();
|
||||
$reflection = new \ReflectionClass( get_called_class() );
|
||||
$reflection = new \ReflectionClass( \get_called_class() );
|
||||
foreach ( $reflection->getConstants() as $k => $v )
|
||||
{
|
||||
if ( mb_substr( $k, 0, 7 ) === 'STATUS_' )
|
||||
@@ -277,7 +277,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
just create a dummy if so */
|
||||
$itemsJson = array_filter( $itemsJson, function( $val )
|
||||
{
|
||||
return is_array( $val ) and isset( $val['act'] );
|
||||
return \is_array( $val ) and isset( $val['act'] );
|
||||
} );
|
||||
if ( !$itemsJson and $this->total->amount->isGreaterThanZero() )
|
||||
{
|
||||
@@ -354,7 +354,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function get_paid()
|
||||
{
|
||||
return $this->_data['paid'] ? \IPS\DateTime::ts( $this->_data['paid'] ) : NULL;
|
||||
return ( isset( $this->_data['paid'] ) and $this->_data['paid'] ) ? \IPS\DateTime::ts( $this->_data['paid'] ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,7 +442,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\GeoLocation::buildFromJson( \IPS\Db::i()->select( 'address', 'nexus_customer_addresses', array( 'member=? AND primary_shipping=1', $this->member->member_id ) )->first() );
|
||||
return \IPS\GeoLocation::buildFromJson( \IPS\Db::i()->select( 'address', 'nexus_customer_addresses', array( '`member`=? AND primary_shipping=1', $this->member->member_id ) )->first() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
@@ -485,10 +485,18 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
* @param \IPS\GeoLocation $billingAddress The billing address
|
||||
* @return void
|
||||
*/
|
||||
public function set_billaddress( \IPS\GeoLocation $billingAddress )
|
||||
public function set_billaddress( \IPS\GeoLocation $billingAddress = NULL )
|
||||
{
|
||||
$this->_data['billaddress'] = json_encode( $billingAddress );
|
||||
$this->_data['billcountry'] = $billingAddress->country;
|
||||
if ( $billingAddress )
|
||||
{
|
||||
$this->_data['billaddress'] = json_encode( $billingAddress );
|
||||
$this->_data['billcountry'] = $billingAddress->country;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_data['billaddress'] = NULL;
|
||||
$this->_data['billcountry'] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -621,7 +629,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
/* Parent? */
|
||||
if ( isset( $item->parent ) and $item->parent !== NULL )
|
||||
{
|
||||
if ( is_int( $item->parent ) )
|
||||
if ( \is_int( $item->parent ) )
|
||||
{
|
||||
$data['assoc'] = $item->parent;
|
||||
$data['assocBought'] = FALSE;
|
||||
@@ -646,6 +654,24 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$data['grace_period'] = \IPS\DateTime::create()->add( $item->renewalTerm->gracePeriod )->getTimestamp() - time();
|
||||
}
|
||||
}
|
||||
if ( isset( $item->initialInterval ) )
|
||||
{
|
||||
if( $item->initialInterval->y )
|
||||
{
|
||||
$data['initial_interval_term'] = $item->initialInterval->y;
|
||||
$data['initial_interval_unit'] = 'y';
|
||||
}
|
||||
elseif( $item->initialInterval->m )
|
||||
{
|
||||
$data['initial_interval_term'] = $item->initialInterval->m;
|
||||
$data['initial_interval_unit'] = 'm';
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['initial_interval_term'] = $item->initialInterval->d;
|
||||
$data['initial_interval_unit'] = 'd';
|
||||
}
|
||||
}
|
||||
|
||||
/* Expire date? */
|
||||
if ( isset( $item->expireDate ) )
|
||||
@@ -780,7 +806,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if ( isset( $item->extra['items'] ) )
|
||||
{
|
||||
$itemCount = count( $item->extra['items'] );
|
||||
$itemCount = \count( $item->extra['items'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -796,7 +822,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
foreach ( clone $this->items as $k => $_item ) // We have to clone because $items is an iterator, and we're already looping them, but we need a separate loop
|
||||
{
|
||||
if ( $_item != $item and !( $_item instanceof \IPS\nexus\extensions\nexus\Item\CouponDiscount ) and !( $_item instanceof \IPS\nexus\extensions\nexus\Item\ShippingCharge ) and ( !isset( $item->extra['items'] ) or in_array( $k, $item->extra['items'] ) ) )
|
||||
if ( $_item != $item and !( $_item instanceof \IPS\nexus\extensions\nexus\Item\CouponDiscount ) and !( $_item instanceof \IPS\nexus\extensions\nexus\Item\ShippingCharge ) and ( !isset( $item->extra['items'] ) or \in_array( $k, $item->extra['items'] ) ) )
|
||||
{
|
||||
if ( $item->extra['type'] == 'p' )
|
||||
{
|
||||
@@ -881,7 +907,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$return['shipping'][ $k ] = $item;
|
||||
}
|
||||
$return['shippingTotal'] = new \IPS\nexus\Money( $shipping, $this->currency );
|
||||
|
||||
|
||||
/* Now work out the tax */
|
||||
$return['tax'] = array();
|
||||
$tax = new \IPS\Math\Number('0');
|
||||
@@ -892,7 +918,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
$amount = new \IPS\nexus\Money( $amount, $this->currency );
|
||||
|
||||
$return['tax'][ $taxId ] = array( 'name' => $taxClasses[ $taxId ]->_title, 'rate' => $rate, 'amount' => $amount );
|
||||
$return['tax'][ $taxId ] = array( 'name' => '', 'rate' => $rate, 'amount' => $amount, 'type' => $taxClasses[ $taxId ]->type ); // "name" is no longer used. It is definef here only to not break custom themes. Get the title from the ID instead.
|
||||
$tax = $tax->add( $amount->amount );
|
||||
}
|
||||
$return['taxTotal'] = new \IPS\nexus\Money( $tax, $this->currency );
|
||||
@@ -997,7 +1023,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
try
|
||||
{
|
||||
/* Get the referrer */
|
||||
$referrer = \IPS\Member::load( \IPS\Db::i()->select( 'referred_by', 'nexus_referrals', array( 'member_id=?', $this->member->member_id ) )->first() );
|
||||
$referrer = \IPS\Member::load( \IPS\Db::i()->select( 'referred_by', 'core_referrals', array( 'member_id=?', $this->member->member_id ) )->first() );
|
||||
if ( !$referrer->member_id or $referrer->inGroup( explode( ',', \IPS\Settings::i()->nexus_no_commission ) ) )
|
||||
{
|
||||
throw new \UnderflowException;
|
||||
@@ -1088,7 +1114,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$packageId = $item->id;
|
||||
}
|
||||
elseif ( $commissionRule->purchase_renewal and $item instanceof \IPS\nexus\Invoice\Item\Renewal and $item::$application == 'nexus' and $item::$type == 'package' )
|
||||
elseif ( $commissionRule->purchase_renewal and $item instanceof \IPS\nexus\Invoice\Item\Renewal and $item->appKey == 'nexus' and $item->typeKey == 'package' )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1098,7 +1124,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Is it in our list? */
|
||||
if ( !$packageId or !in_array( $packageId, explode( ',', $commissionRule->purchase_packages ) ) )
|
||||
if ( !$packageId or !\in_array( $packageId, explode( ',', $commissionRule->purchase_packages ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1126,7 +1152,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
foreach ( explode( ',', $commissionRule->purchase_packages ) as $pid )
|
||||
{
|
||||
if ( !in_array( $pid, $itemsToCount ) )
|
||||
if ( !\in_array( $pid, $itemsToCount ) )
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
@@ -1291,7 +1317,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$url = $this->acpUrl()->setQueryString( 'r', $ref );
|
||||
$return = array();
|
||||
|
||||
if ( $this->status !== \IPS\nexus\Invoice::STATUS_PAID and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_add' ) )
|
||||
if ( $this->status !== \IPS\nexus\Invoice::STATUS_PAID and ( $this->member->member_id or $this->guest_data ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_add' ) )
|
||||
{
|
||||
$return['edit'] = array(
|
||||
'title' => 'edit',
|
||||
@@ -1300,18 +1326,18 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
);
|
||||
}
|
||||
|
||||
if ( $this->status === \IPS\nexus\Invoice::STATUS_PENDING )
|
||||
if ( $this->status === \IPS\nexus\Invoice::STATUS_PENDING and ( $this->member->member_id or $this->guest_data ) )
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_edit' ) )
|
||||
{
|
||||
$return['paid'] = array(
|
||||
'title' => 'invoice_mark_paid',
|
||||
'icon' => 'check',
|
||||
'link' => $url->setQueryString( 'do', 'paid' ),
|
||||
'data' => count( $this->transactions( array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ) ) ) ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('invoice_mark_paid') ) : array( 'confirm' => '' )
|
||||
'link' => $url->setQueryString( 'do', 'paid' )->csrf(),
|
||||
'data' => \count( $this->transactions( array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ) ) ) ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('invoice_mark_paid') ) : array( 'confirm' => '' )
|
||||
);
|
||||
}
|
||||
if ( count( \IPS\nexus\Gateway::manualChargeGateways() ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'chargetocard' ) )
|
||||
if ( \count( \IPS\nexus\Gateway::manualChargeGateways( $this->member ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'chargetocard' ) )
|
||||
{
|
||||
$return['card'] = array(
|
||||
'title' => 'invoice_charge_to_card',
|
||||
@@ -1334,7 +1360,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$return['resend'] = array(
|
||||
'title' => 'invoice_reissue',
|
||||
'icon' => 'refresh',
|
||||
'link' => $url->setQueryString( 'do', 'resend' ),
|
||||
'link' => $url->setQueryString( 'do', 'resend' )->csrf(),
|
||||
'data' => array(
|
||||
'confirm' => '',
|
||||
'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('invoice_reissue_confirm'),
|
||||
@@ -1368,7 +1394,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$return['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => $url->setQueryString( 'do', 'delete' ),
|
||||
'link' => $url->setQueryString( 'do', 'delete' )->csrf(),
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('invoice_delete_warning') )
|
||||
);
|
||||
}
|
||||
@@ -1496,7 +1522,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$where[] = array( 't_invoice=?', $this->id );
|
||||
if ( $statuses )
|
||||
{
|
||||
$where[] = \IPS\Db::i()->in( 't_status', $statuses );
|
||||
$where[] = array( \IPS\Db::i()->in( 't_status', $statuses ) );
|
||||
}
|
||||
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_transactions', $where ), 'IPS\nexus\Transaction' );
|
||||
@@ -1542,6 +1568,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'];
|
||||
$cards = isset( $this->guest_data['cards'] ) ? $this->guest_data['cards'] : array();
|
||||
|
||||
/* If the member has already been created (the user made two separate purchases with the same data), use that, otherwise create one */
|
||||
try
|
||||
@@ -1553,19 +1580,25 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$memberToSave = new \IPS\nexus\Customer;
|
||||
foreach ( $this->guest_data['member'] as $k => $v )
|
||||
{
|
||||
$memberToSave->_data[ $k ] = $v;
|
||||
$memberToSave->changed[ $k ] = $v;
|
||||
$memberToSave->$k = $v;
|
||||
}
|
||||
$memberToSave->save();
|
||||
|
||||
/* Was this a referral? */
|
||||
if( $this->guest_data['referred_by'] )
|
||||
{
|
||||
$referredBy = \IPS\Member::load( $this->guest_data['referred_by'] )->addReferral( $memberToSave );
|
||||
}
|
||||
|
||||
$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;
|
||||
$postBeforeRegister = isset( $this->guest_data['pbr'] ) ? $this->guest_data['pbr'] : NULL;
|
||||
$this->guest_data = isset( $this->guest_data['guestTransactionKey'] ) ? array( 'guestTransactionKey' => $this->guest_data['guestTransactionKey'] ) : NULL;
|
||||
$this->save();
|
||||
|
||||
/* If we provided answers to security questions in check out, save those */
|
||||
if ( \IPS\Settings::i()->security_questions_enabled and in_array( \IPS\Settings::i()->security_questions_prompt, array( 'register', 'optional' ) ) )
|
||||
if ( \IPS\Settings::i()->security_questions_enabled and \in_array( \IPS\Settings::i()->security_questions_prompt, array( 'register', 'optional' ) ) )
|
||||
{
|
||||
if ( $securityAnswers )
|
||||
{
|
||||
@@ -1614,14 +1647,21 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$profileFields['member_id'] = $memberToSave->member_id;
|
||||
\IPS\Db::i()->replace( 'core_pfields_content', $profileFields );
|
||||
|
||||
/* If we opted to save a card at checkout, save it */
|
||||
foreach ( $cards as $card )
|
||||
{
|
||||
$card['card_member'] = $memberToSave->member_id;
|
||||
\IPS\Db::i()->insert( 'nexus_customer_cards', $card );
|
||||
}
|
||||
|
||||
/* Validation */
|
||||
if ( \IPS\Settings::i()->nexus_checkreg_validate or !$this->total->amount->isGreaterThanZero() )
|
||||
{
|
||||
$this->member->postRegistration( FALSE, TRUE );
|
||||
$this->member->postRegistration( FALSE, TRUE, $postBeforeRegister );
|
||||
}
|
||||
else if( \IPS\Settings::i()->new_reg_notify )
|
||||
else
|
||||
{
|
||||
\IPS\Email::buildFromTemplate( 'core', 'registration_notify', array( $memberToSave, $profileFields ), \IPS\Email::TYPE_LIST )->send( \IPS\Settings::i()->email_in );
|
||||
$this->member->validationComplete( FALSE, $postBeforeRegister );
|
||||
}
|
||||
|
||||
/* Update associated transactions */
|
||||
@@ -1666,9 +1706,16 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
if ( $this->status !== static::STATUS_PAID )
|
||||
{
|
||||
/* Create the member account if this was a guest */
|
||||
if ( !$this->member->member_id and $this->guest_data and $this->requiresLogin() )
|
||||
if ( !$this->member->member_id and $this->requiresLogin() )
|
||||
{
|
||||
$return = $this->createAccountForGuest();
|
||||
if ( $this->guest_data )
|
||||
{
|
||||
$return = $this->createAccountForGuest();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \RuntimeException('NO_MEMBER_DATA');
|
||||
}
|
||||
}
|
||||
|
||||
/* Init */
|
||||
@@ -1707,7 +1754,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
if ( $item->renewalTerm )
|
||||
{
|
||||
$purchase->renewals = $item->renewalTerm;
|
||||
$purchase->expire = \IPS\DateTime::create()->add( $item->renewalTerm->interval );
|
||||
$purchase->expire = \IPS\DateTime::create()->add( $item->initialInterval ?: $item->renewalTerm->interval );
|
||||
if ( $item->renewalTerm->gracePeriod )
|
||||
{
|
||||
$purchase->grace_period = \IPS\DateTime::create()->add( $item->renewalTerm->gracePeriod )->getTimestamp() - time();
|
||||
@@ -1723,7 +1770,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
$purchase->app = $item::$application;
|
||||
$purchase->type = $item::$type;
|
||||
$purchase->item_id = intval( $item->id );
|
||||
$purchase->item_id = \intval( $item->id );
|
||||
$purchase->custom_fields = $item->purchaseDetails;
|
||||
$purchase->original_invoice = $this;
|
||||
$purchase->tax = $item->tax ? $item->tax->id : 0;
|
||||
@@ -1810,6 +1857,10 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$extra['commission'][ $item->payTo->member_id ] = array( 'amount' => new \IPS\Math\Number('0') );
|
||||
}
|
||||
elseif ( !( $extra['commission'][ $item->payTo->member_id ]['amount'] instanceof \IPS\Math\Number ) )
|
||||
{
|
||||
$extra['commission'][ $item->payTo->member_id ]['amount'] = new \IPS\Math\Number( "{$extra['commission'][ $item->payTo->member_id ]['amount']}" );
|
||||
}
|
||||
$extra['commission'][ $item->payTo->member_id ]['amount'] = $extra['commission'][ $item->payTo->member_id ]['amount']->add( $recipientAmounts['recipient_final']->amount );
|
||||
|
||||
$item->payTo->log( 'comission', array(
|
||||
@@ -1832,13 +1883,13 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
},
|
||||
iterator_to_array( $item->payTo->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
( ( \in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Referral Commission */
|
||||
if ( \IPS\Settings::i()->cm_ref_on and $commission = $this->commission( $amountReceived ) and $commission['amount'] )
|
||||
if ( \IPS\Settings::i()->ref_on and $commission = $this->commission( $amountReceived ) and $commission['amount'] )
|
||||
{
|
||||
$credits = $commission['referrer']->cm_credits;
|
||||
$credits[ $this->currency ]->amount = $credits[ $this->currency ]->amount->add( $commission['amount']->amount );
|
||||
@@ -1849,7 +1900,10 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$extra['commission'][ $commission['referrer']->member_id ] = array( 'amount' => new \IPS\Math\Number('0') );
|
||||
}
|
||||
|
||||
elseif ( !( $extra['commission'][ $commission['referrer']->member_id ]['amount'] instanceof \IPS\Math\Number ) )
|
||||
{
|
||||
$extra['commission'][ $commission['referrer']->member_id ]['amount'] = new \IPS\Math\Number( "{$extra['commission'][ $commission['referrer']->member_id ]['amount']}" );
|
||||
}
|
||||
$extra['commission'][ $commission['referrer']->member_id ]['amount'] = $extra['commission'][ $commission['referrer']->member_id ]['amount']->add( $commission['amount']->amount );
|
||||
|
||||
$commission['referrer']->log( 'comission', array(
|
||||
@@ -1862,7 +1916,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
'invoice_title' => $this->title
|
||||
), FALSE );
|
||||
|
||||
$record = \IPS\Db::i()->select( '*', 'nexus_referrals', array( 'member_id=? AND referred_by=?', $this->member->member_id, $commission['referrer']->member_id ) )->first();
|
||||
$record = \IPS\Db::i()->select( '*', 'core_referrals', array( 'member_id=? AND referred_by=?', $this->member->member_id, $commission['referrer']->member_id ) )->first();
|
||||
$amounts = $record['amount'] ? json_decode( $record['amount'], TRUE ) : array();
|
||||
if ( !isset( $amounts[ $this->currency ] ) )
|
||||
{
|
||||
@@ -1873,7 +1927,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$amounts[ $this->currency ] = new \IPS\Math\Number( number_format( $amounts[ $this->currency ], \IPS\nexus\Money::numberOfDecimalsForCurrency( $this->currency ), '.', '' ) );
|
||||
}
|
||||
$amounts[ $this->currency ] = $amounts[ $this->currency ]->add( $commission['amount']->amount );
|
||||
\IPS\Db::i()->update( 'nexus_referrals', array( 'amount' => json_encode( $amounts ) ), array( 'member_id=? AND referred_by=?', $this->member->member_id, $commission['referrer']->member_id ) );
|
||||
\IPS\Db::i()->update( 'core_referrals', array( 'amount' => json_encode( $amounts ) ), array( 'member_id=? AND referred_by=?', $this->member->member_id, $commission['referrer']->member_id ) );
|
||||
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'commissionEarned', array( $this, NULL, $commission['amount'] ), \IPS\Email::TYPE_TRANSACTIONAL )
|
||||
->send(
|
||||
@@ -1885,7 +1939,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
},
|
||||
iterator_to_array( $commission['referrer']->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
( ( \in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1951,6 +2005,8 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
'invoice_id' => $this->id,
|
||||
'invoice_title' => $this->title
|
||||
), FALSE );
|
||||
|
||||
\IPS\core\AdminNotification::send( 'nexus', 'Shipment', NULL, TRUE, $shipOrder );
|
||||
}
|
||||
|
||||
/* Refuse any pending transactions */
|
||||
@@ -1979,6 +2035,12 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
/* Update invoice */
|
||||
$this->status = static::STATUS_PAID;
|
||||
$this->paid = new \IPS\DateTime;
|
||||
|
||||
/* Set our billing address automatically if it's not already set */
|
||||
if( !$this->billaddress )
|
||||
{
|
||||
$this->billaddress = $this->member->primaryBillingAddress();
|
||||
}
|
||||
|
||||
/* Log */
|
||||
if ( $member )
|
||||
@@ -2044,7 +2106,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
},
|
||||
iterator_to_array( $item->payTo->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
( ( \in_array( 'commission_earned', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2052,7 +2114,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
/* Delete purchases */
|
||||
foreach ( $this->purchasesCreated() as $purchase )
|
||||
{
|
||||
$purchase->delete();
|
||||
$purchase->delete( FALSE );
|
||||
}
|
||||
|
||||
/* Delete shipping orders */
|
||||
@@ -2097,17 +2159,22 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
$return = array();
|
||||
|
||||
$purchases = $this->purchasesCreated();
|
||||
if ( count( $purchases ) )
|
||||
if ( \count( $purchases ) )
|
||||
{
|
||||
$return['purchases'] = array();
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$return['purchases'][] = \IPS\Theme::i()->getTemplate( 'purchases', 'nexus' )->link( $purchase );
|
||||
$return['purchases'][ $purchase->id ] = \IPS\Theme::i()->getTemplate( 'purchases', 'nexus' )->link( $purchase );
|
||||
|
||||
foreach ( $purchase->children( NULL ) as $child )
|
||||
{
|
||||
$return['unassociate'][ $purchase->id ][ $child->id ] = \IPS\Theme::i()->getTemplate( 'purchases', 'nexus' )->link( $child );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shipments = $this->shipments();
|
||||
if ( count( $shipments ) )
|
||||
if ( \count( $shipments ) )
|
||||
{
|
||||
$return['shipments'] = array();
|
||||
foreach ( $shipments as $shipment )
|
||||
@@ -2144,7 +2211,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
if( count( $item->onUnpaidDescription( $this ) ) )
|
||||
if( \count( $item->onUnpaidDescription( $this ) ) )
|
||||
{
|
||||
foreach( $item->onUnpaidDescription( $this ) as $desc )
|
||||
{
|
||||
@@ -2163,7 +2230,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function sendNotification()
|
||||
{
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'newInvoice', array( $this, $this->summary() ), \IPS\Email::TYPE_TRANSACTIONAL )
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'newInvoice', array( $this, $this->summary( $this->member->language() ) , ( $this->paid ) ? $this->member->language()->get('invoice_mailsub_paid') : $this->member->language()->get('invoice_mailsub_pend') ), \IPS\Email::TYPE_TRANSACTIONAL )
|
||||
->send(
|
||||
$this->member,
|
||||
array_map(
|
||||
@@ -2173,7 +2240,7 @@ class _Invoice extends \IPS\Patterns\ActiveRecord
|
||||
},
|
||||
iterator_to_array( $this->member->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( in_array( 'new_invoice', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
( ( \in_array( 'new_invoice', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Invoice;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -137,7 +137,7 @@ abstract class _Item
|
||||
* @brief Group With Parent
|
||||
*/
|
||||
public $groupWithParent = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -181,7 +181,7 @@ abstract class _Item
|
||||
*/
|
||||
public function taxRate( \IPS\GeoLocation $location = NULL )
|
||||
{
|
||||
return new \IPS\Math\Number( $this->tax ? $this->tax->rate( $location ?: $this->billaddress ) : '0' );
|
||||
return new \IPS\Math\Number( $this->tax ? $this->tax->rate( $location ) : '0' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +338,7 @@ abstract class _Item
|
||||
*/
|
||||
public function requiresBillingAddress()
|
||||
{
|
||||
return in_array( 'other', explode( ',', \IPS\Settings::i()->nexus_require_billing ) );
|
||||
return \in_array( 'other', explode( ',', \IPS\Settings::i()->nexus_require_billing ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,8 +388,8 @@ abstract class _Item
|
||||
* @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)
|
||||
* @apiresponse 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)
|
||||
* @apiresponse \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( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
@@ -413,7 +413,7 @@ abstract class _Item
|
||||
'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( $authorizedMember ) : null,
|
||||
'parentItem' => ( isset( $this->parent ) and is_int( $this->parent ) ) ? $this->parent : 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( $authorizedMember ) : null,
|
||||
'commission' => $this->commission,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -33,6 +33,11 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
*/
|
||||
public static $requiresAccount = TRUE;
|
||||
|
||||
/**
|
||||
* @brief \DateInterval Length granted by initial purchase before normal renewal term starts (or NULL to match renewal term)
|
||||
*/
|
||||
public $initialInterval;
|
||||
|
||||
/**
|
||||
* @brief \IPS\nexus\Purchase\RenewalTerm Renewal Term
|
||||
*/
|
||||
@@ -100,7 +105,7 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
$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 ) )
|
||||
if ( \is_array( $id ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'ps_item_id', $id ) );
|
||||
}
|
||||
@@ -186,7 +191,7 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
if ( !$purchase->billing_agreement or $purchase->billing_agreement->canceled )
|
||||
{
|
||||
$form->add( new \IPS\nexus\Form\RenewalTerm( 'ps_renewals', $renewals, FALSE, array( 'lockTerm' => !$purchase->canChangeExpireDate() ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'ps_grace_period', $purchase->grace_period / 86400, FALSE, array( 'max' => \IPS\Settings::i()->cm_invoice_expireafter ?: NULL ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('days') ) );
|
||||
$form->add( new \IPS\Helpers\Form\Interval( 'ps_grace_period', $purchase->grace_period / 86400, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'max' => \IPS\Settings::i()->cm_invoice_expireafter ?: NULL, 'min' => NULL ), NULL, NULL, NULL ) );
|
||||
}
|
||||
|
||||
if ( !$purchase->grouped_renewals )
|
||||
@@ -205,6 +210,25 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
public static function acpEditSave( \IPS\nexus\Purchase $purchase, array $values )
|
||||
{
|
||||
$purchase->name = $values['ps_name'];
|
||||
|
||||
/* Figure out tax for renewals */
|
||||
$tax = NULL;
|
||||
|
||||
try
|
||||
{
|
||||
if( $purchase->tax )
|
||||
{
|
||||
$tax = \IPS\nexus\Tax::load( $purchase->tax );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ){}
|
||||
|
||||
if( $tax AND $values['ps_renewals'] )
|
||||
{
|
||||
$values['ps_renewals']->tax = $tax;
|
||||
}
|
||||
|
||||
/* Then save */
|
||||
if ( $purchase->grouped_renewals )
|
||||
{
|
||||
$purchase->ungroupFromParent();
|
||||
@@ -439,7 +463,7 @@ abstract class _Purchase extends \IPS\nexus\Invoice\Item
|
||||
*/
|
||||
public function requiresBillingAddress()
|
||||
{
|
||||
return in_array( 'product', explode( ',', \IPS\Settings::i()->nexus_require_billing ) );
|
||||
return \in_array( 'product', explode( ',', \IPS\Settings::i()->nexus_require_billing ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -178,12 +178,7 @@ class _Renewal extends \IPS\nexus\Invoice\Item
|
||||
$expire->sub( $interval );
|
||||
}
|
||||
$purchase->expire = $expire;
|
||||
|
||||
if ( $status === \IPS\nexus\Invoice::STATUS_PENDING )
|
||||
{
|
||||
$purchase->invoice_pending = $invoice;
|
||||
}
|
||||
|
||||
$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 ) );
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Invoice\Item;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Invoice;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -41,7 +41,7 @@ class _ItemsIterator extends \ArrayIterator
|
||||
*/
|
||||
public function arrayToObject( $data )
|
||||
{
|
||||
if ( is_object( $data ) )
|
||||
if ( \is_object( $data ) )
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
@@ -56,12 +56,12 @@ class _ItemsIterator extends \ArrayIterator
|
||||
if ( static::$classnames === NULL )
|
||||
{
|
||||
static::$classnames = array();
|
||||
foreach ( \IPS\Application::allExtensions( 'nexus', 'Item', TRUE, NULL, NULL, FALSE ) as $ext )
|
||||
foreach ( \IPS\Application::allExtensions( 'nexus', 'Item', FALSE, 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' ) ) )
|
||||
if ( $data['app'] === 'nexus' and \in_array( $data['type'], array( 'product', 'hosting', 'ad' ) ) )
|
||||
{
|
||||
$data['type'] = 'package';
|
||||
}
|
||||
@@ -151,6 +151,10 @@ class _ItemsIterator extends \ArrayIterator
|
||||
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 );
|
||||
if ( isset( $data['initial_interval_term'] ) and $data['initial_interval_term'] )
|
||||
{
|
||||
$obj->initialInterval = new \DateInterval( 'P' . $data['initial_interval_term'] . mb_strtoupper( $data['initial_interval_unit'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Expire Date */
|
||||
@@ -189,7 +193,11 @@ class _ItemsIterator extends \ArrayIterator
|
||||
{
|
||||
if ( $data['assocBought'] )
|
||||
{
|
||||
$obj->parent = \IPS\nexus\Purchase::load( $data['assoc'] );
|
||||
try
|
||||
{
|
||||
$obj->parent = \IPS\nexus\Purchase::load( $data['assoc'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user