Skip to content

Commit a20c5a1

Browse files
Sridhar Mocherlagmlewis
Sridhar Mocherla
authored andcommitted
Support updates to Marketplace APIs and webhook payload (google#1042)
Helps google#1040.
1 parent 8c3c3ba commit a20c5a1

File tree

4 files changed

+111
-24
lines changed

4 files changed

+111
-24
lines changed

github/apps_marketplace.go

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,52 @@ type MarketplaceService struct {
2727

2828
// MarketplacePlan represents a GitHub Apps Marketplace Listing Plan.
2929
type MarketplacePlan struct {
30-
URL *string `json:"url,omitempty"`
31-
AccountsURL *string `json:"accounts_url,omitempty"`
32-
ID *int64 `json:"id,omitempty"`
33-
Name *string `json:"name,omitempty"`
34-
Description *string `json:"description,omitempty"`
35-
MonthlyPriceInCents *int `json:"monthly_price_in_cents,omitempty"`
36-
YearlyPriceInCents *int `json:"yearly_price_in_cents,omitempty"`
37-
PriceModel *string `json:"price_model,omitempty"`
38-
UnitName *string `json:"unit_name,omitempty"`
39-
Bullets *[]string `json:"bullets,omitempty"`
30+
URL *string `json:"url,omitempty"`
31+
AccountsURL *string `json:"accounts_url,omitempty"`
32+
ID *int64 `json:"id,omitempty"`
33+
Name *string `json:"name,omitempty"`
34+
Description *string `json:"description,omitempty"`
35+
MonthlyPriceInCents *int `json:"monthly_price_in_cents,omitempty"`
36+
YearlyPriceInCents *int `json:"yearly_price_in_cents,omitempty"`
37+
// The pricing model for this listing. Can be one of "flat-rate", "per-unit", or "free".
38+
PriceModel *string `json:"price_model,omitempty"`
39+
UnitName *string `json:"unit_name,omitempty"`
40+
Bullets *[]string `json:"bullets,omitempty"`
41+
// State can be one of the values "draft" or "published".
42+
State *string `json:"state,omitempty"`
43+
HasFreeTrial *bool `json:"has_free_trial,omitempty"`
4044
}
4145

4246
// MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
4347
type MarketplacePurchase struct {
48+
// BillingCycle can be one of the values "yearly", "monthly" or nil.
4449
BillingCycle *string `json:"billing_cycle,omitempty"`
45-
NextBillingDate *string `json:"next_billing_date,omitempty"`
50+
NextBillingDate *Timestamp `json:"next_billing_date,omitempty"`
4651
UnitCount *int `json:"unit_count,omitempty"`
4752
Plan *MarketplacePlan `json:"plan,omitempty"`
4853
Account *MarketplacePlanAccount `json:"account,omitempty"`
54+
OnFreeTrial *bool `json:"on_free_trial,omitempty"`
55+
FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"`
56+
}
57+
58+
// MarketplacePendingChange represents a pending change to a GitHub Apps Marketplace Plan.
59+
type MarketplacePendingChange struct {
60+
EffectiveDate *Timestamp `json:"effective_date,omitempty"`
61+
UnitCount *int `json:"unit_count,omitempty"`
62+
ID *int64 `json:"id,omitempty"`
63+
Plan *MarketplacePlan `json:"plan,omitempty"`
4964
}
5065

5166
// MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan.
5267
type MarketplacePlanAccount struct {
53-
URL *string `json:"url,omitempty"`
54-
Type *string `json:"type,omitempty"`
55-
ID *int64 `json:"id,omitempty"`
56-
Login *string `json:"login,omitempty"`
57-
Email *string `json:"email,omitempty"`
58-
OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
59-
MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
68+
URL *string `json:"url,omitempty"`
69+
Type *string `json:"type,omitempty"`
70+
ID *int64 `json:"id,omitempty"`
71+
Login *string `json:"login,omitempty"`
72+
Email *string `json:"email,omitempty"`
73+
OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
74+
MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
75+
MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"`
6076
}
6177

6278
// ListPlans lists all plans for your Marketplace listing.
@@ -155,7 +171,6 @@ func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context
155171
if err != nil {
156172
return nil, resp, err
157173
}
158-
159174
return purchases, resp, nil
160175
}
161176

github/apps_marketplace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
111111

112112
mux.HandleFunc("/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) {
113113
testMethod(t, r, "GET")
114-
fmt.Fprint(w, `[{"id":1}]`)
114+
fmt.Fprint(w, `[{"id":1, "marketplace_pending_change": {"id": 77}}]`)
115115
})
116116

117117
opt := &ListOptions{Page: 1, PerPage: 2}
@@ -121,7 +121,7 @@ func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
121121
t.Errorf("Marketplace.ListPlanAccountsForAccount returned error: %v", err)
122122
}
123123

124-
want := []*MarketplacePlanAccount{{ID: Int64(1)}}
124+
want := []*MarketplacePlanAccount{{ID: Int64(1), MarketplacePendingChange: &MarketplacePendingChange{ID: Int64(77)}}}
125125
if !reflect.DeepEqual(accounts, want) {
126126
t.Errorf("Marketplace.ListPlanAccountsForAccount returned %+v, want %+v", accounts, want)
127127
}

github/event_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ type LabelEvent struct {
308308
// Github API docs: https://developer.github.com/v3/activity/events/types/#marketplacepurchaseevent
309309
type MarketplacePurchaseEvent struct {
310310
// Action is the action that was performed. Possible values are:
311-
// "purchased", "cancelled", "changed".
311+
// "purchased", "cancelled", "pending_change", "pending_change_cancelled", "changed".
312312
Action *string `json:"action,omitempty"`
313313

314314
// The following fields are only populated by Webhook events.

github/github-accessors.go

Lines changed: 74 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)