ynote

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: MIT Imports: 12 Imported by: 0

README

ynote-go

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides a generic go client for the Y-Note API

Installation

ynote-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/ynote-go

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/ynote-go"

Implemented

  • Token
    • POST /oauth2/token: Get Access Token
  • Refund
    • POST /prod/refund: Refund a transaction
    • GET /prod/refund/status/{transactionID}: Get the status of a refund transaction

Usage

Initializing the Client

An instance of the client can be created using New().

package main

import (
    "github.com/NdoleStudio/ynote-go"
)

func main() {
    client := ynote.New(
        ynote.WithClientID(""),
        ynote.WithClientSecret(""),
    )
}
Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

transaction, response, err := client.Refund.Status(context.Background(), "messageID")
if err != nil {
    //handle error
}

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenResponse

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

AccessTokenResponse is the response when fetching the access token

type Client

type Client struct {
	Refund *RefundService
	// contains filtered or unexported fields
}

Client is the Y-Note API client. Do not instantiate this client with Client{}. Use the New method instead.

func New

func New(options ...Option) *Client

New creates and returns a new ynote.Client from a slice of ynote.Option.

func (*Client) AccessToken

func (client *Client) AccessToken(ctx context.Context) (*AccessTokenResponse, *Response, error)

AccessToken fetches the access token used to authenticate api requests.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is options for constructing a client

func WithAPIURL

func WithAPIURL(apiURL string) Option

WithAPIURL set's the api URL for the Y-Note API

func WithClientID

func WithClientID(clientID string) Option

WithClientID sets the Y-Note API clientID used to fetch the access token

func WithClientSecret

func WithClientSecret(clientSecret string) Option

WithClientSecret sets the Y-Note API client secret used to fetch the access token

func WithCustomerKey

func WithCustomerKey(customerKey string) Option

WithCustomerKey sets the customer key used to make API requests

func WithCustomerSecret

func WithCustomerSecret(customerSecret string) Option

WithCustomerSecret sets the customer secret used to make API requests

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the underlying HTTP client used for API requests. By default, http.DefaultClient is used.

func WithTokenURL

func WithTokenURL(tokenURL string) Option

WithTokenURL set's the token URL for the Y-Note API

type RefundParams

type RefundParams struct {
	ChannelUserMsisdn         string `json:"channelUserMsisdn"`
	Pin                       string `json:"pin"`
	Webhook                   string `json:"webhook"`
	Amount                    string `json:"amount"`
	FinalCustomerPhone        string `json:"final_customer_phone"`
	FinalCustomerName         string `json:"final_customer_name"`
	RefundMethod              string `json:"refund_method"`
	FeesIncluded              bool   `json:"fees_included"`
	MaximumRetries            string `json:"maximum_retries"`
	FinalCustomerNameAccuracy string `json:"final_customer_name_accuracy"`
}

RefundParams are the parameters for executing a refund transaction

type RefundService

type RefundService service

RefundService is the API client for the `/prod/refund` endpoint

func (*RefundService) Refund

func (service *RefundService) Refund(ctx context.Context, params *RefundParams) (*RefundTransaction, *Response, error)

Refund executes an initiated transaction

func (*RefundService) Status

func (service *RefundService) Status(ctx context.Context, transactionID string) (*RefundTransactionStatus, *Response, error)

Status returns the status of an initiated transaction

type RefundTransaction

type RefundTransaction struct {
	MD5OfMessageBody       string `json:"MD5OfMessageBody"`
	MD5OfMessageAttributes string `json:"MD5OfMessageAttributes"`
	MessageID              string `json:"MessageId"`
	ResponseMetadata       struct {
		RequestID      string `json:"RequestId"`
		HTTPStatusCode int    `json:"HTTPStatusCode"`
		HTTPHeaders    struct {
			XAmznRequestid string `json:"x-amzn-requestid"`
			Date           string `json:"date"`
			ContentType    string `json:"content-type"`
			ContentLength  string `json:"content-length"`
			Connection     string `json:"connection"`
		} `json:"HTTPHeaders"`
		RetryAttempts int `json:"RetryAttempts"`
	} `json:"ResponseMetadata"`
}

RefundTransaction is the response from a refund transaction

type RefundTransactionStatus

type RefundTransactionStatus struct {
	Status       *string `json:"status"`
	ErrorCode    *int    `json:"ErrorCode"`
	ErrorMessage *string `json:"ErrorMessage"`
	Result       *struct {
		Message string `json:"message"`
		Data    struct {
			CreatedAt         string `json:"createtime"`
			SubscriberMsisdn  string `json:"subscriberMsisdn"`
			Amount            any    `json:"amount"`
			PayToken          string `json:"payToken"`
			TransactionID     string `json:"txnid"`
			TransactionMode   string `json:"txnmode"`
			TransactionStatus string `json:"txnstatus"`
			OrderID           string `json:"orderId"`
			Status            string `json:"status"`
			ChannelUserMsisdn string `json:"channelUserMsisdn"`
			Description       string `json:"description"`
		} `json:"data"`
	} `json:"result"`
	Parameters struct {
		Amount                    string `json:"amount"`
		Xauth                     string `json:"xauth"`
		ChannelUserMsisdn         string `json:"channel_user_msisdn"`
		CustomerKey               string `json:"customer_key"`
		CustomerSecret            string `json:"customer_secret"`
		FinalCustomerName         string `json:"final_customer_name"`
		FinalCustomerPhone        string `json:"final_customer_phone"`
		FinalCustomerNameAccuracy any    `json:"final_customer_name_accuracy"`
	} `json:"parameters"`
	CreatedAt  string `json:"CreateAt"`
	MessageID  string `json:"MessageId"`
	RefundStep string `json:"RefundStep"`
}

RefundTransactionStatus is the response from a refund transaction status

func (*RefundTransactionStatus) IsFailed added in v0.0.2

func (status *RefundTransactionStatus) IsFailed() bool

IsFailed checks if the refund transaction is failed

func (*RefundTransactionStatus) IsPending added in v0.0.2

func (status *RefundTransactionStatus) IsPending() bool

IsPending checks if the refund transaction is pending

func (*RefundTransactionStatus) IsSuccessful added in v0.0.2

func (status *RefundTransactionStatus) IsSuccessful() bool

IsSuccessful checks if the refund transaction is successful

type Response

type Response struct {
	HTTPResponse *http.Response
	Body         *[]byte
}

Response captures the http response

func (*Response) Error

func (r *Response) Error() error

Error ensures that the response can be decoded into a string inc ase it's an error response

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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