Debian Codegraph @

scrape/payment.go

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