Go to file
2022-11-24 15:22:28 +01:00
.github/workflows use go 1.15 because of %w 2021-03-03 15:31:59 +01:00
testdata finish client for transactions, add tests and workflows 2021-03-03 15:23:20 +01:00
.gitignore Initial commit 2021-02-19 17:11:49 +01:00
client_test.go Add merchant specific opaque data container 2021-05-19 16:03:56 +02:00
client.go OptionMerchant.apply set also MerchantID as internal key 2021-07-08 13:30:38 +02:00
dto.go add field "MerchantID" to ResponseStatus 2022-11-24 15:22:28 +01:00
error.go finish client for transactions, add tests and workflows 2021-03-03 15:23:20 +01:00
go.mod finish client for transactions, add tests and workflows 2021-03-03 15:23:20 +01:00
LICENSE Initial basic version, WIP 2021-03-03 08:45:14 +01:00
README.md update readme 2021-03-04 13:28:53 +01:00
webhook_test.go add webhook 2021-03-03 17:11:51 +01:00
webhook.go add more endpoints 2021-03-04 11:15:55 +01:00

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


	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?

	ri := &datatrans.RequestInitialize{
		Currency:   "CHF",
		RefNo:      "234234",
		AutoSettle: true,
		Amount:     10023,
		Language:   "DE",
		CustomFields: map[string]interface{}{
			"TWI": map[string]interface{}{
				"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


	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