mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
✨ New action to refresh merchant data from server
This commit is contained in:
parent
c97464d7e2
commit
b4d1596fd1
6 changed files with 70 additions and 0 deletions
|
@ -7,12 +7,15 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
import { dispatch } from '@wordpress/data';
|
||||
import apiFetch from '@wordpress/api-fetch';
|
||||
|
||||
import {
|
||||
STORE_NAME,
|
||||
REST_PERSIST_PATH,
|
||||
REST_MANUAL_CONNECTION_PATH,
|
||||
REST_CONNECTION_URL_PATH,
|
||||
REST_HYDRATE_MERCHANT_PATH,
|
||||
} from './constants';
|
||||
import ACTION_TYPES from './action-types';
|
||||
|
||||
|
@ -99,4 +102,23 @@ export const controls = {
|
|||
|
||||
return result;
|
||||
},
|
||||
|
||||
async [ ACTION_TYPES.DO_REFRESH_MERCHANT ]() {
|
||||
let result = null;
|
||||
|
||||
try {
|
||||
result = await apiFetch( { path: REST_HYDRATE_MERCHANT_PATH } );
|
||||
|
||||
if ( result.success && result.merchant ) {
|
||||
await dispatch( STORE_NAME ).hydrate( result );
|
||||
}
|
||||
} catch ( e ) {
|
||||
result = {
|
||||
success: false,
|
||||
error: e,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue