-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathpayment.go
51 lines (41 loc) · 1.29 KB
/
payment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// apps.go contains functions for accessing data about applications installed
// on a GitHub organization.
package scrape
import (
"strings"
"github.com/PuerkitoBio/goquery"
)
// OrgPaymentInformation returns payment information for the specified org.
func (c *Client) OrgPaymentInformation(org string) (PaymentInformation, error) {
var info PaymentInformation
doc, err := c.get("/organizations/%s/settings/billing/payment_information", org)
if err != nil {
return info, err
}
doc.Find("main h4.mb-1").Each(func(i int, s *goquery.Selection) {
name := strings.TrimSpace(strings.ToLower(s.Text()))
value := strings.Join(strings.Fields(strings.TrimSpace(s.NextFiltered("p").Text())), " ")
switch name {
case "payment method":
info.PaymentMethod = value
case "last payment":
info.LastPayment = value
case "coupon":
info.Coupon = value
case "extra information":
info.ExtraInformation = value
}
})
return info, nil
}
// PaymentInformation for an organization on a paid plan.
type PaymentInformation struct {
PaymentMethod string
LastPayment string
Coupon string
ExtraInformation string
}