Skip to content

Feature: Donation details overview backend #7976

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

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feature: add prepare_items_for_response method
  • Loading branch information
alaca committed Jun 17, 2025
commit 0a8649373acd91ac1351fa264de1b00fc233b991
27 changes: 27 additions & 0 deletions src/API/REST/V3/Routes/Donations/DonationController.php
Original file line number Diff line number Diff line change
@@ -2,9 +2,11 @@

namespace Give\API\REST\V3\Routes\Donations;

use Give\API\REST\V3\Routes\CURIE;
use Give\API\REST\V3\Routes\Donations\ValueObjects\DonationAnonymousMode;
use Give\API\REST\V3\Routes\Donations\ValueObjects\DonationRoute;
use Give\Donations\Models\Donation;
use Give\Framework\Exceptions\Primitives\Exception;
use WP_Error;
use WP_REST_Controller;
use WP_REST_Request;
@@ -356,6 +358,31 @@ public function get_collection_params(): array
return $params;
}

/**
* @unreleased
* @throws Exception
*/
public function prepare_item_for_response($item, $request): WP_REST_Response
{
$self_url = rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $request->get_param('id')));
$statistics_url = add_query_arg([
'mode' => $request->get_param('mode'),
'campaignId' => $request->get_param('campaignId'),
], $self_url . '/statistics');
$links = [
'self' => ['href' => $self_url],
CURIE::relationUrl('statistics') => [
'href' => $statistics_url,
'embeddable' => true,
],
];

$response = new WP_REST_Response($item);
$response->add_links($links);

return $response;
}

/**
* @unreleased
*/