我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

GitHub Marketplace API 的 web 挂钩事件

GitHub Marketplace app 从 Marketplace 购买事件 web 挂钩接收有关用户计划更改的信息。 当用户购买、取消或更改其付款计划时,就会触发 Marketplace 购买事件。 有关如何响应每类事件的详细信息,请参阅“帐单流程”。

此文档对您有帮助吗?

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。

GitHub Marketplace 购买 web 挂钩有效负载

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

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

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

每个 marketplace_purchase web 挂钩有效负载都含有以下信息:

类型描述
action字符串为生成 web 挂钩而执行的操作。 可以是 purchasedcancelledpending_changepending_change_cancelledchanged。 更多信息请参阅下面的 web 挂钩有效负载示例。 注:pending_changepending_change_cancelled 有效负载包含与 changed 有效负载示例中所示键相同的键。
effective_date字符串action 开始生效的日期。
sender对象执行 action 触发 web 挂钩的人。
marketplace_purchase对象GitHub Marketplace 购买信息。

marketplace_purchase 对象含有以下键:

类型描述
帐户对象与订阅关联的 organizationuser 帐户。 组织帐户将包含 Organization_billing_email, 这是组织的行政电子邮件地址。 要查找个人帐户的电子邮件地址,您可以使用获取经过身份验证的用户端点。
billing_cycle字符串可以是 yearlymonthly。 如果 account 所有者拥有免费 GitHub 计划并且购买了免费 GitHub Marketplace 计划,则 billing_cycle 将为 nil
unit_count整数购买的单位数。
on_free_trial布尔值account 处于免费试用期时,该值为 true
free_trial_ends_on字符串免费试用到期日期。
next_billing_date字符串下一个结算周期开始日期。 如果 account 所有者拥有免费 GitHub.com 计划并且购买了免费 GitHub Marketplace 计划,则 next_billing_date 将为 nil
plan对象userorganization 购买的计划。

plan 对象含有以下键:

类型描述
id整数此计划的唯一标识符。
name字符串计划的名称。
说明字符串此计划的说明。
monthly_price_in_cents整数此计划的每月价格(以美分为单位)。 例如,每月费用 10 美元的商品将显示价格 1000 美分。
yearly_price_in_cents整数此计划的每年价格(以美分为单位)。 例如,每月费用 100 美元的商品将显示价格 10000 美分。
price_model字符串此商品的定价模型。 可以是 flat-rateper-unitfree 之一。
has_free_trial布尔值当此商品提供免费试用时,该值为 true
unit_name字符串单位的名称。 如果定价模型不是 per-unit,则该值为 nil
bullet字符串数组定价计划中设置的项目符号的名称。

purchased 事件的 web 挂钩有效负载示例

此示例提供 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,
      "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 事件的 web 挂钩有效负载示例

计划中的更改包括升级和降级。 此示例表示 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,
      "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,
      "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 事件的 web 挂钩有效负载示例

{
  "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,
      "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"
      ]
    }
  }
}

此文档对您有帮助吗?

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。