-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreceipts.go
executable file
·214 lines (188 loc) · 6.7 KB
/
receipts.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Code generated by `go-sdk-gen`. DO NOT EDIT.
package sumup
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
)
// Receipt is a schema definition.
type Receipt struct {
AcquirerData *ReceiptAcquirerData `json:"acquirer_data,omitempty"`
EmvData *ReceiptEmvData `json:"emv_data,omitempty"`
// Receipt merchant data
MerchantData *ReceiptMerchantData `json:"merchant_data,omitempty"`
// Transaction information.
TransactionData *ReceiptTransaction `json:"transaction_data,omitempty"`
}
// ReceiptAcquirerData is a schema definition.
type ReceiptAcquirerData struct {
AuthorizationCode *string `json:"authorization_code,omitempty"`
LocalTime *string `json:"local_time,omitempty"`
ReturnCode *string `json:"return_code,omitempty"`
Tid *string `json:"tid,omitempty"`
}
// ReceiptEmvData is a schema definition.
type ReceiptEmvData struct {
}
// ReceiptCard is a schema definition.
type ReceiptCard struct {
// Card last 4 digits.
Last4Digits *string `json:"last_4_digits,omitempty"`
// Card Scheme.
Type *string `json:"type,omitempty"`
}
// ReceiptEvent is a schema definition.
type ReceiptEvent struct {
// Amount of the event.
Amount *AmountEvent `json:"amount,omitempty"`
// Unique ID of the transaction event.
// Format: int64
Id *EventId `json:"id,omitempty"`
ReceiptNo *string `json:"receipt_no,omitempty"`
// Status of the transaction event.
Status *EventStatus `json:"status,omitempty"`
// Date and time of the transaction event.
Timestamp *TimestampEvent `json:"timestamp,omitempty"`
// Unique ID of the transaction.
TransactionId *TransactionId `json:"transaction_id,omitempty"`
// Type of the transaction event.
Type *EventType `json:"type,omitempty"`
}
// ReceiptMerchantData: Receipt merchant data
type ReceiptMerchantData struct {
Locale *string `json:"locale,omitempty"`
MerchantProfile *ReceiptMerchantDataMerchantProfile `json:"merchant_profile,omitempty"`
}
// ReceiptMerchantDataMerchantProfile is a schema definition.
type ReceiptMerchantDataMerchantProfile struct {
Address *ReceiptMerchantDataMerchantProfileAddress `json:"address,omitempty"`
BusinessName *string `json:"business_name,omitempty"`
Email *string `json:"email,omitempty"`
MerchantCode *string `json:"merchant_code,omitempty"`
}
// ReceiptMerchantDataMerchantProfileAddress is a schema definition.
type ReceiptMerchantDataMerchantProfileAddress struct {
AddressLine1 *string `json:"address_line_1,omitempty"`
City *string `json:"city,omitempty"`
Country *string `json:"country,omitempty"`
CountryEnName *string `json:"country_en_name,omitempty"`
CountryNativeName *string `json:"country_native_name,omitempty"`
Landline *string `json:"landline,omitempty"`
PostCode *string `json:"post_code,omitempty"`
}
// ReceiptTransaction: Transaction information.
type ReceiptTransaction struct {
// Transaction amount.
Amount *string `json:"amount,omitempty"`
Card *ReceiptCard `json:"card,omitempty"`
// Transaction currency.
Currency *string `json:"currency,omitempty"`
// Transaction entry mode.
EntryMode *string `json:"entry_mode,omitempty"`
// Events
Events *[]ReceiptEvent `json:"events,omitempty"`
// Number of installments.
InstallmentsCount *int `json:"installments_count,omitempty"`
// Transaction type.
PaymentType *string `json:"payment_type,omitempty"`
// Products
Products *[]ReceiptTransactionProduct `json:"products,omitempty"`
// Receipt number
ReceiptNo *string `json:"receipt_no,omitempty"`
// Transaction processing status.
Status *string `json:"status,omitempty"`
// Time created at.
Timestamp *time.Time `json:"timestamp,omitempty"`
// Tip amount (included in transaction amount).
TipAmount *string `json:"tip_amount,omitempty"`
// Transaction code.
TransactionCode *string `json:"transaction_code,omitempty"`
// Transaction VAT amount.
VatAmount *string `json:"vat_amount,omitempty"`
// Vat rates.
VatRates *[]ReceiptTransactionVatRate `json:"vat_rates,omitempty"`
// Cardholder verification method.
VerificationMethod *string `json:"verification_method,omitempty"`
}
// ReceiptTransactionProduct is a schema definition.
type ReceiptTransactionProduct struct {
// Product description.
Description *string `json:"description,omitempty"`
// Product name.
Name *string `json:"name,omitempty"`
// Product price.
Price *float64 `json:"price,omitempty"`
// Product quantity.
Quantity *int `json:"quantity,omitempty"`
// Quantity x product price.
TotalPrice *float64 `json:"total_price,omitempty"`
}
// ReceiptTransactionVatRate is a schema definition.
type ReceiptTransactionVatRate struct {
// Gross
Gross *float64 `json:"gross,omitempty"`
// Net
Net *float64 `json:"net,omitempty"`
// Rate
Rate *float64 `json:"rate,omitempty"`
// Vat
Vat *float64 `json:"vat,omitempty"`
}
// GetReceiptParams: query parameters for GetReceipt
type GetReceiptParams struct {
// Merchant code.
Mid string
// The ID of the transaction event (refund).
TxEventId *int
}
// QueryValues converts [GetReceiptParams] into [url.Values].
func (p *GetReceiptParams) QueryValues() url.Values {
q := make(url.Values)
q.Set("mid", p.Mid)
if p.TxEventId != nil {
q.Set("tx_event_id", strconv.Itoa(*p.TxEventId))
}
return q
}
type ReceiptsService service
// Get: Retrieve receipt details
// Retrieves receipt specific data for a transaction.
func (s *ReceiptsService) Get(ctx context.Context, id string, params GetReceiptParams) (*Receipt, error) {
path := fmt.Sprintf("/v1.1/receipts/%v", id)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
req.URL.RawQuery = params.QueryValues().Encode()
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
switch resp.StatusCode {
case http.StatusOK:
var v Receipt
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
case http.StatusBadRequest:
var apiErr Error
if err := json.NewDecoder(resp.Body).Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
case http.StatusUnauthorized:
var apiErr Error
if err := json.NewDecoder(resp.Body).Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
default:
return nil, fmt.Errorf("unexpected response %d: %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
}