Documentation ¶
Index ¶
- Constants
- type CheckoutInvoice
- type DirectPay
- type Invoice
- func (i *Invoice) AddItem(name string, quantity int, unitPrice float32, totalPrice float32, desc string) error
- func (i *Invoice) AddTax(name string, amount float32) error
- func (i *Invoice) Clear()
- func (i *Invoice) ClearAllItems()
- func (i *Invoice) ClearAllTaxes()
- func (i *Invoice) PrepareForRequest()
- func (i *Invoice) RemoveItem(name string)
- func (i *Invoice) RemoveTax(name string)
- func (i *Invoice) SetCustomData(key string, val interface{})
- func (i *Invoice) SetDescription(desc string)
- func (i *Invoice) SetTotalAmount(amt float32)
- type OnsiteInvoice
- type Setup
- type Store
Constants ¶
const ( BASE_URL_LIVE = "https://app.mpowerpayments.com/api/v1" BASE_URL_TEST = "https://app.mpowerpayments.com/sandbox-api/v1" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckoutInvoice ¶
type CheckoutInvoice struct { Invoice ResponseCode string `json:"-"` ResponseText string `json:"-"` Description string `json:"-"` Token string `json:"-"` Status string `json:"-"` // contains filtered or unexported fields }
CheckoutInvoice holds all the data related to checkout invoice Invoice is an embedded struct, so all methods of Invoice can be called on it
func NewCheckoutInvoice ¶
func NewCheckoutInvoice(setup *Setup, store *Store) *CheckoutInvoice
NewCheckoutInvoice - create a new checkout instance
Example.
checkout := mpower.NewCheckoutInvoice(newSetup, newStore)
func (*CheckoutInvoice) Create ¶
func (c *CheckoutInvoice) Create() (bool, error)
Create - creates a new invoice on mpower Returns `boolean` and `error` The `boolean` is used to determine if an error was encountered while making the request
Example.
if ok, err := checkout.Create(); ok { //do something with the response info on the checkout instance fmt.Printf("%s %s %s %s\n\n", checkout.ResponseCode, checkout.ResponseText, checkout.Description, checkout.Token) } else { //there was an error }
func (*CheckoutInvoice) GetInvoiceUrl ¶
func (c *CheckoutInvoice) GetInvoiceUrl() string
GetInvoiceUrl - get the invoice's url from the response
Example.
str := checkout.GetInvoiceUrl()
type DirectPay ¶
type DirectPay struct { Setup *Setup Status string ResponseCode string ResponseText string Description string TransactionId string // contains filtered or unexported fields }
DirectPay - the direct pay object as defined by mpower
func NewDirectPay ¶
NewDirectPay - creates a DirectPay instance
type Invoice ¶
type Invoice struct { sync.RWMutex Setup *Setup `json:"-"` Store Store `json:"store"` InvoiceIn invoice `json:"invoice"` CustomData map[string]interface{} `json:"custom_data,omitempty"` }
The invoice definition It specifies the required field keys and values we will be sending over to mpower This is supposed to be an embedded struct in the Onsite Invoice and Checkout Invoice
func (*Invoice) AddItem ¶
func (i *Invoice) AddItem(name string, quantity int, unitPrice float32, totalPrice float32, desc string) error
AddItem add an `item - struct` to the items in the invoice
Example.
checkout := mpower.NewCheckoutInvoice(newSetup, newStore) checkout.AddItem("Yam Phone", 1, 50.00, 50.00, "Hello World")
func (*Invoice) AddTax ¶
AddItem add an `tax - struct` to the taxes in the invoice
Example.
checkout := mpower.NewCheckoutInvoice(newSetup, newStore) checkout.AddTax("VAT", 30.00)
func (*Invoice) Clear ¶
func (i *Invoice) Clear()
Clear clears all the items in the invoice
Example.
checkout.Clear()
func (*Invoice) ClearAllItems ¶
func (i *Invoice) ClearAllItems()
ClearAllItems clears all the items in the invoice
Example.
checkout.ClearAllItems()
func (*Invoice) ClearAllTaxes ¶
func (i *Invoice) ClearAllTaxes()
ClearAllTaxes clears all the taxes in the invoice
Example.
checkout.ClearAllTaxes()
func (*Invoice) PrepareForRequest ¶
func (i *Invoice) PrepareForRequest()
func (*Invoice) RemoveItem ¶
RemoveItem removes the item with name of `name`
Example.
checkout.RemoveItem()
func (*Invoice) RemoveTax ¶
RemoveTax removes the tax with name of `name`
Example.
checkout.RemoveTax()
func (*Invoice) SetCustomData ¶
Sets the total amount on the invoice
Example.
checkout := mpower.NewCheckoutInvoice(newSetup, newStore) checkout.SetCustomData("bonus", yeah)
func (*Invoice) SetDescription ¶
Sets the description for the invoice
Example.
checkout := mpower.NewCheckoutInvoice(newSetup, newStore) checkout.SetDescription("Hello World")
func (*Invoice) SetTotalAmount ¶
Sets the total amount on the invoice
Example.
checkout := mpower.NewCheckoutInvoice(newSetup, newStore) checkout.SetTotalAmount(80.00)
type OnsiteInvoice ¶
type OnsiteInvoice struct { Invoice `json:"invoice_data"` OPRData struct { Alias string `json:"account_alias"` } `json:"opr_data"` ReceiptUrl string `json:"-"` ResponseCode string `json:"-"` ResponseText string `json:"-"` Description string `json:"-"` Token string `json:"-"` InvoiceToken string `json:"-"` Status string `json:"-"` Customer struct { Name string `json:"-"` Phone string `json:"-"` Email string `json:"-"` } `json:"-"` // contains filtered or unexported fields }
The onsite definition as defined by mpower documentation This struct holds all the data with respect to onsite request
func NewOnsiteInvoice ¶
func NewOnsiteInvoice(setup *Setup, store *Store) *OnsiteInvoice
NewOnsiteInvoice create a new onsite invoice object It require a setup and store object
Example.
onsite := mpower.NewOnsiteInvoice(newSetup, newStore)
func (*OnsiteInvoice) Charge ¶
func (on *OnsiteInvoice) Charge(oprToken, confirmToken string) (bool, error)
Charge - it charges the customer on mpower and returns a response json object which contains the receipt url with other information The `confirmToken` is from the customer Returns a `boolean` and `error` The boolean signifies whether the customer was chargeed or not The response json object can be retrieved on the onsite invoice object
Example.
if ok, err := onsite.Charge(onsite.Token, "4346"); ok { //doSomething } else { }
func (*OnsiteInvoice) Create ¶
func (on *OnsiteInvoice) Create(name string) (bool, error)
Create - creates a bew invoice on mpowers server Returns a `boolean` and `error` The boolean signifies whether the inovoice was created on not The response json object can be retrieved on the onsite invoice object created by the NewOnsiteInvoice
Example.
ok, err := onsite.Create("hello") if ok { fmt.Printf("%s %s %s %s", onsite.ResponseCode, onsite.ResponseText, onsite.Description, onsite.Token) } else { fmt.Printf("%v", err) }
type Setup ¶
type Setup struct { MasterKey string PrivateKey string PublicKey string Token string ContentType string BASE_URL string }
The Setup as defined by mpower docs with the exception of the BASE_URL
func NewSetup ¶
NewSetup - returns a new setup object
Example.
newSetup := mpower.NewSetup(map[string]string{ "masterKey": YOUR MASTER KEY, "privateKey": YOUR PRIVATE KEY, "publicKey": "YOUR PUBLIC KEY, "token": YOUR TOKEN, "mode": MODE, })
func (*Setup) Get ¶
Get - gets a value from the struct by using its field name
Example.
key := newSetup.Get("MasterKey")
func (*Setup) GetHeaders ¶
GetHeaders - gets the respective headers to set on a request for an mpower transaction
type Store ¶
type Store struct { Name string `json:"name"` Tagline string `json:"tagline"` PhoneNumber string `json:"phone"` PostalAddress string `json:"postal_address"` LogoURL string `json:"logo_url"` }
The Store holds the store information and ised to define the store data for mpower transaction
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Godeps
|
|
_workspace/src/github.com/parnurzeal/gorequest
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client
|
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client |
_workspace/src/github.com/stretchr/testify/assert
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. |
_workspace/src/github.com/stretchr/testify/require
Alternative testing tools which stop test execution if test failed.
|
Alternative testing tools which stop test execution if test failed. |
_workspace/src/github.com/stretchr/testify/suite
The suite package contains logic for creating testing suite structs and running the methods on those structs as tests.
|
The suite package contains logic for creating testing suite structs and running the methods on those structs as tests. |
_workspace/src/golang.org/x/net/publicsuffix
Package publicsuffix provides a public suffix list based on data from http://publicsuffix.org/.
|
Package publicsuffix provides a public suffix list based on data from http://publicsuffix.org/. |