dana

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: GPL-3.0 Imports: 19 Imported by: 0

README

Dana Sangu

Usage blueprint

  1. There is a type named Client (dana.Client) that should be instantiated through NewClient which hold any possible setting to the library.
  2. There is a gateway classes which you will be using depending on whether you used. The gateway type need a Client instance.
  3. All Header field is handled by this library
  4. There's also VerifySignature to verify whether the signature response/request is valid.

Example

    danaClient := dana.NewClient()
    danaClient.BaseUrl = "DANA_BASE_URL",
    ---
    ---

    coreGateway := dana.CoreGateway{
        Client: danaClient,
    }

    body := &dana.RequestBody{
        Order: {},
        MerchantId: "MERCHANT_ID",
        ---
        ---
        ---
    }

    res, _ := coreGateway.Order(req)

Documentation

Index

Constants

View Source
const (
	TYPE_ORDER      = "ORDER"
	TYPE_PAY_NOTIFY = "PAY_NOTIFY"
)
View Source
const (
	//ORDER_PATH       = "https://api-sandbox.saas.dana.id/alipayplus/acquiring/order/createOrder.htm"
	ORDER_PATH       = "alipayplus/acquiring/order/createOrder.htm"
	QUERY_PATH       = "alipayplus/acquiring/order/query.htm"
	DANA_TIME_LAYOUT = "2006-01-02T15:04:05.000-07:00"
	CURRENCY_IDR     = "IDR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount struct {
	Currency string `json:"currency"`
	Value    string `json:"value"`
}

type Client

type Client struct {
	BaseUrl      string
	Version      string
	Function     string
	ClientId     string
	ClientSecret string
	PrivateKey   []byte
	PublicKey    []byte
	LogLevel     int
	Logger       *log.Logger
}

Client struct

func NewClient

func NewClient() Client

NewClient : this function will always be called when the library is in use

func (*Client) Call

func (c *Client) Call(method, path string, header map[string]string, body io.Reader, v interface{}) error

Call the Dana API at specific `path` using the specified HTTP `method`. The result will be given to `v` if there is no error. If any error occurred, the return of this function is the error itself, otherwise nil.

func (*Client) ExecuteRequest

func (c *Client) ExecuteRequest(req *http.Request, v interface{}) error

ExecuteRequest : execute request

func (*Client) NewRequest

func (c *Client) NewRequest(method string, fullPath string, headers map[string]string, body io.Reader) (*http.Request, error)

NewRequest : send new request

type CoreGateway

type CoreGateway struct {
	Client Client
}

CoreGateway struct

func (*CoreGateway) Call

func (gateway *CoreGateway) Call(method, path string, header map[string]string, body io.Reader, v interface{}) error

Call : base method to call Core API

func (*CoreGateway) GenerateSignature added in v0.3.0

func (gateway *CoreGateway) GenerateSignature(req interface{}) (signature string, err error)

func (*CoreGateway) Order

func (gateway *CoreGateway) Order(reqBody *RequestBody) (res OrderResponse, err error)

func (*CoreGateway) VerifySignature added in v0.3.0

func (gateway *CoreGateway) VerifySignature(res interface{}, signature string) (err error)

type EnvInfo

type EnvInfo struct {
	SessionID          string `json:"sessionId,omitempty"`
	TokenID            string `json:"tokenId,omitempty"`
	WebsiteLanguage    string `json:"websiteLanguage,omitempty"`
	ClientIP           string `json:"clientIp,omitempty"`
	OsType             string `json:"osType,omitempty"`
	AppVersion         string `json:"appVersion,omitempty"`
	SdkVersion         string `json:"sdkVersion,omitempty"`
	SourcePlatform     string `json:"sourcePlatform"`
	TerminalType       string `json:"terminalType"`
	ClientKey          string `json:"clientKey,omitempty"`
	OrderTerminalType  string `json:"orderTerminalType"`
	OrderOsType        string `json:"orderOsType,omitempty"`
	MerchantAppVersion string `json:"merchantAppVersion,omitempty"`
	ExtendInfo         string `json:"extendInfo,omitempty"`
}

type Good

type Good struct {
	MerchantGoodsID    string `json:"merchantGoodsId,omitempty"`
	Description        string `json:"description"`
	Category           string `json:"category,omitempty"`
	Price              Amount `json:"price"`
	Unit               string `json:"unit,omitempty"`
	Quantity           string `json:"quantity,omitempty"`
	MerchantShippingID string `json:"merchantShippingId,omitempty"`
	SnapshotURL        string `json:"snapshotUrl,omitempty"`
	ExtendInfo         string `json:"extendInfo,omitempty"`
}

type NotificationUrl

type NotificationUrl struct {
	URL  string `json:"url"`
	Type string `json:"type"`
}

type Order

type Order struct {
	OrderTitle        string         `json:"orderTitle"`
	OrderAmount       Amount         `json:"orderAmount"`
	MerchantTransID   string         `json:"merchantTransId"`
	MerchantTransType string         `json:"merchantTransType,omitempty"`
	OrderMemo         string         `json:"orderMemo,omitempty"`
	CreatedTime       string         `json:"createdTime,omitempty"`
	ExpiryTime        string         `json:"expiryTime,omitempty"`
	Goods             []Good         `json:"goods,omitempty"`
	ShippingInfo      []ShippingInfo `json:"shippingInfo,omitempty"`
}

type OrderRequest

type OrderRequest struct {
	Request   Request `json:"request" valid:"required"`
	Signature string  `json:"signature" valid:"required"`
}

type OrderResponse

type OrderResponse struct {
	Response  Response `json:"response" valid:"required"`
	Signature string   `json:"signature" valid:"required"`
}

