@@ -37,138 +37,138 @@  | 
                                                    ||
| 37 | 37 | * @since 4.0  | 
                                                        
| 38 | 38 | */  | 
                                                        
| 39 | 39 |  if (function_exists('espresso_version')) { | 
                                                        
| 40 | -    if (! function_exists('espresso_duplicate_plugin_error')) { | 
                                                        |
| 41 | - /**  | 
                                                        |
| 42 | - * espresso_duplicate_plugin_error  | 
                                                        |
| 43 | - * displays if more than one version of EE is activated at the same time.  | 
                                                        |
| 44 | - */  | 
                                                        |
| 45 | - function espresso_duplicate_plugin_error()  | 
                                                        |
| 46 | -        { | 
                                                        |
| 47 | - ?>  | 
                                                        |
| 40 | +	if (! function_exists('espresso_duplicate_plugin_error')) { | 
                                                        |
| 41 | + /**  | 
                                                        |
| 42 | + * espresso_duplicate_plugin_error  | 
                                                        |
| 43 | + * displays if more than one version of EE is activated at the same time.  | 
                                                        |
| 44 | + */  | 
                                                        |
| 45 | + function espresso_duplicate_plugin_error()  | 
                                                        |
| 46 | +		{ | 
                                                        |
| 47 | + ?>  | 
                                                        |
| 48 | 48 | <div class="error">  | 
                                                        
| 49 | 49 | <p>  | 
                                                        
| 50 | 50 | <?php  | 
                                                        
| 51 | - echo esc_html__(  | 
                                                        |
| 52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',  | 
                                                        |
| 53 | - 'event_espresso'  | 
                                                        |
| 54 | - ); ?>  | 
                                                        |
| 51 | + echo esc_html__(  | 
                                                        |
| 52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',  | 
                                                        |
| 53 | + 'event_espresso'  | 
                                                        |
| 54 | + ); ?>  | 
                                                        |
| 55 | 55 | </p>  | 
                                                        
| 56 | 56 | </div>  | 
                                                        
| 57 | 57 | <?php  | 
                                                        
| 58 | - espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 59 | - }  | 
                                                        |
| 60 | - }  | 
                                                        |
| 61 | -    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); | 
                                                        |
| 58 | + espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 59 | + }  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | +	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); | 
                                                        |
| 62 | 62 |  } else { | 
                                                        
| 63 | -    define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); | 
                                                        |
| 64 | -    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { | 
                                                        |
| 65 | - /**  | 
                                                        |
| 66 | - * espresso_minimum_php_version_error  | 
                                                        |
| 67 | - *  | 
                                                        |
| 68 | - * @return void  | 
                                                        |
| 69 | - */  | 
                                                        |
| 70 | - function espresso_minimum_php_version_error()  | 
                                                        |
| 71 | -        { | 
                                                        |
| 72 | - ?>  | 
                                                        |
| 63 | +	define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); | 
                                                        |
| 64 | +	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { | 
                                                        |
| 65 | + /**  | 
                                                        |
| 66 | + * espresso_minimum_php_version_error  | 
                                                        |
| 67 | + *  | 
                                                        |
| 68 | + * @return void  | 
                                                        |
| 69 | + */  | 
                                                        |
| 70 | + function espresso_minimum_php_version_error()  | 
                                                        |
| 71 | +		{ | 
                                                        |
| 72 | + ?>  | 
                                                        |
| 73 | 73 | <div class="error">  | 
                                                        
| 74 | 74 | <p>  | 
                                                        
| 75 | 75 | <?php  | 
                                                        
| 76 | - printf(  | 
                                                        |
| 77 | - esc_html__(  | 
                                                        |
| 78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',  | 
                                                        |
| 79 | - 'event_espresso'  | 
                                                        |
| 80 | - ),  | 
                                                        |
| 81 | - EE_MIN_PHP_VER_REQUIRED,  | 
                                                        |
| 82 | - PHP_VERSION,  | 
                                                        |
| 83 | - '<br/>',  | 
                                                        |
| 84 | - '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'  | 
                                                        |
| 85 | - );  | 
                                                        |
| 86 | - ?>  | 
                                                        |
| 76 | + printf(  | 
                                                        |
| 77 | + esc_html__(  | 
                                                        |
| 78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',  | 
                                                        |
| 79 | + 'event_espresso'  | 
                                                        |
| 80 | + ),  | 
                                                        |
| 81 | + EE_MIN_PHP_VER_REQUIRED,  | 
                                                        |
| 82 | + PHP_VERSION,  | 
                                                        |
| 83 | + '<br/>',  | 
                                                        |
| 84 | + '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'  | 
                                                        |
| 85 | + );  | 
                                                        |
| 86 | + ?>  | 
                                                        |
| 87 | 87 | </p>  | 
                                                        
| 88 | 88 | </div>  | 
                                                        
| 89 | 89 | <?php  | 
                                                        
| 90 | - espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 91 | - }  | 
                                                        |
| 90 | + espresso_deactivate_plugin(plugin_basename(__FILE__));  | 
                                                        |
| 91 | + }  | 
                                                        |
| 92 | 92 | |
| 93 | -        add_action('admin_notices', 'espresso_minimum_php_version_error', 1); | 
                                                        |
| 94 | -    } else { | 
                                                        |
| 95 | -        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); | 
                                                        |
| 93 | +		add_action('admin_notices', 'espresso_minimum_php_version_error', 1); | 
                                                        |
| 94 | +	} else { | 
                                                        |
| 95 | +		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); | 
                                                        |
| 96 | 96 | |
| 97 | - require_once __DIR__ . '/vendor/autoload.php';  | 
                                                        |
| 97 | + require_once __DIR__ . '/vendor/autoload.php';  | 
                                                        |
| 98 | 98 | |
| 99 | - /**  | 
                                                        |
| 100 | - * espresso_version  | 
                                                        |
| 101 | - * Returns the plugin version  | 
                                                        |
| 102 | - *  | 
                                                        |
| 103 | - * @return string  | 
                                                        |
| 104 | - */  | 
                                                        |
| 105 | - function espresso_version(): string  | 
                                                        |
| 106 | -        { | 
                                                        |
| 107 | -            return apply_filters('FHEE__espresso__espresso_version', '5.0.34.rc.000'); | 
                                                        |
| 108 | - }  | 
                                                        |
| 99 | + /**  | 
                                                        |
| 100 | + * espresso_version  | 
                                                        |
| 101 | + * Returns the plugin version  | 
                                                        |
| 102 | + *  | 
                                                        |
| 103 | + * @return string  | 
                                                        |
| 104 | + */  | 
                                                        |
| 105 | + function espresso_version(): string  | 
                                                        |
| 106 | +		{ | 
                                                        |
| 107 | +			return apply_filters('FHEE__espresso__espresso_version', '5.0.34.rc.000'); | 
                                                        |
| 108 | + }  | 
                                                        |
| 109 | 109 | |
| 110 | - /**  | 
                                                        |
| 111 | - * espresso_plugin_activation  | 
                                                        |
| 112 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page  | 
                                                        |
| 113 | - */  | 
                                                        |
| 114 | - function espresso_plugin_activation()  | 
                                                        |
| 115 | -        { | 
                                                        |
| 116 | -            update_option('ee_espresso_activation', true); | 
                                                        |
| 117 | -            update_option('event-espresso-core_allow_tracking', 'no'); | 
                                                        |
| 118 | -            update_option('event-espresso-core_tracking_notice', 'hide'); | 
                                                        |
| 119 | - // Run WP GraphQL activation callback  | 
                                                        |
| 120 | - espressoLoadWpGraphQL();  | 
                                                        |
| 121 | - graphql_activation_callback();  | 
                                                        |
| 122 | - }  | 
                                                        |
| 110 | + /**  | 
                                                        |
| 111 | + * espresso_plugin_activation  | 
                                                        |
| 112 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page  | 
                                                        |
| 113 | + */  | 
                                                        |
| 114 | + function espresso_plugin_activation()  | 
                                                        |
| 115 | +		{ | 
                                                        |
| 116 | +			update_option('ee_espresso_activation', true); | 
                                                        |
| 117 | +			update_option('event-espresso-core_allow_tracking', 'no'); | 
                                                        |
| 118 | +			update_option('event-espresso-core_tracking_notice', 'hide'); | 
                                                        |
| 119 | + // Run WP GraphQL activation callback  | 
                                                        |
| 120 | + espressoLoadWpGraphQL();  | 
                                                        |
| 121 | + graphql_activation_callback();  | 
                                                        |
| 122 | + }  | 
                                                        |
| 123 | 123 | |
| 124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');  | 
                                                        |
| 124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');  | 
                                                        |
| 125 | 125 | |
| 126 | - /**  | 
                                                        |
| 127 | - * espresso_plugin_deactivation  | 
                                                        |
| 128 | - */  | 
                                                        |
| 129 | - function espresso_plugin_deactivation()  | 
                                                        |
| 130 | -        { | 
                                                        |
| 131 | - // Run WP GraphQL deactivation callback  | 
                                                        |
| 132 | - espressoLoadWpGraphQL();  | 
                                                        |
| 133 | - graphql_deactivation_callback();  | 
                                                        |
| 134 | -            delete_option('event-espresso-core_allow_tracking'); | 
                                                        |
| 135 | -            delete_option('event-espresso-core_tracking_notice'); | 
                                                        |
| 136 | - }  | 
                                                        |
| 137 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');  | 
                                                        |
| 126 | + /**  | 
                                                        |
| 127 | + * espresso_plugin_deactivation  | 
                                                        |
| 128 | + */  | 
                                                        |
| 129 | + function espresso_plugin_deactivation()  | 
                                                        |
| 130 | +		{ | 
                                                        |
| 131 | + // Run WP GraphQL deactivation callback  | 
                                                        |
| 132 | + espressoLoadWpGraphQL();  | 
                                                        |
| 133 | + graphql_deactivation_callback();  | 
                                                        |
| 134 | +			delete_option('event-espresso-core_allow_tracking'); | 
                                                        |
| 135 | +			delete_option('event-espresso-core_tracking_notice'); | 
                                                        |
| 136 | + }  | 
                                                        |
| 137 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');  | 
                                                        |
| 138 | 138 | |
| 139 | - require_once __DIR__ . '/core/bootstrap_espresso.php';  | 
                                                        |
| 140 | - bootstrap_espresso();  | 
                                                        |
| 141 | - }  | 
                                                        |
| 139 | + require_once __DIR__ . '/core/bootstrap_espresso.php';  | 
                                                        |
| 140 | + bootstrap_espresso();  | 
                                                        |
| 141 | + }  | 
                                                        |
| 142 | 142 | }  | 
                                                        
| 143 | 143 | |
| 144 | 144 |  if (! function_exists('espresso_deactivate_plugin')) { | 
                                                        
| 145 | - /**  | 
                                                        |
| 146 | - * deactivate_plugin  | 
                                                        |
| 147 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ ));  | 
                                                        |
| 148 | - *  | 
                                                        |
| 149 | - * @access public  | 
                                                        |
| 150 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file  | 
                                                        |
| 151 | - * @return void  | 
                                                        |
| 152 | - */  | 
                                                        |
| 153 | - function espresso_deactivate_plugin(string $plugin_basename = '')  | 
                                                        |
| 154 | -    { | 
                                                        |
| 155 | -        if (! function_exists('deactivate_plugins')) { | 
                                                        |
| 156 | - require_once ABSPATH . 'wp-admin/includes/plugin.php';  | 
                                                        |
| 157 | - }  | 
                                                        |
| 158 | - unset($_GET['activate'], $_REQUEST['activate']);  | 
                                                        |
| 159 | - deactivate_plugins($plugin_basename);  | 
                                                        |
| 160 | - }  | 
                                                        |
| 145 | + /**  | 
                                                        |
| 146 | + * deactivate_plugin  | 
                                                        |
| 147 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ ));  | 
                                                        |
| 148 | + *  | 
                                                        |
| 149 | + * @access public  | 
                                                        |
| 150 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file  | 
                                                        |
| 151 | + * @return void  | 
                                                        |
| 152 | + */  | 
                                                        |
| 153 | + function espresso_deactivate_plugin(string $plugin_basename = '')  | 
                                                        |
| 154 | +	{ | 
                                                        |
| 155 | +		if (! function_exists('deactivate_plugins')) { | 
                                                        |
| 156 | + require_once ABSPATH . 'wp-admin/includes/plugin.php';  | 
                                                        |
| 157 | + }  | 
                                                        |
| 158 | + unset($_GET['activate'], $_REQUEST['activate']);  | 
                                                        |
| 159 | + deactivate_plugins($plugin_basename);  | 
                                                        |
| 160 | + }  | 
                                                        |
| 161 | 161 | }  | 
                                                        
| 162 | 162 | |
| 163 | 163 | |
| 164 | 164 |  if (! function_exists('espressoLoadWpGraphQL')) { | 
                                                        
| 165 | - function espressoLoadWpGraphQL()  | 
                                                        |
| 166 | -    { | 
                                                        |
| 167 | - if (  | 
                                                        |
| 168 | -            ! class_exists('WPGraphQL') | 
                                                        |
| 169 | - && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')  | 
                                                        |
| 170 | -        ) { | 
                                                        |
| 171 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';  | 
                                                        |
| 172 | - }  | 
                                                        |
| 173 | - }  | 
                                                        |
| 165 | + function espressoLoadWpGraphQL()  | 
                                                        |
| 166 | +	{ | 
                                                        |
| 167 | + if (  | 
                                                        |
| 168 | +			! class_exists('WPGraphQL') | 
                                                        |
| 169 | + && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')  | 
                                                        |
| 170 | +		) { | 
                                                        |
| 171 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';  | 
                                                        |
| 172 | + }  | 
                                                        |
| 173 | + }  | 
                                                        |
| 174 | 174 | }  | 
                                                        
@@ -30,302 +30,302 @@  | 
                                                    ||
| 30 | 30 | */  | 
                                                        
| 31 | 31 | class CreateOrder extends OrdersApi  | 
                                                        
