dana

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 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

func VerifySignature added in v0.2.0

func VerifySignature(data interface{}, sig string, publicKey []byte, typeResponse string) error

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) Order

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

type EnvInfo

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

type Good

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

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"`
	OrderMemo         string         `json:"orderMemo"`
	CreatedTime       string         `json:"createdTime"`
	ExpiryTime        string         `json:"expiryTime"`
	Goods             []Good         `json:"goods"`
	ShippingInfo      []ShippingInfo `json:"shippingInfo"`
}

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" valid:"optional"`
	ProductCode       string            `json:"productCode" valid:"required"`
	EnvInfo           EnvInfo           `json:"envInfo" valid:"required"`
	NotificationUrls  []NotificationUrl `json:"notificationUrls" valid:"optional"`
	ExtendInfo        string            `json:"extendInfo" valid:"optional"`
	PaymentPreference PaymentPreference `json:"paymentPreference" 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" valid:"optional"`
	Reserve      string `json:"reserve" 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 {
	Version   string `json:"version" valid:"required"`
	Function  string `json:"function" valid:"required"`
	ClientID  string `json:"clientId" 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"`
	Carrier            string `json:"carrier"`
	ChargeAmount       Amount `json:"chargeAmount"`
	CountryName        string `json:"countryName"`
	StateName          string `json:"stateName"`
	CityName           string `json:"cityName"`
	AreaName           string `json:"areaName"`
	Address1           string `json:"address1"`
	Address2           string `json:"address2"`
	FirstName          string `json:"firstName"`
	LastName           string `json:"lastName"`
	MobileNo           string `json:"mobileNo"`
	PhoneNo            string `json:"phoneNo"`
	ZipCode            string `json:"zipCode"`
	Email              string `json:"email"`
	FaxNo              string `json:"faxNo"`
}

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