README

Rave

import "github.com/0sc/rave"

Setup

Sign up for a rave account; here for a sandbox account and here for a live account. Follow the instructions here to generate relevant public and private keys. Set your keys as enviroment variables like so:

export RAVE_PUBLIC_KEY=FLWPUBK-your-rave-public-key
export RAVE_SECRET_KEY=FLWSECK-your-rave-secret-key
export RAVE_MODE=test # can be either of test or live

Be sure that the set mode matches the keys provided; use your sandbox account keys for the test mode and your live account keys for the live mode. Rave will be sad if you do otherwise.

Usage

Card
package main

import (
	"fmt"
	"log"

	"github.com/0sc/rave"
)

func main(){
  card := &rave.Card{
		CardNo:      "5438898014560229",
		Currency:    "NGN",
		Country:     "NG",
		Cvv:         "789",
		Expirymonth: "09",
		Expiryyear:  "19",
		Pin:         "3310",
  }
  
  chargeRequest := rave.ChargeRequest{
		Amount:            300,
		Email:             "tester@flutter.co",
		IP:                "103.238.105.185",
		TxRef:             "'MXX-ASC-4579",
		PhoneNumber:       "0926420185",
		DeviceFingerprint: "69e6b7f0sb72037aa8428b70fbe03986c",
  }
  
  chargeResponse, err := chargeRequest.Charge(card)
	if err != nil {
		log.Println(err)
	}

	validationResponse, err := chargeResponse.OTPValidation("123")
	if err != nil {
		log.Println(err)
  }
  
  fmt.Println(validationResponse.Message)
}
Account
package main

import (
	"fmt"
	"log"

	"github.com/0sc/rave"
)

func main(){
  account := &rave.Account{
		AccountBank:   "044",
		AccountNumber: "0690000031",
		Country:       "NG",
  }
  
  chargeRequest := rave.ChargeRequest{
		Amount:            300,
		Email:             "tester@flutter.co",
		IP:                "103.238.105.185",
		TxRef:             "'MXX-ASC-4579",
		PhoneNumber:       "0926420185",
		DeviceFingerprint: "69e6b7f0sb72037aa8428b70fbe03986c",
  }
  
  chargeResponse, err := chargeRequest.Charge(account)
	if err != nil {
		log.Println(err)
	}

	validationResponse, err := chargeResponse.OTPValidation("123")
	if err != nil {
		log.Println(err)
  }
  
  fmt.Println(validationResponse.Message)
}
Transaction
Status check
package main

import (
	"fmt"

	"github.com/0sc/rave"
)

func main(){
  ref := "FLW-MOCK-a08e154ad6bcd97fba7fa66e4438614c"
  expAmt := 300
  currency := "NGN"

  txnChecklist := rave.NewTxnVerificationChecklist(expAmt, ref, currency)
  _, errs := txnChecklist.VerifyTransaction()

  if len(errs) == 0 {
    fmt.Println("Transaction checks out 🎉")
  } else {
    fmt.Println(errs)
  }
}
Status check using XRequery
package main

import (
	"fmt"

	"github.com/0sc/rave"
)