| 32 | 32 |  { | 
                                                        
| 33 | - /**  | 
                                                        |
| 34 | - * Line items total.  | 
                                                        |
| 35 | - *  | 
                                                        |
| 36 | - * @var float  | 
                                                        |
| 37 | - */  | 
                                                        |
| 38 | - protected float $items_total = 0.0;  | 
                                                        |
| 33 | + /**  | 
                                                        |
| 34 | + * Line items total.  | 
                                                        |
| 35 | + *  | 
                                                        |
| 36 | + * @var float  | 
                                                        |
| 37 | + */  | 
                                                        |
| 38 | + protected float $items_total = 0.0;  | 
                                                        |
| 39 | 39 | |
| 40 | - /**  | 
                                                        |
| 41 | - * Promotions total.  | 
                                                        |
| 42 | - *  | 
                                                        |
| 43 | - * @var float  | 
                                                        |
| 44 | - */  | 
                                                        |
| 45 | - protected float $promos_total = 0.0;  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * Promotions total.  | 
                                                        |
| 42 | + *  | 
                                                        |
| 43 | + * @var float  | 
                                                        |
| 44 | + */  | 
                                                        |
| 45 | + protected float $promos_total = 0.0;  | 
                                                        |
| 46 | 46 | |
| 47 | - /**  | 
                                                        |
| 48 | - * Tax total.  | 
                                                        |
| 49 | - *  | 
                                                        |
| 50 | - * @var float  | 
                                                        |
| 51 | - */  | 
                                                        |
| 52 | - protected float $tax_total = 0.0;  | 
                                                        |
| 47 | + /**  | 
                                                        |
| 48 | + * Tax total.  | 
                                                        |
| 49 | + *  | 
                                                        |
| 50 | + * @var float  | 
                                                        |
| 51 | + */  | 
                                                        |
| 52 | + protected float $tax_total = 0.0;  | 
                                                        |
| 53 | 53 | |
| 54 | - /**  | 
                                                        |
| 55 | - * Currency.  | 
                                                        |
| 56 | - *  | 
                                                        |
| 57 | - * @var string  | 
                                                        |
| 58 | - */  | 
                                                        |
| 59 | - protected string $currency_code;  | 
                                                        |
| 54 | + /**  | 
                                                        |
| 55 | + * Currency.  | 
                                                        |
| 56 | + *  | 
                                                        |
| 57 | + * @var string  | 
                                                        |
| 58 | + */  | 
                                                        |
| 59 | + protected string $currency_code;  | 
                                                        |
| 60 | 60 | |
| 61 | - /**  | 
                                                        |
| 62 | - * Billing info.  | 
                                                        |
| 63 | - *  | 
                                                        |
| 64 | - * @var array  | 
                                                        |
| 65 | - */  | 
                                                        |
| 66 | - protected array $billing_info;  | 
                                                        |
| 61 | + /**  | 
                                                        |
| 62 | + * Billing info.  | 
                                                        |
| 63 | + *  | 
                                                        |
| 64 | + * @var array  | 
                                                        |
| 65 | + */  | 
                                                        |
| 66 | + protected array $billing_info;  | 
                                                        |
| 67 | 67 | |
| 68 | - /**  | 
                                                        |
| 69 | - * Transaction this order is for.  | 
                                                        |
| 70 | - *  | 
                                                        |
| 71 | - * @var EE_Transaction  | 
                                                        |
| 72 | - */  | 
                                                        |
| 73 | - protected EE_Transaction $transaction;  | 
                                                        |
| 68 | + /**  | 
                                                        |
| 69 | + * Transaction this order is for.  | 
                                                        |
| 70 | + *  | 
                                                        |
| 71 | + * @var EE_Transaction  | 
                                                        |
| 72 | + */  | 
                                                        |
| 73 | + protected EE_Transaction $transaction;  | 
                                                        |
| 74 | 74 | |
| 75 | - private FeatureFlags $feature;  | 
                                                        |
| 75 | + private FeatureFlags $feature;  | 
                                                        |
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /**  | 
                                                        |
| 79 | - * CreateOrder constructor.  | 
                                                        |
| 80 | - *  | 
                                                        |
| 81 | - * @param PayPalApi $api  | 
                                                        |
| 82 | - * @param EE_Transaction $transaction  | 
                                                        |
| 83 | - * @param array $billing_info  | 
                                                        |
| 84 | - * @param FeatureFlags $feature  | 
                                                        |
| 85 | - */  | 
                                                        |
| 86 | - public function __construct(PayPalApi $api, EE_Transaction $transaction, array $billing_info, FeatureFlags $feature)  | 
                                                        |
| 87 | -    { | 
                                                        |
| 88 | - parent::__construct($api);  | 
                                                        |
| 89 | - $this->transaction = $transaction;  | 
                                                        |
| 90 | - $this->feature = $feature;  | 
                                                        |
| 91 | - $this->currency_code = CurrencyManager::currencyCode();  | 
                                                        |
| 92 | - $this->sanitizeRequestParameters($billing_info);  | 
                                                        |
| 93 | - }  | 
                                                        |
| 78 | + /**  | 
                                                        |
| 79 | + * CreateOrder constructor.  | 
                                                        |
| 80 | + *  | 
                                                        |
| 81 | + * @param PayPalApi $api  | 
                                                        |
| 82 | + * @param EE_Transaction $transaction  | 
                                                        |
| 83 | + * @param array $billing_info  | 
                                                        |
| 84 | + * @param FeatureFlags $feature  | 
                                                        |
| 85 | + */  | 
                                                        |
| 86 | + public function __construct(PayPalApi $api, EE_Transaction $transaction, array $billing_info, FeatureFlags $feature)  | 
                                                        |
| 87 | +	{ | 
                                                        |
| 88 | + parent::__construct($api);  | 
                                                        |
| 89 | + $this->transaction = $transaction;  | 
                                                        |
| 90 | + $this->feature = $feature;  | 
                                                        |
| 91 | + $this->currency_code = CurrencyManager::currencyCode();  | 
                                                        |
| 92 | + $this->sanitizeRequestParameters($billing_info);  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /**  | 
                                                        |
| 97 | - * Sanitize the array of billing form data.  | 
                                                        |
| 98 | - *  | 
                                                        |
| 99 | - * @param array $billing_info  | 
                                                        |
| 100 | - * @return void  | 
                                                        |
| 101 | - */  | 
                                                        |
| 102 | - public function sanitizeRequestParameters(array $billing_info): void  | 
                                                        |
| 103 | -    { | 
                                                        |
| 104 | - $sanitizer = new RequestSanitizer(new Basic());  | 
                                                        |
| 105 | -        foreach ($billing_info as $item => $value) { | 
                                                        |
| 106 | - $this->billing_info[ $item ] = $sanitizer->clean($value);  | 
                                                        |
| 107 | - }  | 
                                                        |
| 108 | - }  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * Sanitize the array of billing form data.  | 
                                                        |
| 98 | + *  | 
                                                        |
| 99 | + * @param array $billing_info  | 
                                                        |
| 100 | + * @return void  | 
                                                        |
| 101 | + */  | 
                                                        |
| 102 | + public function sanitizeRequestParameters(array $billing_info): void  | 
                                                        |
| 103 | +	{ | 
                                                        |
| 104 | + $sanitizer = new RequestSanitizer(new Basic());  | 
                                                        |
| 105 | +		foreach ($billing_info as $item => $value) { | 
                                                        |
| 106 | + $this->billing_info[ $item ] = $sanitizer->clean($value);  | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | + }  | 
                                                        |
| 109 | 109 | |
| 110 | 110 | |
| 111 | - /**  | 
                                                        |
| 112 | - * Create PayPal Order.  | 
                                                        |
| 113 | - *  | 
                                                        |
| 114 | - * @return array  | 
                                                        |
| 115 | - * @throws EE_Error  | 
                                                        |
| 116 | - * @throws ReflectionException  | 
                                                        |
| 117 | - */  | 
                                                        |
| 118 | - public function create(): array  | 
                                                        |
| 119 | -    { | 
                                                        |
| 120 | - $order_parameters = $this->getParameters();  | 
                                                        |
| 121 | - // Create Order request.  | 
                                                        |
| 122 | - $create_response = $this->api->sendRequest($order_parameters, $this->request_url);  | 
                                                        |
| 123 | - return $this->validateOrder($create_response, $order_parameters);  | 
                                                        |
| 124 | - }  | 
                                                        |
| 111 | + /**  | 
                                                        |
| 112 | + * Create PayPal Order.  | 
                                                        |
| 113 | + *  | 
                                                        |
| 114 | + * @return array  | 
                                                        |
| 115 | + * @throws EE_Error  | 
                                                        |
| 116 | + * @throws ReflectionException  | 
                                                        |
| 117 | + */  | 
                                                        |
| 118 | + public function create(): array  | 
                                                        |
| 119 | +	{ | 
                                                        |
| 120 | + $order_parameters = $this->getParameters();  | 
                                                        |
| 121 | + // Create Order request.  | 
                                                        |
| 122 | + $create_response = $this->api->sendRequest($order_parameters, $this->request_url);  | 
                                                        |
| 123 | + return $this->validateOrder($create_response, $order_parameters);  | 
                                                        |
| 124 | + }  | 
                                                        |
| 125 | 125 | |
| 126 | 126 | |
| 127 | - /**  | 
                                                        |
| 128 | - * Form order parameters.  | 
                                                        |
| 129 | - *  | 
                                                        |
| 130 | - * @return array  | 
                                                        |
| 131 | - * @throws EE_Error  | 
                                                        |
| 132 | - * @throws ReflectionException  | 
                                                        |
| 133 | - * @throws Exception  | 
                                                        |
| 134 | - */  | 
                                                        |
| 135 | - protected function getParameters(): array  | 
                                                        |
| 136 | -    { | 
                                                        |
| 137 | - $registrant = $this->transaction->primary_registration();  | 
                                                        |
| 138 | - $attendee = $registrant->attendee();  | 
                                                        |
| 139 | - $event = $registrant->event();  | 
                                                        |
| 140 | - $description = $event->name() ?: sprintf(  | 
                                                        |
| 141 | -            esc_html__('Tickets for an event at %1$s', 'event_espresso'), | 
                                                        |
| 142 | -            get_bloginfo('name') | 
                                                        |
| 143 | - );  | 
                                                        |
| 144 | - $parameters = [  | 
                                                        |
| 145 | - 'intent' => 'CAPTURE',  | 
                                                        |
| 146 | - 'purchase_units' => [  | 
                                                        |
| 147 | - [  | 
                                                        |
| 148 | - 'custom_id' => $this->transaction->ID(),  | 
                                                        |
| 149 | - 'description' => substr(wp_strip_all_tags($description), 0, 125),  | 
                                                        |
| 150 | - 'items' => $this->getLineItems(),  | 
                                                        |
| 151 | - 'amount' => [  | 
                                                        |
| 152 | - 'value' => (string) CurrencyManager::normalizeValue($this->transaction->remaining()),  | 
                                                        |
| 153 | - 'currency_code' => $this->currency_code,  | 
                                                        |
| 154 | - 'breakdown' => $this->getBreakdown(),  | 
                                                        |
| 155 | - ],  | 
                                                        |
| 156 | - ],  | 
                                                        |
| 157 | - ],  | 
                                                        |
| 158 | - 'application_context' => [  | 
                                                        |
| 159 | - 'shipping_preference' => 'NO_SHIPPING',  | 
                                                        |
| 160 | - 'user_action' => 'PAY_NOW',  | 
                                                        |
| 161 | - ],  | 
                                                        |
| 162 | - 'payer' => [  | 
                                                        |
| 163 | - 'email_address' => $attendee->email(),  | 
                                                        |
| 164 | - 'name' => [  | 
                                                        |
| 165 | - 'given_name' => $attendee->fname(),  | 
                                                        |
| 166 | - 'surname' => $attendee->lname(),  | 
                                                        |
| 127 | + /**  | 
                                                        |
| 128 | + * Form order parameters.  | 
                                                        |
| 129 | + *  | 
                                                        |
| 130 | + * @return array  | 
                                                        |
| 131 | + * @throws EE_Error  | 
                                                        |
| 132 | + * @throws ReflectionException  | 
                                                        |
| 133 | + * @throws Exception  | 
                                                        |
| 134 | + */  | 
                                                        |
| 135 | + protected function getParameters(): array  | 
                                                        |
| 136 | +	{ | 
                                                        |
| 137 | + $registrant = $this->transaction->primary_registration();  | 
                                                        |
| 138 | + $attendee = $registrant->attendee();  | 
                                                        |
| 139 | + $event = $registrant->event();  | 
                                                        |
| 140 | + $description = $event->name() ?: sprintf(  | 
                                                        |
| 141 | +			esc_html__('Tickets for an event at %1$s', 'event_espresso'), | 
                                                        |
| 142 | +			get_bloginfo('name') | 
                                                        |
| 143 | + );  | 
                                                        |
| 144 | + $parameters = [  | 
                                                        |
| 145 | + 'intent' => 'CAPTURE',  | 
                                                        |
| 146 | + 'purchase_units' => [  | 
                                                        |
| 147 | + [  | 
                                                        |
| 148 | + 'custom_id' => $this->transaction->ID(),  | 
                                                        |
| 149 | + 'description' => substr(wp_strip_all_tags($description), 0, 125),  | 
                                                        |
| 150 | + 'items' => $this->getLineItems(),  | 
                                                        |
| 151 | + 'amount' => [  | 
                                                        |
| 152 | + 'value' => (string) CurrencyManager::normalizeValue($this->transaction->remaining()),  | 
                                                        |
| 153 | + 'currency_code' => $this->currency_code,  | 
                                                        |
| 154 | + 'breakdown' => $this->getBreakdown(),  | 
                                                        |
| 155 | + ],  | 
                                                        |
| 156 | + ],  | 
                                                        |
| 157 | + ],  | 
                                                        |
| 158 | + 'application_context' => [  | 
                                                        |
| 159 | + 'shipping_preference' => 'NO_SHIPPING',  | 
                                                        |
| 160 | + 'user_action' => 'PAY_NOW',  | 
                                                        |
| 161 | + ],  | 
                                                        |
| 162 | + 'payer' => [  | 
                                                        |
| 163 | + 'email_address' => $attendee->email(),  | 
                                                        |
| 164 | + 'name' => [  | 
                                                        |
| 165 | + 'given_name' => $attendee->fname(),  | 
                                                        |
| 166 | + 'surname' => $attendee->lname(),  | 
                                                        |
| 167 | 167 | |
| 168 | - ],  | 
                                                        |
| 169 | - ],  | 
                                                        |
| 170 | - ];  | 
                                                        |
| 171 | - // Do we have the permissions for the fees ?  | 
                                                        |
| 172 | - $scopes = PayPalExtraMetaManager::getPmOption(  | 
                                                        |
| 173 | - $this->transaction->payment_method(),  | 
                                                        |
| 174 | - Domain::META_KEY_AUTHORIZED_SCOPES  | 
                                                        |
| 175 | - );  | 
                                                        |
| 176 | - if (  | 
                                                        |
| 177 | - (  | 
                                                        |
| 178 | -                (defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES) | 
                                                        |
| 179 | -                || (! defined('EE_PPC_USE_PAYMENT_FEES') | 
                                                        |
| 180 | - && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES)  | 
                                                        |
| 181 | - )  | 
                                                        |
| 182 | - )  | 
                                                        |
| 183 | -            && ! empty($scopes) && in_array('partnerfee', $scopes) | 
                                                        |
| 184 | -        ) { | 
                                                        |
| 185 | - /** @var PartnerPaymentFees $payment_fees */  | 
                                                        |
| 186 | - $payment_fees = LoaderFactory::getShared(PartnerPaymentFees::class);  | 
                                                        |
| 187 | - $parameters['purchase_units'][0]['payment_instruction'] = [  | 
                                                        |
| 188 | - 'platform_fees' => [  | 
                                                        |
| 189 | - [  | 
                                                        |
| 190 | - 'amount' => [  | 
                                                        |
| 191 | - 'value' => (string) $payment_fees->getPartnerFee($this->transaction),  | 
                                                        |
| 192 | - 'currency_code' => $this->currency_code,  | 
                                                        |
| 193 | - ],  | 
                                                        |
| 194 | - ],  | 
                                                        |
| 195 | - ]  | 
                                                        |
| 196 | - ];  | 
                                                        |
| 197 | - }  | 
                                                        |
| 198 | - return $parameters;  | 
                                                        |
| 199 | - }  | 
                                                        |
| 168 | + ],  | 
                                                        |
| 169 | + ],  | 
                                                        |
| 170 | + ];  | 
                                                        |
| 171 | + // Do we have the permissions for the fees ?  | 
                                                        |
| 172 | + $scopes = PayPalExtraMetaManager::getPmOption(  | 
                                                        |
| 173 | + $this->transaction->payment_method(),  | 
                                                        |
| 174 | + Domain::META_KEY_AUTHORIZED_SCOPES  | 
                                                        |
| 175 | + );  | 
                                                        |
| 176 | + if (  | 
                                                        |
| 177 | + (  | 
                                                        |
| 178 | +				(defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES) | 
                                                        |
| 179 | +				|| (! defined('EE_PPC_USE_PAYMENT_FEES') | 
                                                        |
| 180 | + && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES)  | 
                                                        |
| 181 | + )  | 
                                                        |
| 182 | + )  | 
                                                        |
| 183 | +			&& ! empty($scopes) && in_array('partnerfee', $scopes) | 
                                                        |
| 184 | +		) { | 
                                                        |
| 185 | + /** @var PartnerPaymentFees $payment_fees */  | 
                                                        |
| 186 | + $payment_fees = LoaderFactory::getShared(PartnerPaymentFees::class);  | 
                                                        |
| 187 | + $parameters['purchase_units'][0]['payment_instruction'] = [  | 
                                                        |
| 188 | + 'platform_fees' => [  | 
                                                        |
| 189 | + [  | 
                                                        |
| 190 | + 'amount' => [  | 
                                                        |
| 191 | + 'value' => (string) $payment_fees->getPartnerFee($this->transaction),  | 
                                                        |
| 192 | + 'currency_code' => $this->currency_code,  | 
                                                        |
| 193 | + ],  | 
                                                        |
| 194 | + ],  | 
                                                        |
| 195 | + ]  | 
                                                        |
| 196 | + ];  | 
                                                        |
| 197 | + }  | 
                                                        |
| 198 | + return $parameters;  | 
                                                        |
| 199 | + }  | 
                                                        |
| 200 | 200 | |
| 201 | 201 | |
| 202 | - /**  | 
                                                        |
| 203 | - * Itemize the payment. List all the line items, discounts and taxes.  | 
                                                        |
| 204 | - *  | 
                                                        |
| 205 | - * @return array  | 
                                                        |
| 206 | - * @throws EE_Error|ReflectionException  | 
                                                        |
| 207 | - */  | 
                                                        |
| 208 | - protected function getLineItems(): array  | 
                                                        |
| 209 | -    { | 
                                                        |
| 210 | - // Order line items.  | 
                                                        |
| 211 | - $line_items = [];  | 
                                                        |
| 212 | - $event_line_items = $this->transaction->items_purchased();  | 
                                                        |
| 213 | - // List actual line items.  | 
                                                        |
| 214 | -        foreach ($event_line_items as $line_item) { | 
                                                        |
| 215 | - if (  | 
                                                        |
| 216 | - $line_item instanceof EE_Line_Item  | 
                                                        |
| 217 | - && $line_item->OBJ_type() !== 'Promotion'  | 
                                                        |
| 218 | - && $line_item->quantity() > 0  | 
                                                        |
| 219 | -            ) { | 
                                                        |
| 220 | - $item_money = CurrencyManager::normalizeValue($line_item->unit_price());  | 
                                                        |
| 221 | -                $li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso'); | 
                                                        |
| 222 | - $line_items [] = [  | 
                                                        |
| 223 | - 'name' => substr(wp_strip_all_tags($line_item->name()), 0, 126),  | 
                                                        |
| 224 | - 'quantity' => $line_item->quantity(),  | 
                                                        |
| 225 | - 'description' => substr(wp_strip_all_tags($li_description), 0, 125),  | 
                                                        |
| 226 | - 'unit_amount' => [  | 
                                                        |
| 227 | - 'currency_code' => $this->currency_code,  | 
                                                        |
| 228 | - 'value' => (string) $item_money,  | 
                                                        |
| 229 | - ],  | 
                                                        |
| 230 | - 'category' => 'DIGITAL_GOODS',  | 
                                                        |
| 231 | - ];  | 
                                                        |
| 232 | - // Line item total.  | 
                                                        |
| 233 | - $this->items_total += $line_item->pretaxTotal();  | 
                                                        |
| 234 | -            } elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) { | 
                                                        |
| 235 | - // Promotions total.  | 
                                                        |
| 236 | - $this->promos_total += $line_item->total();  | 
                                                        |
| 237 | - }  | 
                                                        |
| 238 | - }  | 
                                                        |
| 239 | - // Make sure we have an absolute number with only two decimal laces.  | 
                                                        |
| 240 | - $this->items_total = CurrencyManager::normalizeValue($this->items_total);  | 
                                                        |
| 241 | - $this->promos_total = CurrencyManager::normalizeValue($this->promos_total);  | 
                                                        |
| 242 | - // If this is a partial payment, apply the paid amount as a promo.  | 
                                                        |
| 243 | -        if ($this->transaction->paid() > 0) { | 
                                                        |
| 244 | - $this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid());  | 
                                                        |
| 245 | - }  | 
                                                        |
| 246 | - $this->countTaxTotal();  | 
                                                        |
| 247 | - return $line_items;  | 
                                                        |
| 248 | - }  | 
                                                        |
| 202 | + /**  | 
                                                        |
| 203 | + * Itemize the payment. List all the line items, discounts and taxes.  | 
                                                        |
| 204 | + *  | 
                                                        |
| 205 | + * @return array  | 
                                                        |
| 206 | + * @throws EE_Error|ReflectionException  | 
                                                        |
| 207 | + */  | 
                                                        |
| 208 | + protected function getLineItems(): array  | 
                                                        |
| 209 | +	{ | 
                                                        |
| 210 | + // Order line items.  | 
                                                        |
| 211 | + $line_items = [];  | 
                                                        |
| 212 | + $event_line_items = $this->transaction->items_purchased();  | 
                                                        |
| 213 | + // List actual line items.  | 
                                                        |
| 214 | +		foreach ($event_line_items as $line_item) { | 
                                                        |
| 215 | + if (  | 
                                                        |
| 216 | + $line_item instanceof EE_Line_Item  | 
                                                        |
| 217 | + && $line_item->OBJ_type() !== 'Promotion'  | 
                                                        |
| 218 | + && $line_item->quantity() > 0  | 
                                                        |
| 219 | +			) { | 
                                                        |
| 220 | + $item_money = CurrencyManager::normalizeValue($line_item->unit_price());  | 
                                                        |
| 221 | +				$li_description = $line_item->desc() ?? esc_html__('Event Ticket', 'event_espresso'); | 
                                                        |
| 222 | + $line_items [] = [  | 
                                                        |
| 223 | + 'name' => substr(wp_strip_all_tags($line_item->name()), 0, 126),  | 
                                                        |
| 224 | + 'quantity' => $line_item->quantity(),  | 
                                                        |
| 225 | + 'description' => substr(wp_strip_all_tags($li_description), 0, 125),  | 
                                                        |
| 226 | + 'unit_amount' => [  | 
                                                        |
| 227 | + 'currency_code' => $this->currency_code,  | 
                                                        |
| 228 | + 'value' => (string) $item_money,  | 
                                                        |
| 229 | + ],  | 
                                                        |
| 230 | + 'category' => 'DIGITAL_GOODS',  | 
                                                        |
| 231 | + ];  | 
                                                        |
| 232 | + // Line item total.  | 
                                                        |
| 233 | + $this->items_total += $line_item->pretaxTotal();  | 
                                                        |
| 234 | +			} elseif ($line_item->OBJ_type() === 'Promotion' && $line_item->quantity() > 0) { | 
                                                        |
| 235 | + // Promotions total.  | 
                                                        |
| 236 | + $this->promos_total += $line_item->total();  | 
                                                        |
| 237 | + }  | 
                                                        |
| 238 | + }  | 
                                                        |
| 239 | + // Make sure we have an absolute number with only two decimal laces.  | 
                                                        |
| 240 | + $this->items_total = CurrencyManager::normalizeValue($this->items_total);  | 
                                                        |
| 241 | + $this->promos_total = CurrencyManager::normalizeValue($this->promos_total);  | 
                                                        |
| 242 | + // If this is a partial payment, apply the paid amount as a promo.  | 
                                                        |
| 243 | +		if ($this->transaction->paid() > 0) { | 
                                                        |
| 244 | + $this->promos_total += CurrencyManager::normalizeValue($this->transaction->paid());  | 
                                                        |
| 245 | + }  | 
                                                        |
| 246 | + $this->countTaxTotal();  | 
                                                        |
| 247 | + return $line_items;  | 
                                                        |
| 248 | + }  | 
                                                        |
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /**  | 
                                                        |
| 252 | - * Count the tax total.  | 
                                                        |
| 253 | - *  | 
                                                        |
| 254 | - * @return void  | 
                                                        |
| 255 | - * @throws EE_Error|ReflectionException  | 
                                                        |
| 256 | - */  | 
                                                        |
| 257 | - protected function countTaxTotal(): void  | 
                                                        |
| 258 | -    { | 
                                                        |
| 259 | - // List taxes.  | 
                                                        |
| 260 | - $this->tax_total = 0.0;  | 
                                                        |
| 261 | - $tax_items = $this->transaction->tax_items();  | 
                                                        |
| 262 | -        foreach ($tax_items as $tax_item) { | 
                                                        |
| 263 | - $this->tax_total += $tax_item->total();  | 
                                                        |
| 264 | - }  | 
                                                        |
| 265 | - $this->tax_total = CurrencyManager::normalizeValue($this->tax_total);  | 
                                                        |
| 266 | - }  | 
                                                        |
| 251 | + /**  | 
                                                        |
| 252 | + * Count the tax total.  | 
                                                        |
| 253 | + *  | 
                                                        |
| 254 | + * @return void  | 
                                                        |
| 255 | + * @throws EE_Error|ReflectionException  | 
                                                        |
| 256 | + */  | 
                                                        |
| 257 | + protected function countTaxTotal(): void  | 
                                                        |
| 258 | +	{ | 
                                                        |
| 259 | + // List taxes.  | 
                                                        |
| 260 | + $this->tax_total = 0.0;  | 
                                                        |
| 261 | + $tax_items = $this->transaction->tax_items();  | 
                                                        |
| 262 | +		foreach ($tax_items as $tax_item) { | 
                                                        |
| 263 | + $this->tax_total += $tax_item->total();  | 
                                                        |
| 264 | + }  | 
                                                        |
| 265 | + $this->tax_total = CurrencyManager::normalizeValue($this->tax_total);  | 
                                                        |
| 266 | + }  | 
                                                        |
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /**  | 
                                                        |
| 270 | - * Itemize the payment the breakdown list.  | 
                                                        |
| 271 | - *  | 
                                                        |
| 272 | - * @return array  | 
                                                        |
| 273 | - */  | 
                                                        |
| 274 | - protected function getBreakdown(): array  | 
                                                        |
| 275 | -    { | 
                                                        |
| 276 | - $breakdown['item_total'] = [  | 
                                                        |
| 277 | - 'currency_code' => $this->currency_code,  | 
                                                        |
| 278 | - 'value' => (string) $this->items_total,  | 
                                                        |
| 279 | - ];  | 
                                                        |
| 280 | - $breakdown['tax_total'] = [  | 
                                                        |
| 281 | - 'currency_code' => $this->currency_code,  | 
                                                        |
| 282 | - 'value' => (string) $this->tax_total,  | 
                                                        |
| 283 | - ];  | 
                                                        |
| 284 | - $breakdown['discount'] = [  | 
                                                        |
| 285 | - 'currency_code' => $this->currency_code,  | 
                                                        |
| 286 | - 'value' => (string) abs($this->promos_total),  | 
                                                        |
| 287 | - ];  | 
                                                        |
| 288 | - return $breakdown;  | 
                                                        |
| 289 | - }  | 
                                                        |
| 269 | + /**  | 
                                                        |
| 270 | + * Itemize the payment the breakdown list.  | 
                                                        |
| 271 | + *  | 
                                                        |
| 272 | + * @return array  | 
                                                        |
| 273 | + */  | 
                                                        |
| 274 | + protected function getBreakdown(): array  | 
                                                        |
| 275 | +	{ | 
                                                        |
| 276 | + $breakdown['item_total'] = [  | 
                                                        |
| 277 | + 'currency_code' => $this->currency_code,  | 
                                                        |
| 278 | + 'value' => (string) $this->items_total,  | 
                                                        |
| 279 | + ];  | 
                                                        |
| 280 | + $breakdown['tax_total'] = [  | 
                                                        |
| 281 | + 'currency_code' => $this->currency_code,  | 
                                                        |
| 282 | + 'value' => (string) $this->tax_total,  | 
                                                        |
| 283 | + ];  | 
                                                        |
| 284 | + $breakdown['discount'] = [  | 
                                                        |
| 285 | + 'currency_code' => $this->currency_code,  | 
                                                        |
| 286 | + 'value' => (string) abs($this->promos_total),  | 
                                                        |
| 287 | + ];  | 
                                                        |
| 288 | + return $breakdown;  | 
                                                        |
| 289 | + }  | 
                                                        |
| 290 | 290 | |
| 291 | 291 | |
| 292 | - /**  | 
                                                        |
| 293 | - * Makes sure that we have received an Order back from the API call.  | 
                                                        |
| 294 | - *  | 
                                                        |
| 295 | - * @param $response  | 
                                                        |
| 296 | - * @param $parameters  | 
                                                        |
| 297 | - * @return array  | 
                                                        |
| 298 | - * @throws EE_Error  | 
                                                        |
| 299 | - * @throws ReflectionException  | 
                                                        |
| 300 | - */  | 
                                                        |
| 301 | - public function validateOrder($response, $parameters): array  | 
                                                        |
| 302 | -    { | 
                                                        |
| 303 | - PayPalLogger::errorLog(  | 
                                                        |
| 304 | -            esc_html__('Validating Order Create:', 'event_espresso'), | 
                                                        |
| 305 | - [$this->request_url, $response],  | 
                                                        |
| 306 | - $this->transaction->payment_method(),  | 
                                                        |
| 307 | - false,  | 
                                                        |
| 308 | - $this->transaction  | 
                                                        |
| 309 | - );  | 
                                                        |
| 310 | -        if (! empty($response['error'])) { | 
                                                        |
| 311 | - return $response;  | 
                                                        |
| 312 | - }  | 
                                                        |
| 313 | -        if (! isset($response['id'])) { | 
                                                        |
| 314 | -            $message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso'); | 
                                                        |
| 315 | -            try { | 
                                                        |
| 316 | - PayPalLogger::errorLog(  | 
                                                        |
| 317 | - $message,  | 
                                                        |
| 318 | - [$this->request_url, $parameters, $response],  | 
                                                        |
| 319 | - $this->transaction->payment_method()  | 
                                                        |
| 320 | - );  | 
                                                        |
| 321 | -            } catch (EE_Error | ReflectionException $e) { | 
                                                        |
| 322 | -                error_log("PayPalLogger Error: $message: " . json_encode($response)); | 
                                                        |
| 323 | - }  | 
                                                        |
| 324 | - return [  | 
                                                        |
| 325 | - 'error' => $response['error'] ?? 'missing_order',  | 
                                                        |
| 326 | - 'message' => $response['message'] ?? $message,  | 
                                                        |
| 327 | - ];  | 
                                                        |
| 328 | - }  | 
                                                        |
| 329 | - return $response;  | 
                                                        |
| 330 | - }  | 
                                                        |
| 292 | + /**  | 
                                                        |
| 293 | + * Makes sure that we have received an Order back from the API call.  | 
                                                        |
| 294 | + *  | 
                                                        |
| 295 | + * @param $response  | 
                                                        |
| 296 | + * @param $parameters  | 
                                                        |
| 297 | + * @return array  | 
                                                        |
| 298 | + * @throws EE_Error  | 
                                                        |
| 299 | + * @throws ReflectionException  | 
                                                        |
| 300 | + */  | 
                                                        |
| 301 | + public function validateOrder($response, $parameters): array  | 
                                                        |
| 302 | +	{ | 
                                                        |
| 303 | + PayPalLogger::errorLog(  | 
                                                        |
| 304 | +			esc_html__('Validating Order Create:', 'event_espresso'), | 
                                                        |
| 305 | + [$this->request_url, $response],  | 
                                                        |
| 306 | + $this->transaction->payment_method(),  | 
                                                        |
| 307 | + false,  | 
                                                        |
| 308 | + $this->transaction  | 
                                                        |
| 309 | + );  | 
                                                        |
| 310 | +		if (! empty($response['error'])) { | 
                                                        |
| 311 | + return $response;  | 
                                                        |
| 312 | + }  | 
                                                        |
| 313 | +		if (! isset($response['id'])) { | 
                                                        |
| 314 | +			$message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso'); | 
                                                        |
| 315 | +			try { | 
                                                        |
| 316 | + PayPalLogger::errorLog(  | 
                                                        |
| 317 | + $message,  | 
                                                        |
| 318 | + [$this->request_url, $parameters, $response],  | 
                                                        |
| 319 | + $this->transaction->payment_method()  | 
                                                        |
| 320 | + );  | 
                                                        |
| 321 | +			} catch (EE_Error | ReflectionException $e) { | 
                                                        |
| 322 | +				error_log("PayPalLogger Error: $message: " . json_encode($response)); | 
                                                        |
| 323 | + }  | 
                                                        |
| 324 | + return [  | 
                                                        |
| 325 | + 'error' => $response['error'] ?? 'missing_order',  | 
                                                        |
| 326 | + 'message' => $response['message'] ?? $message,  | 
                                                        |
| 327 | + ];  | 
                                                        |
| 328 | + }  | 
                                                        |
| 329 | + return $response;  | 
                                                        |
| 330 | + }  | 
                                                        |
| 331 | 331 | }  | 
                                                        
@@ -103,7 +103,7 @@ discard block  | 
                                                    ||
| 103 | 103 |      { | 
                                                        
| 104 | 104 | $sanitizer = new RequestSanitizer(new Basic());  | 
                                                        
| 105 | 105 |          foreach ($billing_info as $item => $value) { | 
                                                        
| 106 | - $this->billing_info[ $item ] = $sanitizer->clean($value);  | 
                                                        |
| 106 | + $this->billing_info[$item] = $sanitizer->clean($value);  | 
                                                        |
| 107 | 107 | }  | 
                                                        
| 108 | 108 | }  | 
                                                        
| 109 | 109 | |
@@ -141,7 +141,7 @@ discard block  | 
                                                    ||
| 141 | 141 |              esc_html__('Tickets for an event at %1$s', 'event_espresso'), | 
                                                        
| 142 | 142 |              get_bloginfo('name') | 
                                                        
| 143 | 143 | );  | 
                                                        
