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

Include transaction ID with reader charges summary request #10333

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Include transaction ID when requesting card reader fee charges summary.
6 changes: 4 additions & 2 deletions includes/admin/class-wc-rest-payments-reader-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public function register_routes() {
* @return WP_REST_Response|WP_Error
*/
public function get_summary( $request ) {

$transaction_id = $request->get_param( 'transaction_id' );

try {
Expand All @@ -159,7 +158,10 @@ public function get_summary( $request ) {
if ( empty( $transaction ) ) {
return rest_ensure_response( [] );
}
$summary = $this->api_client->get_readers_charge_summary( gmdate( 'Y-m-d', $transaction['created'] ) );
$summary = $this->api_client->get_readers_charge_summary(
gmdate( 'Y-m-d', $transaction['created'] ),
$transaction_id
);
} catch ( API_Exception $e ) {
return rest_ensure_response( new WP_Error( 'wcpay_get_summary', $e->getMessage() ) );
}
Expand Down
11 changes: 8 additions & 3 deletions includes/wc-payment-api/class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2811,12 +2811,17 @@ private function uuid() {
/**
* Fetch readers charge summary.
*
* @param string $charge_date Charge date for readers.
* @param string $charge_date Charge date for readers.
* @param string|null $transaction_id Optional transaction ID to filter results.
*
* @return array reader objects.
*/
public function get_readers_charge_summary( string $charge_date ): array {
return $this->request( [ 'charge_date' => $charge_date ], self::READERS_CHARGE_SUMMARY, self::GET );
public function get_readers_charge_summary( string $charge_date, ?string $transaction_id = null ): array {
$params = [ 'charge_date' => $charge_date ];
if ( $transaction_id ) {
$params['transaction_id'] = $transaction_id;
}
return $this->request( $params, self::READERS_CHARGE_SUMMARY, self::GET );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,29 @@ public function test_get_summary() {
],
];

$transaction_id = uniqid( 'trx_' );

$this->mock_api_client
->expects( $this->once() )
->method( 'get_transaction' )
->willReturn( [ 'created' => 1634291278 ] );
->with( $transaction_id )
->willReturn(
[
'created' => 1634291278,
'id' => $transaction_id,
]
);

$this->mock_api_client
->expects( $this->once() )
->method( 'get_readers_charge_summary' )
->with( gmdate( 'Y-m-d', 1634291278 ) )
->with( gmdate( 'Y-m-d', 1634291278 ), $transaction_id )
->willReturn( $readers );

$request = new WP_REST_Request( 'GET' );
$request->set_param( 'transaction_id', 1 );
$request->set_param( 'transaction_id', $transaction_id );
$request->set_param( 'charge_date', gmdate( 'Y-m-d', 1634291278 ) );

$response = $this->controller->get_summary( $request );
$this->assertSame( $readers, $response->get_data() );
}
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/wc-payment-api/test-class-wc-payments-api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,42 @@ public function test_update_compatibility_data() {
$this->assertSame( 'success', $result['result'] );
}

public function test_get_readers_charge_summary() {
$transaction_id = uniqid( 'trx_' );
$charge_date = gmdate( 'Y-m-d', 1634291278 );
$this->mock_http_client
->expects( $this->once() )
->method( 'remote_request' )
->willReturn(
[
'body' => wp_json_encode(
[
'result' => 'success',
'data' => [
(object) [
'reader_id' => 'reader_1',
'count' => 1,
'status' => 'active',
'fee' => [
'amount' => 100,
'currency' => 'USD',
],
],
],
]
),
'response' => [
'code' => 200,
'message' => 'OK',
],
]
);

$result = $this->payments_api_client->get_readers_charge_summary( '2024-01-01', $transaction_id );
$this->assertSame( 1, $result['data'][0]['count'] );
}


public function test_get_tracking_info() {
$expect = [ 'hosting-provider' => 'test' ];

Expand Down
Loading