Skip to content

Commit 712c295

Browse files
committed
Use different accountId depending on selector
1 parent 474c3c6 commit 712c295

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
*** MONEI Payments for WooCommerce ***
22

3-
2025-04-29 - version 6.3.2
3+
2025-05-05 - version 6.3.2
44
* Fix - Error in checkout when no subscription plugin present
55
* Fix - Showing only available payment methods when subscription product in cart
6+
* Fix - Error in API key selector expected test/live account id
67

78
2025-04-25 - version 6.3.1
89
* Fix - Checkout errors. Rollback to version 6.2.1

readme.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ By using this plugin you agree with MONEI [Terms of Service](https://monei.com/l
103103

104104
== Changelog ==
105105

106-
2025-04-29 - version 6.3.2
106+
2025-05-05 - version 6.3.2
107107
* Fix - Error in checkout when no subscription plugin present
108108
* Fix - Showing only available payment methods when subscription product in cart
109+
* Fix - Error in API key selector expected test/live account id
109110

110111
2025-04-25 - version 6.3.1
111112
* Fix - Checkout errors. Rollback to version 6.2.1

src/Core/container-definitions.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@
4444
'notice-admin-gateway-not-enabled-monei' => DI\get( NoticeGatewayNotEnabledMonei::class ),
4545
)
4646
),
47-
// ========== PAYMENT METHOD SERVICES ==========
48-
PaymentMethodsRepository::class => DI\factory(
49-
function () {
50-
$accountId = get_option( 'monei_accountid' );
51-
return new Monei\Repositories\PaymentMethodsRepository( $accountId );
52-
}
53-
),
47+
ApiKeyService::class => DI\autowire(ApiKeyService::class),
48+
PaymentMethodsRepository::class => DI\factory(
49+
function (ApiKeyService $apiKeyService) {
50+
$accountId = $apiKeyService->get_account_id();
51+
return new Monei\Repositories\PaymentMethodsRepository($accountId);
52+
}
53+
)->parameter('apiKeyService', DI\get(ApiKeyService::class)),
5454
PaymentMethodsService::class => DI\create( PaymentMethodsService::class )
5555
->constructor( DI\get( PaymentMethodsRepository::class ) ),
5656
MoneiPaymentServices::class => DI\autowire( MoneiPaymentServices::class ),
5757
BlockSupportService::class => DI\create( BlockSupportService::class )
5858
->constructor( $blocksPath, $blockNamespacePrefix ),
5959
MoneiApplePayVerificationService::class => DI\autowire( MoneiApplePayVerificationService::class )
6060
->constructor( DI\get( MoneiPaymentServices::class ) ),
61-
ApiKeyService::class => DI\autowire( ApiKeyService::class ),
61+
6262
MoneiSdkClientFactory::class => DI\autowire( MoneiSdkClientFactory::class )
6363
->constructor( DI\get( ApiKeyService::class ) ),
6464
WooCommerceSubscriptionsHandler::class => \DI\create(

src/Services/ApiKeyService.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ class ApiKeyService {
66
private string $test_api_key;
77
private string $live_api_key;
88
private string $api_key_mode;
9-
private string $account_id;
9+
private string $test_account_id;
10+
private string $live_account_id;
1011

11-
public function __construct() {
12+
13+
public function __construct() {
1214
// Load the API keys and mode from the database
1315
$this->test_api_key = get_option( 'monei_test_apikey', '' );
1416
$this->live_api_key = get_option( 'monei_live_apikey', '' );
1517
$this->api_key_mode = get_option( 'monei_apikey_mode', 'test' );
16-
$this->account_id = get_option( 'monei_accountid' );
18+
$this->test_account_id = get_option( 'monei_test_accountid' );
19+
$this->live_account_id = get_option( 'monei_live_accountid' );
20+
21+
// Copy the API keys to the central settings when the plugin is activated or updated
1722
add_action( 'init', array( $this, 'copyKeysToCentralSettings' ), 0 );
1823
}
1924

@@ -41,7 +46,7 @@ public function is_test_mode(): bool {
4146
* @return string
4247
*/
4348
public function get_account_id(): string {
44-
return $this->account_id;
49+
return ( $this->api_key_mode === 'test' ) ? $this->test_account_id : $this->live_account_id;
4550
}
4651

4752
/**
@@ -51,6 +56,8 @@ public function get_account_id(): string {
5156
public function update_keys(): void {
5257
$this->test_api_key = get_option( 'monei_test_apikey', '' );
5358
$this->live_api_key = get_option( 'monei_live_apikey', '' );
59+
$this->test_account_id = get_option( 'monei_test_accountid' );
60+
$this->live_account_id = get_option( 'monei_live_accountid' );
5461
$this->api_key_mode = get_option( 'monei_apikey_mode', 'test' );
5562
}
5663

@@ -66,22 +73,22 @@ function ( $default_params ) {
6673
if ( empty( $centralApiKey ) && empty( $ccApiKey ) ) {
6774
return $default_params;
6875
}
69-
7076
$keyToUse = ! empty( $centralApiKey ) ? $centralApiKey : $ccApiKey;
77+
$accountId =! empty( $centralAccountId )? $centralAccountId : $ccAccountId;
7178

7279
if ( strpos( $keyToUse, 'pk_test_' ) === 0 ) {
7380
update_option( 'monei_test_apikey', $keyToUse );
7481
update_option( 'monei_apikey_mode', 'test' );
75-
} else {
82+
update_option( 'monei_test_accountid', $accountId );
83+
delete_option( 'monei_apikey' );
84+
delete_option( 'monei_accountid' );
85+
} else if(strpos( $keyToUse, 'pk_live_' ) === 0) {
7686
update_option( 'monei_live_apikey', $keyToUse );
7787
update_option( 'monei_apikey_mode', 'live' );
78-
}
79-
80-
delete_option( 'monei_apikey' );
81-
82-
if ( empty( $centralAccountId ) && ! empty( $ccAccountId ) ) {
83-
update_option( 'monei_accountid', $ccAccountId );
84-
}
88+
update_option( 'monei_live_accountid', $accountId );
89+
delete_option( 'monei_apikey' );
90+
delete_option( 'monei_accountid' );
91+
}
8592

8693
return $default_params;
8794
},

src/Settings/MoneiSettings.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ public function get_settings() {
3030
'type' => 'title',
3131
'id' => 'monei_settings_title',
3232
),
33-
array(
34-
'title' => __( 'Account ID *', 'monei' ),
35-
'type' => 'text',
36-
'desc' => __( 'Enter your MONEI Account ID here.', 'monei' ),
37-
'desc_tip' => true,
38-
'id' => 'monei_accountid',
39-
'default' => '',
40-
),
4133
array(
4234
'title' => __( 'API Key Mode', 'monei' ),
4335
'type' => 'select',
@@ -50,6 +42,24 @@ public function get_settings() {
5042
'live' => __( 'Live API Key', 'monei' ),
5143
),
5244
),
45+
array(
46+
'title' => __( 'Test Account ID *', 'monei' ),
47+
'type' => 'text',
48+
'desc' => __( 'Enter your MONEI Test Account ID here.', 'monei' ),
49+
'desc_tip' => true,
50+
'id' => 'monei_test_accountid',
51+
'default' => '',
52+
'class' => 'monei-api-key-field monei-test-api-key-field',
53+
),
54+
array(
55+
'title' => __( 'Live Account ID *', 'monei' ),
56+
'type' => 'text',
57+
'desc' => __( 'Enter your MONEI Test Account ID here.', 'monei' ),
58+
'desc_tip' => true,
59+
'id' => 'monei_live_accountid',
60+
'default' => '',
61+
'class' => 'monei-api-key-field monei-live-api-key-field',
62+
),
5363
array(
5464
'title' => __( 'Test API Key *', 'monei' ),
5565
'type' => 'text',

0 commit comments

Comments
 (0)