| 144 | - $parameters = [  | 
                                                        |
| 144 | + $parameters = [  | 
                                                        |
| 145 | 145 | 'intent' => 'CAPTURE',  | 
                                                        
| 146 | 146 | 'purchase_units' => [  | 
                                                        
| 147 | 147 | [  | 
                                                        
@@ -176,7 +176,7 @@ discard block  | 
                                                    ||
| 176 | 176 | if (  | 
                                                        
| 177 | 177 | (  | 
                                                        
| 178 | 178 |                  (defined('EE_PPC_USE_PAYMENT_FEES') && EE_PPC_USE_PAYMENT_FEES) | 
                                                        
| 179 | -                || (! defined('EE_PPC_USE_PAYMENT_FEES') | 
                                                        |
| 179 | +                || ( ! defined('EE_PPC_USE_PAYMENT_FEES') | 
                                                        |
| 180 | 180 | && $this->feature->allowed(FeatureFlag::USE_PAYMENT_PROCESSOR_FEES)  | 
                                                        
| 181 | 181 | )  | 
                                                        
| 182 | 182 | )  | 
                                                        
@@ -277,11 +277,11 @@ discard block  | 
                                                    ||
| 277 | 277 | 'currency_code' => $this->currency_code,  | 
                                                        
| 278 | 278 | 'value' => (string) $this->items_total,  | 
                                                        
| 279 | 279 | ];  | 
                                                        
| 280 | - $breakdown['tax_total'] = [  | 
                                                        |
| 280 | + $breakdown['tax_total'] = [  | 
                                                        |
| 281 | 281 | 'currency_code' => $this->currency_code,  | 
                                                        
| 282 | 282 | 'value' => (string) $this->tax_total,  | 
                                                        
| 283 | 283 | ];  | 
                                                        
| 284 | - $breakdown['discount'] = [  | 
                                                        |
| 284 | + $breakdown['discount'] = [  | 
                                                        |
| 285 | 285 | 'currency_code' => $this->currency_code,  | 
                                                        
| 286 | 286 | 'value' => (string) abs($this->promos_total),  | 
                                                        
| 287 | 287 | ];  | 
                                                        
@@ -307,10 +307,10 @@ discard block  | 
                                                    ||
| 307 | 307 | false,  | 
                                                        
| 308 | 308 | $this->transaction  | 
                                                        
| 309 | 309 | );  | 
                                                        
| 310 | -        if (! empty($response['error'])) { | 
                                                        |
| 310 | +        if ( ! empty($response['error'])) { | 
                                                        |
| 311 | 311 | return $response;  | 
                                                        
| 312 | 312 | }  | 
                                                        
| 313 | -        if (! isset($response['id'])) { | 
                                                        |
| 313 | +        if ( ! isset($response['id'])) { | 
                                                        |
| 314 | 314 |              $message = esc_html__('Unexpected response. Unable to find the order.', 'event_espresso'); | 
                                                        
| 315 | 315 |              try { | 
                                                        
| 316 | 316 | PayPalLogger::errorLog(  | 
                                                        
@@ -319,7 +319,7 @@ discard block  | 
                                                    ||
| 319 | 319 | $this->transaction->payment_method()  | 
                                                        
| 320 | 320 | );  | 
                                                        
| 321 | 321 |              } catch (EE_Error | ReflectionException $e) { | 
                                                        
| 322 | -                error_log("PayPalLogger Error: $message: " . json_encode($response)); | 
                                                        |
| 322 | +                error_log("PayPalLogger Error: $message: ".json_encode($response)); | 
                                                        |
| 323 | 323 | }  | 
                                                        
| 324 | 324 | return [  | 
                                                        
| 325 | 325 | 'error' => $response['error'] ?? 'missing_order',  | 
                                                        
@@ -23,469 +23,469 @@  | 
                                                    ||
| 23 | 23 | */  | 
                                                        
| 24 | 24 | class EED_PayPalCommerce extends EED_Module  | 
                                                        
| 25 | 25 |  { | 
                                                        
| 26 | - /**  | 
                                                        |
| 27 | - * @return EED_Module  | 
                                                        |
| 28 | - * @throws EE_Error  | 
                                                        |
| 29 | - * @throws ReflectionException  | 
                                                        |
| 30 | - */  | 
                                                        |
| 31 | - public static function instance(): EED_Module  | 
                                                        |
| 32 | -    { | 
                                                        |
| 33 | - return parent::get_instance(__CLASS__);  | 
                                                        |
| 34 | - }  | 
                                                        |
| 35 | -  | 
                                                        |
| 36 | -  | 
                                                        |
| 37 | - /**  | 
                                                        |
| 38 | - * Run - initial module setup.  | 
                                                        |
| 39 | - *  | 
                                                        |
| 40 | - * @param WP $WP  | 
                                                        |
| 41 | - * @return void  | 
                                                        |
| 42 | - */  | 
                                                        |
| 43 | - public function run($WP)  | 
                                                        |
| 44 | -    { | 
                                                        |
| 45 | - }  | 
                                                        |
| 46 | -  | 
                                                        |
| 47 | -  | 
                                                        |
| 48 | - /**  | 
                                                        |
| 49 | - * For hooking into EE Core and other modules.  | 
                                                        |
| 50 | - *  | 
                                                        |
| 51 | - * @return void  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - public static function set_hooks(): void  | 
                                                        |
| 54 | -    { | 
                                                        |
| 55 | -        if (DbStatus::isOnline()) { | 
                                                        |
| 56 | - // Don't load PM on the front-end if not Connected.  | 
                                                        |
| 57 | - add_filter(  | 
                                                        |
| 58 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        |
| 59 | - [__CLASS__, 'filterPaymentMethods'],  | 
                                                        |
| 60 | - 100  | 
                                                        |
| 61 | - );  | 
                                                        |
| 62 | - }  | 
                                                        |
| 63 | - }  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | - /**  | 
                                                        |
| 67 | - * For hooking into EE Core and other modules Admin.  | 
                                                        |
| 68 | - *  | 
                                                        |
| 69 | - * @return void  | 
                                                        |
| 70 | - */  | 
                                                        |
| 71 | - public static function set_hooks_admin(): void  | 
                                                        |
| 72 | -    { | 
                                                        |
| 73 | -        if (DbStatus::isOnline()) { | 
                                                        |
| 74 | - // Create an Order.  | 
                                                        |
| 75 | -            add_action('wp_ajax_eeaPPCCreateOrder', [__CLASS__, 'createOrderRequest']); | 
                                                        |
| 76 | -            add_action('wp_ajax_nopriv_eeaPPCCreateOrder', [__CLASS__, 'createOrderRequest']); | 
                                                        |
| 77 | - // Log errors from the JS side.  | 
                                                        |
| 78 | -            add_action('wp_ajax_eeaPPCommerceLogError', [__CLASS__, 'logJsError']); | 
                                                        |
| 79 | -            add_action('wp_ajax_nopriv_eeaPPCommerceLogError', [__CLASS__, 'logJsError']); | 
                                                        |
| 80 | - // Don't load PM in the admin if not Connected.  | 
                                                        |
| 81 | - add_filter(  | 
                                                        |
| 82 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        |
| 83 | - [__CLASS__, 'filterPaymentMethods'],  | 
                                                        |
| 84 | - 100  | 
                                                        |
| 85 | - );  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | - }  | 
                                                        |
| 88 | -  | 
                                                        |
| 89 | -  | 
                                                        |
| 90 | - /**  | 
                                                        |
| 91 | - * Create the order and return its data as JSON.  | 
                                                        |
| 92 | - * (AJAX)  | 
                                                        |
| 93 | - *  | 
                                                        |
| 94 | - * @return void  | 
                                                        |
| 95 | - * @throws EE_Error  | 
                                                        |
| 96 | - * @throws ReflectionException  | 
                                                        |
| 97 | - */  | 
                                                        |
| 98 | - public static function createOrderRequest(): void  | 
                                                        |
| 99 | -    { | 
                                                        |
| 100 | - $paypal_pm = EED_PayPalCommerce::getPaymentMethod();  | 
                                                        |
| 101 | - $post_params = EED_Module::getRequest()->postParams();  | 
                                                        |
| 102 | -        if (! $paypal_pm instanceof EE_Payment_Method) { | 
                                                        |
| 103 | - PayPalLogger::errorLogAndExit(  | 
                                                        |
| 104 | -                esc_html__('Related payment method not found (create Order).', 'event_espresso'), | 
                                                        |
| 105 | - $post_params  | 
                                                        |
| 106 | - );  | 
                                                        |
| 107 | - }  | 
                                                        |
| 108 | - $transaction = EED_PayPalCommerce::getTransaction();  | 
                                                        |
| 109 | - $billing_info = $post_params['billing_info'] ?? [];  | 
                                                        |
| 110 | -        if ($billing_info) { | 
                                                        |
| 111 | - $billing_info_decoded = json_decode(stripslashes($billing_info), true);  | 
                                                        |
| 112 | - $billing_info = is_array($billing_info_decoded) ? $billing_info_decoded : [];  | 
                                                        |
| 113 | - }  | 
                                                        |
| 114 | -        if (! $transaction) { | 
                                                        |
| 115 | - PayPalLogger::errorLogAndExit(  | 
                                                        |
| 116 | -                esc_html__('Transaction info not found.', 'event_espresso'), | 
                                                        |
| 117 | - $post_params,  | 
                                                        |
| 118 | - $paypal_pm  | 
                                                        |
| 119 | - );  | 
                                                        |
| 120 | - }  | 
                                                        |
| 121 | - $order_data = EED_PayPalCommerce::createOrder($transaction, $billing_info, $paypal_pm);  | 
                                                        |
| 122 | - wp_send_json($order_data);  | 
                                                        |
| 123 | - }  | 
                                                        |
| 124 | -  | 
                                                        |
| 125 | -  | 
                                                        |
| 126 | - /**  | 
                                                        |
| 127 | - * Create a new Order using the PP API.  | 
                                                        |
| 128 | - *  | 
                                                        |
| 129 | - * @param EE_Transaction $transaction  | 
                                                        |
| 130 | - * @param array $billing_info  | 
                                                        |
| 131 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 132 | - * @return array  | 
                                                        |
| 133 | - * @throws EE_Error  | 
                                                        |
| 134 | - * @throws ReflectionException  | 
                                                        |
| 135 | - */  | 
                                                        |
| 136 | - public static function createOrder(  | 
                                                        |
| 137 | - EE_Transaction $transaction,  | 
                                                        |
| 138 | - array $billing_info,  | 
                                                        |
| 139 | - EE_Payment_Method $paypal_pm  | 
                                                        |
| 140 | -    ): array { | 
                                                        |
| 141 | - $create_order_api = EED_PayPalCommerce::getCreateOrderApi($transaction, $billing_info, $paypal_pm);  | 
                                                        |
| 142 | -        if (! $create_order_api instanceof CreateOrder) { | 
                                                        |
| 143 | - return [  | 
                                                        |
| 144 | - 'error' => 'CREATE_ORDER_API_FAULT',  | 
                                                        |
| 145 | -                'message' => esc_html__('The Create Order API request fault.', 'event_espresso'), | 
                                                        |
| 146 | - ];  | 
                                                        |
| 147 | - }  | 
                                                        |
| 148 | - // Make sure we have a payment method saved.  | 
                                                        |
| 149 | - $payment_method = EED_PayPalCommerce::getPaymentMethod();  | 
                                                        |
| 150 | -        if ($payment_method->ID()) { | 
                                                        |
| 151 | - $transaction->set_payment_method_ID($payment_method->ID());  | 
                                                        |
| 152 | - }  | 
                                                        |
| 153 | - $order = $create_order_api->create();  | 
                                                        |
| 154 | -        if (isset($order['error'])) { | 
                                                        |
| 155 | - $last_payment = $transaction->last_payment();  | 
                                                        |
| 156 | -            if ($last_payment instanceof EE_Payment) { | 
                                                        |
| 157 | - EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 158 | - $last_payment,  | 
                                                        |
| 159 | - EEM_Payment::status_id_failed,  | 
                                                        |
| 160 | - $order,  | 
                                                        |
| 161 | - $order['error']  | 
                                                        |
| 162 | - );  | 
                                                        |
| 163 | - }  | 
                                                        |
| 164 | - return [  | 
                                                        |
| 165 | - 'error' => 'CREATE_ORDER_API_RESPONSE_ERROR',  | 
                                                        |
| 166 | - 'message' => $order['message'],  | 
                                                        |
| 167 | - ];  | 
                                                        |
| 168 | - }  | 
                                                        |
| 169 | - return [  | 
                                                        |
| 170 | - 'pp_order_id' => $order['id'],  | 
                                                        |
| 171 | - ];  | 
                                                        |
| 172 | - }  | 
                                                        |
| 173 | -  | 
                                                        |
| 174 | -  | 
                                                        |
| 175 | - /**  | 
                                                        |
| 176 | - * Create a new Order using the PP API.  | 
                                                        |
| 177 | - *  | 
                                                        |
| 178 | - * @param EE_Transaction $transaction  | 
                                                        |
| 179 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 180 | - * @param string $order_id  | 
                                                        |
| 181 | - * @return array  | 
                                                        |
| 182 | - * @throws EE_Error  | 
                                                        |
| 183 | - * @throws ReflectionException  | 
                                                        |
| 184 | - */  | 
                                                        |
| 185 | - public static function captureOrder(  | 
                                                        |
| 186 | - EE_Transaction $transaction,  | 
                                                        |
| 187 | - EE_Payment_Method $paypal_pm,  | 
                                                        |
| 188 | - string $order_id  | 
                                                        |
| 189 | -    ): array { | 
                                                        |
| 190 | - $capture_order_api = EED_PayPalCommerce::getCaptureOrderApi($transaction, $paypal_pm, $order_id);  | 
                                                        |
| 191 | -        if (! $capture_order_api instanceof CaptureOrder) { | 
                                                        |
| 192 | - return [  | 
                                                        |
| 193 | - 'error' => 'CAPTURE_ORDER_API_FAULT',  | 
                                                        |
| 194 | -                'message' => esc_html__('A capture Order API request fault.', 'event_espresso'), | 
                                                        |
| 195 | - ];  | 
                                                        |
| 196 | - }  | 
                                                        |
| 197 | - return $capture_order_api->capture();  | 
                                                        |
| 198 | - }  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | -  | 
                                                        |
| 201 | - /**  | 
                                                        |
| 202 | - * Get Order Details using the PP API.  | 
                                                        |
| 203 | - *  | 
                                                        |
| 204 | - * @param string $order_id  | 
                                                        |
| 205 | - * @param EE_Transaction $transaction  | 
                                                        |
| 206 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 207 | - * @return array  | 
                                                        |
| 208 | - * @throws EE_Error  | 
                                                        |
| 209 | - * @throws ReflectionException  | 
                                                        |
| 210 | - */  | 
                                                        |
| 211 | - public static function getOrderDetails(  | 
                                                        |
| 212 | - string $order_id,  | 
                                                        |
| 213 | - EE_Transaction $transaction,  | 
                                                        |
| 214 | - EE_Payment_Method $paypal_pm  | 
                                                        |
| 215 | -    ): array { | 
                                                        |
| 216 | - $order_details = EED_PayPalCommerce::getOrderDetailsApi($order_id, $transaction, $paypal_pm);  | 
                                                        |
| 217 | -        if (! $order_details instanceof OrderDetails) { | 
                                                        |
| 218 | - return [  | 
                                                        |
| 219 | - 'error' => 'ORDER_DETAILS_API_FAULT',  | 
                                                        |
| 220 | -                'message' => esc_html__('Get Order Details API request fault.', 'event_espresso'), | 
                                                        |
| 221 | - ];  | 
                                                        |
| 222 | - }  | 
                                                        |
| 223 | - return $order_details->get();  | 
                                                        |
| 224 | - }  | 
                                                        |
| 225 | -  | 
                                                        |
| 226 | -  | 
                                                        |
| 227 | - /**  | 
                                                        |
| 228 | - * Initialize and return Create Order API.  | 
                                                        |
| 229 | - *  | 
                                                        |
| 230 | - * @param EE_Transaction $transaction  | 
                                                        |
| 231 | - * @param array $billing_info  | 
                                                        |
| 232 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 233 | - * @return CreateOrder|null  | 
                                                        |
| 234 | - * @throws EE_Error  | 
                                                        |
| 235 | - * @throws ReflectionException  | 
                                                        |
| 236 | - */  | 
                                                        |
| 237 | - public static function getCreateOrderApi(  | 
                                                        |
| 238 | - EE_Transaction $transaction,  | 
                                                        |
| 239 | - array $billing_info,  | 
                                                        |
| 240 | - EE_Payment_Method $paypal_pm  | 
                                                        |
| 241 | -    ): ?CreateOrder { | 
                                                        |
| 242 | - $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 243 | -        if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 244 | - return null;  | 
                                                        |
| 245 | - }  | 
                                                        |
| 246 | - return LoaderFactory::getNew(CreateOrder::class, [$paypal_api, $transaction, $billing_info]);  | 
                                                        |
| 247 | - }  | 
                                                        |
| 248 | -  | 
                                                        |
| 249 | -  | 
                                                        |
| 250 | - /**  | 
                                                        |
| 251 | - * Initialize and return Capture Order API.  | 
                                                        |
| 252 | - *  | 
                                                        |
| 253 | - * @param EE_Transaction $transaction  | 
                                                        |
| 254 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 255 | - * @param string $order_id  | 
                                                        |
| 256 | - * @return CaptureOrder|null  | 
                                                        |
| 257 | - * @throws EE_Error  | 
                                                        |
| 258 | - * @throws ReflectionException  | 
                                                        |
| 259 | - */  | 
                                                        |
| 260 | - public static function getCaptureOrderApi(  | 
                                                        |
| 261 | - EE_Transaction $transaction,  | 
                                                        |
| 262 | - EE_Payment_Method $paypal_pm,  | 
                                                        |
| 263 | - string $order_id  | 
                                                        |
| 264 | -    ): ?CaptureOrder { | 
                                                        |
| 265 | - $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 266 | -        if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 267 | - return null;  | 
                                                        |
| 268 | - }  | 
                                                        |
| 269 | - return LoaderFactory::getNew(CaptureOrder::class, [$paypal_api, $transaction, $order_id]);  | 
                                                        |
| 270 | - }  | 
                                                        |
| 271 | -  | 
                                                        |
| 272 | -  | 
                                                        |
| 273 | - /**  | 
                                                        |
| 274 | - * Initialize and return Order Details API.  | 
                                                        |
| 275 | - *  | 
                                                        |
| 276 | - * @param EE_Transaction $transaction  | 
                                                        |
| 277 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 278 | - * @param string $order_id  | 
                                                        |
| 279 | - * @return OrderDetails|null  | 
                                                        |
| 280 | - * @throws EE_Error  | 
                                                        |
| 281 | - * @throws ReflectionException  | 
                                                        |
| 282 | - */  | 
                                                        |
| 283 | - public static function getOrderDetailsApi(  | 
                                                        |
| 284 | - string $order_id,  | 
                                                        |
| 285 | - EE_Transaction $transaction,  | 
                                                        |
| 286 | - EE_Payment_Method $paypal_pm  | 
                                                        |
| 287 | -    ): ?OrderDetails { | 
                                                        |
| 288 | - $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 289 | -        if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 290 | - return null;  | 
                                                        |
| 291 | - }  | 
                                                        |
| 292 | - return LoaderFactory::getNew(OrderDetails::class, [$paypal_api, $order_id, $transaction]);  | 
                                                        |
| 293 | - }  | 
                                                        |
| 294 | -  | 
                                                        |
| 295 | -  | 
                                                        |
| 296 | - /**  | 
                                                        |
| 297 | - * Return a PayPal API object, or false on failure.  | 
                                                        |
| 298 | - *  | 
                                                        |
| 299 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 300 | - * @return PayPalApi|null  | 
                                                        |
| 301 | - * @throws EE_Error  | 
                                                        |
| 302 | - * @throws ReflectionException  | 
                                                        |
| 303 | - */  | 
                                                        |
| 304 | - public static function getPayPalApi(EE_Payment_Method $paypal_pm): ?PayPalApi  | 
                                                        |
| 305 | -    { | 
                                                        |
| 306 | - // Try getting the first party credentials to determine if this is a first party integration that's active.  | 
                                                        |
| 307 | - $client_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_CLIENT_ID);  | 
                                                        |
| 308 | - $client_secret = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_CLIENT_SECRET);  | 
                                                        |
| 309 | - $bn_code = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_BN_CODE);  | 
                                                        |
| 310 | -        if ($client_id && $client_secret) { | 
                                                        |
| 311 | - return new FirstPartyPayPalApi($client_id, $client_secret, $bn_code, $paypal_pm->debug_mode());  | 
                                                        |
| 312 | - }  | 
                                                        |
| 313 | - // Third party integration credentials:  | 
                                                        |
| 314 | - $access_token = EED_PayPalOnboard::getPartnerAccessToken($paypal_pm);  | 
                                                        |
| 315 | -        if (! $access_token || ! $bn_code) { | 
                                                        |
| 316 | - return null;  | 
                                                        |
| 317 | - }  | 
                                                        |
| 318 | - $partner_client_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PARTNER_CLIENT_ID) ?: '';  | 
                                                        |
| 319 | - $payer_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_SELLER_MERCHANT_ID) ?: '';  | 
                                                        |
| 320 | - return new ThirdPartyPayPalApi(  | 
                                                        |
| 321 | - $access_token,  | 
                                                        |
| 322 | - $bn_code,  | 
                                                        |
| 323 | - $partner_client_id,  | 
                                                        |
| 324 | - $payer_id,  | 
                                                        |
| 325 | - $paypal_pm->debug_mode()  | 
                                                        |
| 326 | - );  | 
                                                        |
| 327 | - }  | 
                                                        |
| 328 | -  | 
                                                        |
| 329 | -  | 
                                                        |
| 330 | - /**  | 
                                                        |
| 331 | - * Requests a client token.  | 
                                                        |
| 332 | - *  | 
                                                        |
| 333 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 334 | - * @return array  | 
                                                        |
| 335 | - * @throws EE_Error  | 
                                                        |
| 336 | - * @throws ReflectionException  | 
                                                        |
| 337 | - */  | 
                                                        |
| 338 | - public static function requestClientToken(EE_Payment_Method $paypal_pm): array  | 
                                                        |
| 339 | -    { | 
                                                        |
| 340 | - $error = ['error' => 'GET_CLIENT_TOKEN_FAULT'];  | 
                                                        |
| 341 | - $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 342 | -        if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 343 | -            $error['message'] = esc_html__('Got an error while trying to get the client token.', 'event_espresso'); | 
                                                        |
| 344 | - return $error;  | 
                                                        |
| 345 | - }  | 
                                                        |
| 346 | - $client_token_api = new ClientToken($paypal_api, $paypal_pm->debug_mode());  | 
                                                        |
| 347 | - $client_token = $client_token_api->getToken();  | 
                                                        |
| 348 | -        if (isset($client_token['error'])) { | 
                                                        |
| 349 | - return $client_token;  | 
                                                        |
| 350 | - }  | 
                                                        |
| 351 | -        if (empty($client_token)) { | 
                                                        |
| 352 | -            $error['message'] = esc_html__('Client token not valid.', 'event_espresso'); | 
                                                        |
| 353 | - return $error;  | 
                                                        |
| 354 | - }  | 
                                                        |
| 355 | - return $client_token;  | 
                                                        |
| 356 | - }  | 
                                                        |
| 357 | -  | 
                                                        |
| 358 | -  | 
                                                        |
| 359 | - /**  | 
                                                        |
| 360 | - * Retrieve the payment method from the provided data.  | 
                                                        |
| 361 | - *  | 
                                                        |
| 362 | - * @return EE_Transaction|null  | 
                                                        |
| 363 | - */  | 
                                                        |
| 364 | - public static function getTransaction(): ?EE_Transaction  | 
                                                        |
| 365 | -    { | 
                                                        |
| 366 | -        try { | 
                                                        |
| 367 | -            $txn_id      = EED_Module::getRequest()->getRequestParam('txn_id', 0, DataType::INT); | 
                                                        |
| 368 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id);  | 
                                                        |
| 369 | -            if (! $transaction instanceof EE_Transaction) { | 
                                                        |
| 370 | - PayPalLogger::errorLog(  | 
                                                        |
| 371 | -                    esc_html__('No transaction found by ID:', 'event_espresso'), | 
                                                        |
| 372 | - EED_Module::getRequest()->postParams()  | 
                                                        |
| 373 | - );  | 
                                                        |
| 374 | - return null;  | 
                                                        |
| 375 | - }  | 
                                                        |
| 376 | -        } catch (Exception $e) { | 
                                                        |
| 377 | - return null;  | 
                                                        |
| 378 | - }  | 
                                                        |
| 379 | - return $transaction;  | 
                                                        |
| 380 | - }  | 
                                                        |
| 381 | -  | 
                                                        |
| 382 | -  | 
                                                        |
| 383 | - /**  | 
                                                        |
| 384 | - * Return a PayPal API object, or false on failure.  | 
                                                        |
| 385 | - *  | 
                                                        |
| 386 | - * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 387 | - * @return bool  | 
                                                        |
| 388 | - * @throws EE_Error  | 
                                                        |
| 389 | - * @throws ReflectionException  | 
                                                        |
| 390 | - */  | 
                                                        |
| 391 | - public static function isThirdParty(EE_Payment_Method $paypal_pm): bool  | 
                                                        |
| 392 | -    { | 
                                                        |
| 393 | - $pp_meta_data = PayPalExtraMetaManager::getAllData($paypal_pm);  | 
                                                        |
| 394 | - return ! empty($pp_meta_data[ Domain::META_KEY_SELLER_MERCHANT_ID ])  | 
                                                        |
| 395 | - && ! empty($pp_meta_data[ Domain::META_KEY_ACCESS_TOKEN ]);  | 
                                                        |
| 396 | - }  | 
                                                        |
| 397 | -  | 
                                                        |
| 398 | -  | 
                                                        |
| 399 | - /**  | 
                                                        |
| 400 | - * Retrieve the payment method from the provided data.  | 
                                                        |
| 401 | - *  | 
                                                        |
| 402 | - * @return EE_Payment_Method|null  | 
                                                        |
| 403 | - */  | 
                                                        |
| 404 | - public static function getPaymentMethod(): ?EE_Payment_Method  | 
                                                        |
| 405 | -    { | 
                                                        |
| 406 | -        try { | 
                                                        |
| 407 | - // Check if all required parameters are present.  | 
                                                        |
| 408 | -            $pm_slug        = EED_Module::getRequest()->getRequestParam('payment_method'); | 
                                                        |
| 409 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_slug);  | 
                                                        |
| 410 | -            if ($payment_method instanceof EE_Payment_Method) { | 
                                                        |
| 411 | - return $payment_method;  | 
                                                        |
| 412 | - }  | 
                                                        |
| 413 | -        } catch (Exception $e) { | 
                                                        |
| 414 | - return null;  | 
                                                        |
| 415 | - }  | 
                                                        |
| 416 | - return null;  | 
                                                        |
| 417 | - }  | 
                                                        |
| 418 | -  | 
                                                        |
| 419 | -  | 
                                                        |
| 420 | - /**  | 
                                                        |
| 421 | - * Log JS error.  | 
                                                        |
| 422 | - *  | 
                                                        |
| 423 | - * @return void  | 
                                                        |
| 424 | - */  | 
                                                        |
| 425 | - public static function logJsError(): void  | 
                                                        |
| 426 | -    { | 
                                                        |
| 427 | - // Default to the "first" PayPal checkout PM.  | 
                                                        |
| 428 | - $request = EED_Module::getRequest();  | 
                                                        |
| 429 | -        $pm_slug        = $request->getRequestParam('pm_slug', Domain::PM_SLUG); | 
                                                        |
| 430 | - $payment_method = null;  | 
                                                        |
| 431 | - $txn_id = 'unknown';  | 
                                                        |
| 432 | -        try { | 
                                                        |
| 433 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pm_slug);  | 
                                                        |
| 434 | -            $txn_id         = sanitize_text_field($request->getRequestParam('txn_id', '-')); | 
                                                        |
| 435 | -        } catch (Exception $e) { | 
                                                        |
| 436 | - // Don't throw out anything, log at least something.  | 
                                                        |
| 437 | - }  | 
                                                        |
| 438 | - $transaction = EED_PayPalCommerce::getTransaction();  | 
                                                        |
| 439 | - PayPalLogger::errorLog(  | 
                                                        |
| 440 | - "JS Error on transaction: $txn_id",  | 
                                                        |
| 441 | - $request->postParams(),  | 
                                                        |
| 442 | - $payment_method,  | 
                                                        |
| 443 | - false,  | 
                                                        |
| 444 | - $transaction  | 
                                                        |
| 445 | - );  | 
                                                        |
| 446 | - }  | 
                                                        |
| 447 | -  | 
                                                        |
| 448 | -  | 
                                                        |
| 449 | - /**  | 
                                                        |
| 450 | - * Filter the Payment Methods list.  | 
                                                        |
| 451 | - * if needed, this filter can also supply the $transaction and $scope parameters.  | 
                                                        |
| 452 | - *  | 
                                                        |
| 453 | - * @param EE_Payment_Method[] $payment_methods  | 
                                                        |
| 454 | - * @return array  | 
                                                        |
| 455 | - * @throws EE_Error  | 
                                                        |
| 456 | - * @throws ReflectionException  | 
                                                        |
| 457 | - */  | 
                                                        |
| 458 | - public static function filterPaymentMethods(array $payment_methods): array  | 
                                                        |
| 459 | -    { | 
                                                        |
| 460 | - // Don't allow this PM on the checkout page if not Connected.  | 
                                                        |
| 461 | -        foreach ($payment_methods as $key => $pm) { | 
                                                        |
| 462 | - // It is a PayPal Commerce payment method. Check if it's connected. If not - remove from the list.  | 
                                                        |
| 463 | -            if (str_contains($pm->slug(), Domain::PM_SLUG) && ! EED_PayPalOnboard::isOnboard($pm)) { | 
                                                        |
| 464 | - unset($payment_methods[ $key ]);  | 
                                                        |
| 465 | - }  | 
                                                        |
| 466 | - }  | 
                                                        |
| 467 | - return $payment_methods;  | 
                                                        |
| 468 | - }  | 
                                                        |
| 469 | -  | 
                                                        |
| 470 | -  | 
                                                        |
| 471 | - /**  | 
                                                        |
| 472 | - * Get all active states.  | 
                                                        |
| 473 | - *  | 
                                                        |
| 474 | - * @return array  | 
                                                        |
| 475 | - * @throws EE_Error  | 
                                                        |
| 476 | - * @throws ReflectionException  | 
                                                        |
| 477 | - */  | 
                                                        |
| 478 | - public static function getActiveStates(): array  | 
                                                        |
| 479 | -    { | 
                                                        |
| 480 | - $state_options = [];  | 
                                                        |
| 481 | - $states = EEM_State::instance()->get_all_active_states();  | 
                                                        |
| 482 | -        if (! empty($states)) { | 
                                                        |
| 483 | -            foreach ($states as $numeral => $state) { | 
                                                        |
| 484 | -                if ($state instanceof EE_State) { | 
                                                        |
| 485 | - $state_options[ $numeral ] = $state->abbrev();  | 
                                                        |
| 486 | - }  | 
                                                        |
| 487 | - }  | 
                                                        |
| 488 | - }  | 
                                                        |
| 489 | - return $state_options;  | 
                                                        |
| 490 | - }  | 
                                                        |
| 26 | + /**  | 
                                                        |
| 27 | + * @return EED_Module  | 
                                                        |
| 28 | + * @throws EE_Error  | 
                                                        |
| 29 | + * @throws ReflectionException  | 
                                                        |
| 30 | + */  | 
                                                        |
| 31 | + public static function instance(): EED_Module  | 
                                                        |
| 32 | +	{ | 
                                                        |
| 33 | + return parent::get_instance(__CLASS__);  | 
                                                        |
| 34 | + }  | 
                                                        |
| 35 | +  | 
                                                        |
| 36 | +  | 
                                                        |
| 37 | + /**  | 
                                                        |
| 38 | + * Run - initial module setup.  | 
                                                        |
| 39 | + *  | 
                                                        |
| 40 | + * @param WP $WP  | 
                                                        |
| 41 | + * @return void  | 
                                                        |
| 42 | + */  | 
                                                        |
| 43 | + public function run($WP)  | 
                                                        |
| 44 | +	{ | 
                                                        |
| 45 | + }  | 
                                                        |
| 46 | +  | 
                                                        |
| 47 | +  | 
                                                        |
