https://github.com/fawry-api/fawry-go
https://github.com/fawry-api/fawry-go
fawry go golang pack payment
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fawry-api/fawry-go
- Owner: fawry-api
- License: mit
- Created: 2019-11-12T10:31:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T10:10:08.000Z (over 6 years ago)
- Last Synced: 2024-03-28T05:17:16.049Z (about 2 years ago)
- Topics: fawry, go, golang, pack, payment
- Language: Go
- Size: 433 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fawry-go
[](https://travis-ci.com/fawry-api/fawry-go)
[](https://codecov.io/gh/fawry-api/fawry-go?branch=master)
## Description
fawry-go is a Go package interfacing with Fawry's payment gateway API. this package is inspired by Amr Bakry's ruby [gem](https://github.com/fawry-api/fawry "fawry-ruby§")
_**`important note`**_: You need to have a contract with fawry to use their service.
## Requirements
Go 1.8 or above.
## Getting Started
### Installation
Run the following command to install the package:
```
go get github.com/fawry-api/fawry-go
```
### Charge Request
```go
package main
import (
"fmt"
"io/ioutil"
"github.com/ahmedshaaban/fawry-go"
)
func main() {
fc := fawry.Client{
IsSandbox: true,
FawrySecureKey: "SecuredKeyProvidedByFawry",
}
charge := fawry.Charge{
MerchantCode: "is0N+YQzlE4=",
MerchantRefNum: "9990064204",
CustomerProfileID: "9990064204",
CustomerMobile: "01000000200",
CustomerEmail: "77@test.com",
PaymentMethod: "PAYATFAWRY",
Amount: "20.10",
CurrencyCode: "EGP",
Description: "the charge request description",
PaymentExpiry: 1516554874077,
ChargeItems: []fawry.ChargeItem{
fawry.ChargeItem{
ItemID: "897fa8e81be26df25db592e81c31c",
Description: "lorem",
Price: "15.20",
Quantity: 1,
},
},
}
resp, err := fc.ChargeRequest(charge)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}
```
### Refund Request
```go
package main
import (
"fmt"
"io/ioutil"
"github.com/ahmedshaaban/fawry-go"
)
func main() {
fc := fawry.Client{
IsSandbox: true,
FawrySecureKey: "SecuredKeyProvidedByFawry",
}
refund := fawry.Refund{
MerchantCode: "1013969",
ReferenceNumber: "322818",
RefundAmount: "100.00",
Reason: "Bad Quality ",
}
resp, err := fc.RefundRequest(refund)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}
```
### Status Request
```go
package main
import (
"fmt"
"io/ioutil"
"github.com/ahmedshaaban/fawry-go"
)
func main() {
fc := fawry.Client{
IsSandbox: true,
FawrySecureKey: "SecuredKeyProvidedByFawry",
}
status := fawry.Status{
MerchantCode: "is0N+YQzlE4=",
MerchantRefNum: "99900642041",
}
resp, err := fc.StatusRequest(refund)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}
```
## TODO:
- Read configuration keys (merchant code, secure key) from env vars
- Add public API documentation to README
- Increase code coverage