/
interface.go
121 lines (105 loc) · 4.79 KB
/
interface.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
package concardis
import (
"context"
"errors"
"time"
)
type ConcardisDownstream interface {
CreatePaymentLink(ctx context.Context, request PaymentLinkCreateRequest) (PaymentLinkCreated, error)
QueryPaymentLink(ctx context.Context, id uint) (PaymentLinkQueryResponse, error)
DeletePaymentLink(ctx context.Context, id uint) error
QueryTransactions(ctx context.Context, timeGreaterThan time.Time, timeLessThan time.Time) ([]TransactionData, error)
}
var (
NoSuchID404Error = errors.New("payment link id not found")
DownstreamError = errors.New("downstream unavailable - see log for details")
NotSuccessful = errors.New("response body status field did not indicate success")
)
// -- CreatePaymentLink --
// PaymentLinkCreateRequest contains the data to construct the paylink create request body.
//
// Note that the json field names are not actually used because the Concardis API doesn't
// accept JSON, and instead insists on a slightly unusual XWwwFormUrlencoded request.
type PaymentLinkCreateRequest struct {
Title string `json:"title"`
Description string `json:"description"`
PSP uint64 `json:"psp"`
ReferenceId string `json:"referenceId"`
OrderId string `json:"concardisOrderId"`
Purpose string `json:"purpose"`
Amount int64 `json:"amount"` // in cents
VatRate float64 `json:"vatRate"` // in %
Currency string `json:"currency"`
SKU string `json:"sku"`
Email string `json:"email"`
SuccessRedirectUrl string `json:"successRedirectUrl"` // optional - leave empty
FailedRedirectUrl string `json:"failedRedirectUrl"` // optional - leave empty
}
type PaymentLinkCreated struct {
ID uint `json:"id"`
ReferenceID string `json:"referenceId"`
Link string `json:"link"`
}
// -- QueryPaymentLink --
type PaymentLinkQueryResponse struct {
ID uint `json:"id"` // not the payment link id!
Status string `json:"status"`
ReferenceID string `json:"referenceId"`
Link string `json:"link"`
Invoices []PaymentLinkInvoice `json:"invoices"`
Name string `json:"name"`
Purpose map[string]string `json:"purpose"`
Amount int64 `json:"amount"`
Currency string `json:"currency"`
CreatedAt int64 `json:"createdAt"`
VatRate float64 `json:"vatRate"`
}
type PaymentLinkInvoice struct {
ReferenceID string `json:"referenceId"`
PaymentRequestId uint `json:"paymentRequestId"` // the payment link id
Currency string `json:"currency"`
Amount int64 `json:"amount"`
Transactions []TransactionData `json:"transactions"`
}
// -- QueryTransactions --
// Status
//
// Successful payment processed (status: confirmed) => book
//
// Payment aborted by customer (status: cancelled) => log info and ignore
// Payment declined (status: declined) => log info and ignore
//
// Order placed (status: waiting) => log warn and notify
//
// Pre-authorization successful (status: authorized) => log error and notify
// Payment (partial-) refunded by merchant (status: refunded / partially-refunded) => log error and notify
// Refund pending (status: refund_pending) (for transactions for which the refund has been initialized but not yet confirmed by the bank) => log error and notify
// Chargeback by card holder (status: chargeback) => log error and notify
// Technical error (status: error) => log error and notify
// Uncaptured (status: uncaptured) (only with PSP Clearhaus Acquiring) => log error and notify
// Reserved (status: reserved) (??? not explained in docs) => log error and notify
type TransactionData struct {
ID int64 `json:"id"`
UUID string `json:"uuid"` // sent as merchantOrderId
Amount int64 `json:"amount"`
Status string `json:"status"` // react to declined, confirmed, authorized, what else?
Time string `json:"time"` // take effective date from first 10 chars (ISO Date)
Lang string `json:"lang"` // ISO 639-1 of shopper language (de, en)
PageUUID string `json:"pageUuid"`
Payment Payment `json:"payment"`
Psp string `json:"psp"` // Name of the payment service provider used, for example "ConCardis_PayEngine_3"
PspID int64 `json:"pspId"` // ID of the Psp
Mode string `json:"mode"` // "LIVE", "TEST"
ReferenceID string `json:"referenceId"`
Invoice Invoice `json:"invoice"`
}
type Payment struct {
Brand string `json:"brand"`
}
type Invoice struct {
ReferenceID string `json:"referenceId"`
PaymentRequestId uint `json:"paymentRequestId"` // the payment link id
Currency string `json:"currency"` // "EUR"
OriginalAmount int64 `json:"originalAmount"`
RefundedAmount int64 `json:"refundedAmount"`
}