Skip to content

Commit 38a5d64

Browse files
author
mintali
committed
Version 1.0.0
1 parent 6c7e2e0 commit 38a5d64

23 files changed

+1325
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
# JetBrains IDE
18+
.idea/
19+
# Config Files
20+
config.yml
21+
# Coverrage
22+
cover.out
23+
coverage.out

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2022-01-06
9+
10+
### Added
11+
12+
- Initial Public Release.

CONTRIBUTING.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [Github](https://github.com/orientswiss/zoodpay-api-go-sdk).
6+
7+
8+
## Pull Requests
9+
10+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
11+
12+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
13+
14+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
15+
16+
- **Create feature branches** - Don't ask us to pull from your master branch.
17+
18+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
19+
20+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
21+
22+
**Happy coding**!

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 ZoodPay
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# GO SDK for ZoodPay API
2+
3+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
4+
5+
### ZoodPay API
6+
7+
ZoodPay wants to provide its payment solution to every online business who may be interested in it. ZoodPay API v0 is
8+
the latest version which offers our latest features.
9+
10+
[ZoodPay API Documentation](https://apidocs.zoodpay.com/)
11+
12+
[ZoodPay API API Simulator](https://apidocs.zoodpay.com/docs)
13+
14+
zoodpay-api-sdk is a Go SDK library for accessing [ZoodPay API][].
15+
16+
Currently, zoodpay-api-sdk requires Go version 1.13 or greater.
17+
18+
## Installation
19+
20+
zoodpay-api-sdk is compatible with modern Go releases in module mode, with Go installed:
21+
22+
```bash
23+
$ go get github.com/orientswiss/zoodpay-api-go-sdk
24+
```
25+
26+
Alternatively the same can be achieved if you use import in a package:
27+
28+
```go
29+
import "github.com/orientswiss/zoodpay-api-go-sdk"
30+
```
31+
32+
## Usage
33+
The application configuration is represented in `./config/config.go`. When the package imported before execution of each request,
34+
it loads the configuration from a configuration file. The path to the configuration
35+
file is specified via the `-config` command line argument which defaults to `config.yml`. (Copy config.yml.sample to config.yml and fill with necessary information)
36+
37+
38+
```go
39+
import "github.com/orientswiss/zoodpay-api-go-sdk/requests" // with go modules disabled
40+
41+
func main() {
42+
43+
//Init Merchant
44+
merchant = requests.NewClient()
45+
46+
//Health-check Endpoint
47+
healthCheckResponse, err := merchant.Healthcheck()
48+
49+
//Configuration Endpoint
50+
configurationsResponse, err := merchant.GetConfiguration(requests.ConfigurationRequest{
51+
MarketCode: merchant.MarketCode,
52+
})
53+
54+
configurations := configurationsResponse.Configurations
55+
56+
57+
58+
//Order Type
59+
or := requests.OrderRequest{
60+
61+
ServiceCode: "",
62+
Amount: 0,
63+
MarketCode: "",
64+
Currency: "",
65+
MerchantReferenceNo: "",
66+
DiscountAmount: 0,
67+
ShippingAmount: 0,
68+
TaxAmount: 0,
69+
Language: "",
70+
Signature: "",
71+
72+
}
73+
//Create Signature for Transaction
74+
or.Signature = merchant.GenerateSignatureCreateTransaction(or)
75+
//Transaction Endpoint
76+
transaction, err := merchant.CreateTransaction(requests.TransactionRequest{
77+
//Customer Type
78+
Customer: requests.CustomerRequest{
79+
FirstName: "",
80+
LastName: "",
81+
CustomerEmail: "",
82+
CustomerPhone: "",
83+
CustomerDOB: "",
84+
CustomerPID: 0,
85+
},
86+
//Billing Type
87+
Billing: requests.ContactRequest{
88+
Name: "",
89+
AddressLine1: "",
90+
AddressLine2: "",
91+
City: "",
92+
State: "",
93+
Zipcode: "",
94+
CountryCode: "",
95+
PhoneNumber: "",
96+
},
97+
//Shipping
98+
Shipping: requests.ContactRequest{
99+
Name: "",
100+
AddressLine1: "",
101+
AddressLine2: "",
102+
City: "",
103+
State: "",
104+
Zipcode: "",
105+
CountryCode: "",
106+
PhoneNumber: "",
107+
},
108+
// ShippingService Type
109+
ShippingService: requests.ShippingServiceRequest{{
110+
Name: "",
111+
ShippedAt: "",
112+
Tracking: "",
113+
Priority: "",
114+
},
115+
//Items Type
116+
Items: []requests.ItemRequest{
117+
{
118+
Name: "",
119+
Sku: "",
120+
Price: 0,
121+
Quantity: 0,
122+
DiscountAmount: 0,
123+
TaxAmount: 0,
124+
CurrencyCode: "",
125+
Categories: [][]string{
126+
{
127+
"",
128+
},
129+
},
130+
},
131+
},
132+
Order: or,
133+
})
134+
135+
136+
//Get transaction Status from API
137+
transactionStatus, err := merchant.GetTransactionStatus(requests.TransactionStatusRequest{
138+
TransactionID: "",
139+
})
140+
141+
//Set Delivery Date
142+
delivery, err := merchant.AddDelivery(
143+
requests.TransactionStatusRequest{
144+
TransactionID: "",
145+
},
146+
requests.DeliveryRequest{
147+
DeliveredAt: "",
148+
FinalCaptureAmount: 0,
149+
},
150+
151+
//Create Refund for Paid Transaction
152+
refund, err := merchant.CreateRefund(requests.RefundRequest{
153+
TransactionID: "",
154+
Amount: 0,
155+
Reason: "",
156+
RequestID: "",
157+
MerchantRefundReference: randomTransRefNo,
158+
})
159+
160+
//Get Customer Credit Balance
161+
balance, err := merchant.GetCreditBalance("")
162+
163+
164+
}
165+
166+
167+
168+
```
169+
170+
## Changelog
171+
172+
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
173+
174+
## Contributing
175+
176+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
177+
178+
## Support
179+
180+
For any inquiry write to [email protected] with a detailed description of the issue.
181+
182+
## Credits
183+
184+
- [ZoodPay](https://github.com/orientswiss)
185+
186+
## License
187+
188+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
189+
190+
191+
[ZoodPay API]: https://apidocs.zoodpay.com/

config.yml.sample

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
api_url: http://localhost:8080
2+
version: v0
3+
default_code: -1 # Default Error Code
4+
cst: yml # cst: Credential Source Type. Choices: `yml`, `db`.
5+
# Yml configuration to get the credentials from the yml file. Can be ignored if `cst` is db. Values shall be in string
6+
yml:
7+
merchant_key: ~
8+
merchant_secret: ~
9+
merchant_salt: ~
10+
market_code: ~
11+
# Database Configuration to get the credentials from the database. Can be ignored if `cst` is yml. Values shall be in string
12+
db:
13+
host: ~
14+
port: ~
15+
user_name: ~
16+
password: ~
17+
database: ~
18+
table: ~ # Please have zoodpay_merchant_key, zoodpay_merchant_secret, zoodpay_merchant_salt and zoodpay_merchant_market_code columns in your table to store key, secret and salt respectively.

config/config.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package config
2+
3+
import (
4+
"gopkg.in/yaml.v2"
5+
"io/ioutil"
6+
)
7+
8+
// Config represents an application configuration.
9+
type Config struct {
10+
// Data Source Endpoint/Name
11+
Host string `yaml:"api_url"`
12+
// Api Version
13+
Version string `yaml:"version"`
14+
// Default Error Code
15+
DefaultCode string `yaml:"default_code"`
16+
// Credential Source Type
17+
CST string `yaml:"cst"`
18+
// Yml Configurations
19+
YML map[string]string `yaml:"yml,omitempty"`
20+
// Database Configurations
21+
DB map[string]string `yaml:"db,omitempty"`
22+
}
23+
24+
// Load returns an application configuration which is populated from the given configuration file and environment variables.
25+
func Load(file string) (*Config, error) {
26+
// default config
27+
c := Config{}
28+
29+
// load from YAML config file
30+
bytes, err := ioutil.ReadFile(file)
31+
if err != nil {
32+
return nil, err
33+
}
34+
if err = yaml.Unmarshal(bytes, &c); err != nil {
35+
return nil, err
36+
}
37+
38+
return &c, err
39+
}

go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/orientswiss/zoodpay-api-go-sdk
2+
3+
go 1.13
4+
5+
require (
6+
github.com/go-sql-driver/mysql v1.5.0
7+
gopkg.in/yaml.v2 v2.4.0
8+
)

requests/commons.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package requests
2+
3+
import (
4+
"crypto/sha512"
5+
"encoding/json"
6+
"fmt"
7+
"io/ioutil"
8+
"math/rand"
9+
"net/http"
10+
"time"
11+
)
12+
13+
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
14+
15+
func GetHTTPStatusCode400ErrorMessage(response *http.Response) string {
16+
var errorMsg string
17+
result := HTTPStatusCode400{}
18+
data, err := ioutil.ReadAll(response.Body)
19+
20+
if err != nil {
21+
errorMsg = err.Error()
22+
} else {
23+
json.Unmarshal(data, &result)
24+
25+
if len(result.Details) > 0 {
26+
for _, detail := range result.Details {
27+
if errorMsg != "" {
28+
errorMsg = errorMsg + "\n"
29+
}
30+
errorMsg = errorMsg + detail.Field + ": " + detail.Error
31+
}
32+
} else {
33+
var m map[string]string
34+
json.Unmarshal(data, &m)
35+
errorMsg = errorMsg + m["message"]
36+
}
37+
}
38+
return errorMsg
39+
}
40+
41+
//Sha512Encrypt used to convert string into encrypted string using Sha 512 algorithm
42+
func Sha512Encrypt(input string) string {
43+
sha512 := sha512.New()
44+
sha512.Write([]byte(input))
45+
return fmt.Sprintf("%x", sha512.Sum(nil))
46+
}
47+
48+
// RandStringBytes used to generate random string (For Merchant Reference No)
49+
func RandStringBytes(n int) string {
50+
b := make([]byte, n)
51+
rand.Seed(time.Now().UnixNano())
52+
for i := range b {
53+
b[i] = letters[rand.Intn(len(letters))]
54+
}
55+
return string(b)
56+
}

0 commit comments

Comments
 (0)