SDK for Go

SDK for Go is a software development kit for development of web services which are capable of integrating with the Benker 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.

What can I do with SDK for Go?

SDK for Go allows you to do the following:
  • 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

To start using SDK for Go you need to complete the following tasks:
  1. Make sure you have ready your merchant ID and secret key obtained from Benker.
    1. If your company has never obtained any ID or secret key from Benker, you need to submit an application for connecting to the Benker payment platform.
    2. If your company already has an ID and a secret key to sign messages obtained from Benker, you need to notify the Benker technical support specialists that you want to use SDK for Go and consult the customer support on how to arrange a test run.
  2. Integrate the Benker payment solution in your web service:
    1. Install the SDK for Go libraries into a directory inside your web service project.
    2. Import the libraries you need into your web service application.
  3. Test and put your web service in production mode.

With any questions regarding the use of SDK for Go, contact the Benker technical support specialists at help@benker.io.

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.

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 Benker 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:

  1. 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.ParamCustomerId, "customer_122")
              // Customer ID
    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 can also use any other optional parameters available for Payment Page. For more information about the Payment Page invocation parameters, see Parameters for opening the payment form.

  2. Create a gate instance and initiate it with the secret key you obtained from the Benker 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
  3. Generate the URL for opening the payment form:

    paymentPageUrl := gate.GetPaymentPageUrl(*payment)

    The URL must contain payment parameters and signature (abbreviated):

    https://paymentpage.benker.io/payment?signature=OEKRlLXQsa2..
                   ..gWg%3D%3D&payment_id=pid_1555943554067...
  4. 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.

Figure 1. Example of generating the URL for opening Payment Page
payment := paymentpage.NewPayment(186, "test_payment_id")
    // Project ID and payment ID, must be unique within your project scope
payment.SetParam(paymentpage.ParamPaymentAmount, 1000)
    // Amount in minor currency units
payment.SetParam(paymentpage.ParamPaymentCurrency, "EUR")
    // Currency in the ISO-4217 alpha-3 format
payment.SetParam(paymentpage.ParamCustomerId, "customer_122")
          // Customer ID
payment.SetParam(paymentpage.ParamPaymentDescription, "Test payment")
    // Payment description (optional)
payment.SetParam(paymentpage.ParamLanguageCode, "en")
    // Language code to use in payment form
gate := paymentpage.NewGate("<secret_key")
    // Secret key
paymentPageUrl := gate.GetPaymentPageUrl(*payment)
    // Complete request with signature

Processing callbacks

The Benker payment platform sends payment results to the callback URL you specified when connecting to Benker. 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:

  1. Create an instance of gate and initiate it with the secret key if you did not do it earlier:
    gate := paymentpage.NewGate("<secret_key>")
  2. Create an instance of callback by using the JSON string from the callback obtained from the Benker 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.

  3. 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.

Figure 2. Sample payment callback
POST /notify/success HTTP/1.1
Content-Length: 1237
User-Agent: GuzzleHttp/6.3.3 curl/7.47.0 PHP/7.0.32-0ubuntu0.16.04.1
Content-Type: application/json
Host: webservice.com

{
  "project_id": 200,
  "payment": {
    "id": "abc12345",
    "type": "purchase",
    "status": "success",
    "date": "2025-03-20T14:22:06+0000",
    "method": "Greek Banks",
    "sum": {
      "amount": 1000,
      "currency": "EUR"
    },
    "description": "Success"
  },
  "customer": {
    "id": "123"
  },
  "operation": {
    "id": 9529253065607,
    "type": "sale",
    "status": "success",
    "date": "2025-03-20T14:22:06+0000",
    "created_date": "2025-03-20T14:22:00+0000",
    "request_id": "f1de353331a01fd14163fe4226-00009530",
    "sum_initial": {
      "amount": 1000,
      "currency": "EUR"
    },
    "sum_converted": {
      "amount": 1000,
      "currency": "EUR"
    },
    "code": "0",
    "message": "Success",
    "provider": {
      "id": 1914,
      "payment_id": "",
      "auth_code": ""
    }
  },
  "signature": "OBjT3RaJnOWsDXOclvWoC6+CFSCtLprTo8VFbN6BYVQD2tVK/3d9k+RRA/7N9TV6OQqk+0uPUnx4/c8uaUurw=="
}

Related links