func main(){
  flwRef := "FLW-MOCK-a08e154ad6bcd97fba7fa66e4438614c"
  txRef := "'MXX-ASC-4579"
  expAmt := 300
  currency := "NGN"

  txnChecklist := rave.NewXRQTxnVerificationChecklist(expAmt, ref, currency)
  _, errs := txnChecklist.VerifyXRequeryTransaction()

  if len(errs) == 0 {
    fmt.Println("Transaction checks out 🎉")
  } else {
    fmt.Println(errs)
  }
}
Preauth
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  card := &rave.Card{
		CardNo:      "5840406187553286",
		Currency:    "NGN",
		Country:     "NG",
		Cvv:         "116",
		Expirymonth: "09",
		Expiryyear:  "18",
		Pin:         "1111",
  }
  
  chargeRequest := rave.ChargeRequest{
		Amount:            300,
		ChargeType:        "preauth",
		Email:             "tester@flutter.co",
		IP:                "103.238.105.185",
		TxRef:             "'MXX-ASC-4579",
		PhoneNumber:       "0926420185",
		DeviceFingerprint: "69e6b7f0sb72037aa8428b70fbe03986c",
  }
  
  chargeResponse, err := chargeRequest.Charge(card)
	if err != nil {
		log.Println(err)
  }
  ref := chargeResponse.Data.FlwRef
  
  /// CAPTURE PAYMENT
  resp, err := rave.CapturePreAuthPayment(ref)
  if err != nil {
		log.Println(err)
  }
  fmt.Println(resp.Status)

  /// VOID PAYMENT
  res, err := rave.VoidPreAuthPayment(ref)
  if err != nil {
		log.Println(err)
  }
  fmt.Println(res.Status)

  /// REFUND PAYMENT
  res, err = rave.RefundPreAuthPayment(chargeRef)
  if err != nil {
		log.Println(err)
  }
  fmt.Println(res.Status)
}
List Banks
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  banks, err := rave.ListBanks()
  if err != nil {
    log.Println(err)
  }

  fmt.Println(banks)
}
Get Fees
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  feeReq := &rave.GetFeeRequest{
    Amount:   "100",
		Currency: "USD",
  }

  resp, err := rave.GetFee(feeReq)
  if err != nil {
		log.Println(err)
  }
  fmt.Println(resp.Data.Fee)
}
Exchange Rates
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  feeReq := &rave.ForexParams{
    Amount:   "100",
    OriginCurrency: "USD",
    DestinationCurrency: "NGN",
  }

  resp, err := rave.GetFee(feeReq)

  if err != nil {
    log.Println(err)
  }
  fmt.Printf("Converted amount: %d, rate %d \n", resp.Data.ConvertedAmount, resp.Data.Rate)
}
Direct Charge Refunds
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  ref := "FLW-MOCK-a08e154ad6bcd97fba7fa66e4438614c"
  resp, err := rave.Refund(ref)
  if err != nil {
    log.Println(err)
  }
  fmt.Println(resp.Status)
}
Alternative Payments
USSD
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  ussd := &rave.USSD{
		AccountBank:   "044",
		AccountNumber: "0690000031",
		Currency:      "NGN",
		Country:       "NG",
		FirstName:     "jsksk",
		LastName:      "ioeoe",
  }
  
  chargeRequest := rave.ChargeRequest{
    Amount:            300,
    PaymentType:       "ussd",
		Email:             "tester@flutter.co",
		IP:                "103.238.105.185",
		TxRef:             "'MXX-ASC-4579",
		PhoneNumber:       "0926420185",
		DeviceFingerprint: "69e6b7f0sb72037aa8428b70fbe03986c",
  }
  
  chargeResponse, err := chargeRequest.Charge(ussd)
	if err != nil {
		log.Println(err)
  }
  
  fmt.Printf("%+v\n", rave.USSDPaymentInstruction(chargeResponse))

	validationResponse, err := chargeResponse.OTPValidation("123")
	if err != nil {
		log.Println(err)
  }
  
  fmt.Println(validationResponse.Message)
}
Mpesa
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  mpesa := &rave.Mpesa{
		Currency:  "KES",
		Country:   "NG",
		FirstName: "jsksk",
		LastName:  "ioeoe",
		IsMpesa:   "1",
	}
  
  chargeRequest := rave.ChargeRequest{
    Amount:            300,
    PaymentType:       "mpesa",
		Email:             "tester@flutter.co",
		IP:                "103.238.105.185",
		TxRef:             "'MXX-ASC-4579",
		PhoneNumber:       "0926420185",
		DeviceFingerprint: "69e6b7f0sb72037aa8428b70fbe03986c",
  }
  
  chargeResponse, err := chargeRequest.Charge(mpesa)
	if err != nil {
		log.Println(err)
	}

  instructions := rave.MpesaPaymentInstruction(chargeResponse)
	fmt.Printf("Complete transaction by sending %d to %s\n", instructions.Amount, instructions.BusinessNumber)
}
Mobile Money Ghana
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

