mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-05 17:40:33 +08:00
## Summary Patreon API v1 has been deprecated for years and the Patreon team has requested we migrate to v2 (see https://meta.discourse.org/t/upgrade-patreon-discourse-plugin-to-api-v2/386701). Since hundreds of existing customers have v1 OAuth clients, this PR supports **both versions simultaneously** via an adapter pattern, controlled by a new `patreon_api_version` site setting (defaults to `"1"` so no one breaks on upgrade). ### What changed - **Adapter pattern**: `Patreon::ApiVersion::V1` and `ApiVersion::V2` modules with identical interfaces for endpoints, response parsing, and OAuth config. `ApiVersion.current` routes based on the site setting. - **v2 API support**: campaigns endpoint returns tiers (not rewards), members fetched separately with cursor-based pagination, v2 identity endpoint with explicit field selection, v2 OAuth scopes - **Webhooks accept both formats**: payload version detected from `data.type` (`"pledge"` → v1, `"member"` → v2), regardless of the site setting - **Admin deprecation notice**: `ProblemCheck::PatreonApiV1Deprecated` warns on the dashboard when still using v1 - **Shared logic unchanged**: rate limiting, PluginStore, group sync, admin UI all version-agnostic - Also fixes pre-existing flaky seed/campaign spec failures ### Migration path for existing users 1. Admin sees deprecation warning on dashboard 2. Create a new v2 OAuth client at https://www.patreon.com/portal/registration/register-clients 3. Update credentials in site settings 4. Switch `patreon_api_version` to `"2"` 5. Creator re-authenticates via Patreon login to get v2-scoped tokens 6. Trigger a manual data sync from the Patreon admin panel ### Future v1 removal When ready to drop v1: delete `lib/api_version/v1.rb`, the problem check, the site setting, v1 fixtures, and v1 test contexts — one clean cut. ## Test plan - [x] All 41 plugin specs pass (both v1 and v2 contexts) - [x] Lint passes on all changed files - [x] Zeitwerk reload passes (`bin/rails runner "Rails.application.reloader.reload!"`) - [x] Manual testing with a real Patreon v2 OAuth client
92 lines
2.1 KiB
JSON
92 lines
2.1 KiB
JSON
{
|
|
"data": [
|
|
{
|
|
"attributes": {
|
|
"currently_entitled_amount_cents": 0,
|
|
"last_charge_date": null,
|
|
"last_charge_status": "Paid",
|
|
"patron_status": "active_patron",
|
|
"email": "foo@bar.com"
|
|
},
|
|
"id": "member-1",
|
|
"relationships": {
|
|
"currently_entitled_tiers": {
|
|
"data": [{ "id": "999999", "type": "tier" }]
|
|
},
|
|
"user": {
|
|
"data": { "id": "111111", "type": "user" }
|
|
}
|
|
},
|
|
"type": "member"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"currently_entitled_amount_cents": 100,
|
|
"last_charge_date": "2017-11-07T20:59:52+00:00",
|
|
"last_charge_status": "Declined",
|
|
"patron_status": "declined_patron",
|
|
"email": "boo@far.com"
|
|
},
|
|
"id": "member-2",
|
|
"relationships": {
|
|
"currently_entitled_tiers": {
|
|
"data": [{ "id": "999998", "type": "tier" }]
|
|
},
|
|
"user": {
|
|
"data": { "id": "111112", "type": "user" }
|
|
}
|
|
},
|
|
"type": "member"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"currently_entitled_amount_cents": 200,
|
|
"last_charge_date": "2017-11-10T20:59:52+00:00",
|
|
"last_charge_status": "Declined",
|
|
"patron_status": "declined_patron",
|
|
"email": "roo@aar.com"
|
|
},
|
|
"id": "member-3",
|
|
"relationships": {
|
|
"currently_entitled_tiers": {
|
|
"data": [{ "id": "999997", "type": "tier" }]
|
|
},
|
|
"user": {
|
|
"data": { "id": "111113", "type": "user" }
|
|
}
|
|
},
|
|
"type": "member"
|
|
}
|
|
],
|
|
"included": [
|
|
{
|
|
"attributes": {
|
|
"email": "foo@bar.com",
|
|
"full_name": "Foo Bar"
|
|
},
|
|
"id": "111111",
|
|
"type": "user"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"email": "boo@far.com",
|
|
"full_name": "Boo Far"
|
|
},
|
|
"id": "111112",
|
|
"type": "user"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"email": "roo@aar.com",
|
|
"full_name": "Roo Aar"
|
|
},
|
|
"id": "111113",
|
|
"type": "user"
|
|
}
|
|
],
|
|
"meta": {
|
|
"pagination": {
|
|
"total": 3
|
|
}
|
|
}
|
|
}
|