https://github.com/globusdigital/datatrans
This Go package implements the new JSON based Datatrans API #golang #paymentprovider
https://github.com/globusdigital/datatrans
Last synced: 5 months ago
JSON representation
This Go package implements the new JSON based Datatrans API #golang #paymentprovider
- Host: GitHub
- URL: https://github.com/globusdigital/datatrans
- Owner: globusdigital
- License: mpl-2.0
- Created: 2021-02-19T16:11:48.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-10T13:22:00.000Z (over 1 year ago)
- Last Synced: 2025-03-10T14:28:12.094Z (over 1 year ago)
- Language: Go
- Size: 101 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# datatrans
This Go package implements the new JSON based Datatrans API #golang #paymentprovider
## Documentation
https://api-reference.datatrans.ch
https://docs.datatrans.ch/docs
## Usage
```go
c, err := datatrans.MakeClient(
datatrans.OptionMerchant{
InternalID: "",
EnableProduction: true,
EnableIdempotency: true,
MerchantID: "32234323242",
Password: "dbce0e6cfc012e475c843c1bbb0ca439a048fe8e",
},
// add more merchants if you like
datatrans.OptionMerchant{
InternalID: "B",
EnableProduction: false,
MerchantID: "78967896789",
Password: "e249002bc8e0c36dd89c393bfc7f7aa369c5842f",
},
)
// uses the merchant B
bc := c.WithMerchant("B")
bc.Status("324234234")
// uses default merchant
c.Status("65784567")
```
### My request needs additional fields which aren't in the struct!
How can I extend the JSON data posted to datatrans?
```go
ri := &datatrans.RequestInitialize{
Currency: "CHF",
RefNo: "234234",
AutoSettle: true,
Amount: 10023,
Language: "DE",
CustomFields: map[string]any{
"TWI": map[string]any{
"alias": "ZGZhc2RmYXNkZmFzZGZhc2Q=",
},
},
}
data, err := datatrans.MarshalJSON(ri)
// handle error
// using TWI for Twint specific parameters
const wantJSON = `{"TWI":{"alias":"ZGZhc2RmYXNkZmFzZGZhc2Q="},"amount":10023,"autoSettle":true,"currency":"CHF","language":"DE","refno":"234234"}`
if string(data) != wantJSON {
t.Errorf("\nWant: %s\nHave: %s", wantJSON, data)
}
```
### I need a custom http.Client
```go
c, err := datatrans.MakeClient(
datatrans.OptionHTTPRequestFn((&http.Client{
Timeout: 30*time.Second,
}).Do),
datatrans.OptionMerchant{
InternalID: "",
EnableProduction: true,
EnableIdempotency: true,
MerchantID: "32234323242",
Password: "dbce0e6cfc012e475c843c1bbb0ca439a048fe8e",
},
)
```
# License
Mozilla Public License Version 2.0