Nicepay ❤️ Go !
Go is a highly modern programming language that combines aspects of dynamic and static typing, making it particularly well-suited for web development and various other applications. It has a concise syntax and offers the advantages of both dynamic and static typing. Furthermore, Go has a small memory footprint, which is a notable benefit. The purpose of this module is to assist you in utilizing Nicepay product's REST APIs effectively within the Go programming language.
Run this command on your project to initialize Go mod (if you haven't):
go mod init
then reference Nicepay-go in your project file with import
:
import (
"github.com/nicepay-dev/golang-nicepay"
"github.com/nicepay-dev/golang-nicepay/snap"
)
Also, the alternative way you can use go get
the package into your project
go get -u github.com/nicepay-dev/golang-nicepay
There is a type named Client
(snap.Client
) that should be instantiated through
function New
which holds any possible setting to the library. Any activity (charge, approve, etc) is done in the client level.
We have 3 different products that you can use:
- Snap - Customizable payment popup will appear on your web/app (no redirection). doc ref
- Snap Redirect - Customer need to be redirected to payment url hosted by Nicepay. doc ref
To learn more and understand each of the product's quick overview you can visit https://docs.Nicepay.com.
Get your client key and server key from Nicepay Dashboard
Create API client object, You can also check the project's implementation for more examples. Please proceed there for more detail on how to run the example.
Set a config with globally, (except for iris api)
snap := Snap{}
privateKey := key.(*rsa.PrivateKey)
config := map[string]interface{}{
"isProduction": false,
"privateKey": privateKey,
"clientSecret": "33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==",
"clientId": "IONPAYTEST",
}
snap.ApiConfig.SetConfiguration(config)
Snap is Nicepay existing tool to help merchant charge customers using a mobile-friendly, in-page, no-redirect checkout facilities. Using snap is simple.
Available methods for Snap
// CreateTransaction : Do `/transactions` API request to SNAP API to get Snap token and redirect url with `snap.Request`
func RequestSnapTransaction(parameter map[string]interface{}) ([]byte, error)
// CreateTransactionToken : Do `/transactions` API request to SNAP API to get Snap token with `snap.Request`
func RequestSnapAccessToken(parameter map[string]interface{}) ([]byte, error)
Snap usage example, create transaction with minimum Snap parameters (choose one of alternatives below):
Sample usage if you prefer Nicepay global configuration & using static function. Useful if you only use 1 merchant account API key, and keep the code short.
// 1. Set you ServerKey with globally
snap := Snap{}
privateKey := key.(*rsa.PrivateKey)
config := map[string]interface{}{
"isProduction": false,
"privateKey": privateKey,
"clientSecret": "33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A==",
"clientId": "IONPAYTEST",
}
snap.ApiConfig.SetConfiguration(config)
// 2. Initiate Snap request
parameter := map[string]interface{}{
"grantType": "client_credentials",
"additionalInfo": map[string]interface{}{},
}
reqToken := snap.RequestSnapAccessToken(parameter)
Integration test are available
- Nicepay Docs
- Nicepay Dashboard
- SNAP documentation
- Can't find answer you looking for? email to cs@nicepay.co.id