Skip to content

Commit 07da70d

Browse files
author
Brian Yu
authored
Update account summary API with default values, is_live, test_mode (#2269)
* Wrap account summary API in WP_REST_Response * Add is_live and test_mode to account summary API (#2272) * Add is_live and test_mode to account summary API * Add default value for charges_enabled * Fix account summary API response when no account linked (#2275)
1 parent 51f1529 commit 07da70d

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
= 6.1.0 - 2022-xx-xx =
44
* Tweak - Use the newly exposed LoadableMask component provided by WooCommerce Blocks to trigger the loading state for Payment Request Buttons.
5+
* Fix - Response type for account summary API.
6+
* Fix - Invalid response in account summary API when missing account data.
7+
* Add - Live and test mode information in account summary API.
58
* Add - Add filter call when updating an existent intent (wc_stripe_update_existing_intent_request).
69
* Add - Add ability to test Stripe account keys' validity.
710
* Fix - Fixed full bank statement field description.

includes/admin/class-wc-rest-stripe-account-controller.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,22 @@ public function get_account() {
9898
public function get_account_summary() {
9999
$account = $this->account->get_cached_account_data();
100100

101-
return [
102-
'has_pending_requirements' => $this->account->has_pending_requirements(),
103-
'has_overdue_requirements' => $this->account->has_overdue_requirements(),
104-
'current_deadline' => $account['requirements']['current_deadline'] ?? null,
105-
'status' => $this->account->get_account_status(),
106-
'statement_descriptor' => $account['settings']['payments']['statement_descriptor'] ?? '',
107-
'store_currencies' => [
108-
'default' => $account['default_currency'] ?? '',
109-
'supported' => $this->account->get_supported_store_currencies(),
110-
],
111-
'country' => $account['country'] ?? '',
112-
];
101+
return new WP_REST_Response(
102+
[
103+
'has_pending_requirements' => $this->account->has_pending_requirements(),
104+
'has_overdue_requirements' => $this->account->has_overdue_requirements(),
105+
'current_deadline' => $account['requirements']['current_deadline'] ?? null,
106+
'status' => $this->account->get_account_status(),
107+
'statement_descriptor' => $account['settings']['payments']['statement_descriptor'] ?? '',
108+
'store_currencies' => [
109+
'default' => $account['default_currency'] ?? get_woocommerce_currency(),
110+
'supported' => $this->account->get_supported_store_currencies(),
111+
],
112+
'country' => $account['country'] ?? WC()->countries->get_base_country(),
113+
'is_live' => $account['charges_enabled'] ?? false,
114+
'test_mode' => WC_Stripe_Webhook_State::get_testmode(),
115+
]
116+
);
113117
}
114118

115119
/**

includes/class-wc-stripe-account.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class WC_Stripe_Account {
1414
const TEST_ACCOUNT_OPTION = 'wcstripe_account_data_test';
1515

1616
const STATUS_COMPLETE = 'complete';
17+
const STATUS_NO_ACCOUNT = 'NOACCOUNT';
1718
const STATUS_RESTRICTED_SOON = 'restricted_soon';
1819
const STATUS_RESTRICTED = 'restricted';
1920

@@ -153,8 +154,12 @@ public function has_overdue_requirements() {
153154
* @return string The account's status.
154155
*/
155156
public function get_account_status() {
156-
$requirements = $this->get_cached_account_data()['requirements'] ?? [];
157+
$account = $this->get_cached_account_data();
158+
if ( empty( $account ) ) {
159+
return self::STATUS_NO_ACCOUNT;
160+
}
157161

162+
$requirements = $account['requirements'] ?? [];
158163
if ( empty( $requirements ) ) {
159164
return self::STATUS_COMPLETE;
160165
}
@@ -189,7 +194,7 @@ public function get_account_status() {
189194
public function get_supported_store_currencies(): array {
190195
$account = $this->get_cached_account_data();
191196
if ( ! isset( $account['external_accounts']['data'] ) ) {
192-
return [ $account['default_currency'] ?? '' ];
197+
return [ $account['default_currency'] ?? get_woocommerce_currency() ];
193198
}
194199

195200
$currencies = array_filter( array_column( $account['external_accounts']['data'], 'currency' ) );

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ If you get stuck, you can ask for help in the Plugin Forum.
130130

131131
= 6.x.x - 2022-xx-xx =
132132
* Tweak - Use the newly exposed LoadableMask component provided by WooCommerce Blocks to trigger the loading state for Payment Request Buttons.
133+
* Fix - Response type for account summary API.
134+
* Fix - Invalid response in account summary API when missing account data.
135+
* Add - Live and test mode information in account summary API.
133136
* Add - Add filter call when updating an existent intent (wc_stripe_update_existing_intent_request).
134137
* Add - Add ability to test Stripe account keys' validity.
135138
* Fix - Fixed full bank statement field description.

0 commit comments

Comments
 (0)