-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapple_pay_client.go
135 lines (128 loc) · 4.61 KB
/
apple_pay_client.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package paystack
import "net/http"
// ApplePayClient interacts with endpoints related to paystack Apple Pay resource that
// lets you register your application's top-level domain or subdomain.
type ApplePayClient struct {
*baseAPIClient
}
// NewApplePayClient creates a ApplePayClient
//
// Example:
//
// import p "github.com/gray-adeyi/paystack"
//
// applePayClient := p.NewApplePayClient(p.WithSecretKey("<paystack-secret-key>"))
func NewApplePayClient(options ...ClientOptions) *ApplePayClient {
client := NewAPIClient(options...)
return client.ApplePay
}
// Register lets you register a top-level domain or subdomain for your Apple Pay Integration.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// applePayClient := p.ApplePayClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access an Apple Pay client from APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.ApplePay field is a `ApplePayClient`
// // Therefore, this is possible
// // resp, err := paystackClient.ApplePay.Register("<domainName>")
//
// resp, err := applePayClient.Register("<domainName>")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (a *ApplePayClient) Register(domainName string) (*Response, error) {
payload := make(map[string]interface{})
payload["domainName"] = domainName
return a.APICall(http.MethodPost, "/apple-pay/domain", payload)
}
// All lets you retrieve all registered domains on your Integration.
// Returns an empty array if no domains have been added.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// applePayClient := p.NewApplePayClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access an Apple Pay client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.ApplePay field is a `ApplePayClient`
// // Therefore, this is possible
// // resp, err := paystackClient.ApplePay.All()
//
// // All also accepts queries, so say you want to use cursor, you can write it like so.
// // resp, err := applePayClient.All(p.WithQuery("use_cursor","true"))
//
// // see https://paystack.com/docs/api/apple-pay/#list-domains for supported query parameters
//
// resp, err := applePayClient.All()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (a *ApplePayClient) All(queries ...Query) (*Response, error) {
url := AddQueryParamsToUrl("/apple-pay/domain", queries...)
return a.APICall(http.MethodGet, url, nil)
}
// Unregister lets you unregister a top-level domain or subdomain previously used for your Apple Pay Integration.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// applePayClient := p.ApplePayClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access an Apple Pay client from APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.ApplePay field is a `ApplePayClient`
// // Therefore, this is possible
// // resp, err := paystackClient.ApplePay.Unregister("<domainName>")
//
// resp, err := applePayClient.Unregister("<domainName>")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (a *ApplePayClient) Unregister(domainName string) (*Response, error) {
payload := make(map[string]interface{})
payload["domainName"] = domainName
return a.APICall(http.MethodDelete, "/apple-pay/domain", payload)
}