-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayments.go
79 lines (65 loc) · 1.94 KB
/
payments.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
package tebexgo
import (
"encoding/json"
"fmt"
"log"
"github.com/itschip/tebexgo/internal"
)
// Retrive the latest payments (up to a maximum of 100) made on your webstore.
func (s *Session) GetAllPayments() (*[]Payment, error) {
resp, err := internal.GetRequest(s.Secret, PaymentsEndpoint)
if err != nil {
log.Println("Failed to get all payments")
return nil, err
}
var payments []Payment
err = internal.UnmarshalResponse(resp, &payments)
if err != nil {
log.Println("Failed to unmarshal response")
return nil, err
}
return &payments, nil
}
// Retrive a payment made on your webstore by transaction ID.
func (s *Session) RetrievePayment(transactionId string) (*Payment, error) {
endpoint := fmt.Sprintf("%s/%s", PaymentsEndpoint, transactionId)
resp, err := internal.GetRequest(s.Secret, endpoint)
if err != nil {
log.Println("Failed to get payment")
return nil, err
}
var payment Payment
err = internal.UnmarshalResponse(resp, &payment)
if err != nil {
log.Println("Failed to unmarshal response")
return nil, err
}
return &payment, err
}
// Returns an array of fields (custom variables, etc) required to
// be entered for a manual payment to be created for a package.
func (s *Session) GetRequiredPaymentFields(packageId string) (*[]PaymentPackageFields, error) {
endpoint := fmt.Sprintf("%s/fields/%s", PaymentsEndpoint, packageId)
resp, err := internal.GetRequest(s.Secret, endpoint)
if err != nil {
return nil, err
}
var paymentFields []PaymentPackageFields
err = internal.UnmarshalResponse(resp, &paymentFields)
if err != nil {
return nil, err
}
return &paymentFields, nil
}
func (s *Session) UpdatePayment(transactionId string, object *UpdatePaymentObject) error {
endpoint := fmt.Sprintf("%s/%s", PaymentsEndpoint, transactionId)
jsonBody, err := json.Marshal(&object)
if err != nil {
return err
}
_, err = internal.PutRequest(s.Secret, endpoint, jsonBody)
if err != nil {
return err
}
return nil
}