Documentation ¶
Index ¶
- Variables
- func VerifySignature(merchantPem []byte, response []byte, signature string) (bool, error)
- type Callback
- type Canopus
- func (cano *Canopus) GenerateCart(payload CartPayload, paymentMethod PaymentMethod) (CartResponse, error)
- func (cano *Canopus) GenerateSignature(payload []byte) (string, error)
- func (cano *Canopus) GetAvailableMethod(amount float64) ([]PaymentMethod, error)
- func (cano *Canopus) GetToken() (string, error)
- type CartPayload
- type CartPayloadItemDetail
- type CartResponse
- type CommonMessage
- type DataCallback
- type InitService
- type Message
- type NotifData
- type PaymentMethod
- type RawMessage
- type Result
Constants ¶
This section is empty.
Variables ¶
View Source
var ( BaseURL = "https://canopus-auth.sumpahpalapa.com" DefaultDuration = time.Second * time.Duration(10) DefaultType = "api" Err002 = errors.New("required parameter is missing") Err004 = errors.New("parameter has illegal value") Err007 = errors.New("signature is invalid") Err008 = errors.New("payement method is not available") )
Functions ¶
Types ¶
type Callback ¶
type Callback struct { Request struct { Data DataCallback `json:"data"` Result Result `json:"result"` } `json:"request"` Signature string `json:"signature"` }
Callback canopus body when payment settlement, expired and canopus notification
type Canopus ¶
type Canopus struct { Type string // snap | api MerchantKey []byte MerchantPem []byte MerchantID string Secret string Client *http.Client Token string Validator *validator.Validate }
func CreateService ¶
func CreateService(init InitService) (*Canopus, error)
TODO: create validation in parameter for each function
func (*Canopus) GenerateCart ¶
func (cano *Canopus) GenerateCart(payload CartPayload, paymentMethod PaymentMethod) (CartResponse, error)
func (*Canopus) GenerateSignature ¶
GenerateSignature ...
func (*Canopus) GetAvailableMethod ¶
func (cano *Canopus) GetAvailableMethod(amount float64) ([]PaymentMethod, error)
GetAvailableMethod Get all available method by merhantID
type CartPayload ¶
type CartPayload struct { CartDetails struct { ID string `json:"id" validate:"required"` Payment struct { Key string `json:"key"` Type string `json:"type"` } `json:"payment"` Amount float64 `json:"amount" validate:"required"` Title string `json:"title" validate:"required"` Currency string `json:"currency" validate:"required"` ExpiredAt string `json:"expiredAt" validate:"required"` } `json:"cartDetails" validate:"required"` ItemDetails []CartPayloadItemDetail `json:"itemDetails" validate:"required"` CustomerDetails struct { FirstName string `json:"firstName" validate:"required"` LastName string `json:"lastName"` Email string `json:"email" validate:"required"` Phone string `json:"phone" validate:"required"` BillingAddress struct { FirstName string `json:"firstName"` LastName string `json:"lastName"` Phone string `json:"phone"` Address string `json:"address"` City string `json:"city"` PostalCode string `json:"postalCode"` } `json:"billingAddress"` ShippingAddress struct { FirstName string `json:"firstName"` LastName string `json:"lastName"` Phone string `json:"phone"` Address string `json:"address"` City string `json:"city"` PostalCode string `json:"postalCode"` } `json:"shippingAddress"` } `json:"customerDetails" validate:"required"` Environment struct { Agent string `json:"agent"` Mode string `json:"mode"` Os string `json:"os"` Version string `json:"version"` } `json:"environment"` URL struct { ReturnURL string `json:"returnURL" validate:"required"` CancelURL string `json:"cancelURL" validate:"required"` NotificationURL string `json:"notificationURL" validate:"required"` } `json:"url" validate:"required"` ExtendInfo struct { AdditionalPrefix string `json:"additionalPrefix"` } `json:"extendInfo"` }
CartPayload payload to create cart
type CartPayloadItemDetail ¶
type CartPayloadItemDetail struct { Name string `json:"name" validate:"required"` Desc string `json:"desc"` Price float64 `json:"price" validate:"required"` Quantity int `json:"quantity" validate:"required"` SKU string `json:"SKU" validate:"required"` AdditionalInfo struct { NoHandphone string `json:"No Handphone"` } `json:"additionalInfo"` }
CartPayloadItemDetail item cart detail
type CartResponse ¶
type CartResponse struct { CartID string `json:"cartID"` PayTo string `json:"payto"` Amount string `json:"amount"` Bank string `json:"bank"` Number string `json:"number"` }
CartResponse response after generate cart
type CommonMessage ¶
type CommonMessage struct { Response Message `json:"response,omitempty"` Request Message `json:"request,omitempty"` Signature string `json:"signature"` }
CommonMessage canopus request/response
func ValidateResponse ¶
func ValidateResponse(resp []byte) (CommonMessage, error)
type DataCallback ¶
type DataCallback struct { Amount int `json:"amount"` Bank string `json:"bank"` MerchantID string `json:"merchantID"` MerchantOrderID string `json:"merchantOrderId"` Number string `json:"number"` OrderID string `json:"orderID"` Status string `json:"status"` Time struct { Created time.Time `json:"created"` Updated time.Time `json:"updated"` } `json:"time"` TransactionID string `json:"transactionID"` Type string `json:"type"` }
DataCallback data callback from canopus
type InitService ¶ added in v1.0.2
type InitService struct { Type string // snap | api MerchantKey []byte `validate:"required"` MerchantPem []byte `validate:"required"` MerchantID string `validate:"required"` Secret string `validate:"required"` TimeOut time.Duration }
InitService to create canoput service
type NotifData ¶
type NotifData struct { Amount float64 `json:"amount"` Bank string `json:"bank"` Number string `json:"number"` }
NotifData extract data when notification callback
type PaymentMethod ¶
type PaymentMethod struct { Key string `json:"key" validate:"required"` Name string `json:"name"` Type string `json:"type" validate:"required"` Logo string `json:"logo"` Instruction interface{} `json:"instruction"` }
PaymentMethod payment method available
type RawMessage ¶
type RawMessage struct { Response json.RawMessage `json:"response,omitempty"` Request json.RawMessage `json:"request,omitempty"` Signature string `json:"signature"` }
RawMessage partly get json for validate request/response and signature
Click to show internal directories.
Click to hide internal directories.