func main(){
  mm := &rave.MobileMoneyGH{
		Currency:        "GHS",
		Country:         "GH",
		Network:         "MTN",
		IsMobileMoneyGH: 1,
	}
  
  chargeRequest := rave.ChargeRequest{
    Amount:            300,
    PaymentType:       "mobilemoneygh",
		Email:             "tester@flutter.co",
		IP:                "103.238.105.185",
		TxRef:             "'MXX-ASC-4579",
		PhoneNumber:       "0926420185",
		DeviceFingerprint: "69e6b7f0sb72037aa8428b70fbe03986c",
  }
  
  chargeResponse, err := chargeRequest.Charge(mpesa)
	if err != nil {
		log.Println(err)
	}

  fmt.Println(chargeResponse.Status)
}
Checksum
  package main

  import (
  "fmt"

	"github.com/0sc/rave"
)

  func main(){
    payload := rave.Payment{
      Amount:            20,
      PaymentMethod:     "both",
      CustomDescription: "Pay Internet",
      CustomLogo:        "http://localhost/payporte-3/skin/frontend/ultimo/shoppy/custom/images/logo.svg",
      CustomTitle:       "Shoppy Global systems",
      Country:           "NG",
      Currency:          "NGN",
      CustomerEmail:     "user@example.com",
      CustomerFirstname: "Temi",
      CustomerLastname:  "Adelewa",
      CustomerPhone:     "234099940409",
      TxRef:             "MG-1500041286295",
    }
    prefix := []byte(rave.PublicKey)
    suffix := []byte(rave.Secret)

    checksum := rave.CalculateChecksum(payload, prefix, suffix)
    fmt.Println(checksum)
  }
Utils
package main

import (
  "fmt"
  "log"

	"github.com/0sc/rave"
)

 func main(){
   // check currentMode
   rave.CurrentMode() // => live or test

   // manually set public key
   rave.PublicKey = FLWPUBK-your-rave-public-key
 
   // manually set secret key
   rave.SecretKey = FLWSECK-your-rave-secret-key

   // switch to live mode
   rave.SwitchToLiveMode()

   // switch to test mode
   rave.SwitchToTestMode()
 }

Todo

[ ] Add pre request validations where applicable

[ ] Implement a cleaner way for reasonably handling the inconsistences with Rave API request/response parameters

[ ] Switch to pointers for json struct fields to better manage Go's default type

Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// PublicKey is your rave secret key
	PublicKey string
	// SecretKey is your rave secret key
	SecretKey string
)

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CalculateChecksum

func CalculateChecksum(payload interface{}, prefix, suffix []byte) string

CalculateChecksum implements rave's checksum integrity check for inline js https://flutterwavedevelopers.readme.io/docs/checksum To use with a payment payload, provide the payment object as the payload interface add the payment PBFPubKey and your secret key as byte prefix and suffix respectively

func CurrentMode

func CurrentMode() string

CurrentMode returns the current mode of operation, live or test This actual variable itself, currentMode is not exposed to prevent direct (external) modification (external) modification should only be done via the helper methods below

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func SwitchToLiveMode

func SwitchToLiveMode()

SwitchToLiveMode changes to current operation mode to live Rave api requests in the live mode are made to the real live rave api servers and not the test servers

func SwitchToTestMode

func SwitchToTestMode()

SwitchToTestMode changes to current operation mode to test Rave api requests in the live mode are made to the test rave api servers and not the live servers

Types

type Account

type Account struct {
	AccountBank          string `json:"account_bank"` // TODO: account_bank vs accountbank
	AccountIsBlacklisted int    `json:"account_is_blacklisted"`
	AccountNumber        string `json:"account_number"`
	AccountToken         struct {
		Token string `json:"token"`
	} `json:"account_token"`
	ChargeAccountURL         string      `json:"-"`
	ValidateAccountChargeURL string      `json:"-"`
	Country                  string      `json:"country"`
	CreatedAt                string      `json:"createdAt"`
	Currency                 string      `json:"currency"`
	DeletedAt                interface{} `json:"deletedAt"`
	FirstName                string      `json:"first_name"`
	ID                       int         `json:"id"`
	LastName                 string      `json:"last_name"`
	Passcode                 string      `json:"passcode"`
	UpdatedAt                string      `json:"updatedAt"`
}

Account is a type that encapsulates rave's account description It has all account attributes necessary for rave api card references It also implements the chargable interface required for making charge requests and validating them

func (*Account) BuildChargeRequestPayload

func (a *Account) BuildChargeRequestPayload(creq *ChargeRequest) []byte

BuildChargeRequestPayload is an implemenation of the Chargeable interface it returns the byte representation of the charge request client at the ChargeRequest level, chargeables are merely interface objects so trying to compose a struct with an interface object results in go adding the interface name key to the result bytes see https://play.golang.com/p/MFfbuPLrjo6 so here we upend it so the individual concrete types do the marshalling

func (*Account) ChargeURL

func (a *Account) ChargeURL() string

ChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given account