| 48 | + /**  | 
                                                        |
| 49 | + * For hooking into EE Core and other modules.  | 
                                                        |
| 50 | + *  | 
                                                        |
| 51 | + * @return void  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + public static function set_hooks(): void  | 
                                                        |
| 54 | +	{ | 
                                                        |
| 55 | +		if (DbStatus::isOnline()) { | 
                                                        |
| 56 | + // Don't load PM on the front-end if not Connected.  | 
                                                        |
| 57 | + add_filter(  | 
                                                        |
| 58 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        |
| 59 | + [__CLASS__, 'filterPaymentMethods'],  | 
                                                        |
| 60 | + 100  | 
                                                        |
| 61 | + );  | 
                                                        |
| 62 | + }  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * For hooking into EE Core and other modules Admin.  | 
                                                        |
| 68 | + *  | 
                                                        |
| 69 | + * @return void  | 
                                                        |
| 70 | + */  | 
                                                        |
| 71 | + public static function set_hooks_admin(): void  | 
                                                        |
| 72 | +	{ | 
                                                        |
| 73 | +		if (DbStatus::isOnline()) { | 
                                                        |
| 74 | + // Create an Order.  | 
                                                        |
| 75 | +			add_action('wp_ajax_eeaPPCCreateOrder', [__CLASS__, 'createOrderRequest']); | 
                                                        |
| 76 | +			add_action('wp_ajax_nopriv_eeaPPCCreateOrder', [__CLASS__, 'createOrderRequest']); | 
                                                        |
| 77 | + // Log errors from the JS side.  | 
                                                        |
| 78 | +			add_action('wp_ajax_eeaPPCommerceLogError', [__CLASS__, 'logJsError']); | 
                                                        |
| 79 | +			add_action('wp_ajax_nopriv_eeaPPCommerceLogError', [__CLASS__, 'logJsError']); | 
                                                        |
| 80 | + // Don't load PM in the admin if not Connected.  | 
                                                        |
| 81 | + add_filter(  | 
                                                        |
| 82 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',  | 
                                                        |
| 83 | + [__CLASS__, 'filterPaymentMethods'],  | 
                                                        |
| 84 | + 100  | 
                                                        |
| 85 | + );  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | + }  | 
                                                        |
| 88 | +  | 
                                                        |
| 89 | +  | 
                                                        |
| 90 | + /**  | 
                                                        |
| 91 | + * Create the order and return its data as JSON.  | 
                                                        |
| 92 | + * (AJAX)  | 
                                                        |
| 93 | + *  | 
                                                        |
| 94 | + * @return void  | 
                                                        |
| 95 | + * @throws EE_Error  | 
                                                        |
| 96 | + * @throws ReflectionException  | 
                                                        |
| 97 | + */  | 
                                                        |
| 98 | + public static function createOrderRequest(): void  | 
                                                        |
| 99 | +	{ | 
                                                        |
| 100 | + $paypal_pm = EED_PayPalCommerce::getPaymentMethod();  | 
                                                        |
| 101 | + $post_params = EED_Module::getRequest()->postParams();  | 
                                                        |
| 102 | +		if (! $paypal_pm instanceof EE_Payment_Method) { | 
                                                        |
| 103 | + PayPalLogger::errorLogAndExit(  | 
                                                        |
| 104 | +				esc_html__('Related payment method not found (create Order).', 'event_espresso'), | 
                                                        |
| 105 | + $post_params  | 
                                                        |
| 106 | + );  | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | + $transaction = EED_PayPalCommerce::getTransaction();  | 
                                                        |
| 109 | + $billing_info = $post_params['billing_info'] ?? [];  | 
                                                        |
| 110 | +		if ($billing_info) { | 
                                                        |
| 111 | + $billing_info_decoded = json_decode(stripslashes($billing_info), true);  | 
                                                        |
| 112 | + $billing_info = is_array($billing_info_decoded) ? $billing_info_decoded : [];  | 
                                                        |
| 113 | + }  | 
                                                        |
| 114 | +		if (! $transaction) { | 
                                                        |
| 115 | + PayPalLogger::errorLogAndExit(  | 
                                                        |
| 116 | +				esc_html__('Transaction info not found.', 'event_espresso'), | 
                                                        |
| 117 | + $post_params,  | 
                                                        |
| 118 | + $paypal_pm  | 
                                                        |
| 119 | + );  | 
                                                        |
| 120 | + }  | 
                                                        |
| 121 | + $order_data = EED_PayPalCommerce::createOrder($transaction, $billing_info, $paypal_pm);  | 
                                                        |
| 122 | + wp_send_json($order_data);  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | +  | 
                                                        |
| 125 | +  | 
                                                        |
| 126 | + /**  | 
                                                        |
| 127 | + * Create a new Order using the PP API.  | 
                                                        |
| 128 | + *  | 
                                                        |
| 129 | + * @param EE_Transaction $transaction  | 
                                                        |
| 130 | + * @param array $billing_info  | 
                                                        |
| 131 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 132 | + * @return array  | 
                                                        |
| 133 | + * @throws EE_Error  | 
                                                        |
| 134 | + * @throws ReflectionException  | 
                                                        |
| 135 | + */  | 
                                                        |
| 136 | + public static function createOrder(  | 
                                                        |
| 137 | + EE_Transaction $transaction,  | 
                                                        |
| 138 | + array $billing_info,  | 
                                                        |
| 139 | + EE_Payment_Method $paypal_pm  | 
                                                        |
| 140 | +	): array { | 
                                                        |
| 141 | + $create_order_api = EED_PayPalCommerce::getCreateOrderApi($transaction, $billing_info, $paypal_pm);  | 
                                                        |
| 142 | +		if (! $create_order_api instanceof CreateOrder) { | 
                                                        |
| 143 | + return [  | 
                                                        |
| 144 | + 'error' => 'CREATE_ORDER_API_FAULT',  | 
                                                        |
| 145 | +				'message' => esc_html__('The Create Order API request fault.', 'event_espresso'), | 
                                                        |
| 146 | + ];  | 
                                                        |
| 147 | + }  | 
                                                        |
| 148 | + // Make sure we have a payment method saved.  | 
                                                        |
| 149 | + $payment_method = EED_PayPalCommerce::getPaymentMethod();  | 
                                                        |
| 150 | +		if ($payment_method->ID()) { | 
                                                        |
| 151 | + $transaction->set_payment_method_ID($payment_method->ID());  | 
                                                        |
| 152 | + }  | 
                                                        |
| 153 | + $order = $create_order_api->create();  | 
                                                        |
| 154 | +		if (isset($order['error'])) { | 
                                                        |
| 155 | + $last_payment = $transaction->last_payment();  | 
                                                        |
| 156 | +			if ($last_payment instanceof EE_Payment) { | 
                                                        |
| 157 | + EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 158 | + $last_payment,  | 
                                                        |
| 159 | + EEM_Payment::status_id_failed,  | 
                                                        |
| 160 | + $order,  | 
                                                        |
| 161 | + $order['error']  | 
                                                        |
| 162 | + );  | 
                                                        |
| 163 | + }  | 
                                                        |
| 164 | + return [  | 
                                                        |
| 165 | + 'error' => 'CREATE_ORDER_API_RESPONSE_ERROR',  | 
                                                        |
| 166 | + 'message' => $order['message'],  | 
                                                        |
| 167 | + ];  | 
                                                        |
| 168 | + }  | 
                                                        |
| 169 | + return [  | 
                                                        |
| 170 | + 'pp_order_id' => $order['id'],  | 
                                                        |
| 171 | + ];  | 
                                                        |
| 172 | + }  | 
                                                        |
| 173 | +  | 
                                                        |
| 174 | +  | 
                                                        |
| 175 | + /**  | 
                                                        |
| 176 | + * Create a new Order using the PP API.  | 
                                                        |
| 177 | + *  | 
                                                        |
| 178 | + * @param EE_Transaction $transaction  | 
                                                        |
| 179 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 180 | + * @param string $order_id  | 
                                                        |
| 181 | + * @return array  | 
                                                        |
| 182 | + * @throws EE_Error  | 
                                                        |
| 183 | + * @throws ReflectionException  | 
                                                        |
| 184 | + */  | 
                                                        |
| 185 | + public static function captureOrder(  | 
                                                        |
| 186 | + EE_Transaction $transaction,  | 
                                                        |
| 187 | + EE_Payment_Method $paypal_pm,  | 
                                                        |
| 188 | + string $order_id  | 
                                                        |
| 189 | +	): array { | 
                                                        |
| 190 | + $capture_order_api = EED_PayPalCommerce::getCaptureOrderApi($transaction, $paypal_pm, $order_id);  | 
                                                        |
| 191 | +		if (! $capture_order_api instanceof CaptureOrder) { | 
                                                        |
| 192 | + return [  | 
                                                        |
| 193 | + 'error' => 'CAPTURE_ORDER_API_FAULT',  | 
                                                        |
| 194 | +				'message' => esc_html__('A capture Order API request fault.', 'event_espresso'), | 
                                                        |
| 195 | + ];  | 
                                                        |
| 196 | + }  | 
                                                        |
| 197 | + return $capture_order_api->capture();  | 
                                                        |
| 198 | + }  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | +  | 
                                                        |
| 201 | + /**  | 
                                                        |
| 202 | + * Get Order Details using the PP API.  | 
                                                        |
| 203 | + *  | 
                                                        |
| 204 | + * @param string $order_id  | 
                                                        |
| 205 | + * @param EE_Transaction $transaction  | 
                                                        |
| 206 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 207 | + * @return array  | 
                                                        |
| 208 | + * @throws EE_Error  | 
                                                        |
| 209 | + * @throws ReflectionException  | 
                                                        |
| 210 | + */  | 
                                                        |
| 211 | + public static function getOrderDetails(  | 
                                                        |
| 212 | + string $order_id,  | 
                                                        |
| 213 | + EE_Transaction $transaction,  | 
                                                        |
| 214 | + EE_Payment_Method $paypal_pm  | 
                                                        |
| 215 | +	): array { | 
                                                        |
| 216 | + $order_details = EED_PayPalCommerce::getOrderDetailsApi($order_id, $transaction, $paypal_pm);  | 
                                                        |
| 217 | +		if (! $order_details instanceof OrderDetails) { | 
                                                        |
| 218 | + return [  | 
                                                        |
| 219 | + 'error' => 'ORDER_DETAILS_API_FAULT',  | 
                                                        |
| 220 | +				'message' => esc_html__('Get Order Details API request fault.', 'event_espresso'), | 
                                                        |
| 221 | + ];  | 
                                                        |
| 222 | + }  | 
                                                        |
| 223 | + return $order_details->get();  | 
                                                        |
| 224 | + }  | 
                                                        |
| 225 | +  | 
                                                        |
| 226 | +  | 
                                                        |
| 227 | + /**  | 
                                                        |
| 228 | + * Initialize and return Create Order API.  | 
                                                        |
| 229 | + *  | 
                                                        |
| 230 | + * @param EE_Transaction $transaction  | 
                                                        |
| 231 | + * @param array $billing_info  | 
                                                        |
| 232 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 233 | + * @return CreateOrder|null  | 
                                                        |
| 234 | + * @throws EE_Error  | 
                                                        |
| 235 | + * @throws ReflectionException  | 
                                                        |
| 236 | + */  | 
                                                        |
| 237 | + public static function getCreateOrderApi(  | 
                                                        |
| 238 | + EE_Transaction $transaction,  | 
                                                        |
| 239 | + array $billing_info,  | 
                                                        |
| 240 | + EE_Payment_Method $paypal_pm  | 
                                                        |
| 241 | +	): ?CreateOrder { | 
                                                        |
| 242 | + $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 243 | +		if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 244 | + return null;  | 
                                                        |
| 245 | + }  | 
                                                        |
| 246 | + return LoaderFactory::getNew(CreateOrder::class, [$paypal_api, $transaction, $billing_info]);  | 
                                                        |
| 247 | + }  | 
                                                        |
| 248 | +  | 
                                                        |
| 249 | +  | 
                                                        |
| 250 | + /**  | 
                                                        |
| 251 | + * Initialize and return Capture Order API.  | 
                                                        |
| 252 | + *  | 
                                                        |
| 253 | + * @param EE_Transaction $transaction  | 
                                                        |
| 254 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 255 | + * @param string $order_id  | 
                                                        |
| 256 | + * @return CaptureOrder|null  | 
                                                        |
| 257 | + * @throws EE_Error  | 
                                                        |
| 258 | + * @throws ReflectionException  | 
                                                        |
| 259 | + */  | 
                                                        |
| 260 | + public static function getCaptureOrderApi(  | 
                                                        |
| 261 | + EE_Transaction $transaction,  | 
                                                        |
| 262 | + EE_Payment_Method $paypal_pm,  | 
                                                        |
| 263 | + string $order_id  | 
                                                        |
| 264 | +	): ?CaptureOrder { | 
                                                        |
| 265 | + $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 266 | +		if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 267 | + return null;  | 
                                                        |
| 268 | + }  | 
                                                        |
| 269 | + return LoaderFactory::getNew(CaptureOrder::class, [$paypal_api, $transaction, $order_id]);  | 
                                                        |
| 270 | + }  | 
                                                        |
| 271 | +  | 
                                                        |
| 272 | +  | 
                                                        |
| 273 | + /**  | 
                                                        |
| 274 | + * Initialize and return Order Details API.  | 
                                                        |
| 275 | + *  | 
                                                        |
| 276 | + * @param EE_Transaction $transaction  | 
                                                        |
| 277 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 278 | + * @param string $order_id  | 
                                                        |
| 279 | + * @return OrderDetails|null  | 
                                                        |
| 280 | + * @throws EE_Error  | 
                                                        |
| 281 | + * @throws ReflectionException  | 
                                                        |
| 282 | + */  | 
                                                        |
| 283 | + public static function getOrderDetailsApi(  | 
                                                        |
| 284 | + string $order_id,  | 
                                                        |
| 285 | + EE_Transaction $transaction,  | 
                                                        |
| 286 | + EE_Payment_Method $paypal_pm  | 
                                                        |
| 287 | +	): ?OrderDetails { | 
                                                        |
| 288 | + $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 289 | +		if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 290 | + return null;  | 
                                                        |
| 291 | + }  | 
                                                        |
| 292 | + return LoaderFactory::getNew(OrderDetails::class, [$paypal_api, $order_id, $transaction]);  | 
                                                        |
| 293 | + }  | 
                                                        |
| 294 | +  | 
                                                        |
| 295 | +  | 
                                                        |
| 296 | + /**  | 
                                                        |
| 297 | + * Return a PayPal API object, or false on failure.  | 
                                                        |
| 298 | + *  | 
                                                        |
| 299 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 300 | + * @return PayPalApi|null  | 
                                                        |
| 301 | + * @throws EE_Error  | 
                                                        |
| 302 | + * @throws ReflectionException  | 
                                                        |
| 303 | + */  | 
                                                        |
| 304 | + public static function getPayPalApi(EE_Payment_Method $paypal_pm): ?PayPalApi  | 
                                                        |
| 305 | +	{ | 
                                                        |
| 306 | + // Try getting the first party credentials to determine if this is a first party integration that's active.  | 
                                                        |
| 307 | + $client_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_CLIENT_ID);  | 
                                                        |
| 308 | + $client_secret = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_CLIENT_SECRET);  | 
                                                        |
| 309 | + $bn_code = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_BN_CODE);  | 
                                                        |
| 310 | +		if ($client_id && $client_secret) { | 
                                                        |
| 311 | + return new FirstPartyPayPalApi($client_id, $client_secret, $bn_code, $paypal_pm->debug_mode());  | 
                                                        |
| 312 | + }  | 
                                                        |
| 313 | + // Third party integration credentials:  | 
                                                        |
| 314 | + $access_token = EED_PayPalOnboard::getPartnerAccessToken($paypal_pm);  | 
                                                        |
| 315 | +		if (! $access_token || ! $bn_code) { | 
                                                        |
| 316 | + return null;  | 
                                                        |
| 317 | + }  | 
                                                        |
| 318 | + $partner_client_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_PARTNER_CLIENT_ID) ?: '';  | 
                                                        |
| 319 | + $payer_id = PayPalExtraMetaManager::getPmOption($paypal_pm, Domain::META_KEY_SELLER_MERCHANT_ID) ?: '';  | 
                                                        |
| 320 | + return new ThirdPartyPayPalApi(  | 
                                                        |
| 321 | + $access_token,  | 
                                                        |
| 322 | + $bn_code,  | 
                                                        |
| 323 | + $partner_client_id,  | 
                                                        |
| 324 | + $payer_id,  | 
                                                        |
| 325 | + $paypal_pm->debug_mode()  | 
                                                        |
| 326 | + );  | 
                                                        |
| 327 | + }  | 
                                                        |
| 328 | +  | 
                                                        |
| 329 | +  | 
                                                        |
| 330 | + /**  | 
                                                        |
| 331 | + * Requests a client token.  | 
                                                        |
| 332 | + *  | 
                                                        |
| 333 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 334 | + * @return array  | 
                                                        |
| 335 | + * @throws EE_Error  | 
                                                        |
| 336 | + * @throws ReflectionException  | 
                                                        |
| 337 | + */  | 
                                                        |
| 338 | + public static function requestClientToken(EE_Payment_Method $paypal_pm): array  | 
                                                        |
| 339 | +	{ | 
                                                        |
| 340 | + $error = ['error' => 'GET_CLIENT_TOKEN_FAULT'];  | 
                                                        |
| 341 | + $paypal_api = EED_PayPalCommerce::getPayPalApi($paypal_pm);  | 
                                                        |
| 342 | +		if (! $paypal_api instanceof PayPalApi) { | 
                                                        |
| 343 | +			$error['message'] = esc_html__('Got an error while trying to get the client token.', 'event_espresso'); | 
                                                        |
| 344 | + return $error;  | 
                                                        |
| 345 | + }  | 
                                                        |
| 346 | + $client_token_api = new ClientToken($paypal_api, $paypal_pm->debug_mode());  | 
                                                        |
| 347 | + $client_token = $client_token_api->getToken();  | 
                                                        |
| 348 | +		if (isset($client_token['error'])) { | 
                                                        |
| 349 | + return $client_token;  | 
                                                        |
| 350 | + }  | 
                                                        |
| 351 | +		if (empty($client_token)) { | 
                                                        |
| 352 | +			$error['message'] = esc_html__('Client token not valid.', 'event_espresso'); | 
                                                        |
| 353 | + return $error;  | 
                                                        |
| 354 | + }  | 
                                                        |
| 355 | + return $client_token;  | 
                                                        |
| 356 | + }  | 
                                                        |
| 357 | +  | 
                                                        |
| 358 | +  | 
                                                        |
| 359 | + /**  | 
                                                        |
| 360 | + * Retrieve the payment method from the provided data.  | 
                                                        |
| 361 | + *  | 
                                                        |
| 362 | + * @return EE_Transaction|null  | 
                                                        |
| 363 | + */  | 
                                                        |
| 364 | + public static function getTransaction(): ?EE_Transaction  | 
                                                        |
| 365 | +	{ | 
                                                        |
| 366 | +		try { | 
                                                        |
| 367 | +			$txn_id      = EED_Module::getRequest()->getRequestParam('txn_id', 0, DataType::INT); | 
                                                        |
| 368 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($txn_id);  | 
                                                        |
| 369 | +			if (! $transaction instanceof EE_Transaction) { | 
                                                        |
| 370 | + PayPalLogger::errorLog(  | 
                                                        |
| 371 | +					esc_html__('No transaction found by ID:', 'event_espresso'), | 
                                                        |
| 372 | + EED_Module::getRequest()->postParams()  | 
                                                        |
| 373 | + );  | 
                                                        |
| 374 | + return null;  | 
                                                        |
| 375 | + }  | 
                                                        |
| 376 | +		} catch (Exception $e) { | 
                                                        |
| 377 | + return null;  | 
                                                        |
| 378 | + }  | 
                                                        |
| 379 | + return $transaction;  | 
                                                        |
| 380 | + }  | 
                                                        |
| 381 | +  | 
                                                        |
| 382 | +  | 
                                                        |
| 383 | + /**  | 
                                                        |
| 384 | + * Return a PayPal API object, or false on failure.  | 
                                                        |
| 385 | + *  | 
                                                        |
| 386 | + * @param EE_Payment_Method $paypal_pm  | 
                                                        |
| 387 | + * @return bool  | 
                                                        |
| 388 | + * @throws EE_Error  | 
                                                        |
| 389 | + * @throws ReflectionException  | 
                                                        |
| 390 | + */  | 
                                                        |
| 391 | + public static function isThirdParty(EE_Payment_Method $paypal_pm): bool  | 
                                                        |
| 392 | +	{ | 
                                                        |
| 393 | + $pp_meta_data = PayPalExtraMetaManager::getAllData($paypal_pm);  | 
                                                        |
| 394 | + return ! empty($pp_meta_data[ Domain::META_KEY_SELLER_MERCHANT_ID ])  | 
                                                        |
| 395 | + && ! empty($pp_meta_data[ Domain::META_KEY_ACCESS_TOKEN ]);  | 
                                                        |
| 396 | + }  | 
                                                        |
| 397 | +  | 
                                                        |
| 398 | +  | 
                                                        |
| 399 | + /**  | 
                                                        |
| 400 | + * Retrieve the payment method from the provided data.  | 
                                                        |
| 401 | + *  | 
                                                        |
| 402 | + * @return EE_Payment_Method|null  | 
                                                        |
| 403 | + */  | 
                                                        |
| 404 | + public static function getPaymentMethod(): ?EE_Payment_Method  | 
                                                        |
| 405 | +	{ | 
                                                        |
| 406 | +		try { | 
                                                        |
| 407 | + // Check if all required parameters are present.  | 
                                                        |
| 408 | +			$pm_slug        = EED_Module::getRequest()->getRequestParam('payment_method'); | 
                                                        |
| 409 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_slug);  | 
                                                        |
| 410 | +			if ($payment_method instanceof EE_Payment_Method) { | 
                                                        |
| 411 | + return $payment_method;  | 
                                                        |
| 412 | + }  | 
                                                        |
| 413 | +		} catch (Exception $e) { | 
                                                        |
| 414 | + return null;  | 
                                                        |
| 415 | + }  | 
                                                        |
| 416 | + return null;  | 
                                                        |
| 417 | + }  | 
                                                        |
| 418 | +  | 
                                                        |
| 419 | +  | 
                                                        |
| 420 | + /**  | 
                                                        |
| 421 | + * Log JS error.  | 
                                                        |
| 422 | + *  | 
                                                        |
| 423 | + * @return void  | 
                                                        |
| 424 | + */  | 
                                                        |
| 425 | + public static function logJsError(): void  | 
                                                        |
| 426 | +	{ | 
                                                        |
| 427 | + // Default to the "first" PayPal checkout PM.  | 
                                                        |
| 428 | + $request = EED_Module::getRequest();  | 
                                                        |
| 429 | +		$pm_slug        = $request->getRequestParam('pm_slug', Domain::PM_SLUG); | 
                                                        |
| 430 | + $payment_method = null;  | 
                                                        |
| 431 | + $txn_id = 'unknown';  | 
                                                        |
| 432 | +		try { | 
                                                        |
| 433 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pm_slug);  | 
                                                        |
| 434 | +			$txn_id         = sanitize_text_field($request->getRequestParam('txn_id', '-')); | 
                                                        |
| 435 | +		} catch (Exception $e) { | 
                                                        |
| 436 | + // Don't throw out anything, log at least something.  | 
                                                        |
| 437 | + }  | 
                                                        |
| 438 | + $transaction = EED_PayPalCommerce::getTransaction();  | 
                                                        |
| 439 | + PayPalLogger::errorLog(  | 
                                                        |
| 440 | + "JS Error on transaction: $txn_id",  | 
                                                        |
| 441 | + $request->postParams(),  | 
                                                        |
| 442 | + $payment_method,  | 
                                                        |
| 443 | + false,  | 
                                                        |
| 444 | + $transaction  | 
                                                        |
| 445 | + );  | 
                                                        |
| 446 | + }  | 
                                                        |
| 447 | +  | 
                                                        |
| 448 | +  | 
                                                        |
| 449 | + /**  | 
                                                        |
| 450 | + * Filter the Payment Methods list.  | 
                                                        |
| 451 | + * if needed, this filter can also supply the $transaction and $scope parameters.  | 
                                                        |
| 452 | + *  | 
                                                        |
| 453 | + * @param EE_Payment_Method[] $payment_methods  | 
                                                        |
| 454 | + * @return array  | 
                                                        |
| 455 | + * @throws EE_Error  | 
                                                        |
| 456 | + * @throws ReflectionException  | 
                                                        |
| 457 | + */  | 
                                                        |
| 458 | + public static function filterPaymentMethods(array $payment_methods): array  | 
                                                        |
| 459 | +	{ | 
                                                        |
| 460 | + // Don't allow this PM on the checkout page if not Connected.  | 
                                                        |
| 461 | +		foreach ($payment_methods as $key => $pm) { | 
                                                        |
| 462 | + // It is a PayPal Commerce payment method. Check if it's connected. If not - remove from the list.  | 
                                                        |
| 463 | +			if (str_contains($pm->slug(), Domain::PM_SLUG) && ! EED_PayPalOnboard::isOnboard($pm)) { | 
                                                        |
| 464 | + unset($payment_methods[ $key ]);  | 
                                                        |
| 465 | + }  | 
                                                        |
| 466 | + }  | 
                                                        |
| 467 | + return $payment_methods;  | 
                                                        |
| 468 | + }  | 
                                                        |
| 469 | +  | 
                                                        |
| 470 | +  | 
                                                        |
| 471 | + /**  | 
                                                        |
| 472 | + * Get all active states.  | 
                                                        |
| 473 | + *  | 
                                                        |
| 474 | + * @return array  | 
                                                        |
| 475 | + * @throws EE_Error  | 
                                                        |
| 476 | + * @throws ReflectionException  | 
                                                        |
| 477 | + */  | 
                                                        |
| 478 | + public static function getActiveStates(): array  | 
                                                        |
| 479 | +	{ | 
                                                        |
| 480 | + $state_options = [];  | 
                                                        |
| 481 | + $states = EEM_State::instance()->get_all_active_states();  | 
                                                        |
| 482 | +		if (! empty($states)) { | 
                                                        |
| 483 | +			foreach ($states as $numeral => $state) { | 
                                                        |
| 484 | +				if ($state instanceof EE_State) { | 
                                                        |
| 485 | + $state_options[ $numeral ] = $state->abbrev();  | 
                                                        |
| 486 | + }  | 
                                                        |
| 487 | + }  | 
                                                        |
| 488 | + }  | 
                                                        |
| 489 | + return $state_options;  | 
                                                        |
| 490 | + }  | 
                                                        |
| 491 | 491 | }  | 
                                                        
@@ -13,310 +13,310 @@  | 
                                                    ||
| 13 | 13 | */  | 
                                                        
| 14 | 14 | class EEG_PayPalCheckout extends EE_Onsite_Gateway  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | - /**  | 
                                                        |
| 17 | - * Currencies supported by this gateway.  | 
                                                        |
| 18 | - *  | 
                                                        |
| 19 | - * @var array  | 
                                                        |
| 20 | - */  | 
                                                        |
| 21 | - protected $_currencies_supported = [  | 
                                                        |
| 22 | - 'AUD',  | 
                                                        |
| 23 | - 'BRL',  | 
                                                        |
| 24 | - 'CAD',  | 
                                                        |
| 25 | - 'CNY',  | 
                                                        |
| 26 | - 'CZK',  | 
                                                        |
| 27 | - 'DKK',  | 
                                                        |
| 28 | - 'EUR',  | 
                                                        |
| 29 | - 'HKD',  | 
                                                        |
| 30 | - 'HUF',  | 
                                                        |
| 31 | - 'ILS',  | 
                                                        |
| 32 | - 'JPY',  | 
                                                        |
| 33 | - 'MYR',  | 
                                                        |
| 34 | - 'MXN',  | 
                                                        |
| 35 | - 'TWD',  | 
                                                        |
| 36 | - 'NZD',  | 
                                                        |
| 37 | - 'NOK',  | 
                                                        |
| 38 | - 'PHP',  | 
                                                        |
| 39 | - 'PLN',  | 
                                                        |
| 40 | - 'GBP',  | 
                                                        |
| 41 | - 'RUB',  | 
                                                        |
| 42 | - 'SGD',  | 
                                                        |
| 43 | - 'SEK',  | 
                                                        |
| 44 | - 'CHF',  | 
                                                        |
| 45 | - 'THB',  | 
                                                        |
| 46 | - 'USD',  | 
                                                        |
| 47 | - ];  | 
                                                        |
| 16 | + /**  | 
                                                        |
| 17 | + * Currencies supported by this gateway.  | 
                                                        |
| 18 | + *  | 
                                                        |
| 19 | + * @var array  | 
                                                        |
| 20 | + */  | 
                                                        |
| 21 | + protected $_currencies_supported = [  | 
                                                        |
| 22 | + 'AUD',  | 
                                                        |
| 23 | + 'BRL',  | 
                                                        |
| 24 | + 'CAD',  | 
                                                        |
| 25 | + 'CNY',  | 
                                                        |
| 26 | + 'CZK',  | 
                                                        |
| 27 | + 'DKK',  | 
                                                        |
| 28 | + 'EUR',  | 
                                                        |
| 29 | + 'HKD',  | 
                                                        |
| 30 | + 'HUF',  | 
                                                        |
| 31 | + 'ILS',  | 
                                                        |
| 32 | + 'JPY',  | 
                                                        |
| 33 | + 'MYR',  | 
                                                        |
| 34 | + 'MXN',  | 
                                                        |
| 35 | + 'TWD',  | 
                                                        |
| 36 | + 'NZD',  | 
                                                        |
| 37 | + 'NOK',  | 
                                                        |
| 38 | + 'PHP',  | 
                                                        |
| 39 | + 'PLN',  | 
                                                        |
| 40 | + 'GBP',  | 
                                                        |
| 41 | + 'RUB',  | 
                                                        |
| 42 | + 'SGD',  | 
                                                        |
| 43 | + 'SEK',  | 
                                                        |
| 44 | + 'CHF',  | 
                                                        |
| 45 | + 'THB',  | 
                                                        |
| 46 | + 'USD',  | 
                                                        |
| 47 | + ];  | 
                                                        |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /**  | 
                                                        |
| 51 | - * Override the parent.  | 
                                                        |
| 52 | - *  | 
                                                        |
| 53 | - * @param EE_Payment|null $payment  | 
                                                        |
| 54 | - * @param array|null $billing_info  | 
                                                        |
| 55 | - * @return EE_Payment  | 
                                                        |
| 56 | - * @throws EE_Error|ReflectionException  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - public function do_direct_payment($payment, $billing_info = null)  | 
                                                        |
| 59 | -    { | 
                                                        |
| 60 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);  | 
                                                        |
| 61 | - $post_parameters = $request->postParams();  | 
                                                        |
| 62 | - // Check the payment.  | 
                                                        |
| 63 | - $payment = $this->validatePayment($payment, $request);  | 
                                                        |
| 64 | -        if ($payment->details() === 'error' && $payment->status() === EEM_Payment::status_id_failed) { | 
                                                        |
| 65 | - return $payment;  | 
                                                        |
| 66 | - }  | 
                                                        |
| 67 | - $transaction = $payment->transaction();  | 
                                                        |
| 68 | - $payment_method = $transaction->payment_method();  | 
                                                        |
| 69 | - // Get the order details.  | 
                                                        |
| 70 | -        $order_id = $request->getRequestParam('pp_order_id'); | 
                                                        |
| 71 | -        if (! $order_id) { | 
                                                        |
| 72 | - return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 73 | - $payment,  | 
                                                        |
| 74 | - EEM_Payment::status_id_declined,  | 
                                                        |
| 75 | - $post_parameters,  | 
                                                        |
| 76 | -                esc_html__('Can\'t charge the Order. The Order ID is missing.', 'event_espresso') | 
                                                        |
| 77 | - );  | 
                                                        |
| 78 | - }  | 
                                                        |
| 79 | - // Capture the order.  | 
                                                        |
| 80 | - $capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);  | 
                                                        |
| 81 | - // Check the order status.  | 
                                                        |
| 82 | - $order_status = $this->isOrderCompleted($order_id, $transaction, $payment_method);  | 
                                                        |
| 83 | -        if (! $order_status['completed']) { | 
                                                        |
| 84 | - return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 85 | - $payment,  | 
                                                        |
| 86 | - EEM_Payment::status_id_declined,  | 
                                                        |
| 87 | - $order_status,  | 
                                                        |
| 88 | - $order_status['message'] ?? ''  | 
                                                        |
| 89 | - );  | 
                                                        |
| 90 | - }  | 
                                                        |
| 91 | - // Looks like all is good. Mark payment as a success.  | 
                                                        |
| 92 | - $this->saveBillingDetails($payment, $transaction, $order_status['details'], $billing_info);  | 
                                                        |
| 93 | - return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $capture_status);  | 
                                                        |
| 94 | - }  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * Override the parent.  | 
                                                        |
| 52 | + *  | 
                                                        |
| 53 | + * @param EE_Payment|null $payment  | 
                                                        |
| 54 | + * @param array|null $billing_info  | 
                                                        |
| 55 | + * @return EE_Payment  | 
                                                        |
| 56 | + * @throws EE_Error|ReflectionException  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + public function do_direct_payment($payment, $billing_info = null)  | 
                                                        |
| 59 | +	{ | 
                                                        |
| 60 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);  | 
                                                        |
| 61 | + $post_parameters = $request->postParams();  | 
                                                        |
| 62 | + // Check the payment.  | 
                                                        |
| 63 | + $payment = $this->validatePayment($payment, $request);  | 
                                                        |
| 64 | +		if ($payment->details() === 'error' && $payment->status() === EEM_Payment::status_id_failed) { | 
                                                        |
| 65 | + return $payment;  | 
                                                        |
| 66 | + }  | 
                                                        |
| 67 | + $transaction = $payment->transaction();  | 
                                                        |
| 68 | + $payment_method = $transaction->payment_method();  | 
                                                        |
| 69 | + // Get the order details.  | 
                                                        |
| 70 | +		$order_id = $request->getRequestParam('pp_order_id'); | 
                                                        |
| 71 | +		if (! $order_id) { | 
                                                        |
| 72 | + return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 73 | + $payment,  | 
                                                        |
| 74 | + EEM_Payment::status_id_declined,  | 
                                                        |
| 75 | + $post_parameters,  | 
                                                        |
| 76 | +				esc_html__('Can\'t charge the Order. The Order ID is missing.', 'event_espresso') | 
                                                        |
| 77 | + );  | 
                                                        |
| 78 | + }  | 
                                                        |
| 79 | + // Capture the order.  | 
                                                        |
| 80 | + $capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);  | 
                                                        |
| 81 | + // Check the order status.  | 
                                                        |
| 82 | + $order_status = $this->isOrderCompleted($order_id, $transaction, $payment_method);  | 
                                                        |
| 83 | +		if (! $order_status['completed']) { | 
                                                        |
| 84 | + return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 85 | + $payment,  | 
                                                        |
| 86 | + EEM_Payment::status_id_declined,  | 
                                                        |
| 87 | + $order_status,  | 
                                                        |
| 88 | + $order_status['message'] ?? ''  | 
                                                        |
| 89 | + );  | 
                                                        |
| 90 | + }  | 
                                                        |
| 91 | + // Looks like all is good. Mark payment as a success.  | 
                                                        |
| 92 | + $this->saveBillingDetails($payment, $transaction, $order_status['details'], $billing_info);  | 
                                                        |
| 93 | + return EEG_PayPalCheckout::updatePaymentStatus($payment, EEM_Payment::status_id_approved, $capture_status);  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | 95 | |
| 96 | 96 | |
| 97 | - /**  | 
                                                        |
| 98 | - * Validate the Order.  | 
                                                        |
| 99 | - *  | 
                                                        |
| 100 | - * @param string $order_id  | 
                                                        |
| 101 | - * @param EE_Transaction $transaction  | 
                                                        |
| 102 | - * @param EE_Payment_Method $payment_method  | 
                                                        |
| 103 | -     * @return array ['completed' => {boolean}, 'message' => {string}] | 
                                                        |
| 104 | - * @throws EE_Error  | 
                                                        |
| 105 | - * @throws ReflectionException  | 
                                                        |
| 106 | - */  | 
                                                        |
| 107 | - public static function isOrderCompleted(  | 
                                                        |
| 108 | - string $order_id,  | 
                                                        |
| 109 | - EE_Transaction $transaction,  | 
                                                        |
| 110 | - EE_Payment_Method $payment_method  | 
                                                        |
| 111 | - ): array  | 
                                                        |
