viettelpay

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBatchWaitDisb     = &BatchError{Code: "WAIT_DISB"}
	ErrBatchCancelDisb   = &BatchError{Code: "CANCEL_DISB"}
	ErrBatchDisbursement = &BatchError{Code: "DISBURSEMENT"}
	ErrBatchDisbTimeout  = &BatchError{Code: "DISB_TIMEOUT"}
	ErrBatchDisbSuccess  = &BatchError{Code: "DISB_SUCCESS"}
	ErrBatchDisbFailed   = &BatchError{Code: "DISB_FAILED"}
)
View Source
var ErrNoPEM = errors.New("no PEM data is found")

Functions

func Decrypt

func Decrypt(dst io.Writer, src io.Reader, srcSize int, key *rsa.PrivateKey) error

func Encrypt

func Encrypt(dst io.Writer, src io.Reader, srcSize int, key *rsa.PublicKey) error

func GenOrderID

func GenOrderID() string

func GenerateKeysPEM

func GenerateKeysPEM(prvKeyDst, pubKeyDst io.Writer, bits int) error

func MarshalGzipJSON

func MarshalGzipJSON(w io.Writer, data interface{}) error

func UnmarshalGzipJSON

func UnmarshalGzipJSON(r io.Reader, data interface{}) error

Types

type BatchError

type BatchError struct {
	Code string `json:"batchErrorCode"`
	Desc string `json:"batchErrorDesc"`
}

func (BatchError) Error

func (e BatchError) Error() string

func (*BatchError) Is

func (e *BatchError) Is(target error) bool

type BlockPEM

type BlockPEM []byte

BlockPEM is a slice of bytes where the information is PEM in the environment variable.

func (BlockPEM) Bytes

func (b BlockPEM) Bytes() []byte

Bytes returns the underlying bytes.

func (*BlockPEM) EnvDecode

func (b *BlockPEM) EnvDecode(val string) error

EnvDecode implements env.Decoder.

type CheckAccount

type CheckAccount struct {
	MSISDN       string `json:"msisdn"`
	CustomerName string `json:"customerName"`
}

type CheckAccountResponse

type CheckAccountResponse struct {
	CheckAccount
	Package   string `json:"package"`
	ErrorCode string `json:"errorCode"`
	ErrorDesc string `json:"errorDesc"`
}

func (CheckAccountResponse) Err added in v0.1.1

func (r CheckAccountResponse) Err() error

type Config

type Config struct {
	BaseURL     string `env:"BASE_URL"`
	Username    string `env:"USERNAME"`
	Password    string `env:"PASSWORD"`
	ServiceCode string `env:"SERVICE_CODE"`

	PartnerPrivateKey BlockPEM `env:"PARTNER_PRIVATE_KEY"`
	ViettelPublicKey  BlockPEM `env:"VIETTEL_PUBLIC_KEY"`
}

func ProvideConfig

func ProvideConfig(ctx context.Context) (*Config, error)

type Envelope

type Envelope interface {
	SetData([]byte)
	SetPassword(string)
	SetServiceCode(string)
	SetUsername(string)
}

type EnvelopeBase

type EnvelopeBase struct {
	Password    string `json:"password"`
	ServiceCode string `json:"serviceCode"`
	Username    string `json:"username"`

	Data    []byte `json:"data,omitempty"`
	OrderID string `json:"orderId"`
}

func (*EnvelopeBase) SetData

func (e *EnvelopeBase) SetData(val []byte)

func (*EnvelopeBase) SetPassword

func (e *EnvelopeBase) SetPassword(val string)

func (*EnvelopeBase) SetServiceCode

func (e *EnvelopeBase) SetServiceCode(val string)

func (*EnvelopeBase) SetUsername

func (e *EnvelopeBase) SetUsername(val string)

type EnvelopeResponse

type EnvelopeResponse struct {
	Data      json.RawMessage `json:"data"`
	Signature []byte          `json:"signature"`
}

type EnvelopeResponseData

type EnvelopeResponseData struct {
	Data    []byte `json:"data,omitempty"`
	OrderID string `json:"orderId"`

	RealServiceCode string `json:"realServiceCode"`
	ServiceCode     string `json:"serviceCode"`
	Username        string `json:"username"`

	RequestId string `json:"requestId"`
	TransDate string `json:"transDate"`

	BatchErrorCode string `json:"batchErrorCode"`
	BatchErrorDesc string `json:"batchErrorDesc"`

	ErrorCode string `json:"errorCode"`
	ErrorDesc string `json:"errorDesc"`
}

func (EnvelopeResponseData) CheckError

func (e EnvelopeResponseData) CheckError() error

type Error