func (*Account) ValidateChargeURL

func (a *Account) ValidateChargeURL() string

ValidateChargeURL is an implemenation of the Chargeable interface it returns the url to be used for validating charge on the given account

type Bank

type Bank struct {
	Code            string `json:"bankcode"`
	Name            string `json:"bankname"`
	Internetbanking bool   `json:"internetbanking"`
}

Bank is a type of rave bank resources

func ListBanks

func ListBanks() ([]Bank, error)

ListBanks returns list of banks from the rave api https://flutterwavedevelopers.readme.io/v1.0/reference#list-of-banks

type Card

type Card struct {
	Brand      string `json:"brand,omitempty"`
	CardBIN    string `json:"cardBIN,omitempty"`
	CardNo     string `json:"cardno"`
	CardTokens []struct {
		Embedtoken string `json:"embedtoken"`
		Shortcode  string `json:"shortcode"`
	} `json:"card_tokens,omitempty"`
	ChargeCardURL         string `json:"-"`
	Country               string `json:"country"`
	Currency              string `json:"currency"`
	Cvv                   string `json:"cvv"`
	Expirymonth           string `json:"expirymonth"`
	Expiryyear            string `json:"expiryyear"`
	FirstName             string `json:"firstname,omitempty"`
	Last4digits           string `json:"last4digits,omitempty"`
	LastName              string `json:"lastname,omitempty"`
	Pin                   string `json:"pin"`
	ValidateCardChargeURL string `json:"-"`
}

Card is a type that encapsulates rave's card description It has all card attributes necessary for rave api card references It also implements the chargable interface required for making charge requests and validating them

func (*Card) BuildChargeRequestPayload

func (c *Card) BuildChargeRequestPayload(creq *ChargeRequest) []byte

BuildChargeRequestPayload is an implemenation of the Chargeable interface it returns the byte representation of the charge request client at the ChargeRequest level, chargeables are merely interface objects so trying to compose a struct with an interface object results in go adding the interface name key to the result bytes see https://play.golang.com/p/MFfbuPLrjo6 so here we upend it so the individual concrete types do the marshalling

func (*Card) ChargeURL

func (c *Card) ChargeURL() string

ChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

func (*Card) ValidateChargeURL

func (c *Card) ValidateChargeURL() string

ValidateChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

type ChargeRequest

type ChargeRequest struct {
	PBFPubKey         string  `json:"PBFPubKey"`
	Amount            float64 `json:"amount"`
	ChargeType        string  `json:"charge_type"`
	DeviceFingerprint string  `json:"device_fingerprint"`
	Email             string  `json:"email"`
	IP                string  `json:"IP"`
	TxRef             string  `json:"txRef"`
	PaymentType       string  `json:"payment_type"`
	PhoneNumber       string  `json:"phonenumber"`
	RedirectURL       string  `json:"redirect_url"`
	SuggestedAuth     string  `json:"suggested_auth"`
}

ChargeRequest is a holds information necessary charging a given card it has a charge method defined on it that takes a card and proceeds to charge it with the given information

func (*ChargeRequest) Charge

func (cr *ChargeRequest) Charge(chargeable Chargeable) (*ChargeResponse, error)

Charge makes the request to charge the given card it returns the response from the server

type ChargeResponse

type ChargeResponse struct {
	Data              chargeResponseData `json:"data"`
	Message           string             `json:"message"`
	Status            string             `json:"status"`
	ValidateChargeURL string             `json:"-"`
	PBFPubKey         string             `json:"-"`
}

ChargeResponse is a type of rave response to a charge card request

func CapturePreAuthPayment

func CapturePreAuthPayment(ref string) (*ChargeResponse, error)

CapturePreAuthPayment makes request to rave's capture endpoint to claim preauth payments It takes the flwRef as param and returns the capture response and any error that occures https://flutterwavedevelopers.readme.io/v2.0/reference#capture

func (*ChargeResponse) OTPValidation

func (cr *ChargeResponse) OTPValidation(otp string) (*ChargeValidationResponse, error)

OTPValidation handles the final part to a resource charge using the provided otp returns the server response

type ChargeValidationResponse

