-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathcharge.go
113 lines (101 loc) · 4.26 KB
/
charge.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
package paystack
import (
"fmt"
"net/url"
)
// ChargeService handles operations related to bulk charges
// For more details see https://developers.paystack.co/v1.0/reference#charge-tokenize
type ChargeService service
// Card represents a Card object
type Card struct {
Number string `json:"card_number,omitempty"`
CVV string `json:"card_cvc,omitempty"`
ExpirtyMonth string `json:"expiry_month,omitempty"`
ExpiryYear string `json:"expiry_year,omitempty"`
AddressLine1 string `json:"address_line1,omitempty"`
AddressLine2 string `json:"address_line2,omitempty"`
AddressLine3 string `json:"address_line3,omitempty"`
AddressCountry string `json:"address_country,omitempty"`
AddressPostalCode string `json:"address_postal_code,omitempty"`
Country string `json:"country,omitempty"`
}
// BankAccount is used as bank in a charge request
type BankAccount struct {
Code string `json:"code,omitempty"`
AccountNumber string `json:"account_number,omitempty"`
}
// ChargeRequest represents a Paystack charge request
type ChargeRequest struct {
Email string `json:"email,omitempty"`
Amount float32 `json:"amount,omitempty"`
Birthday string `json:"birthday,omitempty"`
Card *Card `json:"card,omitempty"`
Bank *BankAccount `json:"bank,omitempty"`
AuthorizationCode string `json:"authorization_code,omitempty"`
Pin string `json:"pin,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}
// Create submits a charge request using card details or bank details or authorization code
// For more details see https://developers.paystack.co/v1.0/reference#charge
func (s *ChargeService) Create(req *ChargeRequest) (Response, error) {
resp := Response{}
err := s.client.Call("POST", "/charge", req, &resp)
return resp, err
}
// Tokenize tokenizes payment instrument before a charge
// For more details see https://developers.paystack.co/v1.0/reference#charge-tokenize
func (s *ChargeService) Tokenize(req *ChargeRequest) (Response, error) {
resp := Response{}
err := s.client.Call("POST", "/charge/tokenize", req, &resp)
return resp, err
}
// SubmitPIN submits PIN to continue a charge
// For more details see https://developers.paystack.co/v1.0/reference#submit-pin
func (s *ChargeService) SubmitPIN(pin, reference string) (Response, error) {
data := url.Values{}
data.Add("pin", pin)
data.Add("reference", reference)
resp := Response{}
err := s.client.Call("POST", "/charge/submit_pin", data, &resp)
return resp, err
}
// SubmitOTP submits OTP to continue a charge
// For more details see https://developers.paystack.co/v1.0/reference#submit-pin
func (s *ChargeService) SubmitOTP(otp, reference string) (Response, error) {
data := url.Values{}
data.Add("pin", otp)
data.Add("reference", reference)
resp := Response{}
err := s.client.Call("POST", "/charge/submit_otp", data, &resp)
return resp, err
}
// SubmitPhone submits Phone when requested
// For more details see https://developers.paystack.co/v1.0/reference#submit-pin
func (s *ChargeService) SubmitPhone(phone, reference string) (Response, error) {
data := url.Values{}
data.Add("pin", phone)
data.Add("reference", reference)
resp := Response{}
err := s.client.Call("POST", "/charge/submit_phone", data, &resp)
return resp, err
}
// SubmitBirthday submits Birthday when requested
// For more details see https://developers.paystack.co/v1.0/reference#submit-pin
func (s *ChargeService) SubmitBirthday(birthday, reference string) (Response, error) {
data := url.Values{}
data.Add("pin", birthday)
data.Add("reference", reference)
resp := Response{}
err := s.client.Call("POST", "/charge/submit_birthday", data, &resp)
return resp, err
}
// CheckPending returns pending charges
// When you get "pending" as a charge status, wait 30 seconds or more,
// then make a check to see if its status has changed. Don't call too early as you may get a lot more pending than you should.
// For more details see https://developers.paystack.co/v1.0/reference#check-pending-charge
func (s *ChargeService) CheckPending(reference string) (Response, error) {
u := fmt.Sprintf("/charge/%s", reference)
resp := Response{}
err := s.client.Call("GET", u, nil, &resp)
return resp, err
}