SDK for Go
SDK for Go is a software development kit for development of web services which are capable of integrating with the ecommpay payment solutions to perform purchases by using Payment Page. This section describes how to use SDK for Go to build purchase experience from inside of your web service.
SDK for Go is compatible with Go version 1.8 or later. You can download SDK for Go from Git: https://github.com/ITECOMMPAY/paymentpage-sdk-go.
What can I do with SDK for Go?
- Calculate signature and generate an URL for opening the Payment Page.
- Check callback signatures and extract payment details from callbacks.
What's inside?
SDK for Go contains the libraries for development and automated testing, as well as the service files.
Using SDK for Go
- Make sure you have ready your merchant ID and secret key obtained from ecommpay.
- If your company has never obtained any ID or secret key from ecommpay, you need to submit an application at https://ecommpay.com/apply-now/ for connecting to the ecommpay payment platform.
- If your company already has an ID and a secret key to sign messages obtained from ecommpay, you need to notify the ecommpay technical support specialists that you want to use SDK for Go and consult the customer support on how to arrange a test run.
- Integrate the ecommpay payment solution in your web service:
- Install the SDK for Go libraries into a directory inside your web service project.
- Import the libraries you need into your web service application.
- Test and put your web service in production mode.
- Request test card numbers and test project ID from ecommpay, debug and test your web service.
- Once testing is complete, request your production project ID from ecommpay and put your web service in production mode.
With any questions regarding the use of SDK for Go, contact the ecommpay technical support specialists at support@ecommpay.com.
Installing and importing libraries
You can install the SDK for Go libraries manually or by using automated procedures supported by the development environment you use.
The following steps describe how to manually install the SDK for Go libraries.
- If no $GOPATH environment variable is set, you need to set one. The $GOPATH is used to specify directories outside of $GOROOT that contains the source for Go projects and their binaries.
- Run the following command in the command line of your operating system:
go get github.com/ITECOMMPAY/paymentpage-sdk-go
The command downloads the SDK for Go libraries in the $GOPATH directory to enable you to use all the classes provided by the libraries.
- Import the SDK for Go into your web service source code in
import
section by running the following command:import "github.com/ITECOMMPAY/paymentpage-sdk-go"
Opening payment form
A URL for opening Payment Page consists of a set of parameters, which are signed to secure the data transmitted to the ecommpay payment platform. SDK for Go allows you to seamlessly sign parameters and generate URLs. To open the Payment Page payment form by using SDK for Go do the following:
- Create an instance of the
payment
class and specify payment details.payment := paymentpage.NewPayment(186, "TEST_1555943554067") // Project ID and payment ID, must be unique within your project scope payment.SetParam(paymentpage.ParamPaymentCurrency, "EUR") // Currency in the ISO-4217 alpha-3 format payment.SetParam(paymentpage.ParamPaymentAmount, 1000) // Amount in minor currency units payment.SetParam(paymentpage.ParamPaymentDescription, "Test payment") // Payment description (optional)
All parameters in this example, except for the payment description, are mandatory for any purchase. You may also need to pass other parameters, for example, the customer's email or phone number when the 3‑D Secure authentication is required. Such parameters must be specified as follows.
payment.SetParam(paymentpage.ParamCustomerPhone, "The customer's phone number. Must have from 4 to 24 digits") payment.SetParam(paymentpage.ParamCustomerEmail, "The customer's email")
In addition, for card purchases you are recommended to pass the customer's billing address information: the country code in ISO 3166-1 alpha-2 (details), the postal code, the city, and the street address. Such parameters are specified as follows.
payment.SetParam(paymentpage.ParamBillingPostal, "The postal code of the customer's billing address") payment.SetParam(paymentpage.ParamBillingCountry, "The country of the customer's billing address, in ISO 3166-1 alpha-2") payment.SetParam(paymentpage.ParamBillingCity, "The city of the customer's billing address") payment.SetParam(paymentpage.ParamBillingAddress, "The street of the customer's billing address")
You can also use any other optional parameters available for Payment Page. For more information about the Payment Page invocation parameters, see Parameters for opening payment form.
- Create a
gate
instance and initiate it with the secret key you obtained from the ecommpay technical support specialists. The secret key is required to sign parameters.gate := paymentpage.NewGate("<secret_key>") // Secret key you obtained from the technical support service
-
Generate the URL for opening the payment form:
paymentPageUrl := gate.GetPaymentPageUrl(*payment)
The URL must contain payment parameters and signature (abbreviated):
https://paymentpage.ecommpay.com/payment?signature=OEKRlLXQsa2.. ..gWg%3D%3D&payment_id=pid_1555943554067...
- Use the generated URL for opening the payment form (details).
Here is an example of generating a URL for opening a payment form in English. The payment method selection page includes detailed payment information including amount, currency, and short payment description.
Processing callbacks
The ecommpay payment platform sends payment results to the callback URL you specified when connecting to ecommpay. Callback is an HTTP POST request that contains response data in JSON format. To extract payment information from the response JSON string, do the following:
- Create an instance of
gate
and initiate it with the secret key if you did not do it earlier:gate := paymentpage.NewGate("<secret_key>")
-
Create an instance of
callback
by using the JSON string from the callback obtained from the ecommpay payment platform:callback, err := gate.HandleCallback(data)
If signature is incorrect or extracting payment details from callback results in errors, an
error
instance is returned. -
Use the following methods for extracting callback information. You can get either full payment information or request specific payment parameters:
callback.GetPaymentId() // Getting payment ID callback.GetPaymentStatus() // Getting payment status callback.GetPayment() // Getting payment body
By using SDK for Go, you can automatically check validity of the callback signature. Below, you can find an example of a callback that includes a signature and payment results.