mirror of
https://github.com/discourse/discourse.git
synced 2026-08-09 21:45:25 +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
183 lines
5.6 KiB
JSON
Vendored
183 lines
5.6 KiB
JSON
Vendored
{
|
|
"data": [
|
|
{
|
|
"attributes": {
|
|
"amount_cents": 0,
|
|
"created_at": "2016-07-25T20:59:52+00:00",
|
|
"declined_since": null,
|
|
"patron_pays_fees": false,
|
|
"pledge_cap_cents": null
|
|
},
|
|
"id": "2745627",
|
|
"relationships": {
|
|
"patron": {
|
|
"data": {
|
|
"id": "111111",
|
|
"type": "user"
|
|
},
|
|
"links": {
|
|
"related": "https://www.patreon.com/api/user/111111"
|
|
}
|
|
},
|
|
"reward": {
|
|
"data": {
|
|
"id": "999999"
|
|
}
|
|
}
|
|
},
|
|
"type": "pledge"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"amount_cents": 100,
|
|
"created_at": "2016-08-25T20:59:52+00:00",
|
|
"declined_since": "2017-11-07T20:59:52+00:00",
|
|
"patron_pays_fees": false,
|
|
"pledge_cap_cents": null
|
|
},
|
|
"id": "2745628",
|
|
"relationships": {
|
|
"patron": {
|
|
"data": {
|
|
"id": "111112",
|
|
"type": "user"
|
|
},
|
|
"links": {
|
|
"related": "https://www.patreon.com/api/user/111112"
|
|
}
|
|
},
|
|
"reward": {
|
|
"data": {
|
|
"id": "999998"
|
|
}
|
|
}
|
|
},
|
|
"type": "pledge"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"amount_cents": 200,
|
|
"created_at": "2017-01-15T20:59:52+00:00",
|
|
"declined_since": "2017-11-10T20:59:52+00:00",
|
|
"patron_pays_fees": false,
|
|
"pledge_cap_cents": null
|
|
},
|
|
"id": "2745629",
|
|
"relationships": {
|
|
"patron": {
|
|
"data": {
|
|
"id": "111113",
|
|
"type": "user"
|
|
},
|
|
"links": {
|
|
"related": "https://www.patreon.com/api/user/111113"
|
|
}
|
|
},
|
|
"reward": {
|
|
"data": {
|
|
"id": "999997"
|
|
}
|
|
}
|
|
},
|
|
"type": "pledge"
|
|
}
|
|
],
|
|
"included": [
|
|
{
|
|
"attributes": {
|
|
"about": "sample about text",
|
|
"created": "2015-01-15T07:25:51+00:00",
|
|
"email": "foo@bar.com",
|
|
"facebook": null,
|
|
"first_name": "Foo",
|
|
"full_name": "Foo Bar",
|
|
"gender": 1,
|
|
"image_url": "",
|
|
"is_email_verified": true,
|
|
"last_name": "Bar",
|
|
"social_connections": {
|
|
"deviantart": null,
|
|
"discord": null,
|
|
"facebook": null,
|
|
"spotify": null,
|
|
"twitch": null,
|
|
"twitter": null,
|
|
"youtube": null
|
|
},
|
|
"thumb_url": "",
|
|
"twitch": null,
|
|
"twitter": "foo",
|
|
"url": "https://www.patreon.com/foo",
|
|
"vanity": "foo",
|
|
"youtube": null
|
|
},
|
|
"id": "111111",
|
|
"type": "user"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"about": "about text sample",
|
|
"created": "2015-01-15T07:25:51+00:00",
|
|
"email": "boo@far.com",
|
|
"facebook": null,
|
|
"first_name": "Boo",
|
|
"full_name": "Boo Far",
|
|
"gender": 1,
|
|
"image_url": "",
|
|
"is_email_verified": true,
|
|
"last_name": "Far",
|
|
"social_connections": {
|
|
"deviantart": null,
|
|
"discord": null,
|
|
"facebook": null,
|
|
"spotify": null,
|
|
"twitch": null,
|
|
"twitter": null,
|
|
"youtube": null
|
|
},
|
|
"thumb_url": "",
|
|
"twitch": null,
|
|
"twitter": "boo",
|
|
"url": "https://www.patreon.com/boo",
|
|
"vanity": "boo",
|
|
"youtube": null
|
|
},
|
|
"id": "111112",
|
|
"type": "user"
|
|
},
|
|
{
|
|
"attributes": {
|
|
"about": "sample text about",
|
|
"created": "2015-01-15T07:25:51+00:00",
|
|
"email": "roo@aar.com",
|
|
"facebook": null,
|
|
"first_name": "Roo",
|
|
"full_name": "Roo Aar",
|
|
"gender": 1,
|
|
"image_url": "",
|
|
"is_email_verified": true,
|
|
"last_name": "Aar",
|
|
"social_connections": {
|
|
"deviantart": null,
|
|
"discord": null,
|
|
"facebook": null,
|
|
"spotify": null,
|
|
"twitch": null,
|
|
"twitter": null,
|
|
"youtube": null
|
|
},
|
|
"thumb_url": "",
|
|
"twitch": null,
|
|
"twitter": "roo",
|
|
"url": "https://www.patreon.com/foo",
|
|
"vanity": "roo",
|
|
"youtube": null
|
|
},
|
|
"id": "111113",
|
|
"type": "user"
|
|
}
|
|
],
|
|
"meta": {
|
|
"count": 18
|
|
}
|
|
}
|