Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+342 -87
View File
@@ -5,19 +5,23 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 6 May 2016
*/
namespace IPS\convert\Library;
/* 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;
}
/**
* Invision Commerce (Nexus) Converter
* @note We must extend the Core Library here so we can access methods like convertAttachment, convertFollow, etc
*/
class _Nexus extends \IPS\convert\Library
{
/**
@@ -34,7 +38,7 @@ class _Nexus extends \IPS\convert\Library
public function menuRows( $rowCounts=FALSE )
{
$return = array();
$classname = get_class( $this->software );
$extraRows = $this->software->extraMenuRows();
foreach( $this->getConvertableItems() as $k => $v )
{
@@ -46,7 +50,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomerFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_customer_fields'
);
@@ -54,7 +58,7 @@ class _Nexus extends \IPS\convert\Library
case 'convertNexusCustomers':
$dependencies = array();
if ( in_array( 'convertNexusCustomerFields', $this->getConvertableItems() ) )
if ( \in_array( 'convertNexusCustomerFields', $this->getConvertableItems() ) )
{
$dependencies[] = 'convertNexusCustomerFields';
}
@@ -64,7 +68,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomers',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customers' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => 'nexus_customers',
);
@@ -76,7 +80,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomerAddresses',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'link_type' => 'nexus_customer_addresses',
);
@@ -88,7 +92,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCustomerHistory',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_member_history', array( 'log_app=?', 'nexus' ) ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'link_type' => 'nexus_customer_history',
);
@@ -100,7 +104,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusAlternateContacts',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'link_type' => 'nexus_alternate_contacts'
);
@@ -112,11 +116,23 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusNotes',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_notes' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers' ),
'linK_type' => 'nexus_notes'
);
break;
case 'convertNexusPaymentMethods':
$return[ $k ] = array(
'step_title' => 'convert_nexus_payment_methods',
'step_method' => 'convertNexusPaymentMethods',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_paymethods' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_payment_methods'
);
break;
case 'convertNexusPackageGroups':
$return[ $k ] = array(
@@ -124,7 +140,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusPackageGroups',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_groups' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_package_groups'
);
@@ -136,7 +152,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusPackageFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_package_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_package_fields'
);
@@ -171,7 +187,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusReviews',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_reviews' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
'link_type' => 'nexus_reviews',
'requires_rebuild' => TRUE
@@ -184,7 +200,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusCoupons',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_coupons' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
'link_type' => 'nexus_coupons'
);
@@ -196,20 +212,31 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusInvoices',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusPackages' ),
'link_type' => 'nexus_invoices',
);
break;
case 'convertNexusTransactions':
$dependencies = array();
foreach( array( 'convertNexusCustomers', 'convertNexusInvoices', 'convertNexusPaymentMethods' ) as $dependency )
{
$canConvert = $this->getConvertableItems();
if ( isset( $canConvert[ $dependency ] ) )
{
$dependencies[] = $dependency;
}
}
$return[ $k ] = array(
'step_title' => 'convert_nexus_transactions',
'step_method' => 'convertNexusTransactions',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusInvoices' ),
'per_cycle' => 200,
'dependencies' => $dependencies,
'link_type' => 'nexus_transactions',
);
break;
@@ -220,7 +247,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusPurchases',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusPackages', 'convertNexusInvoices' ),
'link_type' => 'nexus_purchases'
);
@@ -232,7 +259,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusFraudRules',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_fraud_rules' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_fraud_rules',
);
@@ -244,7 +271,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportDepartments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_departments' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusPackages' ),
);
break;
@@ -255,7 +282,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportFields',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_fields' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
'link_type' => 'nexus_support_fields',
);
@@ -267,7 +294,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportStatuses',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_statuses' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array(),
'link_type' => 'nexus_support_statuses',
);
@@ -279,7 +306,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportSeverities',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_severities' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
'link_type' => 'nexus_support_severities'
);
@@ -291,7 +318,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportStockActions',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_stock_actions' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 100,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportDepartments' ),
'link_type' => 'nexus_support_stock_actions'
);
@@ -303,7 +330,7 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportRequests',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_requests' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 1500,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusCustomers', 'convertNexusSupportDepartments', 'convertNexusSupportFields' ),
'link_type' => 'nexus_support_requests',
'requires_rebuild' => TRUE
@@ -316,16 +343,23 @@ class _Nexus extends \IPS\convert\Library
'step_method' => 'convertNexusSupportReplies',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_support_replies' ),
'source_rows' => array( 'table' => $v['table'], 'where' => $v['where'] ),
'per_cycle' => 2000,
'per_cycle' => 200,
'dependencies' => array( 'convertNexusSupportRequests' ),
'link_type' => 'nexus_support_replies',
'requires_rebuild' => TRUE
);
break;
}
}
$return = $this->software->extraMenuRows( $return );
/* Append any extra steps immediately to retain ordering */
if( isset( $v['extra_steps'] ) )
{
foreach( $v['extra_steps'] as $extra )
{
$return[ $extra ] = $extraRows[ $extra ];
}
}
}
/* Run the queries if we want row counts */
if( $rowCounts )
@@ -339,13 +373,13 @@ class _Nexus extends \IPS\convert\Library
/**
* Returns an array of tables that need to be truncated when Empty Local Data is used
*
* @param string The method to truncate.
* @param string $method Method to truncate
* @return array
*/
protected function truncate( $method )
{
$return = array();
$classname = get_class( $this->software );
$classname = \get_class( $this->software );
if( $classname::canConvert() === NULL )
{
@@ -398,7 +432,11 @@ class _Nexus extends \IPS\convert\Library
'nexus_packages_products' => NULL,
);
break;
case 'convertNexusPaymentMethods':
$return['convertNexusPaymentMethods'] = array( 'nexus_paymethods' => NULL );
break;
case 'convertNexusReviews':
$return['convertNexusReviews'] = array( 'nexus_reviews' => NULL );
break;
@@ -473,8 +511,8 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert a customer
*
* @param array Data to insert
* @param array Custom Field Data
* @param array $info Data to insert
* @param array $fields Custom Field Data
* @return int|bool The ID of the inserted customer, or FALSE on failure
*/
public function convertNexusCustomer( $info, $fields=array() )
@@ -516,7 +554,7 @@ class _Nexus extends \IPS\convert\Library
if ( isset( $info['cm_profiles'] ) )
{
if ( is_array( $info['cm_profiles'] ) )
if ( \is_array( $info['cm_profiles'] ) )
{
$info['cm_profiles'] = json_encode( $info['cm_profiles'] );
}
@@ -537,7 +575,7 @@ class _Nexus extends \IPS\convert\Library
/**
* Format Customer Fields for saving
*
* @param array The fields
* @param array $fields The fields
* @return array Formatted Fields
*/
protected function _formatCustomerFields( $fields )
@@ -545,7 +583,7 @@ class _Nexus extends \IPS\convert\Library
$return = array();
foreach( $fields as $key => $value )
{
if ( is_array( $value ) )
if ( \is_array( $value ) )
{
$value = json_encode( $value );
}
@@ -564,11 +602,66 @@ class _Nexus extends \IPS\convert\Library
return $return;
}
/**
* @brief Allowed currencies
*/
protected $_allowedCurrencies = array( 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD',
'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BYR', 'BZD', 'CAD', 'CDF', 'CHF',
'CLF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR',
'FJD', 'FKP', 'GBP', 'GEL', 'GGP', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR',
'ILS', 'IMP', 'INR', 'IQD', 'IRR', 'ISK', 'JEP', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD',
'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR',
'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR',
'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SPL*',
'SRD', 'STD', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TVD', 'TWD', 'TZS', 'UAH', 'UGX',
'USD', 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW', 'ZWD' );
/**
* Convert a currency
*
* @param array Info
* @return int|bool The newly inserted currency, or FALSE on failure
*/
public function convertNexusCurrency( $info )
{
if ( !isset( $info['code'] ) )
{
$this->software->app->log( 'nexus_currency_missing_code', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* Normalise the currency code */
$info['code'] = \strtoupper( $info['code'] );
if ( !\in_array( $info['code'], $this->_allowedCurrencies ) )
{
$this->software->app->log( 'nexus_currency_not_allowed', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
$currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE );
/* Currencies are a little odd in that they don't really have a link */
if( isset( $currencies[ $info['code'] ] ) )
{
return $info['code'];
}
/* Add our currency */
$currencies[ $info['code'] ] = array();
/* save */
\IPS\Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $currencies ) ) );
return $info['code'];
}
/**
* Convert a note
*
* @param array Info
* @param array $info Info
* @return int|bool The newly inserted note ID, or FALSE on failure
*/
public function convertNexusNote( $info )
@@ -650,9 +743,9 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert a package group
*
* @param array Info
* @param string|NULL Path to the groups cover photo, or NULL
* @param string|NULL Raw filedata for the groups cover photo, or NULL
* @param array $info Info
* @param string|NULL $filepath Path to the groups cover photo, or NULL
* @param string|NULL $filedata Raw filedata for the groups cover photo, or NULL
* @return int|bool THe ID of the newly inserted package group, or FALSE on failure
*/
public function convertNexusPackageGroup( $info, $filepath=NULL, $filedata=NULL )
@@ -694,9 +787,9 @@ class _Nexus extends \IPS\convert\Library
$info['pg_parent'] = 0;
}
if ( isset( $info['pg_image'] ) AND ( !is_null( $filepath ) OR !is_null( $filedata ) ) )
if ( isset( $info['pg_image'] ) AND ( !\is_null( $filepath ) OR !\is_null( $filedata ) ) )
{
if ( is_null( $filedata ) AND !is_null( $filepath ) )
if ( \is_null( $filedata ) AND !\is_null( $filepath ) )
{
$filedata = @file_get_contents( rtrim( $filepath, '/' ) . '/' . $info['pg_image'] );
unset( $filepath );
@@ -739,11 +832,74 @@ class _Nexus extends \IPS\convert\Library
}
/**
* Convert a package
* Convert a pay method
*
* @param array $info Info
* @param string $filePath Path to images
* @return int|bool The ID of the newly inserted package, or FALSE on failure
* @return int|bool The ID of the newly inserted payment gateway, or FALSE on failure
*/
public function convertNexusPaymentMethod( $info )
{
/* !Required: ID */
if ( !isset( $info['m_id'] ) )
{
$this->software->app->log( 'nexus_payment_method_missing_id', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* !Required: Method */
if ( !isset( $info['m_gateway'] ) )
{
$this->software->app->log( 'nexus_payment_method_missing_gateway', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['m_id'] );
return FALSE;
}
$info['m_gateway'] = $this->_isPaymentMethodSupported( $info['m_gateway'] );
if( $info['m_gateway'] === FALSE )
{
$this->software->app->log( 'nexus_payment_method_not_supported', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['m_id'] );
return FALSE;
}
if ( isset( $info['m_name'] ) )
{
$name = $info['m_name'];
unset( $info['m_name'] );
}
else
{
$name = $info['m_gateway'];
}
$gateway = array(
'm_gateway' => '',
'm_settings' => '{"client_id":"","secret":""}',
'm_active' => 0,
'm_position' => 0,
'm_countries' => '*'
);
$originalId = $info['m_id'];
unset( $info['m_id'], $info['m_name'] );
/* Save Product Data */
$insertedId = \IPS\Db::i()->insert( 'nexus_paymethods', $this->_getValues( $gateway, $info ) );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$insertedId}", $name );
/* Add Link */
$this->software->app->addLink( $insertedId, $originalId, 'nexus_payment_methods' );
return $insertedId;
}
/**
* Convert a package
*
* @param array $info Info
* @param string|NULL $filePath Path to images
* @return int|bool The ID of the newly inserted package, or FALSE on failure
*/
public function convertNexusPackage( $info, $filePath=NULL )
{
@@ -858,30 +1014,38 @@ class _Nexus extends \IPS\convert\Library
catch( \UnderflowException $e ) { }
}
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$price = new \IPS\nexus\Money( $info['p_base_price'], $currency );
$basePrice = [ $currency => [ 'amount' => $price->amount, 'currency' => $currency ] ];
/* Base Price */
array_walk( $info['p_base_price'], function( &$value, $currency )
{
$price = new \IPS\nexus\Money( $value, $currency );
$value = [ 'amount' => $price->amount, 'currency' => $currency ];
});
$basePrice = $info['p_base_price'];
unset( $info['p_base_price'] );
/* Renewal costs & terms */
if( isset( $info['p_renew_options'] ) AND count( $info['p_renew_options'] ) )
$renewals = array();
if( isset( $info['p_renew_options'] ) AND \count( $info['p_renew_options'] ) )
{
$newOptions = array();
foreach( $info['p_renew_options'] as $value )
foreach ( $info['p_renew_options'] as $currency => $options )
{
$price = new \IPS\nexus\Money( $value['price'], $currency );
$renewPrice = [ $currency => [ 'amount' => $price->amount, 'currency' => $currency ] ];
$newOptions[] = array(
'cost' => $renewPrice,
'term' => $value['term'],
'unit' => $value['unit'],
'add' => isset( $value['add'] ) ? $value['add'] : false
$newOptions = array(
'cost' => [],
'term' => $options['term'],
'unit' => $options['unit'],
'add' => isset( $options['add'] ) ? $options['add'] : false
);
foreach ( $options['cost'] as $currency => $cost )
{
$price = new \IPS\nexus\Money( $cost, $currency );
$newOptions['cost'][ $currency ] = [ 'amount' => $price->amount, 'currency' => $currency ];
}
$renewals[] = $newOptions;
}
$info['p_renew_options'] = json_encode( $newOptions );
$info['p_renew_options'] = json_encode( $renewals );
}
/* Discounts */
@@ -953,7 +1117,7 @@ class _Nexus extends \IPS\convert\Library
$default = 0;
foreach( $productImages as $image )
{
if ( ( isset( $image['data'] ) AND is_null( $image['data'] ) ) AND !is_null( $filePath ) )
if ( ( isset( $image['data'] ) AND \is_null( $image['data'] ) ) AND !\is_null( $filePath ) )
{
$filedata = @file_get_contents( rtrim( $filePath, '/' ) . '/' . $image['filename'] );
unset( $filepath );
@@ -972,9 +1136,9 @@ class _Nexus extends \IPS\convert\Library
}
/* Insert Images */
if( is_array( $images ) AND count( $images ) )
if( \is_array( $images ) AND \count( $images ) )
{
\IPS\Db::insert( 'nexus_package_images', $images );
\IPS\Db::i()->insert( 'nexus_package_images', $images );
}
}
@@ -1004,14 +1168,23 @@ class _Nexus extends \IPS\convert\Library
}
/* Base Price */
if ( !\IPS\Db::i()->checkForColumn( 'nexus_package_base_prices', $currency ) )
$insert = [ 'id' => $insertedId ];
foreach( $basePrice as $currency => $amount )
{
\IPS\Db::i()->addColumn( 'nexus_package_base_prices', array(
'name' => $currency,
'type' => 'FLOAT'
) );
/* check the currency is set up */
$this->convertNexusCurrency( [ 'code' => $currency ] );
/* Check the table */
if ( !\IPS\Db::i()->checkForColumn( 'nexus_package_base_prices', $currency ) )
{
\IPS\Db::i()->addColumn( 'nexus_package_base_prices', array(
'name' => $currency,
'type' => 'FLOAT'
) );
}
$insert[ $currency ] = (string) $amount['amount'];
}
\IPS\Db::i()->insert( 'nexus_package_base_prices', array( 'id' => $insertedId, $currency => $price->amount ) );
\IPS\Db::i()->insert( 'nexus_package_base_prices', $insert );
/* Custom lang strings */
\IPS\Lang::saveCustom( 'nexus', "nexus_package_{$insertedId}", $name );
@@ -1029,10 +1202,11 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert an invoice
*
* @param array $info Info
* @return int|bool The ID of the newly inserted invoice, or FALSE on failure
* @param array $info Info
* @param string $currency Invoice Currency
* @return int|bool The ID of the newly inserted invoice, or FALSE on failure
*/
public function convertNexusInvoice( $info )
public function convertNexusInvoice( $info, $currency )
{
/* !Required: ID */
if ( !isset( $info['i_id'] ) )
@@ -1041,15 +1215,21 @@ class _Nexus extends \IPS\convert\Library
return FALSE;
}
/* !Required: Currency */
if ( !isset( $currency ) OR !$currency = $this->convertNexusCurrency( [ 'code' => $currency ] ) )
{
$this->software->app->log( 'nexus_invoice_currency_invalid', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* !Required: Items */
if ( !isset( $info['i_items'] ) OR !is_array( $info['i_items'] ) )
if ( !isset( $info['i_items'] ) OR !\is_array( $info['i_items'] ) )
{
$this->software->app->log( 'nexus_invoices_missing_items', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['i_id'] );
return FALSE;
}
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$price = new \IPS\nexus\Money( $info['i_total'], $currency );
$info['i_total'] = $price->amount;
@@ -1057,9 +1237,20 @@ class _Nexus extends \IPS\convert\Library
$newItems = array();
foreach( $info['i_items'] as $item )
{
$item['itemID'] = $this->software->app->getLink( $item['itemID'], 'nexus_packages' );
$newItems[] = $item;
try
{
$item['itemID'] = $this->software->app->getLink( $item['itemID'], 'nexus_packages' );
$newItems[] = $item;
}
catch( \OutOfRangeException $e ) {}
}
if( !\count( $newItems ) )
{
$this->software->app->log( 'nexus_invoices_missing_mapped_items', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['i_id'] );
return FALSE;
}
$info['i_items'] = json_encode( $newItems );
/* Find member */
@@ -1111,10 +1302,11 @@ class _Nexus extends \IPS\convert\Library
/**
* Convert a transaction
*
* @param array $info Info
* @return int|bool The ID of the newly inserted transaction, or FALSE on failure
* @param array $info Info
* @param string $currency Transaction Currency
* @return int|bool The ID of the newly inserted transaction, or FALSE on failure
*/
public function convertNexusTransaction( $info )
public function convertNexusTransaction( $info, $currency )
{
/* !Required: ID */
if ( !isset( $info['t_id'] ) )
@@ -1144,8 +1336,24 @@ class _Nexus extends \IPS\convert\Library
return FALSE;
}
/* !Required: Currency */
if ( !isset( $currency ) OR !$currency = $this->convertNexusCurrency( [ 'code' => $currency ] ) )
{
$this->software->app->log( 'nexus_transaction_currency_invalid', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* Map IDs */
$info['t_invoice'] = $this->software->app->getLink( $info['t_invoice'], 'nexus_invoices' );
try
{
$info['t_invoice'] = $this->software->app->getLink( $info['t_invoice'], 'nexus_invoices' );
}
catch( \OutOfRangeException $ex )
{
$this->software->app->log( 'nexus_transactions_missing_invoice', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['t_invoice'] );
return FALSE;
}
try
{
$info['t_member'] = $this->software->app->getLink( $info['t_member'], 'core_members', TRUE );
@@ -1156,8 +1364,20 @@ class _Nexus extends \IPS\convert\Library
return FALSE;
}
/* !Payment Method */
if( isset( $info['t_method'] ) )
{
try
{
$info['t_method'] = $this->software->app->getLink( $info['t_method'], 'nexus_payment_methods' );
}
catch ( \OutOfRangeException $ex )
{
$info['t_method'] = 0;
}
}
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
$price = new \IPS\nexus\Money( $info['t_amount'], $currency );
$info['t_amount'] = $price->amount;
@@ -1193,9 +1413,10 @@ class _Nexus extends \IPS\convert\Library
* Convert a purchase
*
* @param array $info Info
* @return int|bool The ID of the newly inserted purchase, or FALSE on failure
* @param string $currency Transaction Currency
* @return int|bool The ID of the newly inserted purchase, or FALSE on failure
*/
public function convertNexusPurchase( $info )
public function convertNexusPurchase( $info, $currency )
{
/* !Required: ID */
if ( !isset( $info['ps_id'] ) )
@@ -1218,8 +1439,24 @@ class _Nexus extends \IPS\convert\Library
return FALSE;
}
/* !Required: Currency */
if ( !isset( $currency ) OR !$currency = $this->convertNexusCurrency( [ 'code' => $currency ] ) )
{
$this->software->app->log( 'nexus_purchase_currency_invalid', __METHOD__, \IPS\convert\App::LOG_WARNING );
return FALSE;
}
/* Map IDs */
$info['ps_original_invoice'] = $this->software->app->getLink( $info['ps_original_invoice'], 'nexus_invoices' );
try
{
$info['ps_original_invoice'] = $this->software->app->getLink( $info['ps_original_invoice'], 'nexus_invoices' );
}
catch( \OutOfRangeException $ex)
{
$this->software->app->log( 'nexus_purchases_missing_invoice', __METHOD__, \IPS\convert\App::LOG_WARNING, $info['ps_id'] );
return FALSE;
}
$info['ps_item_id'] = $this->software->app->getLink( $info['ps_item_id'], 'nexus_packages' );
try
@@ -1264,7 +1501,7 @@ class _Nexus extends \IPS\convert\Library
}
/* Old Secondary User Groups */
if( isset( $info['ps_extra']['nexus']['old_secondary_groups'] ) AND is_array( $info['ps_extra']['nexus']['old_secondary_groups'] ) )
if( isset( $info['ps_extra']['nexus']['old_secondary_groups'] ) AND \is_array( $info['ps_extra']['nexus']['old_secondary_groups'] ) )
{
$newSecondaryGroups = [];
@@ -1283,7 +1520,6 @@ class _Nexus extends \IPS\convert\Library
$info['ps_extra'] = json_encode( $info['ps_extra'] );
/* Default Currency */
$currency = \IPS\nexus\Customer::loggedIn()->defaultCurrency();
if( isset( $info['ps_renewal_price'] ) )
{
$price = new \IPS\nexus\Money( $info['ps_renewal_price'], $currency );
@@ -1354,4 +1590,23 @@ class _Nexus extends \IPS\convert\Library
return $defaults;
}
/**
* Check whether a given payment method is supported by Commerce
*
* @param $method
* @return bool
*/
protected function _isPaymentMethodSupported( $method )
{
$availableGateways = \IPS\nexus\Gateway::gateways();
$methodKey = array_search( $method, array_keys( array_change_key_case( $availableGateways, CASE_LOWER ) ) );
if( $methodKey !== FALSE )
{
return array_keys( $availableGateways )[ $methodKey ];
}
return FALSE;
}
}