mvola

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: MIT Imports: 1 Imported by: 0

README

mvola-go

Go Reference

MVola Go client library.

Install

  go get -u github.com/tsirysndr/mvola-go

Usage

import (
	"fmt"
	"log"
	"os"
	"time"

	uuid "github.com/google/uuid"
	mvola "github.com/tsirysndr/mvola-go"
)

const ISO8601 = "2006-01-02T15:04:05.999Z"

func main() {
	var (
		consumerKey    = os.Getenv("CONSUMER_KEY")
		consumerSecret = os.Getenv("CONSUMER_SECRET")
	)
	client := mvola.NewClient(mvola.SANDBOX_URL)
	res, err := client.Auth.GenerateToken(consumerKey, consumerSecret)
	if err != nil {
		log.Fatal(err)
	}

	mvola.SetAccessToken(client, res.AccessToken)

	correlationID := uuid.NewString()
	transactionRef := uuid.NewString()
	fmt.Println("correlationID:", correlationID)
	fmt.Println("transactionRef:", transactionRef)

	opt := mvola.Options{
		Version:               "1.0",
		CorrelationID:         correlationID,
		UserLanguage:          "FR",
		UserAccountIdentifier: "msisdn;0343500003",
		PartnerName:           "TestMVola",
		CallbackURL:           nil,
	}
	mvola.SetOptions(client, opt)

	requestDate := time.Now().UTC().Format(ISO8601)

	tx := mvola.TransactionRequest{
		Amount:          "1000",
		Currency:        "Ar",
		DescriptionText: "test",
		RequestingOrganisationTransactionReference: transactionRef,
		RequestDate:                  requestDate,
		OriginalTransactionReference: transactionRef,
		DebitParty: []mvola.KeyValue{{
			Key:   "msisdn",
			Value: "0343500003",
		}},
		CreditParty: []mvola.KeyValue{{
			Key:   "msisdn",
			Value: "0343500004",
		}},
		Metadata: []mvola.KeyValue{{
			Key:   "partnerName",
			Value: "TestMVola",
		},
			{
				Key:   "fc",
				Value: "USD",
			}, {
				Key:   "amountFc",
				Value: "1",
			}},
	}

	txres, err := client.Transaction.SendPayment(&tx)
	fmt.Println(txres)
	fmt.Println(err)
}

Documentation

For details on all the functionality in this library, see the Go documentation.

Author

👤 Tsiry Sandratraina tsiry.sndr@aol.com

Show your support

Give a ⭐️ if this project helped you!

Documentation

Index

Constants

View Source
const PRODUCTION_URL = "https://api.mvola.mg"
View Source
const SANDBOX_URL = "https://devapi.mvola.mg"

Variables

This section is empty.

Functions

func SetAccessToken

func SetAccessToken(c *Client, accessToken string)

func SetOptions

func SetOptions(c *Client, opt Options)

Types

type Auth

type Auth struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
}

type AuthRequest

type AuthRequest struct {
	GrantType string `url:"grant_type"`
	Scope     string `url:"scope"`
}

type AuthService

type AuthService service

func (*AuthService) GenerateToken

func (s *AuthService) GenerateToken(consumerKey, consumerSecret string) (*Auth, error)

type Client

type Client struct {
	Auth        *AuthService
	Transaction *TransactionService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseUrl string) *Client

type Fee

type Fee struct {
	FeeAmount string `json:"feeAmount"`
}

type KeyValue

type KeyValue struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Options

type Options struct {
	Version               string
	CorrelationID         string
	UserLanguage          string
	UserAccountIdentifier string
	PartnerName           string
	CallbackURL           *string
}

type TransactionDetails

type TransactionDetails struct {
	Amount               string     `json:"amount"`
	Currency             string     `json:"currency"`
	TransactionReference string     `json:"transactionReference"`
	TransactionStatus    string     `json:"transactionStatus"`
	CreationDate         string     `json:"creationDate"`
	RequestDate          string     `json:"requestDate"`
	DebitParty           []KeyValue `json:"debitParty"`
	CreditParty          []KeyValue `json:"creditParty"`
	Metadata             []KeyValue `json:"metadata"`
	Fees                 []Fee      `json:"fees"`
}

type TransactionRequest

type TransactionRequest struct {
	Amount                                     string     `json:"amount"`
	Currency                                   string     `json:"currency"`
	DescriptionText                            string     `json:"descriptionText"`
	RequestDate                                string     `json:"requestDate"`
	DebitParty                                 []KeyValue `json:"debitParty"`
	CreditParty                                []KeyValue `json:"creditParty"`
	Metadata                                   []KeyValue `json:"metadata"`
	RequestingOrganisationTransactionReference string     `json:"requestingOrganisationTransactionReference"`
	OriginalTransactionReference               string     `json:"originalTransactionReference"`
}

type TransactionResponse

type TransactionResponse struct {
	Status              string `json:"status"`
	ServerCorrelationID string `json:"serverCorrelationId"`
	NotificationMethod  string `json:"notificationMethod"`
}

type TransactionService

type TransactionService service

func (*TransactionService) GetTransactionDetails

func (s *TransactionService) GetTransactionDetails(transactionID string) (*TransactionDetails, error)

func (*TransactionService) GetTransactionStatus

func (s *TransactionService) GetTransactionStatus(serverCorrelationID string) (*TransactionStatus, error)

func (*TransactionService) SendPayment

type TransactionStatus

type TransactionStatus struct {
	Status              string `json:"status"`
	ServerCorrelationID string `json:"serverCorrelationId"`
	NotificationMethod  string `json:"notificationMethod"`
	ObjectReference     string `json:"objectReference"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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