dana

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: GPL-3.0 Imports: 25 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.
  5. Replace .sample files to your own credential.

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              = "alipayplus/acquiring/order/createOrder.htm"
	QUERY_PATH              = "alipayplus/acquiring/order/query.htm"
	REFUND_PATH             = "alipayplus/acquiring/refund/refund.htm"
	APPLY_ACCESS_TOKEN_PATH = "dana/oauth/auth/applyToken.htm"
	USER_PROFILE_PATH       = "alipayplus/member/query/queryUserProfile.htm"
	DANA_TIME_LAYOUT        = "2006-01-02T15:04:05-07:00"
	CURRENCY_IDR            = "IDR"
	INQUIRY_USER_INFO_PATH  = "v1/customers/user/inquiryUserInfoByAccessToken.htm"

	FUNCTION_CREATE_ORDER       = "dana.acquiring.order.createOrder"
	FUNCTION_QUERY_ORDER        = "dana.acquiring.order.query"
	FUNCTION_REFUND             = "dana.acquiring.refund.refund"
	FUNCTION_APPLY_ACCESS_TOKEN = "dana.oauth.auth.applyToken"
	FUNCTION_USER_PROFILE       = "dana.member.query.queryUserProfile"
	FUNCTION_INQUIRY_USER_INFO  = "customers.openapi.user.inquiryUserInfoByAccessToken"
)
View Source
const (
	APPLICATION_NAME = "sangu-dana"
	LOG_KEY_REQ_ID   = "req_id"
	LOG_KEY_METHOD   = "method"
	LOG_KEY_CALLER   = "caller"
	LOG_LEVEL_TRACE  = "trace"
	LOG_LEVEL_DEBUG  = "debug"
	LOG_LEVEL_INFO   = "info"
	LOG_LEVEL_WARN   = "warn"
	LOG_LEVEL_ERROR  = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenInfo added in v0.6.0

type AccessTokenInfo struct {
	AccessToken  string `json:"accessToken"`
	ExpiresIn    string `json:"expiresIn"`
	RefreshToken string `json:"refreshToken"`
	ReExpiresIn  string `json:"reExpiresIn"`
	TokenStatus  string `json:"tokenStatus"`
}

type ActorContext added in v0.5.0

type ActorContext struct {
	ActorID   string `json:"actorId" valid:"required"`
	ActorType string `json:"actorType" valid:"required"`
}

type ActorTypeEnum added in v0.5.0

type ActorTypeEnum int
const (
	User ActorTypeEnum = iota
	Merchant
	MerchantOperator
	BackOffice
	System
)

func (ActorTypeEnum) String added in v0.5.0

func (a ActorTypeEnum) String() string

type Amount

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

type AmountDetail added in v0.4.1

type AmountDetail struct {
	OrderAmount      Amount `json:"orderAmount" valid:"required"`
	PayAmount        Amount `json:"payAmount" valid:"optional"`
	VoidAmount       Amount `json:"voidAmount" valid:"optional"`
	ConfirmAmount    Amount `json:"confirmAmount" valid:"optional"`
	RefundAmount     Amount `json:"refundAmount" valid:"optional"`
	ChargebackAmount Amount `json:"chargebackAmount" valid:"optional"`
	ChargeAmount     Amount `json:"chargeAmount" valid:"optional"`
}

type ApplyAccessToken added in v0.6.0

type ApplyAccessToken struct {
	ResultInfo      ResultInfo      `json:"resultInfo"`
	AccessTokenInfo AccessTokenInfo `json:"accessTokenInfo"`
}

type AuditInfo added in v0.5.0

type AuditInfo struct {
	ActionReason  string `json:"actionReason" valid:"optional"`
	ThirdClientID string `json:"thirdClientId" valid:"optional"`
}

type Client

type Client struct {
	BaseUrl          string
	Version          string
	ClientId         string
	ClientSecret     string
	PrivateKey       []byte
	PublicKey        []byte
	LogLevel         int
	Logger           Logger
	SignatureEnabled bool
}

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) ApplyAccessToken added in v0.6.0

func (gateway *CoreGateway) ApplyAccessToken(reqBody *RequestApplyAccessToken) (res ResponseBody, err error)

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) InquiryUserInfo added in v0.10.0

func (gateway *CoreGateway) InquiryUserInfo(reqBody *InquiryUserInfoRequest, accessToken string) (res InquiryUserInfoResponse, err error)

func (*CoreGateway) Order

func (gateway *CoreGateway) Order(reqBody *OrderRequestData, accessToken string) (res ResponseBody, err error)

func (*CoreGateway) OrderDetail added in v0.4.1

func (gateway *CoreGateway) OrderDetail(reqBody *OrderDetailRequestData, accessToken string) (res ResponseBody, err error)

func (*CoreGateway) Refund added in v0.5.0

func (gateway *CoreGateway) Refund(reqBody *RefundRequestData, accessToken string) (res ResponseBody, err error)

func (*CoreGateway) UserProfile added in v0.8.0