| 112 | -    { | 
                                                        |
| 113 | - $order_details = EED_PayPalCommerce::getOrderDetails($order_id, $transaction, $payment_method);  | 
                                                        |
| 114 | - $conclusion = [  | 
                                                        |
| 115 | - 'completed' => false,  | 
                                                        |
| 116 | - 'details' => $order_details,  | 
                                                        |
| 117 | - ];  | 
                                                        |
| 118 | -        if (! $order_details) { | 
                                                        |
| 119 | - $conclusion['message'] = esc_html__(  | 
                                                        |
| 120 | - 'Could not validate this payment. The Order details were empty.',  | 
                                                        |
| 121 | - 'event_espresso'  | 
                                                        |
| 122 | - );  | 
                                                        |
| 123 | -        } elseif (! empty($order_details['error'])) { | 
                                                        |
| 124 | - $conclusion['message'] = $order_details['message'] ?? $order_details['error'];  | 
                                                        |
| 125 | -        } elseif (empty($order_details['status'])) { | 
                                                        |
| 126 | - $conclusion['message'] = esc_html__(  | 
                                                        |
| 127 | - 'There was an error with this payment. The status of the Order could not be determined.',  | 
                                                        |
| 128 | - 'event_espresso'  | 
                                                        |
| 129 | - );  | 
                                                        |
| 130 | -        } elseif ($order_details['status'] !== 'COMPLETED') { | 
                                                        |
| 131 | - $conclusion['message'] = esc_html__(  | 
                                                        |
| 132 | - 'There was an error with this payment. Order was not approved.',  | 
                                                        |
| 133 | - 'event_espresso'  | 
                                                        |
| 134 | - );  | 
                                                        |
| 135 | -        } elseif (empty($order_details['purchase_units'][0]['payments']['captures'][0]['status'])) { | 
                                                        |
| 136 | - $conclusion['message'] = esc_html__(  | 
                                                        |
| 137 | - 'There was an error with this payment. The status of the Payment could not be determined.',  | 
                                                        |
| 138 | - 'event_espresso'  | 
                                                        |
| 139 | - );  | 
                                                        |
| 140 | -        } elseif ($order_details['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') { | 
                                                        |
| 141 | - $conclusion['message'] = esc_html__(  | 
                                                        |
| 142 | - 'This payment was declined or failed validation. Please check the billing information you provided.',  | 
                                                        |
| 143 | - 'event_espresso'  | 
                                                        |
| 144 | - );  | 
                                                        |
| 145 | -        } else { | 
                                                        |
| 146 | - // If we didn't fail on the above, the Order should be considered valid.  | 
                                                        |
| 147 | - $conclusion['completed'] = true;  | 
                                                        |
| 148 | -            $conclusion['message']   = esc_html__('Order Valid.', 'event_espresso'); | 
                                                        |
| 149 | - }  | 
                                                        |
| 150 | - return $conclusion;  | 
                                                        |
| 151 | - }  | 
                                                        |
| 97 | + /**  | 
                                                        |
| 98 | + * Validate the Order.  | 
                                                        |
| 99 | + *  | 
                                                        |
| 100 | + * @param string $order_id  | 
                                                        |
| 101 | + * @param EE_Transaction $transaction  | 
                                                        |
| 102 | + * @param EE_Payment_Method $payment_method  | 
                                                        |
| 103 | +	 * @return array ['completed' => {boolean}, 'message' => {string}] | 
                                                        |
| 104 | + * @throws EE_Error  | 
                                                        |
| 105 | + * @throws ReflectionException  | 
                                                        |
| 106 | + */  | 
                                                        |
| 107 | + public static function isOrderCompleted(  | 
                                                        |
| 108 | + string $order_id,  | 
                                                        |
| 109 | + EE_Transaction $transaction,  | 
                                                        |
| 110 | + EE_Payment_Method $payment_method  | 
                                                        |
| 111 | + ): array  | 
                                                        |
| 112 | +	{ | 
                                                        |
| 113 | + $order_details = EED_PayPalCommerce::getOrderDetails($order_id, $transaction, $payment_method);  | 
                                                        |
| 114 | + $conclusion = [  | 
                                                        |
| 115 | + 'completed' => false,  | 
                                                        |
| 116 | + 'details' => $order_details,  | 
                                                        |
| 117 | + ];  | 
                                                        |
| 118 | +		if (! $order_details) { | 
                                                        |
| 119 | + $conclusion['message'] = esc_html__(  | 
                                                        |
| 120 | + 'Could not validate this payment. The Order details were empty.',  | 
                                                        |
| 121 | + 'event_espresso'  | 
                                                        |
| 122 | + );  | 
                                                        |
| 123 | +		} elseif (! empty($order_details['error'])) { | 
                                                        |
| 124 | + $conclusion['message'] = $order_details['message'] ?? $order_details['error'];  | 
                                                        |
| 125 | +		} elseif (empty($order_details['status'])) { | 
                                                        |
| 126 | + $conclusion['message'] = esc_html__(  | 
                                                        |
| 127 | + 'There was an error with this payment. The status of the Order could not be determined.',  | 
                                                        |
| 128 | + 'event_espresso'  | 
                                                        |
| 129 | + );  | 
                                                        |
| 130 | +		} elseif ($order_details['status'] !== 'COMPLETED') { | 
                                                        |
| 131 | + $conclusion['message'] = esc_html__(  | 
                                                        |
| 132 | + 'There was an error with this payment. Order was not approved.',  | 
                                                        |
| 133 | + 'event_espresso'  | 
                                                        |
| 134 | + );  | 
                                                        |
| 135 | +		} elseif (empty($order_details['purchase_units'][0]['payments']['captures'][0]['status'])) { | 
                                                        |
| 136 | + $conclusion['message'] = esc_html__(  | 
                                                        |
| 137 | + 'There was an error with this payment. The status of the Payment could not be determined.',  | 
                                                        |
| 138 | + 'event_espresso'  | 
                                                        |
| 139 | + );  | 
                                                        |
| 140 | +		} elseif ($order_details['purchase_units'][0]['payments']['captures'][0]['status'] !== 'COMPLETED') { | 
                                                        |
| 141 | + $conclusion['message'] = esc_html__(  | 
                                                        |
| 142 | + 'This payment was declined or failed validation. Please check the billing information you provided.',  | 
                                                        |
| 143 | + 'event_espresso'  | 
                                                        |
| 144 | + );  | 
                                                        |
| 145 | +		} else { | 
                                                        |
| 146 | + // If we didn't fail on the above, the Order should be considered valid.  | 
                                                        |
| 147 | + $conclusion['completed'] = true;  | 
                                                        |
| 148 | +			$conclusion['message']   = esc_html__('Order Valid.', 'event_espresso'); | 
                                                        |
| 149 | + }  | 
                                                        |
| 150 | + return $conclusion;  | 
                                                        |
| 151 | + }  | 
                                                        |
| 152 | 152 | |
| 153 | 153 | |
| 154 | - /**  | 
                                                        |
| 155 | - * Set a payment error and log the data.  | 
                                                        |
| 156 | - *  | 
                                                        |
| 157 | - * @param EE_Payment $payment  | 
                                                        |
| 158 | - * @param string $status  | 
                                                        |
| 159 | - * @param array|string $response_data  | 
                                                        |
| 160 | - * @param string $update_message  | 
                                                        |
| 161 | - * @return EE_Payment  | 
                                                        |
| 162 | - * @throws EE_Error|ReflectionException  | 
                                                        |
| 163 | - */  | 
                                                        |
| 164 | - public static function updatePaymentStatus(  | 
                                                        |
| 165 | - EE_Payment $payment,  | 
                                                        |
| 166 | - string $status,  | 
                                                        |
| 167 | - $response_data,  | 
                                                        |
| 168 | - string $update_message = ''  | 
                                                        |
| 169 | -    ): EE_Payment { | 
                                                        |
| 170 | - $paypal_pm = ! empty($payment->payment_method())  | 
                                                        |
| 171 | - ? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name())  | 
                                                        |
| 172 | - : null;  | 
                                                        |
| 173 | - // Is this a successful payment ?  | 
                                                        |
| 174 | -        if ($status === EEM_Payment::status_id_approved) { | 
                                                        |
| 175 | -            $default_message = esc_html__('Successful payment.', 'event_espresso'); | 
                                                        |
| 176 | - $amount = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;  | 
                                                        |
| 177 | - // Don't set the amount if there is no info on that with this order.  | 
                                                        |
| 178 | -            if (! empty($amount)) { | 
                                                        |
| 179 | - $payment->set_amount((float) $amount);  | 
                                                        |
| 180 | - }  | 
                                                        |
| 181 | - $payment->set_txn_id_chq_nmbr(  | 
                                                        |
| 182 | - $response_data['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']  | 
                                                        |
| 183 | - );  | 
                                                        |
| 184 | -        } else { | 
                                                        |
| 185 | - $default_message = sprintf(  | 
                                                        |
| 186 | - esc_html__(  | 
                                                        |
| 187 | - 'Your payment could not be processed successfully due to a technical issue.%1$sPlease try again or contact%2$s for assistance.',  | 
                                                        |
| 188 | - 'event_espresso'  | 
                                                        |
| 189 | - ),  | 
                                                        |
| 190 | - '<br/>',  | 
                                                        |
| 191 | -                EE_Registry::instance()->CFG->organization->get_pretty('email') | 
                                                        |
| 192 | - );  | 
                                                        |
| 193 | - }  | 
                                                        |
| 194 | - $log_message = $update_message ?: $default_message;  | 
                                                        |
| 195 | - PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction());  | 
                                                        |
| 196 | - $payment->set_status($status);  | 
                                                        |
| 197 | - $payment->set_details($log_message);  | 
                                                        |
| 198 | - $payment->set_gateway_response($log_message);  | 
                                                        |
| 199 | - $payment->save();  | 
                                                        |
| 200 | - return $payment;  | 
                                                        |
| 201 | - }  | 
                                                        |
| 154 | + /**  | 
                                                        |
| 155 | + * Set a payment error and log the data.  | 
                                                        |
| 156 | + *  | 
                                                        |
| 157 | + * @param EE_Payment $payment  | 
                                                        |
| 158 | + * @param string $status  | 
                                                        |
| 159 | + * @param array|string $response_data  | 
                                                        |
| 160 | + * @param string $update_message  | 
                                                        |
| 161 | + * @return EE_Payment  | 
                                                        |
| 162 | + * @throws EE_Error|ReflectionException  | 
                                                        |
| 163 | + */  | 
                                                        |
| 164 | + public static function updatePaymentStatus(  | 
                                                        |
| 165 | + EE_Payment $payment,  | 
                                                        |
| 166 | + string $status,  | 
                                                        |
| 167 | + $response_data,  | 
                                                        |
| 168 | + string $update_message = ''  | 
                                                        |
| 169 | +	): EE_Payment { | 
                                                        |
| 170 | + $paypal_pm = ! empty($payment->payment_method())  | 
                                                        |
| 171 | + ? EEM_Payment_Method::instance()->get_one_by_slug($payment->payment_method()->name())  | 
                                                        |
| 172 | + : null;  | 
                                                        |
| 173 | + // Is this a successful payment ?  | 
                                                        |
| 174 | +		if ($status === EEM_Payment::status_id_approved) { | 
                                                        |
| 175 | +			$default_message = esc_html__('Successful payment.', 'event_espresso'); | 
                                                        |
| 176 | + $amount = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;  | 
                                                        |
| 177 | + // Don't set the amount if there is no info on that with this order.  | 
                                                        |
| 178 | +			if (! empty($amount)) { | 
                                                        |
| 179 | + $payment->set_amount((float) $amount);  | 
                                                        |
| 180 | + }  | 
                                                        |
| 181 | + $payment->set_txn_id_chq_nmbr(  | 
                                                        |
| 182 | + $response_data['purchase_units'][0]['payments']['captures'][0]['id'] ?? $response_data['id']  | 
                                                        |
| 183 | + );  | 
                                                        |
| 184 | +		} else { | 
                                                        |
| 185 | + $default_message = sprintf(  | 
                                                        |
| 186 | + esc_html__(  | 
                                                        |
| 187 | + 'Your payment could not be processed successfully due to a technical issue.%1$sPlease try again or contact%2$s for assistance.',  | 
                                                        |
| 188 | + 'event_espresso'  | 
                                                        |
| 189 | + ),  | 
                                                        |
| 190 | + '<br/>',  | 
                                                        |
| 191 | +				EE_Registry::instance()->CFG->organization->get_pretty('email') | 
                                                        |
| 192 | + );  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | + $log_message = $update_message ?: $default_message;  | 
                                                        |
| 195 | + PayPalLogger::errorLog($log_message, $response_data, $paypal_pm, false, $payment->transaction());  | 
                                                        |
| 196 | + $payment->set_status($status);  | 
                                                        |
| 197 | + $payment->set_details($log_message);  | 
                                                        |
| 198 | + $payment->set_gateway_response($log_message);  | 
                                                        |
| 199 | + $payment->save();  | 
                                                        |
| 200 | + return $payment;  | 
                                                        |
| 201 | + }  | 
                                                        |
| 202 | 202 | |
| 203 | 203 | |
| 204 | - /**  | 
                                                        |
| 205 | - * Validate the payment.  | 
                                                        |
| 206 | - *  | 
                                                        |
| 207 | - * @param EE_Payment|null $payment  | 
                                                        |
| 208 | - * @param RequestInterface $request  | 
                                                        |
| 209 | - * @return EE_Payment  | 
                                                        |
| 210 | - * @throws EE_Error  | 
                                                        |
| 211 | - * @throws ReflectionException  | 
                                                        |
| 212 | - */  | 
                                                        |
| 213 | - public function validatePayment(?EE_Payment $payment, RequestInterface $request): EE_Payment  | 
                                                        |
| 214 | -    { | 
                                                        |
| 215 | - $failed_status = $this->_pay_model->failed_status();  | 
                                                        |
| 216 | - // Check the payment.  | 
                                                        |
| 217 | -        if (! $payment instanceof EE_Payment) { | 
                                                        |
| 218 | - $payment = EE_Payment::new_instance();  | 
                                                        |
| 219 | -            $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso'); | 
                                                        |
| 220 | - return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 221 | - $payment,  | 
                                                        |
| 222 | - $failed_status,  | 
                                                        |
| 223 | - $request->postParams(),  | 
                                                        |
| 224 | - $error_message  | 
                                                        |
| 225 | - );  | 
                                                        |
| 226 | - }  | 
                                                        |
| 227 | - // Check the transaction.  | 
                                                        |
| 228 | - $transaction = $payment->transaction();  | 
                                                        |
| 229 | -        if (! $transaction instanceof EE_Transaction) { | 
                                                        |
| 230 | - $error_message = esc_html__(  | 
                                                        |
| 231 | - 'Could not process this payment because it has no associated transaction.',  | 
                                                        |
| 232 | - 'event_espresso'  | 
                                                        |
| 233 | - );  | 
                                                        |
| 234 | - return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 235 | - $payment,  | 
                                                        |
| 236 | - $failed_status,  | 
                                                        |
| 237 | - $request->postParams(),  | 
                                                        |
| 238 | - $error_message  | 
                                                        |
| 239 | - );  | 
                                                        |
| 240 | - }  | 
                                                        |
| 241 | - return $payment;  | 
                                                        |
| 242 | - }  | 
                                                        |
| 204 | + /**  | 
                                                        |
| 205 | + * Validate the payment.  | 
                                                        |
| 206 | + *  | 
                                                        |
| 207 | + * @param EE_Payment|null $payment  | 
                                                        |
| 208 | + * @param RequestInterface $request  | 
                                                        |
| 209 | + * @return EE_Payment  | 
                                                        |
| 210 | + * @throws EE_Error  | 
                                                        |
| 211 | + * @throws ReflectionException  | 
                                                        |
| 212 | + */  | 
                                                        |
| 213 | + public function validatePayment(?EE_Payment $payment, RequestInterface $request): EE_Payment  | 
                                                        |
| 214 | +	{ | 
                                                        |
| 215 | + $failed_status = $this->_pay_model->failed_status();  | 
                                                        |
| 216 | + // Check the payment.  | 
                                                        |
| 217 | +		if (! $payment instanceof EE_Payment) { | 
                                                        |
| 218 | + $payment = EE_Payment::new_instance();  | 
                                                        |
| 219 | +			$error_message = esc_html__('Error. No associated payment was found.', 'event_espresso'); | 
                                                        |
| 220 | + return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 221 | + $payment,  | 
                                                        |
| 222 | + $failed_status,  | 
                                                        |
| 223 | + $request->postParams(),  | 
                                                        |
| 224 | + $error_message  | 
                                                        |
| 225 | + );  | 
                                                        |
| 226 | + }  | 
                                                        |
| 227 | + // Check the transaction.  | 
                                                        |
| 228 | + $transaction = $payment->transaction();  | 
                                                        |
| 229 | +		if (! $transaction instanceof EE_Transaction) { | 
                                                        |
| 230 | + $error_message = esc_html__(  | 
                                                        |
| 231 | + 'Could not process this payment because it has no associated transaction.',  | 
                                                        |
| 232 | + 'event_espresso'  | 
                                                        |
| 233 | + );  | 
                                                        |
| 234 | + return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        |
| 235 | + $payment,  | 
                                                        |
| 236 | + $failed_status,  | 
                                                        |
| 237 | + $request->postParams(),  | 
                                                        |
| 238 | + $error_message  | 
                                                        |
| 239 | + );  | 
                                                        |
| 240 | + }  | 
                                                        |
| 241 | + return $payment;  | 
                                                        |
| 242 | + }  | 
                                                        |
| 243 | 243 | |
| 244 | 244 | |
| 245 | - /**  | 
                                                        |
| 246 | - * Save some transaction details, like billing information.  | 
                                                        |
| 247 | - *  | 
                                                        |
| 248 | - * @param EE_Payment $payment  | 
                                                        |
| 249 | - * @param EE_Transaction $transaction  | 
                                                        |
| 250 | - * @param array $order  | 
                                                        |
| 251 | - * @param array $billing  | 
                                                        |
| 252 | - * @return void  | 
                                                        |
| 253 | - * @throws EE_Error  | 
                                                        |
| 254 | - * @throws ReflectionException  | 
                                                        |
| 255 | - */  | 
                                                        |
| 256 | - public static function saveBillingDetails(  | 
                                                        |
| 257 | - EE_Payment $payment,  | 
                                                        |
| 258 | - EE_Transaction $transaction,  | 
                                                        |
| 259 | - array $order,  | 
                                                        |
| 260 | - array $billing  | 
                                                        |
| 261 | -    ): void { | 
                                                        |
| 262 | - $primary_reg = $transaction->primary_registration();  | 
                                                        |
| 263 | - $att = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;  | 
                                                        |
| 264 | -        if (! $att instanceof EE_Attendee) { | 
                                                        |
| 265 | - // I guess we are done here then. Just save what we have.  | 
                                                        |
| 266 | - $payment->set_details($order);  | 
                                                        |
| 267 | - return;  | 
                                                        |
| 268 | - }  | 
                                                        |
| 269 | - // Defaults:  | 
                                                        |
| 270 | - $billing['credit_card'] = 'empty';  | 
                                                        |
| 271 | - $billing['first_name'] = empty($billing['first_name']) ? ($att->fname() ?: 'empty') : $billing['first_name'];  | 
                                                        |
| 272 | - $billing['last_name'] = empty($billing['last_name']) ? ($att->lname() ?: 'empty') : $billing['last_name'];  | 
                                                        |
| 273 | - $billing['email'] = empty($billing['email']) ? ($att->email() ?: 'empty') : $billing['email'];  | 
                                                        |
| 274 | - $billing['country'] = empty($billing['country']) ? ($att->country() ?: 'empty') : $billing['country'];  | 
                                                        |
| 275 | - $billing['city'] = empty($billing['city']) ? ($att->city() ?: 'empty') : $billing['city'];  | 
                                                        |
| 276 | - $billing['state'] = empty($billing['state']) ? ($att->state_name() ?: 'empty') : $billing['state'];  | 
                                                        |
| 277 | - $billing['address'] = empty($billing['address']) ? ($att->address() ?: 'empty') : $billing['address'];  | 
                                                        |
| 278 | - $billing['address2'] = empty($billing['address2']) ? ($att->address2() ?: 'empty') : $billing['address2'];  | 
                                                        |
| 279 | - $billing['zip'] = empty($billing['zip']) ? ($att->zip() ?: 'empty') : $billing['zip'];  | 
                                                        |
| 280 | - $billing['phone'] = empty($billing['phone']) ? ($att->phone() ?: 'empty') : $billing['phone'];  | 
                                                        |
| 245 | + /**  | 
                                                        |
| 246 | + * Save some transaction details, like billing information.  | 
                                                        |
| 247 | + *  | 
                                                        |
| 248 | + * @param EE_Payment $payment  | 
                                                        |
| 249 | + * @param EE_Transaction $transaction  | 
                                                        |
| 250 | + * @param array $order  | 
                                                        |
| 251 | + * @param array $billing  | 
                                                        |
| 252 | + * @return void  | 
                                                        |
| 253 | + * @throws EE_Error  | 
                                                        |
| 254 | + * @throws ReflectionException  | 
                                                        |
| 255 | + */  | 
                                                        |
| 256 | + public static function saveBillingDetails(  | 
                                                        |
| 257 | + EE_Payment $payment,  | 
                                                        |
| 258 | + EE_Transaction $transaction,  | 
                                                        |
| 259 | + array $order,  | 
                                                        |
| 260 | + array $billing  | 
                                                        |
| 261 | +	): void { | 
                                                        |
| 262 | + $primary_reg = $transaction->primary_registration();  | 
                                                        |
| 263 | + $att = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;  | 
                                                        |
| 264 | +		if (! $att instanceof EE_Attendee) { | 
                                                        |
| 265 | + // I guess we are done here then. Just save what we have.  | 
                                                        |
| 266 | + $payment->set_details($order);  | 
                                                        |
| 267 | + return;  | 
                                                        |
| 268 | + }  | 
                                                        |
| 269 | + // Defaults:  | 
                                                        |
| 270 | + $billing['credit_card'] = 'empty';  | 
                                                        |
| 271 | + $billing['first_name'] = empty($billing['first_name']) ? ($att->fname() ?: 'empty') : $billing['first_name'];  | 
                                                        |
| 272 | + $billing['last_name'] = empty($billing['last_name']) ? ($att->lname() ?: 'empty') : $billing['last_name'];  | 
                                                        |
| 273 | + $billing['email'] = empty($billing['email']) ? ($att->email() ?: 'empty') : $billing['email'];  | 
                                                        |
| 274 | + $billing['country'] = empty($billing['country']) ? ($att->country() ?: 'empty') : $billing['country'];  | 
                                                        |
| 275 | + $billing['city'] = empty($billing['city']) ? ($att->city() ?: 'empty') : $billing['city'];  | 
                                                        |
| 276 | + $billing['state'] = empty($billing['state']) ? ($att->state_name() ?: 'empty') : $billing['state'];  | 
                                                        |
| 277 | + $billing['address'] = empty($billing['address']) ? ($att->address() ?: 'empty') : $billing['address'];  | 
                                                        |
| 278 | + $billing['address2'] = empty($billing['address2']) ? ($att->address2() ?: 'empty') : $billing['address2'];  | 
                                                        |
| 279 | + $billing['zip'] = empty($billing['zip']) ? ($att->zip() ?: 'empty') : $billing['zip'];  | 
                                                        |
| 280 | + $billing['phone'] = empty($billing['phone']) ? ($att->phone() ?: 'empty') : $billing['phone'];  | 
                                                        |
| 281 | 281 | |
| 282 | - // Try getting the payer information from the payment source (PayPal).  | 
                                                        |
| 283 | -        if (! empty($order['payment_source'])) { | 
                                                        |
| 284 | - // A card (ACDC) payment ?  | 
                                                        |
| 285 | -            if (! empty($order['payment_source']['card'])) { | 
                                                        |
| 286 | - $payer = $order['payment_source']['card'];  | 
                                                        |
| 287 | - // Or maybe a PayPal Express payment ?  | 
                                                        |
| 288 | -            } elseif (! empty($order['payment_source']['paypal'])) { | 
                                                        |
| 289 | - $payer = $order['payment_source']['paypal'];  | 
                                                        |
| 290 | - }  | 
                                                        |
| 291 | -            if (! empty($payer)) { | 
                                                        |
| 292 | -                if (! empty($payer['name'])) { | 
                                                        |
| 293 | - // Yup, payment_source card vs PayPal have different info about the payer. So need to differentiate.  | 
                                                        |
| 294 | -                    if (is_string($payer['name'])) { | 
                                                        |
| 295 | -                        $full_name                  = explode(' ', $payer['name']); | 
                                                        |
| 296 | - $billing['first_name'] = $full_name[0] ?? $billing['first_name'];  | 
                                                        |
| 297 | - $billing['last_name'] = $full_name[1] ?? $billing['last_name'];  | 
                                                        |
| 298 | - }  | 
                                                        |
| 299 | - // PayPal info on the Payment:  | 
                                                        |
| 300 | -                    if (is_array($payer['name'])) { | 
                                                        |
| 301 | - $billing['first_name'] = $payer['name']['given_name'] ?? $billing['first_name'];  | 
                                                        |
| 302 | - $billing['last_name'] = $payer['name']['surname'] ?? $billing['last_name'];  | 
                                                        |
| 303 | - }  | 
                                                        |
| 304 | - }  | 
                                                        |
| 305 | - // Possible info on the payer.  | 
                                                        |
| 306 | - $billing['credit_card'] = $payer['last_digits'] ?? $billing['credit_card'];  | 
                                                        |
| 307 | - $billing['email'] = $payer['email_address'] ?? $billing['email'];  | 
                                                        |
| 308 | - $billing['country'] = $payer['address']['country_code'] ?? $billing['country'];  | 
                                                        |
| 309 | - $billing['city'] = $payer['address']['city'] ?? $billing['city'];  | 
                                                        |
| 310 | - $billing['state'] = $payer['address']['state'] ?? $billing['state'];  | 
                                                        |
| 311 | - $billing['address'] = $payer['address']['address'] ?? $billing['address'];  | 
                                                        |
| 312 | - $billing['zip'] = $payer['address']['zip'] ?? $billing['zip'];  | 
                                                        |
| 313 | - }  | 
                                                        |
| 314 | - }  | 
                                                        |
| 315 | - // Update attendee billing info in the transaction details.  | 
                                                        |
| 316 | - $payment_method = $transaction->payment_method();  | 
                                                        |
| 317 | - $post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base  | 
                                                        |
| 318 | - ? 'billing_info_' . $payment_method->type_obj()->system_name()  | 
                                                        |
| 319 | - : '';  | 
                                                        |
| 320 | - update_post_meta($att->ID(), $post_meta_name, $billing);  | 
                                                        |
| 321 | - }  | 
                                                        |
| 282 | + // Try getting the payer information from the payment source (PayPal).  | 
                                                        |
| 283 | +		if (! empty($order['payment_source'])) { | 
                                                        |
| 284 | + // A card (ACDC) payment ?  | 
                                                        |
| 285 | +			if (! empty($order['payment_source']['card'])) { | 
                                                        |
| 286 | + $payer = $order['payment_source']['card'];  | 
                                                        |
| 287 | + // Or maybe a PayPal Express payment ?  | 
                                                        |
| 288 | +			} elseif (! empty($order['payment_source']['paypal'])) { | 
                                                        |
| 289 | + $payer = $order['payment_source']['paypal'];  | 
                                                        |
| 290 | + }  | 
                                                        |
| 291 | +			if (! empty($payer)) { | 
                                                        |
| 292 | +				if (! empty($payer['name'])) { | 
                                                        |
| 293 | + // Yup, payment_source card vs PayPal have different info about the payer. So need to differentiate.  | 
                                                        |
| 294 | +					if (is_string($payer['name'])) { | 
                                                        |
| 295 | +						$full_name                  = explode(' ', $payer['name']); | 
                                                        |
| 296 | + $billing['first_name'] = $full_name[0] ?? $billing['first_name'];  | 
                                                        |
| 297 | + $billing['last_name'] = $full_name[1] ?? $billing['last_name'];  | 
                                                        |
| 298 | + }  | 
                                                        |
| 299 | + // PayPal info on the Payment:  | 
                                                        |
| 300 | +					if (is_array($payer['name'])) { | 
                                                        |
| 301 | + $billing['first_name'] = $payer['name']['given_name'] ?? $billing['first_name'];  | 
                                                        |
| 302 | + $billing['last_name'] = $payer['name']['surname'] ?? $billing['last_name'];  | 
                                                        |
| 303 | + }  | 
                                                        |
| 304 | + }  | 
                                                        |
| 305 | + // Possible info on the payer.  | 
                                                        |
| 306 | + $billing['credit_card'] = $payer['last_digits'] ?? $billing['credit_card'];  | 
                                                        |
| 307 | + $billing['email'] = $payer['email_address'] ?? $billing['email'];  | 
                                                        |
| 308 | + $billing['country'] = $payer['address']['country_code'] ?? $billing['country'];  | 
                                                        |
| 309 | + $billing['city'] = $payer['address']['city'] ?? $billing['city'];  | 
                                                        |
| 310 | + $billing['state'] = $payer['address']['state'] ?? $billing['state'];  | 
                                                        |
| 311 | + $billing['address'] = $payer['address']['address'] ?? $billing['address'];  | 
                                                        |
| 312 | + $billing['zip'] = $payer['address']['zip'] ?? $billing['zip'];  | 
                                                        |
| 313 | + }  | 
                                                        |
| 314 | + }  | 
                                                        |
| 315 | + // Update attendee billing info in the transaction details.  | 
                                                        |
| 316 | + $payment_method = $transaction->payment_method();  | 
                                                        |
| 317 | + $post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base  | 
                                                        |
| 318 | + ? 'billing_info_' . $payment_method->type_obj()->system_name()  | 
                                                        |
| 319 | + : '';  | 
                                                        |
| 320 | + update_post_meta($att->ID(), $post_meta_name, $billing);  | 
                                                        |
| 321 | + }  | 
                                                        |
