Skip to main content

GitHub Marketplace API 的 web 挂钩事件

GitHub Marketplace app 从 Marketplace 购买事件 web 挂钩接收有关用户计划更改的信息。 当用户购买、取消或更改其付款计划时,就会触发 Marketplace 购买事件。

GitHub Marketplace 购买 web 挂钩有效负载

Webhook POST 请求具有特殊的标头。 有关详细信息,请参阅“Webhook 传递头”。 GitHub 不会重新发送失败的递送尝试。 确保您的应用程序可以接收 GitHub 发送的所有 web 挂钩有效负载。

取消和降级在下一个结算周期的第一天生效。 如果新计划在下一个结算周期开始时生效,则将发送降级和取消事件。 新的购买和升级事件会立即生效。 使用 Webhook 有效负载中的 effective_date 来确定何时开始更改。

注意: 如果你发现任何恶意的 GitHub Marketplace 购买或其他恶意行为,请填写 报告滥用表单,提供有关用户的详细信息。

每个 marketplace_purchase Webhook 有效负载将含有以下信息:

密钥类型说明
actionstring为生成 web 挂钩而执行的操作。 可以是 purchasedcancelledpending_changepending_change_cancelledchanged。 更多信息请参阅下面的 web 挂钩有效负载示例。 注意:pending_changepending_change_cancelled 有效负载包含的键与 changed 有效负载示例中所示的键相同。
effective_datestringaction 生效日期。
senderobject采取 action 触发 Webhook 的人。
marketplace_purchaseobjectGitHub Marketplace 购买信息。

marketplace_purchase 对象具有以下键:

密钥类型说明
accountobject与订阅关联的 organizationuser 帐户。 组织帐户将包括 organization_billing_email,这是组织的管理电子邮件地址。 若要查找个人帐户的电子邮件地址,可使用获取已通过身份验证的用户终结点。
billing_cyclestring可以是 yearlymonthly。 如果 account 所有者拥有免费的 GitHub 计划并且已购买免费的 GitHub Marketplace 计划,billing_cycle 将为 nil
unit_countinteger购买的单位数。
on_free_trialbooleanaccount 免费试用时,该值为 true
free_trial_ends_onstring免费试用到期日期。
next_billing_datestring下一个结算周期开始日期。 如果 account 所有者拥有免费的 GitHub.com 计划并且已购买免费的 GitHub Marketplace 计划,next_billing_date 将为 nil
planobjectuserorganization 购买的计划。

plan 对象具有以下键:

密钥类型说明
idinteger此计划的唯一标识符。
namestring计划的名称。
descriptionstring此计划的说明。
monthly_price_in_centsinteger此计划的每月价格(以美分为单位)。 例如,每月费用 10 美元的商品将显示价格 1000 美分。
yearly_price_in_centsinteger此计划的每年价格(以美分为单位)。 例如,每月费用 100 美元的商品将显示价格 120000 美分。
price_modelstring此商品的定价模型。 可以是 flat-rateper-unitfree 之一。
has_free_trialboolean当此商品提供免费试用时,该值为 true
unit_namestring单位的名称。 如果定价模型不是 per-unit,则它将为 nil
bulletarray of strings定价计划中设置的项目符号的名称。

purchased 事件的 Webhook 有效负载示例

此示例提供 purchased 事件有效负载。

{
  "action": "purchased",
  "effective_date": "2017-10-25T00:00:00+00:00",
  "sender": {
    "login": "username",
    "id": 3877742,
    "avatar_url": "https://avatars2.githubusercontent.com/u/3877742?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/username",
    "html_url": "https://github.com/username",
    "followers_url": "https://api.github.com/users/username/followers",
    "following_url": "https://api.github.com/users/username/following{/other_user}",
    "gists_url": "https://api.github.com/users/username/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/username/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/username/subscriptions",
    "organizations_url": "https://api.github.com/users/username/orgs",
    "repos_url": "https://api.github.com/users/username/repos",
    "events_url": "https://api.github.com/users/username/events{/privacy}",
    "received_events_url": "https://api.github.com/users/username/received_events",
    "type": "User",
    "site_admin": true,
    "email": "username@email.com"
  },
  "marketplace_purchase": {
    "account": {
      "type": "Organization",
      "id": 18404719,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
      "login": "username",
      "organization_billing_email": "username@email.com"
    },
    "billing_cycle": "monthly",
    "unit_count": 1,
    "on_free_trial": false,
    "free_trial_ends_on": null,
    "next_billing_date": "2017-11-05T00:00:00+00:00",
    "plan": {
      "id": 435,
      "name": "Basic Plan",
      "description": "Basic Plan",
      "monthly_price_in_cents": 1000,
      "yearly_price_in_cents": 10000,
      "price_model": "per-unit",
      "has_free_trial": true,
      "unit_name": "seat",
      "bullets": [
        "Is Basic",
        "Because Basic "
      ]
    }
  }
}

