PayNet GoLang Rest API
PayNet rest API for GoLang is a package which implements the public API for create paypage of PayNet.
The package covers the following functions:
- [authenticate_key] Authenticate key API
- [create_pay_page] - Create Payment Page API
- [verify_payment] - Verify Payment API
Installation
To install this package please run
go get github.com/Carnelian-Payment-Networks/paynet_golang_api_example
Create Payment Page
The concept behind the PayNet rest API is to create invoice using this API and redirect your merchant to that invoice to collect the payment and here is how to do it.
import (
"fmt"
"github.com/Carnelian-Payment-Networks/paynet_golang_api_example"
)
var data = make(map[string]string)
data["merchant_email"] = "<MERCHANT EMAIL>"
data["secret_key"] = "<MERCHANT SECRET KEY>"
data["currency"] = "USD"
data["amount"] = "10"
data["site_url"] = "<SITE URL>"
data["title"] = "Sell products"
data["quantity"] = "1"
data["unit_price"] = "10"
data["products_per_title"] = "Shoes | Jeans"
data["return_url"] = "<MERCHANT CALLBACK>"
data["m_first_name"] = "Rahul"
data["m_last_name"] = "Sharma"
data["m_phone_number"] = "00973"
data["phone_number"] = "12345678"
data["billing_address"] = "Address"
data["city"] = "Manama"
data["state"] = "Manama"
data["postal_code"] = "1234"
data["country"] = "BHR"
data["email"] = "<EMAIL>"
data["ip_customer"] = "<IP>"
data["ip_merchant"] = "<IP>"
data["address_shipping"] = "Shipping"
data["city_shipping"] = "Shipping"
data["state_shipping"] = "Shipping"
data["postal_code_shipping"] = "973"
data["country_shipping"] = "BHR"
data["other_charges"] = "0"
data["reference_no"] = "1234"
data["refno"]="1234"
data["msg_lang"] = "en"
data["cms_with_version"] = "Golang Lib v1"
resp, err := PayNet.CreatePayPage(data)
if err != nil {
fmt.Println(err)
}
if resp.ResponseCode == "4012" {
fmt.Println(resp.PaymentURL)
} else {
fmt.Println(resp.Result)
}
Verify Payment
After the payment is done you need to verify if it was successfull or not, so in the call back url PayNet will reply with Payment Reference and status, using this reference you can run the following code to make sure it's Paid.
import (
"fmt"
"github.com/Carnelian-Payment-Networks/paynet_golang_api_example"
)
verifyMap := make(map[string]string)
verifyMap["merchant_email"] = "<MERCHANT_EMAIL>"
verifyMap["secret_key"] = "<MERCHANT_SECRET>"
verifyMap["payment_reference"] = "<ORDER_ID>"
result, err := PayNet.VerifyPayment(verifyMap)
if err != nil {
println(err)
}
if result.ResponseCode == "100" {
fmt.Println(result.Result)
} else {
fmt.Println(result.Result)
}
Validate Secret Key
In some cases you will need to validate your secret key, for example if you are allowing to change the secret key infromation through your website control panel, so it's better to validate it before saving. This can be achived using this API
import (
"fmt"
"github.com/Carnelian-Payment-Networks/paynet_golang_api_example"
)
validateMap := make(map[string]string)
validateMap["merchant_email"] = "<MERCHANT_EMAIL>"
validateMap["secret_key"] = "<MERCHANT_SECRET>"
result, err := PayNet.ValidateSecretKey(validateMap)
if err != nil {
println(err)
}
if result.ResponseCode == "4000" {
println(result.Result)
} else {
println(result.Result)
}
Note
You have to handle the call back URL through your application, in which PayNet will reply to your site with the payment result and then you can call verify payment api.
That's it.
Please use the package github page to report any issue or suggestion.