-
Notifications
You must be signed in to change notification settings - Fork 1
/
plans.go
121 lines (105 loc) · 4.49 KB
/
plans.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package paystack
import (
"context"
"fmt"
)
type Plans struct {
client *Client
}
func newPlans(client *Client) *Plans {
return &Plans{
client: client,
}
}
type CreatePlanRequest struct {
Name string `json:"name,omitempty"`
Amount float32 `json:"amount,omitempty"`
Currency string `json:"currency,omitempty"`
Interval string `json:"interval,omitempty"`
Description string `json:"description,omitempty"`
SendInvoices bool `json:"send_invoices,omitempty"`
SendSMS bool `json:"send_sms,omitempty"`
InvoiceLimit bool `json:"invoice_limit,omitempty"`
}
type PlanResponse struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Amount int `json:"amount,omitempty"`
Interval string `json:"interval,omitempty"`
Integration int `json:"integration,omitempty"`
Domain string `json:"domain,omitempty"`
PlanCode string `json:"plan_code,omitempty"`
SendInvoices bool `json:"send_invoices,omitempty"`
SendSms bool `json:"send_sms,omitempty"`
HostedPage bool `json:"hosted_page,omitempty"`
Currency string `json:"currency,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
HostedPageURL string `json:"hosted_page_url,omitempty"`
HostedPageSummary string `json:"hosted_page_summary,omitempty"`
Subscription []SubscriptionResponse `json:"subscription,omitempty"`
}
type PlanSplitList struct {
Meta PaginationMeta `json:"meta"`
Data []PlanSplitResponse `json:"data"`
}
type PlanSplitResponse struct {
Subscription []SubscriptionResponse `json:"subscription,omitempty"`
Integration int `json:"integration,omitempty"`
Domain string `json:"domain,omitempty"`
Name string `json:"name,omitempty"`
PlanCode string `json:"plan_code,omitempty"`
Description interface{} `json:"description,omitempty"`
Amount int `json:"amount,omitempty"`
Interval string `json:"interval,omitempty"`
SendInvoices bool `json:"send_invoices,omitempty"`
SendSms bool `json:"send_sms,omitempty"`
HostedPage bool `json:"hosted_page,omitempty"`
HostedPageURL interface{} `json:"hosted_page_url,omitempty"`
HostedPageSummary interface{} `json:"hosted_page_summary,omitempty"`
Currency string `json:"currency,omitempty"`
ID int `json:"id,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
}
// Create creates a new plan.
// It sends a POST request to the "/plan" endpoint with the provided CreatePlanRequest
// and returns a CreatePlanResponse and an error, if any.
// For more details see https://paystack.com/docs/api/plan/#create
func (pn *Plans) Create(ctx context.Context, pln *CreatePlanRequest) (*PlanResponse, error) {
url := "/plan"
resp := &PlanResponse{}
err := postResource(ctx, pn.client, url, pln, resp)
return resp, err
}
// List/Search Plans
//
// For more details see https://paystack.com/docs/api/plan/#list
func (pn *Plans) List(ctx context.Context, params ...QueryType) (*PlanSplitList, error) {
var url string
if len(params) > 0 {
url = addQueryToUrl("plan", params...)
} else {
url = "/plan"
}
resp := &PlanSplitList{}
err := getResource(ctx, pn.client, url, resp)
return resp, err
}
// Fetch a Plan
//
// For more details see https://paystack.com/docs/api/plan/#fetch
func (pn *Plans) Fetch(ctx context.Context, id string) (*PlanResponse, error) {
url := fmt.Sprintf("/plan/%s", id)
resp := &PlanResponse{}
err := getResource(ctx, pn.client, url, resp)
return resp, err
}
// Update a plan
// For more details see https://paystack.com/docs/api/plan/#update
func (pn *Plans) Update(ctx context.Context, id string, txn *CreatePlanRequest) (*PlanResponse, error) {
url := fmt.Sprintf("/plan/%s", id)
resp := &PlanResponse{}
err := putResource(ctx, pn.client, url, txn, resp)
return resp, err
}