changed 事件的 Webhook 有效负载示例

计划中的更改包括升级和降级。 此示例表示 changedpending_changepending_change_cancelled 事件有效负载。 该操作标识这三个事件中发生了哪一个。

{
  "action": "changed",
  "effective_date": "2017-10-25T00:00:00+00:00",
  "sender": {
    "login": "username",
    "id": 3877742,
    "avatar_url": "https://avatars2.githubusercontent.com/u/3877742?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/username",
    "html_url": "https://github.com/username",
    "followers_url": "https://api.github.com/users/username/followers",
    "following_url": "https://api.github.com/users/username/following{/other_user}",
    "gists_url": "https://api.github.com/users/username/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/username/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/username/subscriptions",
    "organizations_url": "https://api.github.com/users/username/orgs",
    "repos_url": "https://api.github.com/users/username/repos",
    "events_url": "https://api.github.com/users/username/events{/privacy}",
    "received_events_url": "https://api.github.com/users/username/received_events",
    "type": "User",
    "site_admin": true,
    "email": "username@email.com"
  },
  "marketplace_purchase": {
    "account": {
      "type": "Organization",
      "id": 18404719,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
      "login": "username",
      "organization_billing_email": "username@email.com"
    },
    "billing_cycle": "monthly",
    "unit_count": 10,
    "on_free_trial": false,
    "free_trial_ends_on": null,
    "next_billing_date": "2017-11-05T00:00:00+00:00",
    "plan": {
      "id": 435,
      "name": "Basic Plan",
      "description": "Basic Plan",
      "monthly_price_in_cents": 1000,
      "yearly_price_in_cents": 10000,
      "price_model": "per-unit",
      "has_free_trial": true,
      "unit_name": "seat",
      "bullets": [
        "Is Basic",
        "Because Basic "
      ]
    }
  },
  "previous_marketplace_purchase": {
    "account": {
      "type": "Organization",
      "id": 18404719,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
      "login": "username",
      "organization_billing_email": "username@email.com"
    },
    "billing_cycle": "monthly",
    "on_free_trial": false,
    "free_trial_ends_on": null,
    "unit_count": 1,
    "plan": {
      "id": 435,
      "name": "Basic Plan",
      "description": "Basic Plan",
      "monthly_price_in_cents": 1000,
      "yearly_price_in_cents": 10000,
      "price_model": "per-unit",
      "has_free_trial": true,
      "unit_name": "seat",
      "bullets": [
        "Is Basic",
        "Because Basic "
      ]
    }
  }
}

cancelled 事件的 Webhook 有效负载示例

{
  "action": "cancelled",
  "effective_date": "2017-10-25T00:00:00+00:00",
  "sender": {
    "login": "username",
    "id": 3877742,
    "avatar_url": "https://avatars2.githubusercontent.com/u/3877742?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/username",
    "html_url": "https://github.com/username",
    "followers_url": "https://api.github.com/users/username/followers",
    "following_url": "https://api.github.com/users/username/following{/other_user}",
    "gists_url": "https://api.github.com/users/username/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/username/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/username/subscriptions",
    "organizations_url": "https://api.github.com/users/username/orgs",
    "repos_url": "https://api.github.com/users/username/repos",
    "events_url": "https://api.github.com/users/username/events{/privacy}",
    "received_events_url": "https://api.github.com/users/username/received_events",
    "type": "User",
    "site_admin": true,
    "email": "username@email.com"
  },
  "marketplace_purchase": {
    "account": {
      "type": "Organization",
      "id": 28536653,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
      "login": "organizationUsername",
      "organization_billing_email": "organizationusername@gmail.com"
    },
    "billing_cycle": "monthly",
    "unit_count": 0,
    "on_free_trial": false,
    "free_trial_ends_on": null,
    "next_billing_date": "2017-11-08T00:00:00+00:00",
    "plan": {
      "id": 686,
      "name": "Premium Plan",
      "description": "Premium Plan",
      "monthly_price_in_cents": 10000,
      "yearly_price_in_cents": 100000,
      "price_model": "flat-rate",
      "has_free_trial": true,
      "unit_name": null,
      "bullets": [
        "Is Expensive",
        "And Flat Rate"
      ]
    }
  }
}