Skip to content

Commit

Permalink
Fix config merge for clean install
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperstrongBE committed Nov 20, 2024
1 parent f321471 commit da87cad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
51 changes: 22 additions & 29 deletions includes/controllers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
exit; // Exit if accessed directly.
}



/**
* Configuration handler for XPRCheckout payment gateway.
*
Expand Down Expand Up @@ -73,8 +71,7 @@ public static function GetDashbordConfig()
public static function GetBaseConfig()
{
$xprcheckoutGateway = WC()->payment_gateways->payment_gateways()['xprcheckout'];
$rawWallets = $xprcheckoutGateway->get_option('wallets');
$wallets = unserialize($rawWallets);
$wallets = self::GetWalletConfig();
$activeNetwork = $xprcheckoutGateway->get_option('network');
$store = $wallets[$activeNetwork]['store'];

Expand All @@ -101,22 +98,7 @@ public static function GetAdminConfig()
{
$xprcheckoutGateway = WC()->payment_gateways->payment_gateways()['xprcheckout'];
$rawWallets = $xprcheckoutGateway->get_option('wallets');
$wallets = [
'testnet'=>[
'store'=>'',
'verified'=>false
],
'mainnet'=>[
'store'=>'',
'verified'=>false
],
];
if (!is_null($rawWallets)){
$unserializedWallet = unserialize($rawWallets);
if (!is_null($unserializedWallet)){
$wallets = $unserializedWallet;
}
}
$wallets = self::GetWalletConfig();
return array(
"wallets"=>$wallets,
"adminNonce" => wp_create_nonce( 'wp_rest' )
Expand Down Expand Up @@ -158,14 +140,25 @@ public static function GetConfigWithOrderById($orderId)

}

/**
* Retrieves configuration values for XPRCheckout payment gateway merged with cart details.
*
* @return array Associative array containing base configuration from self::GetBaseConfig() merged with:
* - "cartTotal" => float, The total amount in the cart.
* - "paymentKey" => string, The payment key associated with the current cart.
* @access public
* @static
*/
private static function GetWalletConfig (){

$xprcheckoutGateway = WC()->payment_gateways->payment_gateways()['xprcheckout'];
$rawWallets = $xprcheckoutGateway->get_option('wallets');
$defaultWallet = [
'testnet'=>[
'store'=>'',
'verified'=>false
],
'mainnet'=>[
'store'=>'',
'verified'=>false
],
];
if (is_null($rawWallets)) return $defaultWallet;
$unserializedWallet = unserialize($rawWallets);
if (!is_null($unserializedWallet)) return $defaultWallet;
return $unserializedWallet;

}

}
2 changes: 1 addition & 1 deletion includes/controllers/Notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function showWarningNotices()
if ($isTestnet && $testnetActor == "") :
?>
<div class="notice notice-error">
<p><b>XPRCheckout testnet misconfiguration</b> ! XPRCheckout configuration doesn't have registered store account for testnet. <a href="<?php admin_url('admin.php?page=wc-settings&tab=checkout&section=xprcheckout') ?>">Fix it »</a></p>
<p><b>XPRCheckout testnet misconfiguration</b> ! XPRCheckout configuration doesn't have registered store account for testnet. <a href="<?php admin_url('http://wp-admin/admin.php?page=wc-settings&tab=checkout&section=xprcheckout') ?>">Fix it »</a></p>
</div>
<?php
endif;
Expand Down

0 comments on commit da87cad

Please sign in to comment.