func (gateway *CoreGateway) UserProfile(reqBody *UserProfileRequestData, accessToken string) (res ResponseBody, err error)

func (*CoreGateway) VerifySignature added in v0.3.0

func (gateway *CoreGateway) VerifySignature(res []byte, 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 InputUserInfo added in v0.4.1

type InputUserInfo struct {
	UserID           string `json:"userId" valid:"optional"`
	ExternalUserID   string `json:"externalUserId" valid:"optional"`
	ExternalUserType string `json:"externalUserType" valid:"optional"`
	Nickname         string `json:"nickname" valid:"optional"`
}

type InquiryUserInfoRequest added in v0.10.0

type InquiryUserInfoRequest struct {
	AccessToken string `json:"accessToken" valid:"required"`
	ExtendInfo  string `json:"extendInfo,omitempty" valid:"optional"`
}

type InquiryUserInfoResponse added in v0.10.0

type InquiryUserInfoResponse struct {
	Result   ResultInfo     `json:"result" valid:"required"`
	UserInfo ResultUserInfo `json:"userInfo"  valid:"required"`
}

type LogOption added in v0.9.0

type LogOption struct {
	Format          string
	Level           string
	TimestampFormat string
	CallerToggle    bool
	Pretty          bool
}

type Logger added in v0.9.0

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger added in v0.9.0

func NewLogger(option LogOption) *Logger

func (*Logger) Ctx added in v0.9.0

func (l *Logger) Ctx(ctx context.Context) *Logger

func (*Logger) Debug added in v0.9.0

func (l *Logger) Debug(format string, v ...interface{})

func (*Logger) Error added in v0.9.0

func (l *Logger) Error(format string, v ...interface{})

func (*Logger) Info added in v0.9.0

func (l *Logger) Info(format string, v ...interface{})

func (*Logger) Method added in v0.9.0

func (l *Logger) Method(name string) *Logger

func (*Logger) Str added in v0.9.0

func (l *Logger) Str(key string, val string) *Logger

func (*Logger) Trace added in v0.9.0

func (l *Logger) Trace(format string, v ...interface{})

func (*Logger) Warn added in v0.9.0

func (l *Logger) Warn(format string, v ...interface{})

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 OrderDetailData added in v0.4.1

type OrderDetailData struct {
	ResultInfo      ResultInfo     `json:"resultInfo" valid:"required"`
	AcquirementID   string         `json:"acquirementId" valid:"optional"`
	MerchantTransID string         `json:"merchantTransId" valid:"optional"`
	Buyer           InputUserInfo  `json:"buyer" valid:"optional"`
	Seller          InputUserInfo  `json:"seller" valid:"optional"`
	OrderTitle      string         `json:"orderTitle" valid:"optional"`
	ExtendedInfo    string         `json:"extendedInfo" valid:"optional"`
	AmountDetail    AmountDetail   `json:"amountDetail" valid:"optional"`
	TimeDetail      TimeDetail     `json:"timeDetail" valid:"optional"`
	StatusDetail    StatusDetail   `json:"statusDetail" valid:"optional"`
	Goods           []Good         `json:"goods" valid:"optional"`
	ShippingInfo    []ShippingInfo `json:"shippingInfo" valid:"optional"`
	OrderMemo       string         `json:"orderMemo" valid:"optional"`
	PaymentViews    []PaymentView  `json:"paymentViews" valid:"optional"`
}

type OrderDetailRequestData added in v0.4.1

type OrderDetailRequestData struct {
	MerchantID      string `json:"merchantId" valid:"required"`
	AcquirementID   string `json:"acquirementId" valid:"optional"`
	MerchantTransID string `json:"merchantTransId" valid:"optional"`
}

type OrderRequestData added in v0.4.1

type OrderRequestData 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 OrderResponseData added in v0.4.1

type OrderResponseData struct {
	MerchantTransID string     `json:"merchantTransId,omitempty" valid:"optional"`
	AcquirementID   string     `json:"acquirementId,omitempty" valid:"optional"`
	CheckoutURL     string     `json:"checkoutUrl,omitempty" valid:"optional"`
	ResultInfo      ResultInfo `json:"resultInfo" 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 PayMethodEnum added in v0.4.1

type PayMethodEnum int
const (
	Balance PayMethodEnum = iota
	Coupon
	NetBanking
	CreditCard
	DebitCard
	VirtualAccount
	Otc
	DirectDebitCreditCard
	DirectDebitDebitCard
)

func (PayMethodEnum) String added in v0.4.1

func (p PayMethodEnum) String() string

type PayOptionInfo added in v0.4.1

type PayOptionInfo struct {
	PayMethod               string `json:"payMethod" valid:"required"`
	PayAmount               Amount `json:"payAmount" valid:"required"`
	TransAmount             Amount `json:"transAmount" valid:"optional"`
	ChargeAmount            Amount `json:"chargeAmount" valid:"optional"`
	ExtendInfo              string `json:"extendInfo" valid:"optional"`
	PayOptionBillExtendInfo string `json:"payOptionBillExtendInfo" valid:"optional"`
}

type PaymentPreference

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

type PaymentView added in v0.4.1

type PaymentView struct {
	CashierRequestID     string          `json:"cashierRequestId" valid:"required"`
	PaidTime             string          `json:"paidTime" valid:"required"`
	PayOptionInfos       []PayOptionInfo `json:"payOptionInfos" valid:"required"`
	PayRequestExtendInfo string          `json:"payRequestExtendInfo" valid:"optional"`
	ExtendInfo           string          `json:"extendInfo" valid:"optional"`
}

type RefundDestinationEnum added in v0.5.0

type RefundDestinationEnum int
const (
	ToBalance RefundDestinationEnum = iota
	ToSource
)

func (RefundDestinationEnum) String added in v0.5.0

func (r RefundDestinationEnum) String() string

type RefundRequestData added in v0.5.0

type RefundRequestData struct {
	RequestID           string       `json:"requestId" valid:"required"`
	MerchantID          string       `json:"merchantId" valid:"required"`
	AcquirementID       string       `json:"acquirementId,omitempty" valid:"optional"`
	RefundAmount        Amount       `json:"refundAmount,omitempty" valid:"required"`
	RefundAppliedTime   time.Time    `json:"refundAppliedTime,omitempty" valid:"optional"`
	ActorType           string       `json:"actorType,omitempty" valid:"optional"`
	RefundReason        string       `json:"refundReason,omitempty" valid:"optional"`
	ReturnChargeToPayer bool         `json:"returnChargeToPayer,omitempty" valid:"optional"`
	Destination         string       `json:"destination,omitempty" valid:"optional"`
	ExtendInfo          string       `json:"extendInfo,omitempty" valid:"optional"`
	EnvInfo             EnvInfo      `json:"envInfo,omitempty" valid:"optional"`
	AuditInfo           AuditInfo    `json:"auditInfo,omitempty" valid:"optional"`
	ActorContext        ActorContext `json:"actorContext,omitempty" valid:"optional"`
}

type RefundResponseData added in v0.5.0

type RefundResponseData struct {
	ResultInfo ResultInfo `json:"resultInfo" valid:"required"`
	RequestID  string     `json:"requestId,omitempty" valid:"optional"`
	RefundID   string     `json:"refundId,omitempty" valid:"optional"`
}

type Request

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

type RequestApplyAccessToken added in v0.6.0

type RequestApplyAccessToken struct {
	GrantType    string `json:"grantType"`
	AuthCode     string `json:"authCode"`
	RefreshToken string `json:"refreshToken"`
}

type RequestBody

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

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 interface{}    `json:"body" valid:"required"`
}

type ResponseBody

type ResponseBody struct {
	Response  Response `json:"response" valid:"required"`
	Signature string   `json:"signature" 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"`
	ResultMessage string `json:"resultMessage" valid:"optional"`
}

type ResultUserInfo added in v0.10.0

type ResultUserInfo struct {
	UserContactInfoEmail string        `json:"USER_CONTACTINFO_EMAIL" valid:"optional"`
	UserName             string        `json:"USER_NAME" valid:"optional"`
	UserAddress          []UserAddress `json:"USER_ADDRESS" valid:"optional"`
	UserContactInfo      string        `json:"USER_CONTACTINFO" 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 StatusDetail added in v0.4.1

type StatusDetail struct {
	AcquirementStatus string `json:"acquirementStatus" valid:"required"`
	Frozen            bool   `json:"frozen" valid:"required"`
}

type TimeDetail added in v0.4.1

type TimeDetail struct {
	CreatedTime    string   `json:"createdTime" valid:"required"`
	ExpiryTime     string   `json:"expiryTime" valid:"required"`
	PaidTimes      []string `json:"paidTimes" valid:"optional"`
	ConfirmedTimes []string `json:"confirmedTimes" valid:"optional"`
	CancelledTime  string   `json:"cancelledTime" valid:"optional"`
}

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.

type UserAddress added in v0.10.0

type UserAddress struct {
	Area     string `json:"area" valid:"optional"`
	Province string `json:"province" valid:"optional"`
	City     string `json:"city" valid:"optional"`
	Address1 string `json:"address1" valid:"optional"`
}

type UserInfo added in v0.6.0

type UserInfo struct {
	PublicUserID string `json:"publicUserId"`
}

type UserProfileRequestData added in v0.8.0

type UserProfileRequestData struct {
	UserResources []string `json:"userResources" valid:"required"`
}

type UserProfileResponseData added in v0.8.0

type UserProfileResponseData struct {
	ResultInfo        ResultInfo          `json:"resultInfo" valid:"required"`
	UserResourceInfos []UserResourceInfos `json:"userResourceInfos" valid:"required"`
}

type UserResourceInfos added in v0.8.0

type UserResourceInfos struct {
	ResourceType string      `json:"resourceType"`
	Value        interface{} `json:"value"`
}

Jump to

Keyboard shortcuts

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