type ChargeValidationResponse struct {
	Data struct {
		Data struct {
			Responsecode    string `json:"responsecode"`
			Responsemessage string `json:"responsemessage"`
		} `json:"data"`
		Tx chargeResponseData `json:"tx"`
	} `json:"data"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

ChargeValidationResponse is a type of the response from rave for charge validation request It's a hybrid of the response for both card and account validation requests

type Chargeable

type Chargeable interface {
	ChargeURL() string
	ValidateChargeURL() string
	BuildChargeRequestPayload(*ChargeRequest) []byte
}

Chargeable is an abstract representation for chargeable resources like cards and accounts

type Customer

type Customer struct {
	AccountID     int         `json:"AccountId"`
	CreatedAt     string      `json:"createdAt"`
	Customertoken interface{} `json:"customertoken"`
	DeletedAt     interface{} `json:"deletedAt"`
	Email         string      `json:"email"`
	FullName      string      `json:"fullName"`
	ID            int         `json:"id"`
	Phone         interface{} `json:"phone"`
	UpdatedAt     string      `json:"updatedAt"`
}

Customer is a type that encapsulates rave's customer description

type FlwMeta

type FlwMeta struct {
	ACCOUNTVALIDATIONRESPMESSAGE  interface{} `json:"ACCOUNTVALIDATIONRESPMESSAGE"`
	ACCOUNTVALIDATIONRESPONSECODE string      `json:"ACCOUNTVALIDATIONRESPONSECODE"`
	VBVRESPONSECODE               string      `json:"VBVRESPONSECODE"`
	VBVRESPONSEMESSAGE            string      `json:"VBVRESPONSEMESSAGE"`
	ChargeResponse                string      `json:"chargeResponse"`
	ChargeResponseMessage         string      `json:"chargeResponseMessage"`
}

FlwMeta ...

type ForexParams

type ForexParams struct {
	Amount              string `json:"amount"`
	OriginCurrency      string `json:"origin_currency"`
	DestinationCurrency string `json:"destination_currency"`
	SecKey              string `json:"SECKEY"`
}

ForexParams type represents allowed params for querying rave's forex endpoint

type ForexResponse

type ForexResponse struct {
	Data struct {
		ConvertedAmount     int    `json:"converted_amount"`
		Destinationcurrency string `json:"destinationcurrency"`
		Lastupdated         string `json:"lastupdated"`
		OriginalAmount      string `json:"original_amount"`
		Origincurrency      string `json:"origincurrency"`
		Rate                int    `json:"rate"`
	} `json:"data"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

ForexResponse is raves response for forex rate request

func ForexRate

func ForexRate(fxp *ForexParams) (*ForexResponse, error)

ForexRate queries rave forex endpoint for the current rate of the currencies in the params it returns the request response and any error that occurs

type GetFeeRequest

type GetFeeRequest struct {
	Amount    string `json:"amount"`
	PBFPubKey string `json:"PBFPubKey"`
	Currency  string `json:"currency"`
	PType     string `json:"ptype,omitempty"`
	Card6     string `json:"card6,omitempty"`
}

GetFeeRequest encapsulates the params need for requesting fee amount from the rave api https://flutterwavedevelopers.readme.io/v2.0/reference#get-fees

type GetFeeResponse

type GetFeeResponse struct {
	Data struct {
		ChargeAmount string  `json:"charge_amount"`
		Fee          float64 `json:"fee"`
		Merchantfee  string  `json:"merchantfee"`
		Ravefee      string  `json:"ravefee"`
	} `json:"data"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

GetFeeResponse is a type of rave's response to a get fee request

func GetFee

func GetFee(p *GetFeeRequest) (*GetFeeResponse, error)

GetFee returns rave's fee response for the given get fee request it returns any error that occures

type MobileMoneyGH

type MobileMoneyGH struct {
	ChargeRequestURL string `json:"-"`
	Currency         string `json:"currency"`
	Country          string `json:"country"`
	LastName         string `json:"lastname,omitempty"`
	FirstName        string `json:"firstname,omitempty"`
	IsMobileMoneyGH  int    `json:"is_mobile_money_gh"`
	Network          string `json:"network"`
}

MobileMoneyGH is a type that encapsulates rave's ghana mobile money description It has all mpesa attributes necessary for rave api ghana mobile money description references It also implements the chargable interface required for making charge requests and validating them

func (*MobileMoneyGH) BuildChargeRequestPayload

func (gh *MobileMoneyGH) BuildChargeRequestPayload(cReq *ChargeRequest) []byte

BuildChargeRequestPayload is an implemenation of the Chargeable interface it returns the byte representation of the charge request client at the ChargeRequest level, chargeables are merely interface objects so trying to compose a struct with an interface object results in go adding the interface name key to the result bytes see https://play.golang.com/p/MFfbuPLrjo6 so here we upend it so the individual concrete types do the marshalling

func (*MobileMoneyGH) ChargeURL

func (gh *MobileMoneyGH) ChargeURL() string

ChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

func (*MobileMoneyGH) ValidateChargeURL

func (gh *MobileMoneyGH) ValidateChargeURL() string

ValidateChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

type Mpesa

type Mpesa struct {
	ChargeMpesaURL string `json:"-"`
	Currency       string `json:"currency"`
	Country        string `json:"country"`
	LastName       string `json:"lastname,omitempty"`
	FirstName      string `json:"firstname,omitempty"`
	IsMpesa        string `json:"is_mpesa,omitempty"`
}

Mpesa is a type that encapsulates rave's mpesa description It has all mpesa attributes necessary for rave api mpesa references It also implements the chargable interface required for making charge requests and validating them

func (*Mpesa) BuildChargeRequestPayload

func (m *Mpesa) BuildChargeRequestPayload(cReq *ChargeRequest) []byte

BuildChargeRequestPayload is an implemenation of the Chargeable interface it returns the byte representation of the charge request client at the ChargeRequest level, chargeables are merely interface objects so trying to compose a struct with an interface object results in go adding the interface name key to the result bytes see https://play.golang.com/p/MFfbuPLrjo6 so here we upend it so the individual concrete types do the marshalling

func (*Mpesa) ChargeURL

func (m *Mpesa) ChargeURL() string

ChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

func (*Mpesa) ValidateChargeURL

func (m *Mpesa) ValidateChargeURL() string

ValidateChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

type MpesaPaymentInfo

type MpesaPaymentInfo struct {
	AccountNumber  string
	Amount         int
	BusinessNumber string
}

MpesaPaymentInfo is the information necessary for completing mpesa payment

func MpesaPaymentInstruction

func MpesaPaymentInstruction(cr *ChargeResponse) *MpesaPaymentInfo

MpesaPaymentInstruction parses the given charge response and returns the payment info: business number and account number for completing the payment

type Payment

type Payment struct {
	Amount            int    `json:"amount"`
	Country           string `json:"country"`
	Currency          string `json:"currency"`
	CustomDescription string `json:"custom_description"`
	CustomTitle       string `json:"custom_title"`
	CustomerEmail     string `json:"customer_email"`
	CustomerFirstname string `json:"customer_firstname"`
	CustomerLastname  string `json:"customer_lastname"`
	CustomerPhone     string `json:"customer_phone"`
	PaymentMethod     string `json:"payment_method"`
	TxRef             string `json:"txref"`
}

Payment is a type that encapsulates rave's concept of payment together with PaymentVerfication it contains required implementations for interacting with the payment APIs

type PreAuthResponse

type PreAuthResponse struct {
	Data struct {
		Data struct {
			AuthorizeID              string      `json:"authorizeId"`
			Avsresponsecode          interface{} `json:"avsresponsecode"`
			Avsresponsemessage       interface{} `json:"avsresponsemessage"`
			Otptransactionidentifier interface{} `json:"otptransactionidentifier"`
			Redirecturl              interface{} `json:"redirecturl"`
			Responsecode             string      `json:"responsecode"`
			Responsehtml             interface{} `json:"responsehtml"`
			Responsemessage          string      `json:"responsemessage"`
			Responsetoken            interface{} `json:"responsetoken"`
			Transactionreference     string      `json:"transactionreference"`
		} `json:"data"`
		Status string `json:"status"`
	} `json:"data"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

PreAuthResponse is a type of rave response for refund or void preauth payment response

func RefundPreAuthPayment

func RefundPreAuthPayment(ref string) (*PreAuthResponse, error)

RefundPreAuthPayment fullfiles the raves preauth feature by refunding the preauthorized paymemnt It takes the flwRef and makes a request to refund the txn It returns the response and any error that occurs https://flutterwavedevelopers.readme.io/v2.0/reference#refund-or-void

func VoidPreAuthPayment

func VoidPreAuthPayment(ref string) (*PreAuthResponse, error)

VoidPreAuthPayment fullfiles the raves preauth feature by voiding the preauthorized paymemnt It takes the flwRef and makes a request to void the txn It returns the response and any error that occurs https://flutterwavedevelopers.readme.io/v2.0/reference#refund-or-void

type RefundTxnResponse

type RefundTxnResponse struct {
	Data struct {
		AccountID      int    `json:"AccountId"`
		AmountRefunded int    `json:"AmountRefunded"`
		FlwRef         string `json:"FlwRef"`
		TransactionID  int    `json:"TransactionId"`
		CreatedAt      string `json:"createdAt"`
		ID             int    `json:"id"`
		Status         string `json:"status"`
		UpdatedAt      string `json:"updatedAt"`
		WalletID       int    `json:"walletId"`
	} `json:"data"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

RefundTxnResponse is rave's response for refund txn request

func Refund

func Refund(ref string) (*RefundTxnResponse, error)

Refund makes a refund request for txn with the given ref it returns rave's response and any error that occurs

type TxnVerificationChecklist

type TxnVerificationChecklist struct {
	Amount              int    `json:"-"`
	FlwRef              string `json:"flw_ref,omitempty"` // for some weird reason, this just had to be different from below
	Flwref              string `json:"flwref,omitempty"`  // for some weird reason, this just had to be different from above
	LastAttempt         string `json:"last_attempt,omitempty"`
	Normalize           string `json:"normalize"`
	OnlySuccessful      string `json:"only_successful,omitempty"`
	VerificationURL     string `json:"-"`
	SECKEY              string `json:"SECKEY"`
	TransactionCurrency string `json:"-"`
	TxRef               string `json:"tx_ref,omitempty"` // for some weird reason, this just had to be different from above
	Txref               string `json:"txref,omitempty"`  // for some weird reason, this just had to be different from below
	// Done tracks whether verification has been attempted. It starts out false for new objects and changes to true after #verify is called on the object
	Done bool `json:"-"`
}

TxnVerificationChecklist encapsulates the payment verification process It includes details of the payment to verify and the verification response

func NewTxnVerificationChecklist

func NewTxnVerificationChecklist(amount int, flwRef, currency string) *TxnVerificationChecklist

NewTxnVerificationChecklist returns a new paymentVerificationChecklist object with the given params

func NewXRQTxnVerificationChecklist

func NewXRQTxnVerificationChecklist(amount int, flwRef, txRef, currency string) *TxnVerificationChecklist

NewXRQTxnVerificationChecklist returns a new paymentVerificationChecklist object with the given params It sets up the checklist to use the rave's xrequery transaction verification endpoint

func (*TxnVerificationChecklist) Verify

func (tvc *TxnVerificationChecklist) Verify(v Verifiable) []error

Verify performs the rave's recommended verification check on the verifiable resource It returns an array of error for verfications that fail (if any) and marks the verification as Done

func (*TxnVerificationChecklist) VerifyTransaction

func (tvc *TxnVerificationChecklist) VerifyTransaction() (*TxnVerificationResponse, []error)

VerifyTransaction sends a rave Transaction verfication request and then verfies the response It validates that verification checklist contains all the required information for making the request http://flw-pms-dev.eu-west-1.elasticbeanstalk.com/flwv3-pug/getpaidx/api/verify it also marks the verification as done If the verification URL is not set, it set's it to the default from config

func (*TxnVerificationChecklist) VerifyXRequeryTransaction

func (tvc *TxnVerificationChecklist) VerifyXRequeryTransaction() (*XRQTxnVerificationResponse, []error)

VerifyXRequeryTransaction sends a rave XRequery transaction verification request and then verifies the response It validates that verification checklist contains all the required information for making the request it also marks the verification as done https://flutterwavedevelopers.readme.io/v1.0/reference#xrequery-transaction-verification If the verification URL is not set, it set's it to the default from config

type TxnVerificationResponse

type TxnVerificationResponse struct {
	Data    txnVerificationResponseData `json:"data"`
	Message string                      `json:"message"`
	Status  string                      `json:"status"`
}

TxnVerificationResponse is a type of rave response for transaction verification request it implements the verifiable interface to allow rave's recommended followup verification

func (*TxnVerificationResponse) VerifyAmount

func (resp *TxnVerificationResponse) VerifyAmount(amt int) error

VerifyAmount verifies that the given amount matches that in the transaction returns error otherwise

func (*TxnVerificationResponse) VerifyChargeResponseValue

func (resp *TxnVerificationResponse) VerifyChargeResponseValue() error

VerifyChargeResponseValue verifies that the charge response value for the transaction is either '0' or '00'

func (*TxnVerificationResponse) VerifyCurrency

func (resp *TxnVerificationResponse) VerifyCurrency(currency string) error

VerifyCurrency verifies that the currency in the txn verification matches the given currency returns error otherwise

func (*TxnVerificationResponse) VerifyReference

func (resp *TxnVerificationResponse) VerifyReference(ref string) error

VerifyReference verifies that the flw ref in the transaction matches the given ref returns error otherwise

func (*TxnVerificationResponse) VerifyStatus

func (resp *TxnVerificationResponse) VerifyStatus() error

VerifyStatus verifies that response status is success returns error otherwise

type USSD

type USSD struct {
	AccountBank           string `json:"accountbank"` // vs account_bank
	AccountNumber         string `json:"accountnumber"`
	ChargeRequestURL      string `json:"-"`
	ValidateCardChargeURL string `json:"-"`
	Country               string `json:"country"`
	Currency              string `json:"currency"`
	FirstName             string `json:"firstname,omitempty"`
	LastName              string `json:"lastname,omitempty"`
	IsUSSD                string `json:"is_ussd,omitempty"`
	OrderRef              string `json:"orderRef,omitempty"`
}

USSD is a type that encapsulates rave's ussd description It has all ussd attributes necessary for rave api ussd referencess It also implements the chargable interface required for making charge requests

func (*USSD) BuildChargeRequestPayload

func (c *USSD) BuildChargeRequestPayload(cReq *ChargeRequest) []byte

BuildChargeRequestPayload is an implemenation of the Chargeable interface it returns the byte representation of the charge request client at the ChargeRequest level, chargeables are merely interface objects so trying to compose a struct with an interface object results in go adding the interface name key to the result bytes see https://play.golang.com/p/MFfbuPLrjo6 so here we upend it so the individual concrete types do the marshalling

func (*USSD) ChargeURL

func (c *USSD) ChargeURL() string

ChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

func (*USSD) ValidateChargeURL

func (c *USSD) ValidateChargeURL() string

ValidateChargeURL is an implemenation of the Chargeable interface it returns the url to be used for charging the given card

type USSDPaymentInfo

type USSDPaymentInfo struct {
	FlwRef string
	Amount int
}

USSDPaymentInfo is the information necessary for completing mpesa payment

func USSDPaymentInstruction

func USSDPaymentInstruction(cr *ChargeResponse) *USSDPaymentInfo

USSDPaymentInstruction parses the given charge response and returns the payment info for completing the payment

type Verifiable

type Verifiable interface {
	VerifyStatus() error
	VerifyCurrency(string) error
	VerifyAmount(int) error
	VerifyChargeResponseValue() error
	VerifyReference(string) error
}

Verifiable is an abstract representation of any rave resources that can be verified verified here

type XRQTxnVerificationResponse

type XRQTxnVerificationResponse struct {
	Data    xRQTxnVerificationResponseData `json:"data"`
	Message string                         `json:"message"`
	Status  string                         `json:"status"`
}

XRQTxnVerificationResponse is a type of rave response for xrquery transaction verification request it implements the verifiable interface to allow rave's recommended followup verification

func (*XRQTxnVerificationResponse) VerifyAmount

func (resp *XRQTxnVerificationResponse) VerifyAmount(amt int) error

VerifyAmount verifies that the given amount matches that in the transaction returns error otherwise

func (*XRQTxnVerificationResponse) VerifyChargeResponseValue

func (resp *XRQTxnVerificationResponse) VerifyChargeResponseValue() error

VerifyChargeResponseValue verifies that the charge response value for the transaction is either '0' or '00'

func (*XRQTxnVerificationResponse) VerifyCurrency

func (resp *XRQTxnVerificationResponse) VerifyCurrency(currency string) error

VerifyCurrency verifies that the currency in the txn verification matches the given currency returns error otherwise

func (*XRQTxnVerificationResponse) VerifyReference

func (resp *XRQTxnVerificationResponse) VerifyReference(ref string) error

VerifyReference verifies that the flw ref in the transaction matches the given ref returns error otherwise

func (*XRQTxnVerificationResponse) VerifyStatus

func (resp *XRQTxnVerificationResponse) VerifyStatus() error

VerifyStatus verifies that response status is success returns error otherwise