| 322 | 322 | }  | 
                                                        
@@ -68,7 +68,7 @@ discard block  | 
                                                    ||
| 68 | 68 | $payment_method = $transaction->payment_method();  | 
                                                        
| 69 | 69 | // Get the order details.  | 
                                                        
| 70 | 70 |          $order_id = $request->getRequestParam('pp_order_id'); | 
                                                        
| 71 | -        if (! $order_id) { | 
                                                        |
| 71 | +        if ( ! $order_id) { | 
                                                        |
| 72 | 72 | return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        
| 73 | 73 | $payment,  | 
                                                        
| 74 | 74 | EEM_Payment::status_id_declined,  | 
                                                        
@@ -80,7 +80,7 @@ discard block  | 
                                                    ||
| 80 | 80 | $capture_status = EED_PayPalCommerce::captureOrder($transaction, $payment_method, $order_id);  | 
                                                        
| 81 | 81 | // Check the order status.  | 
                                                        
| 82 | 82 | $order_status = $this->isOrderCompleted($order_id, $transaction, $payment_method);  | 
                                                        
| 83 | -        if (! $order_status['completed']) { | 
                                                        |
| 83 | +        if ( ! $order_status['completed']) { | 
                                                        |
| 84 | 84 | return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        
| 85 | 85 | $payment,  | 
                                                        
| 86 | 86 | EEM_Payment::status_id_declined,  | 
                                                        
@@ -115,12 +115,12 @@ discard block  | 
                                                    ||
| 115 | 115 | 'completed' => false,  | 
                                                        
| 116 | 116 | 'details' => $order_details,  | 
                                                        
| 117 | 117 | ];  | 
                                                        
| 118 | -        if (! $order_details) { | 
                                                        |
| 118 | +        if ( ! $order_details) { | 
                                                        |
| 119 | 119 | $conclusion['message'] = esc_html__(  | 
                                                        
| 120 | 120 | 'Could not validate this payment. The Order details were empty.',  | 
                                                        
| 121 | 121 | 'event_espresso'  | 
                                                        
| 122 | 122 | );  | 
                                                        
| 123 | -        } elseif (! empty($order_details['error'])) { | 
                                                        |
| 123 | +        } elseif ( ! empty($order_details['error'])) { | 
                                                        |
| 124 | 124 | $conclusion['message'] = $order_details['message'] ?? $order_details['error'];  | 
                                                        
| 125 | 125 |          } elseif (empty($order_details['status'])) { | 
                                                        
| 126 | 126 | $conclusion['message'] = esc_html__(  | 
                                                        
@@ -175,7 +175,7 @@ discard block  | 
                                                    ||
| 175 | 175 |              $default_message = esc_html__('Successful payment.', 'event_espresso'); | 
                                                        
| 176 | 176 | $amount = $response_data['purchase_units'][0]['payments']['captures'][0]['amount']['value'] ?? 0;  | 
                                                        
| 177 | 177 | // Don't set the amount if there is no info on that with this order.  | 
                                                        
| 178 | -            if (! empty($amount)) { | 
                                                        |
| 178 | +            if ( ! empty($amount)) { | 
                                                        |
| 179 | 179 | $payment->set_amount((float) $amount);  | 
                                                        
| 180 | 180 | }  | 
                                                        
| 181 | 181 | $payment->set_txn_id_chq_nmbr(  | 
                                                        
@@ -214,7 +214,7 @@ discard block  | 
                                                    ||
| 214 | 214 |      { | 
                                                        
| 215 | 215 | $failed_status = $this->_pay_model->failed_status();  | 
                                                        
| 216 | 216 | // Check the payment.  | 
                                                        
| 217 | -        if (! $payment instanceof EE_Payment) { | 
                                                        |
| 217 | +        if ( ! $payment instanceof EE_Payment) { | 
                                                        |
| 218 | 218 | $payment = EE_Payment::new_instance();  | 
                                                        
| 219 | 219 |              $error_message = esc_html__('Error. No associated payment was found.', 'event_espresso'); | 
                                                        
| 220 | 220 | return EEG_PayPalCheckout::updatePaymentStatus(  | 
                                                        
@@ -226,7 +226,7 @@ discard block  | 
                                                    ||
| 226 | 226 | }  | 
                                                        
| 227 | 227 | // Check the transaction.  | 
                                                        
| 228 | 228 | $transaction = $payment->transaction();  | 
                                                        
| 229 | -        if (! $transaction instanceof EE_Transaction) { | 
                                                        |
| 229 | +        if ( ! $transaction instanceof EE_Transaction) { | 
                                                        |
| 230 | 230 | $error_message = esc_html__(  | 
                                                        
| 231 | 231 | 'Could not process this payment because it has no associated transaction.',  | 
                                                        
| 232 | 232 | 'event_espresso'  | 
                                                        
@@ -260,8 +260,8 @@ discard block  | 
                                                    ||
| 260 | 260 | array $billing  | 
                                                        
| 261 | 261 |      ): void { | 
                                                        
| 262 | 262 | $primary_reg = $transaction->primary_registration();  | 
                                                        
| 263 | - $att = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;  | 
                                                        |
| 264 | -        if (! $att instanceof EE_Attendee) { | 
                                                        |
| 263 | + $att = $primary_reg instanceof EE_Registration ? $primary_reg->attendee() : null;  | 
                                                        |
| 264 | +        if ( ! $att instanceof EE_Attendee) { | 
                                                        |
| 265 | 265 | // I guess we are done here then. Just save what we have.  | 
                                                        
| 266 | 266 | $payment->set_details($order);  | 
                                                        
| 267 | 267 | return;  | 
                                                        
@@ -280,19 +280,19 @@ discard block  | 
                                                    ||
| 280 | 280 | $billing['phone'] = empty($billing['phone']) ? ($att->phone() ?: 'empty') : $billing['phone'];  | 
                                                        
| 281 | 281 | |
| 282 | 282 | // Try getting the payer information from the payment source (PayPal).  | 
                                                        
| 283 | -        if (! empty($order['payment_source'])) { | 
                                                        |
| 283 | +        if ( ! empty($order['payment_source'])) { | 
                                                        |
| 284 | 284 | // A card (ACDC) payment ?  | 
                                                        
| 285 | -            if (! empty($order['payment_source']['card'])) { | 
                                                        |
| 285 | +            if ( ! empty($order['payment_source']['card'])) { | 
                                                        |
| 286 | 286 | $payer = $order['payment_source']['card'];  | 
                                                        
| 287 | 287 | // Or maybe a PayPal Express payment ?  | 
                                                        
| 288 | -            } elseif (! empty($order['payment_source']['paypal'])) { | 
                                                        |
| 288 | +            } elseif ( ! empty($order['payment_source']['paypal'])) { | 
                                                        |
| 289 | 289 | $payer = $order['payment_source']['paypal'];  | 
                                                        
| 290 | 290 | }  | 
                                                        
| 291 | -            if (! empty($payer)) { | 
                                                        |
| 292 | -                if (! empty($payer['name'])) { | 
                                                        |
| 291 | +            if ( ! empty($payer)) { | 
                                                        |
| 292 | +                if ( ! empty($payer['name'])) { | 
                                                        |
| 293 | 293 | // Yup, payment_source card vs PayPal have different info about the payer. So need to differentiate.  | 
                                                        
| 294 | 294 |                      if (is_string($payer['name'])) { | 
                                                        
| 295 | -                        $full_name                  = explode(' ', $payer['name']); | 
                                                        |
| 295 | +                        $full_name = explode(' ', $payer['name']); | 
                                                        |
| 296 | 296 | $billing['first_name'] = $full_name[0] ?? $billing['first_name'];  | 
                                                        
| 297 | 297 | $billing['last_name'] = $full_name[1] ?? $billing['last_name'];  | 
                                                        
| 298 | 298 | }  | 
                                                        
@@ -315,7 +315,7 @@ discard block  | 
                                                    ||
| 315 | 315 | // Update attendee billing info in the transaction details.  | 
                                                        
| 316 | 316 | $payment_method = $transaction->payment_method();  | 
                                                        
| 317 | 317 | $post_meta_name = $payment_method->type_obj() instanceof EE_PMT_Base  | 
                                                        
| 318 | - ? 'billing_info_' . $payment_method->type_obj()->system_name()  | 
                                                        |
| 318 | + ? 'billing_info_'.$payment_method->type_obj()->system_name()  | 
                                                        |
| 319 | 319 | : '';  | 
                                                        
| 320 | 320 | update_post_meta($att->ID(), $post_meta_name, $billing);  | 
                                                        
| 321 | 321 | }  | 
                                                        
@@ -13,66 +13,66 @@  | 
                                                    ||
| 13 | 13 | */  | 
                                                        
| 14 | 14 | class CurrencyManager  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | - /**  | 
                                                        |
| 17 | - * Gets the number of decimal places we expect a currency to have.  | 
                                                        |
| 18 | - *  | 
                                                        |
| 19 | - * @param string $currency Accepted currency.  | 
                                                        |
| 20 | - * @return int  | 
                                                        |
| 21 | - */  | 
                                                        |
| 22 | - public static function getDecimalPlaces(string $currency = ''): int  | 
                                                        |
| 23 | -    { | 
                                                        |
| 24 | -        if (! $currency) { | 
                                                        |
| 25 | - $currency = self::currencyCode();  | 
                                                        |
| 26 | - }  | 
                                                        |
| 27 | -        switch (strtoupper($currency)) { | 
                                                        |
| 28 | - // Zero decimal currencies.  | 
                                                        |
| 29 | - case 'BIF':  | 
                                                        |
| 30 | - case 'CLP':  | 
                                                        |
| 31 | - case 'DJF':  | 
                                                        |
| 32 | - case 'GNF':  | 
                                                        |
| 33 | - case 'JPY':  | 
                                                        |
| 34 | - case 'KMF':  | 
                                                        |
| 35 | - case 'KRW':  | 
                                                        |
| 36 | - case 'MGA':  | 
                                                        |
| 37 | - case 'PYG':  | 
                                                        |
| 38 | - case 'RWF':  | 
                                                        |
| 39 | - case 'UGX':  | 
                                                        |
| 40 | - case 'VND':  | 
                                                        |
| 41 | - case 'VUV':  | 
                                                        |
| 42 | - case 'XAF':  | 
                                                        |
| 43 | - case 'XOF':  | 
                                                        |
| 44 | - case 'XPF':  | 
                                                        |
| 45 | - return 0;  | 
                                                        |
| 46 | - default:  | 
                                                        |
| 47 | - return 2;  | 
                                                        |
| 48 | - }  | 
                                                        |
| 49 | - }  | 
                                                        |
| 16 | + /**  | 
                                                        |
| 17 | + * Gets the number of decimal places we expect a currency to have.  | 
                                                        |
| 18 | + *  | 
                                                        |
| 19 | + * @param string $currency Accepted currency.  | 
                                                        |
| 20 | + * @return int  | 
                                                        |
| 21 | + */  | 
                                                        |
| 22 | + public static function getDecimalPlaces(string $currency = ''): int  | 
                                                        |
| 23 | +	{ | 
                                                        |
| 24 | +		if (! $currency) { | 
                                                        |
| 25 | + $currency = self::currencyCode();  | 
                                                        |
| 26 | + }  | 
                                                        |
| 27 | +		switch (strtoupper($currency)) { | 
                                                        |
| 28 | + // Zero decimal currencies.  | 
                                                        |
| 29 | + case 'BIF':  | 
                                                        |
| 30 | + case 'CLP':  | 
                                                        |
| 31 | + case 'DJF':  | 
                                                        |
| 32 | + case 'GNF':  | 
                                                        |
| 33 | + case 'JPY':  | 
                                                        |
| 34 | + case 'KMF':  | 
                                                        |
| 35 | + case 'KRW':  | 
                                                        |
| 36 | + case 'MGA':  | 
                                                        |
| 37 | + case 'PYG':  | 
                                                        |
| 38 | + case 'RWF':  | 
                                                        |
| 39 | + case 'UGX':  | 
                                                        |
| 40 | + case 'VND':  | 
                                                        |
| 41 | + case 'VUV':  | 
                                                        |
| 42 | + case 'XAF':  | 
                                                        |
| 43 | + case 'XOF':  | 
                                                        |
| 44 | + case 'XPF':  | 
                                                        |
| 45 | + return 0;  | 
                                                        |
| 46 | + default:  | 
                                                        |
| 47 | + return 2;  | 
                                                        |
| 48 | + }  | 
                                                        |
| 49 | + }  | 
                                                        |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /**  | 
                                                        |
| 53 | - * Make sure the value is an absolute number with only two decimal places.  | 
                                                        |
| 54 | - *  | 
                                                        |
| 55 | - * @param float $amount  | 
                                                        |
| 56 | - * @return float  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - public static function normalizeValue(float $amount): float  | 
                                                        |
| 59 | -    { | 
                                                        |
| 60 | - // Make sure we get a positive value.  | 
                                                        |
| 61 | - // Don't use abs() because of the possible issues with rounding if 'serialize_precision' is not set to -1.  | 
                                                        |
| 62 | -        if ($amount < 0) { | 
                                                        |
| 63 | - $amount = $amount * -1;  | 
                                                        |
| 64 | - }  | 
                                                        |
| 65 | - return number_format($amount, self::getDecimalPlaces(), '.', '');  | 
                                                        |
| 66 | - }  | 
                                                        |
| 52 | + /**  | 
                                                        |
| 53 | + * Make sure the value is an absolute number with only two decimal places.  | 
                                                        |
| 54 | + *  | 
                                                        |
| 55 | + * @param float $amount  | 
                                                        |
| 56 | + * @return float  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + public static function normalizeValue(float $amount): float  | 
                                                        |
| 59 | +	{ | 
                                                        |
| 60 | + // Make sure we get a positive value.  | 
                                                        |
| 61 | + // Don't use abs() because of the possible issues with rounding if 'serialize_precision' is not set to -1.  | 
                                                        |
| 62 | +		if ($amount < 0) { | 
                                                        |
| 63 | + $amount = $amount * -1;  | 
                                                        |
| 64 | + }  | 
                                                        |
| 65 | + return number_format($amount, self::getDecimalPlaces(), '.', '');  | 
                                                        |
| 66 | + }  | 
                                                        |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /**  | 
                                                        |
| 70 | - * Get currency that's currently set in Event Espresso settings.  | 
                                                        |
| 71 | - *  | 
                                                        |
| 72 | - * @return string  | 
                                                        |
| 73 | - */  | 
                                                        |
| 74 | - public static function currencyCode(): string  | 
                                                        |
| 75 | -    { | 
                                                        |
| 76 | - return EE_Registry::instance()->CFG->currency->code;  | 
                                                        |
| 77 | - }  | 
                                                        |
| 69 | + /**  | 
                                                        |
| 70 | + * Get currency that's currently set in Event Espresso settings.  | 
                                                        |
| 71 | + *  | 
                                                        |
| 72 | + * @return string  | 
                                                        |
| 73 | + */  | 
                                                        |
| 74 | + public static function currencyCode(): string  | 
                                                        |
| 75 | +	{ | 
                                                        |
| 76 | + return EE_Registry::instance()->CFG->currency->code;  | 
                                                        |
| 77 | + }  | 
                                                        |
| 78 | 78 | }  |