type Error struct {
	Code string `json:"errorCode"`
	Desc string `json:"errorDesc"`
}

func (Error) Error

func (e Error) Error() string

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is a client which can make HTTP requests An example implementation is net/http.Client

type KeyStore

type KeyStore interface {
	Sign(data []byte) (signature []byte, err error)
	Verify(data, signature []byte) (err error)
	Decrypt(msg []byte) (string, error)
	Encrypt(msg []byte) (string, error)
}

func NewKeyStore

func NewKeyStore(partnerPriKey, viettelPubKey []byte) (_ KeyStore, err error)

type Option

type Option func(*options)

A Option sets options such as credentials, tls, etc.

func WithAuth

func WithAuth(username, password, serviceCode string) Option

WithAuth is an Option to set BasicAuth

func WithHTTPClient

func WithHTTPClient(c HTTPClient) Option

WithHTTPClient is an Option to set the HTTP client to use

func WithKeyStore

func WithKeyStore(keyStore KeyStore) Option

WithKeyStore is an Option to set BasicAuth

type PartnerAPI

type PartnerAPI interface {
	Process(ctx context.Context, req Request, response interface{}) error

	CheckAccount(ctx context.Context, orderID string, checks ...CheckAccount) ([]CheckAccountResponse, error)
	RequestDisbursement(ctx context.Context, orderID string, transactionContent string, reqs ...RequestDisbursement) ([]RequestDisbursementResponse, error)
	QueryRequests(ctx context.Context, orderID string, query QueryRequests) ([]QueryRequestsResponse, error)
}

func NewPartnerAPI

func NewPartnerAPI(url string, opt ...Option) (_ PartnerAPI, err error)

func ProvidePartnerAPI

func ProvidePartnerAPI(cfg *Config, client HTTPClient) (PartnerAPI, error)

type Process

type Process struct {
	XMLName xml.Name `xml:"ns2:process"`

	Cmd       string `xml:"cmd,omitempty" json:"cmd,omitempty"`
	Data      string `xml:"data,omitempty" json:"data,omitempty"`
	Signature string `xml:"signature,omitempty" json:"signature,omitempty"`
}

type ProcessResponse

type ProcessResponse struct {
	XMLName xml.Name `xml:"http://partnerapi.bankplus.viettel.com/ processResponse"`

	Return_ string `xml:"return,omitempty" json:"return,omitempty"`
}

type QueryByMSISDN

type QueryByMSISDN string

func (QueryByMSISDN) Data

func (q QueryByMSISDN) Data() string

func (QueryByMSISDN) Type

func (q QueryByMSISDN) Type() string

type QueryByTransaction

type QueryByTransaction string

func (QueryByTransaction) Data

func (q QueryByTransaction) Data() string

func (QueryByTransaction) Type

func (q QueryByTransaction) Type() string

type QueryRequestEnvelope

type QueryRequestEnvelope struct {
	EnvelopeBase
	QueryType string `json:"queryType,omitempty"`
	QueryData string `json:"queryData,omitempty"`
}

type QueryRequests

type QueryRequests interface {
	Type() string
	Data() string
}

type QueryRequestsResponse added in v0.1.1

type QueryRequestsResponse struct {
	RequestDisbursement
	ErrorCode string `json:"errorCode"`
	ErrorMsg  string `json:"errorMsg"`
}

func (QueryRequestsResponse) Err added in v0.1.1

func (r QueryRequestsResponse) Err() error

type Request

type Request interface {
	Command() string
	Data() interface{}
	Envelope() Envelope
}

func NewRequest

func NewRequest(cmd string, data interface{}, env Envelope) Request

type RequestDisbursement

type RequestDisbursement struct {
	TransactionID string `json:"transId"`
	MSISDN        string `json:"msisdn"`
	CustomerName  string `json:"customerName"`
	Amount        uint64 `json:"amount"`
	SMSContent    string `json:"smsContent"`
	Note          string `json:"note"`
}

func (RequestDisbursement) CheckAccount

func (rd RequestDisbursement) CheckAccount() CheckAccount

type RequestDisbursementEnvelope

type RequestDisbursementEnvelope struct {
	EnvelopeBase
	TotalAmount        uint64 `json:"totalAmount"`
	TotalTransactions  int    `json:"totalTrans"`
	TransactionContent string `json:"transContent"`
}

type RequestDisbursementResponse

type RequestDisbursementResponse struct {
	RequestDisbursement
	ErrorCode string `json:"errorCode"`
	ErrorDesc string `json:"errorDesc"`
}

func (RequestDisbursementResponse) Err added in v0.1.1

type SoapClient

type SoapClient interface {
	CallContext(ctx context.Context, soapAction string, request, response interface{}) error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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