Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support payment activity widget fetching & displaying differnt deposit currencies #8864

Merged
merged 12 commits into from
Jun 5, 2024
3 changes: 3 additions & 0 deletions client/components/payment-activity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const PaymentActivity: React.FC = () => {
wcpaySettings.isOverviewSurveySubmitted ?? false;

const { paymentActivityData, isLoading } = usePaymentActivityData( {
// In future this will be bound to currency picker via useSelectedCurrency().
// Can hard-code other store settings to test.
currency: wcpaySettings.accountDefaultCurrency,
...getDateRange(),
timezone: moment( new Date() ).format( 'Z' ),
} );
Expand Down
1 change: 1 addition & 0 deletions client/data/payment-activity/test/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe( 'usePaymentActivityData', () => {
);

const result = usePaymentActivityData( {
currency: 'jpy',
date_start: '2021-01-01',
date_end: '2021-01-31',
timezone: 'UTC',
Expand Down
1 change: 1 addition & 0 deletions client/data/payment-activity/test/resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { updatePaymentActivity } from '../actions';
import { getPaymentActivityData } from '../resolvers';

const query = {
currency: 'usd',
date_start: '2020-04-29T04:00:00',
date_end: '2020-04-29T03:59:59',
timezone: '+2:30',
Expand Down
9 changes: 9 additions & 0 deletions client/data/payment-activity/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ export interface PaymentActivityAction {
data: PaymentActivityData;
}

/**
* Query parameters for fetching payment activity data for overview widget.
* Note that these are must match the query parameters for the REST API endpoint.
*
* @see Reporting_Service::get_payment_activity_totals() on WooPayments service.
* Musing: we could move all rest endpoint typedefs to a single place to make it clear that they are coupled to server code.
*/
export interface PaymentActivityQuery {
/** The date range start datetime used to calculate transaction data, e.g. 2024-04-29T16:19:29 */
date_start: string;
/** The date range end datetime used to calculate transaction data, e.g. 2024-04-29T16:19:29 */
date_end: string;
/** The timezone used to calculate the transaction data date range, e.g. 'UTC' */
timezone: string;
/** The currency to display */
currency: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function get_payment_activity( $request ) {
$wcpay_request->set_date_start( $request->get_param( 'date_start' ) );
$wcpay_request->set_date_end( $request->get_param( 'date_end' ) );
$wcpay_request->set_timezone( $request->get_param( 'timezone' ) );
$wcpay_request->set_currency( $request->get_param( 'currency' ) );
return $wcpay_request->handle_rest_request();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,31 @@ The `WCPay\Core\Server\Request\Get_Reporting_Payment_Activity` class is used to
| `date_start`| `set_date_start( string $date_start )` | No | Yes | - |
| `date_end` | `set_date_end( string $date_end )` | No | Yes | - |
| `timezone` | `set_timezone( string $timezone )` | No | Yes | - |
| `currency` | `set_currency( string $currency )` | No | Yes | - |

The `date_start` and `date_end` parameters should be in the 'YYYY-MM-DDT00:00:00' format.
The `timezone` parameter can be passed as an offset or as a [timezone name](https://www.php.net/manual/en/timezones.php).
`currency` should be a currency code for a store deposit currency.

## Filter

When using this request, provide the following filter and arguments:

- Name: `wcpay_get_payment_activity`
- ? what
jessy-p marked this conversation as resolved.
Show resolved Hide resolved

## Example:

```php
// Does this example explain / add any value?
jessy-p marked this conversation as resolved.
Show resolved Hide resolved
$request = Get_Reporting_Payment_Activity::create();
$request->set_date_start( $date_start );
$request->set_date_end( $date_end );
$request->set_timezone( $timezone );
$request->set_currency( $random_variable );
$request->send();
```

## Exceptions

- `Invalid_Request_Parameter_Exception` - Thrown when the provided date or timezone is not in expected format.
- `Invalid_Request_Parameter_Exception` - Thrown when the provided date or timezone is not in expected format.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Get_Reporting_Payment_Activity extends Request {
'date_start',
'date_end',
'timezone',
'currency',
];

/**
Expand Down Expand Up @@ -97,4 +98,17 @@ public function set_timezone( string $timezone ) {
}
$this->set_param( 'timezone', $timezone );
}

/**
* Sets the currency arg for the request.
*
* @param string $currency A deposit currency code e.g. USD. (TODO lower or uppercase?).
* @return void
*
* @throws Invalid_Request_Parameter_Exception Exception if the arg is not in valid format.
*/
public function set_currency( string $currency ) {
// Do we need validation here?
$this->set_param( 'currency', $currency );
}
}
Loading