|
6 | 6 |
|
7 | 7 | ## Description
|
8 | 8 |
|
9 |
| -fawry-go is a Go package interfacing with Fawry's payment gateway API |
| 9 | +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§") |
| 10 | + |
| 11 | +_**`important note`**_: You need to have a contract with fawry to use their service. |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +Go 1.8 or above. |
| 16 | + |
| 17 | +## Getting Started |
| 18 | + |
| 19 | +### Installation |
| 20 | + |
| 21 | +Run the following command to install the package: |
| 22 | +``` |
| 23 | +go get github.com/ahmedshaaban/fawry-go |
| 24 | +``` |
| 25 | + |
| 26 | +### Charge Request |
| 27 | + |
| 28 | +```go |
| 29 | +package main |
| 30 | + |
| 31 | +import ( |
| 32 | + "fmt" |
| 33 | + "io/ioutil" |
| 34 | + |
| 35 | + "github.com/ahmedshaaban/fawry-go" |
| 36 | +) |
| 37 | + |
| 38 | +func main() { |
| 39 | + fc := fawry.Client{ |
| 40 | + IsSandbox: true, |
| 41 | + FawrySecureKey: "SecuredKeyProvidedByFawry", |
| 42 | + } |
| 43 | + |
| 44 | + charge := fawry.Charge{ |
| 45 | + MerchantCode: "is0N+YQzlE4=", |
| 46 | + MerchantRefNum: "9990064204", |
| 47 | + CustomerProfileID: "9990064204", |
| 48 | + CustomerMobile: "01000000200", |
| 49 | + CustomerEmail: "77@test.com", |
| 50 | + PaymentMethod: "PAYATFAWRY", |
| 51 | + Amount: "20.10", |
| 52 | + CurrencyCode: "EGP", |
| 53 | + Description: "the charge request description", |
| 54 | + PaymentExpiry: 1516554874077, |
| 55 | + ChargeItems: []fawry.ChargeItem{ |
| 56 | + fawry.ChargeItem{ |
| 57 | + ItemID: "897fa8e81be26df25db592e81c31c", |
| 58 | + Description: "lorem", |
| 59 | + Price: "15.20", |
| 60 | + Quantity: 1, |
| 61 | + }, |
| 62 | + }, |
| 63 | + } |
| 64 | + |
| 65 | + resp, err := fc.ChargeRequest(charge) |
| 66 | + if err != nil { |
| 67 | + fmt.Println(err) |
| 68 | + return |
| 69 | + } |
| 70 | + |
| 71 | + defer resp.Body.Close() |
| 72 | + |
| 73 | + fmt.Println("response Status:", resp.Status) |
| 74 | + fmt.Println("response Headers:", resp.Header) |
| 75 | + body, _ := ioutil.ReadAll(resp.Body) |
| 76 | + fmt.Println("response Body:", string(body)) |
| 77 | +} |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +### Refund Request |
| 82 | + |
| 83 | +```go |
| 84 | +package main |
| 85 | + |
| 86 | +import ( |
| 87 | + "fmt" |
| 88 | + "io/ioutil" |
| 89 | + |
| 90 | + "github.com/ahmedshaaban/fawry-go" |
| 91 | +) |
| 92 | + |
| 93 | +func main() { |
| 94 | + fc := fawry.Client{ |
| 95 | + IsSandbox: true, |
| 96 | + FawrySecureKey: "SecuredKeyProvidedByFawry", |
| 97 | + } |
| 98 | + |
| 99 | + refund := fawry.Refund{ |
| 100 | + MerchantCode: "1013969", |
| 101 | + ReferenceNumber: "322818", |
| 102 | + RefundAmount: "100.00", |
| 103 | + Reason: "Bad Quality ", |
| 104 | + } |
| 105 | + |
| 106 | + resp, err := fc.RefundRequest(refund) |
| 107 | + if err != nil { |
| 108 | + fmt.Println(err) |
| 109 | + return |
| 110 | + } |
| 111 | + |
| 112 | + defer resp.Body.Close() |
| 113 | + |
| 114 | + fmt.Println("response Status:", resp.Status) |
| 115 | + fmt.Println("response Headers:", resp.Header) |
| 116 | + body, _ := ioutil.ReadAll(resp.Body) |
| 117 | + fmt.Println("response Body:", string(body)) |
| 118 | +} |
| 119 | + |
| 120 | +``` |
| 121 | + |
| 122 | +### Status Request |
| 123 | + |
| 124 | +```go |
| 125 | +package main |
| 126 | + |
| 127 | +import ( |
| 128 | + "fmt" |
| 129 | + "io/ioutil" |
| 130 | + |
| 131 | + "github.com/ahmedshaaban/fawry-go" |
| 132 | +) |
| 133 | + |
| 134 | +func main() { |
| 135 | + fc := fawry.Client{ |
| 136 | + IsSandbox: true, |
| 137 | + FawrySecureKey: "SecuredKeyProvidedByFawry", |
| 138 | + } |
| 139 | + |
| 140 | + status := fawry.Status{ |
| 141 | + MerchantCode: "is0N+YQzlE4=", |
| 142 | + MerchantRefNum: "99900642041", |
| 143 | + } |
| 144 | + |
| 145 | + resp, err := fc.StatusRequest(refund) |
| 146 | + if err != nil { |
| 147 | + fmt.Println(err) |
| 148 | + return |
| 149 | + } |
| 150 | + |
| 151 | + defer resp.Body.Close() |
| 152 | + |
| 153 | + fmt.Println("response Status:", resp.Status) |
| 154 | + fmt.Println("response Headers:", resp.Header) |
| 155 | + body, _ := ioutil.ReadAll(resp.Body) |
| 156 | + fmt.Println("response Body:", string(body)) |
| 157 | +} |
| 158 | + |
| 159 | +``` |
| 160 | + |
| 161 | +## TODO: |
| 162 | +- Read configuration keys (merchant code, secure key) from env vars |
| 163 | +- Add public API documentation to README |
| 164 | +- Increase code coverage |
0 commit comments