-
Notifications
You must be signed in to change notification settings - Fork 0
/
reservedAccounts.go
116 lines (94 loc) · 3.54 KB
/
reservedAccounts.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
package gomonnify
import (
"errors"
"fmt"
"github.com/jcobhams/gomonnify/params"
"net/http"
"strings"
)
//ReserveAccount reserves an account number for a customer based on the provided configuration params.
//Docs: https://docs.teamapt.com/display/MON/Reserving+An+Account
func (r *reservedAccounts) ReserveAccount(params params.ReserveAccountParam) (*ReserveAccountResponse, error) {
url := fmt.Sprintf("%v/v1/bank-transfer/reserved-accounts", r.APIBaseUrl)
rawResponse, statusCode, err := r.postRequest(url, requestAuthTypeBearer, params)
if err != nil {
return nil, err
}
result := ReserveAccountResponse{}
err = r.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
//Details gets the reserved account information for the provided account reference.
//Docs: https://docs.teamapt.com/display/MON/Get+Reserved+Account+Details
func (r *reservedAccounts) Details(accountReference string) (*ReserveAccountResponse, error) {
if accountReference == "" {
return nil, errors.New("accountReference is required")
}
url := fmt.Sprintf("%v/v1/bank-transfer/reserved-accounts/%v", r.APIBaseUrl, accountReference)
rawResponse, statusCode, err := r.getRequest(url, requestAuthTypeBearer)
if err != nil {
return nil, err
}
var result ReserveAccountResponse
err = r.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
//Deallocate deletes a reserved account.
//Docs: https://docs.teamapt.com/display/MON/Deallocating+a+reserved+account
func (r *reservedAccounts) Deallocate(accountNumber string) error {
if accountNumber == "" {
return errors.New("accountNumber is required")
}
url := fmt.Sprintf("%v/v1/bank-transfer/reserved-accounts/%v", r.APIBaseUrl, accountNumber)
rawResponse, statusCode, err := r.deleteRequest(url, requestAuthTypeBearer)
if err != nil {
return err
}
var result ReserveAccountResponse
err = r.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return err
}
if statusCode != http.StatusOK {
return failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return nil
}
//Transactions fetches all the transaction on a reserved account for the provided account reference.
//Docs: https://docs.teamapt.com/display/MON/Getting+all+transactions+on+a+reserved+account
func (r *reservedAccounts) Transactions(accountReference string, page, size int) (*ReservedAccountTransactionsResponse, error) {
if accountReference == "" {
return nil, errors.New("accountNumber is required")
}
url := fmt.Sprintf("%v/v1/bank-transfer/reserved-accounts/transactions?accountReference=%v&page=%v&size=%v", r.APIBaseUrl, accountReference, page, size)
rawResponse, statusCode, err := r.getRequest(url, requestAuthTypeBearer)
if err != nil {
return nil, err
}
var result ReservedAccountTransactionsResponse
err = r.unmarshallJson(strings.NewReader(rawResponse), &result)
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, failedRequestMessage(statusCode, result.ResponseCode, result.ResponseMessage)
}
return &result, nil
}
//TODO
func (r *reservedAccounts) updateIncomeSplitConfig(accountReference string) {
}
func (r *reservedAccounts) updatePaymentSourceFilter(accountReference string) {
}