Canopus-GO is implementation of canopus service using Golang.
Provide an overview of the directory structure and files, for example:
├── README.md
├── LICENSE
├── client.go
├── endpoint.go
├── request.go
├── response.go
├── go.mod
├── go.sum
├── config
│ ├── mocks
│ │ └── HTTPClient.go
│ ├── canopus.go
│ └── http.go
├── helper
│ └── signature.go
├── mocks
│ └── ClientMethod.go
└── example
├── create_cart.go
└── get_available_method.go
Create service first:
key, err := ioutil.ReadFile("/your/path/to/M-00001.key")
if err != nil {
fmt.Println(err)
}
pem, err := ioutil.ReadFile("/your/path/to/M-0001.pem")
if err != nil {
fmt.Println(err)
}
canopusClient := canopus.NewAPICLient(&canopus.ConfigOptions{
MerchantKey: key,
MerchantPem: pem,
MerchantID: "M-0001",
Secret: "yoursupersecret",
Timeout: 10
})
Then you can user this service to create payment
GetAvailableMethod(amount float64) ([]PaymentMethod, error)
GenerateCart(payload CartPayload, paymentMethod PaymentMethod) (CartResponse, error)
Check some examples canopusgo
// canopus.go
Environment = Staging
DefaultAPIType = SNAP
DefaultHttpTimeout = time.Second * time.Duration(10)
DefaultLogLevel = 2
DefaultLogFormat = "{\"log_type\":\"%s\",\"timestamp\":\"%s\",\"event\":\"%s\",\"detail\":\"%s\"}"
//example to change the default value
config.Environment = config.Production