type PayFinishRequest added in v0.2.0

type PayFinishRequest struct {
	Request   RequestPayFinish `json:"request"`
	Signature string           `json:"signature"`
}

type PayFinishResponse added in v0.2.0

type PayFinishResponse struct {
	Response  ResponsePayFinish `json:"response"`
	Signature string            `json:"signature"`
}

type PaymentPreference

type PaymentPreference struct {
	DisabledPayMethods string `json:"disabledPayMethods"`
}

type Request

type Request struct {
	Head RequestHeader `json:"head" valid:"required"`
	Body *RequestBody  `json:"body" valid:"required"`
}

type RequestBody

type RequestBody struct {
	Order             Order              `json:"order" valid:"required"`
	MerchantID        string             `json:"merchantId" valid:"required"`
	Mcc               string             `json:"mcc,omitempty" valid:"optional"`
	ProductCode       string             `json:"productCode" valid:"required"`
	EnvInfo           EnvInfo            `json:"envInfo" valid:"required"`
	NotificationUrls  *[]NotificationUrl `json:"notificationUrls,omitempty" valid:"optional"`
	ExtendInfo        string             `json:"extendInfo,omitempty" valid:"optional"`
	PaymentPreference *PaymentPreference `json:"paymentPreference,omitempty" valid:"optional"`
}

type RequestBodyPayFinish added in v0.2.0

type RequestBodyPayFinish struct {
	AcquirementID     string `json:"acquirementId"`
	MerchantTransID   string `json:"merchantTransId"`
	FinishedTime      string `json:"finishedTime"`
	CreatedTime       string `json:"createdTime"`
	MerchantID        string `json:"merchantId"`
	OrderAmount       Amount `json:"orderAmount"`
	AcquirementStatus string `json:"acquirementStatus"`
	ExtendInfo        string `json:"extendInfo"`
}

type RequestHeader

type RequestHeader struct {
	Version      string `json:"version" valid:"required"`
	Function     string `json:"function" valid:"required"`
	ClientID     string `json:"clientId" valid:"required"`
	ReqTime      string `json:"reqTime" valid:"required"`
	ReqMsgID     string `json:"reqMsgId" valid:"required"`
	ClientSecret string `json:"clientSecret" valid:"required"`
	AccessToken  string `json:"accessToken,omitempty" valid:"optional"`
	Reserve      string `json:"reserve,omitempty" valid:"optional"`
}

type RequestPayFinish added in v0.2.0

type RequestPayFinish struct {
	Head RequestHeader        `json:"head"`
	Body RequestBodyPayFinish `json:"body"`
}

type Response

type Response struct {
	Head ResponseHeader `json:"head" valid:"required"`
	Body ResponseBody   `json:"body" valid:"required"`
}

type ResponseBody

type ResponseBody struct {
	MerchantTransID string     `json:"merchantTransId" valid:"optional"`
	AcquirementID   string     `json:"acquirementId" valid:"optional"`
	CheckoutURL     string     `json:"checkoutUrl" valid:"optional"`
	ResultInfo      ResultInfo `json:"resultInfo" valid:"required"`
}

type ResponseBodyPayFinish added in v0.2.0

type ResponseBodyPayFinish struct {
	ResultInfo ResultInfo `json:"resultInfo"`
}

type ResponseHeader

type ResponseHeader struct {
	Function  string `json:"function" valid:"required"`
	ClientID  string `json:"clientId" valid:"required"`
	Version   string `json:"version" valid:"required"`
	RespTime  string `json:"respTime" valid:"required"`
	RespMsgID string `json:"reqMsgId" valid:"required"`
}

type ResponsePayFinish added in v0.2.0

type ResponsePayFinish struct {
	Head ResponseHeader        `json:"head"`
	Body ResponseBodyPayFinish `json:"body"`
}

type ResultInfo

type ResultInfo struct {
	ResultStatus string `json:"resultStatus" valid:"optional"`
	ResultCodeID string `json:"resultCodeId" valid:"optional"`
	ResultMsg    string `json:"resultMsg" valid:"optional"`
	ResultCode   string `json:"resultCode" valid:"optional"`
}

type ShippingInfo

type ShippingInfo struct {
	MerchantShippingID string `json:"merchantShippingId"`
	TrackingNo         string `json:"trackingNo,omitempty"`
	Carrier            string `json:"carrier,omitempty"`
	ChargeAmount       Amount `json:"chargeAmount,omitempty"`
	CountryName        string `json:"countryName"`
	StateName          string `json:"stateName"`
	CityName           string `json:"cityName"`
	AreaName           string `json:"areaName,omitempty"`
	Address1           string `json:"address1"`
	Address2           string `json:"address2,omitempty"`
	FirstName          string `json:"firstName"`
	LastName           string `json:"lastName"`
	MobileNo           string `json:"mobileNo,omitempty"`
	PhoneNo            string `json:"phoneNo,omitempty"`
	ZipCode            string `json:"zipCode"`
	Email              string `json:"email,omitempty"`
	FaxNo              string `json:"faxNo,omitempty"`
}

type Signer

type Signer interface {
	// Sign returns raw signature for the given data. This method
	// will apply the hash specified for the keytype to the data.
	Sign(data []byte) ([]byte, error)
}

A Signer is can create signatures that verify against a public key.

type Unsigner

type Unsigner interface {
	// Sign returns raw signature for the given data. This method
	// will apply the hash specified for the keytype to the data.
	Unsign(data []byte, sig []byte) error
}

A Signer is can create signatures that verify against a public key.

Jump to

Keyboard shortcuts

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