-
Notifications
You must be signed in to change notification settings - Fork 274
/
transaction_search.go
96 lines (85 loc) · 2.76 KB
/
transaction_search.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
package paypal
import (
"context"
"fmt"
"strconv"
"time"
)
type TransactionSearchRequest struct {
TransactionID *string
TransactionType *string
TransactionStatus *string
TransactionAmount *string
TransactionCurrency *string
StartDate time.Time
EndDate time.Time
PaymentInstrumentType *string
StoreID *string
TerminalID *string
Fields *string
BalanceAffectingRecordsOnly *string
PageSize *int
Page *int
}
type TransactionSearchResponse struct {
TransactionDetails []SearchTransactionDetails `json:"transaction_details"`
AccountNumber string `json:"account_number"`
StartDate JSONTime `json:"start_date"`
EndDate JSONTime `json:"end_date"`
LastRefreshDatetime JSONTime `json:"last_refreshed_datetime"`
Page int `json:"page"`
SharedListResponse
}
// ListTransactions - Use this to search PayPal transactions from the last 31 days.
// Endpoint: GET /v1/reporting/transactions
func (c *Client) ListTransactions(ctx context.Context, req *TransactionSearchRequest) (*TransactionSearchResponse, error) {
response := &TransactionSearchResponse{}
r, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/reporting/transactions"), nil)
if err != nil {
return nil, err
}
q := r.URL.Query()
q.Add("start_date", req.StartDate.Format(time.RFC3339))
q.Add("end_date", req.EndDate.Format(time.RFC3339))
if req.TransactionID != nil {
q.Add("transaction_id", *req.TransactionID)
}
if req.TransactionType != nil {
q.Add("transaction_type", *req.TransactionType)
}
if req.TransactionStatus != nil {
q.Add("transaction_status", *req.TransactionStatus)
}
if req.TransactionAmount != nil {
q.Add("transaction_amount", *req.TransactionAmount)
}
if req.TransactionCurrency != nil {
q.Add("transaction_currency", *req.TransactionCurrency)
}
if req.PaymentInstrumentType != nil {
q.Add("payment_instrument_type", *req.PaymentInstrumentType)
}
if req.StoreID != nil {
q.Add("store_id", *req.StoreID)
}
if req.TerminalID != nil {
q.Add("terminal_id", *req.TerminalID)
}
if req.Fields != nil {
q.Add("fields", *req.Fields)
}
if req.BalanceAffectingRecordsOnly != nil {
q.Add("balance_affecting_records_only", *req.BalanceAffectingRecordsOnly)
}
if req.PageSize != nil {
q.Add("page_size", strconv.Itoa(*req.PageSize))
}
if req.Page != nil {
q.Add("page", strconv.Itoa(*req.Page))
}
r.URL.RawQuery = q.Encode()
if err = c.SendWithAuth(r, response); err != nil {
return nil, err
}
return response, nil
}