fawry

package module
v0.0.0-...-b8746d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 11 Imported by: 0

README

fawry-go

Build Status codecov

Description

fawry-go is a Go package interfacing with Fawry's payment gateway API. this package is inspired by Amr Bakry's ruby gem

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
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
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
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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Charge

type Charge struct {
	MerchantCode      string       `json:"merchantCode"`
	MerchantRefNum    string       `json:"merchantRefNum"`
	CustomerProfileID string       `json:"customerProfileId"`
	Amount            string       `json:"amount"`
	Description       string       `json:"description"`
	CustomerMobile    string       `json:"customerMobile"`
	ChargeItems       []ChargeItem `json:"chargeItems"`
	CurrencyCode      string       `json:"currencyCode"`
	CardToken         string       `json:"cardToken"`
	CustomerEmail     string       `json:"customerEmail"`
	PaymentMethod     string       `json:"paymentMethod"`
	PaymentExpiry     int          `json:"paymentExpiry"`
}

Charge Struct

func (Charge) Validate

func (charge Charge) Validate() error

Validate func for Charge Struct

type ChargeItem

type ChargeItem struct {
	ItemID      string `json:"itemId"`
	Description string `json:"description"`
	Price       string `json:"price"`
	Quantity    int    `json:"quantity"`
}

ChargeItem Struct

func (ChargeItem) Validate

func (chargeItem ChargeItem) Validate() error

Validate func for ChargeItem struct

type Client

type Client struct {
	IsSandbox      bool
	FawrySecureKey string
}

Client Struct

func (Client) ChargeRequest

func (fc Client) ChargeRequest(charge Charge) (*http.Response, error)

ChargeRequest could be used to charge the customer with different payment methods.

It also might be used to create a reference number to be paid at Fawry's outlets or
it can be used to direct debit the customer card using card token.

func (Client) RefundRequest

func (fc Client) RefundRequest(refund Refund) (*http.Response, error)

RefundRequest can refund the payment again to the customer

func (Client) StatusRequest

func (fc Client) StatusRequest(status Status) (*http.Response, error)

StatusRequest can use Get Payment Status Service to retrieve the payment status for the charge request

type Refund

type Refund struct {
	MerchantCode    string `json:"merchantCode"`
	ReferenceNumber string `json:"referenceNumber"`
	RefundAmount    string `json:"refundAmount"`
	Reason          string `json:"reason"`
}

Refund Struct

func (Refund) Validate

func (refund Refund) Validate() error

Validate func for Refund Struct

type Status

type Status struct {
	MerchantCode   string `json:"merchantCode"`
	MerchantRefNum string `json:"merchantRefNum"`
}

Status Struct

func (Status) Validate

func (status Status) Validate() error

Validate func for Status Struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL