Skip to content

omise/omise-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0d3f598 · Mar 24, 2025
Oct 26, 2023
Mar 24, 2025
Sep 10, 2024
Mar 24, 2025
Jun 13, 2017
Mar 21, 2025
Sep 10, 2024
Nov 30, 2015
Mar 24, 2025
Apr 5, 2018
Sep 21, 2023
Sep 10, 2024
Sep 10, 2024
Sep 10, 2024
Mar 3, 2021
Apr 5, 2018
Mar 21, 2025
Mar 2, 2017
Mar 24, 2025
Sep 10, 2024
Mar 29, 2021
May 16, 2017
May 16, 2018
Mar 2, 2017
May 21, 2021
Apr 5, 2018
Apr 5, 2018
Oct 24, 2023
Oct 24, 2023
Oct 24, 2023
Mar 2, 2017
Mar 2, 2017
Aug 11, 2017
Apr 11, 2017
Jun 7, 2017
May 16, 2017
May 15, 2017
Oct 11, 2016
Nov 3, 2015
Mar 2, 2017
Aug 15, 2017
Sep 10, 2024
Mar 2, 2017
Apr 5, 2018
May 21, 2021
May 7, 2024
May 21, 2021
Jun 7, 2017
May 14, 2018
May 14, 2018
Apr 11, 2017
Apr 11, 2017
Sep 10, 2024
Sep 10, 2024
Mar 2, 2017
Apr 5, 2018
Apr 5, 2018
Mar 2, 2017
May 16, 2018
Aug 19, 2019
Apr 5, 2018

Repository files navigation

Omise Go Library

GoDoc omise-go v1

Omise helps merchants of any size accept payments online. This library offers Go integration to the Omise API.

Install with:

go get github.com/omise/omise-go

Security Warning

Please do NOT use Omise Go library versions less than 1.0.5, as they are outdated and have security vulnerabilities.

Compliance warning

Card data should never transit through your server. This library provides the means to create tokens on the server side but should only be used for testing or only if you currently have a valid PCI-DSS Attestation of Compliance (AoC) delivered by a certified QSA Auditor.

Instead, we recommend that you follow our guide on how to safely collect credit information.

Version Guidance

Please refer to the table for specific version compatibility and requirements.

Version Support Omise API Version Go Version
1.x Active <= 2017-11-02 >= 1.16
2.x Upcoming 2019-05-29 >= 1.16

*Maintenance mode means bug fixes and security patches only

Compatibility

Version v1.2.0 and higher of this package is designed to work with Go version 1.16 or higher. It is not compatible with Go versions 1.15 and lower.

If you are using an older version of Go, please consider upgrading to a compatible version to use this library effectively.

Usage

For usage instructions, see godoc.org in tandem with the Omise API Documentation.

Example:

package main

import (
	"log"

	"github.com/omise/omise-go"
	"github.com/omise/omise-go/operations"
)

const (
	// Read these from environment variables or configuration files!
	OmisePublicKey = "pkey_test_no1t4tnemucod0e51mo"
	OmiseSecretKey = "skey_test_no1t4tnemucod0e51mo"
)

func main() {
	client, e := omise.NewClient(OmisePublicKey, OmiseSecretKey)
	if e != nil {
		log.Fatal(e)
	}

  /** Retrieve a token from a request
   * A token should be created from a client side by using our client-side libraries
   * https://docs.omise.co/libraries#client-side-libraries
   * More information:
   * - https://docs.omise.co/collecting-card-information
   * - https://docs.omise.co/security-best-practices
   **/
	token := "tokn_test_no1t4tnemucod0e51mo"

	// Creates a charge from the token
	charge, createCharge := &omise.Charge{}, &operations.CreateCharge{
		Amount:   100000, // ฿ 1,000.00
		Currency: "thb",
		Card:     token,
	}
	if e := client.Do(charge, createCharge); e != nil {
		log.Fatal(e)
	}

	log.Printf("charge: %s  amount: %s %d\n", charge.ID, charge.Currency, charge.Amount)
}

API version

You can choose the API version to use with Omise. Each new API version has new features that might be incompatible with previous versions. You can change the default version by visiting your Omise Dashboard.

The version configured here will have higher priority than the version set in your Omise account. This is useful if you have multiple environments with different API versions for testing. (e.g., Development on the latest version, but production is on an older version).

client.APIVersion = "2015-11-06"

It is highly recommended to set this version to the current version that you are using. You can learn more about this feature in our versioning guide.

Enable debug mode

You can monitor the response code and body from each API call by utilizing the library's debug mode, which you can turn on or off. To activate this feature, invoke SetDebug() immediately after initializing your client.

client, e := omise.NewClient(OmisePublicKey, OmiseSecretKey)
if e != nil {
	log.Fatal(e)
}

// Enabling debug mode to monitor response from API call
client.SetDebug(true)

License

See LICENSE file.