forked from jinmatt/go-quickbooks.v2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
payment.go
74 lines (65 loc) · 2.22 KB
/
payment.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
package quickbooks
import (
"encoding/json"
"fmt"
)
// PaymentObject the complete quickbooks payment object type
type PaymentObject struct {
Payment Payment `json:"Payment"`
Time string `json:"time"`
}
// Payment quickbooks payment type
type Payment struct {
ID string `json:"Id,omitempty"`
CustomerRef *CustomerRef `json:"CustomerRef,omitempty"`
DepositToAccountRef *AccountRef `json:"DepositToAccountRef,omitempty"`
TotalAmt float64 `json:"TotalAmt"`
UnappliedAmt float64 `json:"UnappliedAmt,omitempty"`
ProcessPayment bool `json:"ProcessPayment,omitempty"`
Domain string `json:"domain,omitempty"`
Sparse bool `json:"sparse,omitempty"`
SyncToken string `json:"SyncToken,omitempty"`
TxnDate string `json:"TxnDate,omitempty"`
Line []PaymentLine `json:"Line"`
MetaData *struct {
CreateTime string `json:"CreateTime"`
LastUpdatedTime string `json:"LastUpdatedTime"`
} `json:"MetaData,omitempty"`
PaymentRefNum string `json:"PaymentRefNum,omitempty"`
}
// PaymentLine quickbooks payment line object
type PaymentLine struct {
Amount float64 `json:"Amount"`
LinkedTxn []LinkedTxn `json:"LinkedTxn"`
LineEx *LineEx `json:"LineEx,omitempty"`
}
// LineEx quickbooks payment LineEx object
type LineEx struct {
Any []struct {
Name string `json:"name"`
DeclaredType string `json:"declaredType"`
Scope string `json:"scope"`
Value struct {
Name string `json:"Name"`
Value string `json:"Value"`
} `json:"value"`
Nil bool `json:"nil"`
GlobalScope bool `json:"globalScope"`
TypeSubstituted bool `json:"typeSubstituted"`
} `json:"any"`
}
// CreatePayment creates a payment on quickbooks
func (q *Quickbooks) CreatePayment(payment Payment) (*PaymentObject, error) {
endpoint := fmt.Sprintf("/company/%s/payment", q.RealmID)
res, err := q.makePostRequest(endpoint, payment)
if err != nil {
return nil, err
}
defer res.Body.Close()
newPayment := PaymentObject{}
err = json.NewDecoder(res.Body).Decode(&newPayment)
if err != nil {
return nil, err
}
return &newPayment, nil
}