Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterGatewayGenFun ¶
func RegisterGatewayGenFun(gatewayName string, genFunc gatewayGenFunc)
Types ¶
type Gateway ¶
type Gateway interface {
/*** Status ***/
GatewayStatus() GatewayStatusFlag
/*** Gateway Config ***/
// GatewayConfigTemplate() returns needed parameters in setting up the Gateway.
// Please see examples.go for an example
// this is used for frontend implementation compatibilities
GatewayConfigTemplate() (gatewayConfigTemplate P)
// GatewayConfig() saves gatewayConfiguration to database
GatewayConfig(db *sql.DB, gatewayConfig P) error
/*** Order Operations ***/
// Customer(payer)-only
CreateOrder(db *sql.DB, orderCreationParams P) (orderID string, err error)
// Admin/Customer
LookupOrderID(db *sql.DB, ReferenceID string) (orderID string, err error)
// Admin(payee)-only, should be provided from database.
OrderDetail(db *sql.DB, orderID string) (orderDetails P, err error)
// For Admin(payee)/Customer(payer), should be fetched from remote API
// everytime gets requested
CheckOrderStatus(db *sql.DB, orderID string) (orderStatus P, err error)
//
GenerateOrderForm(db *sql.DB, orderID string) (orderFormTemplate P, err error)
FinalizeOnSiteOrderForm(db *sql.DB, onSiteOrderForm P) error
CancelOrder(db *sql.DB, orderID string) error
}
type GatewayBillable ¶
type GatewayCallback ¶
type GatewayCallback interface {
Gateway
// Set which handlerFunc() to be called with latest orderStatus for an order
// when there's a callback from the Payment provider.
SetCallbackHandler(handlerFunc func(orderStatus P))
// callback URL should be a complete URL
// e.g., https://ulysses.tunnel.work/api/callback/paypal
// caller is responsible to bind Callback() to the same endpoint,
// for both POST and GET method
SetCallbackURL(callback string)
// Actual Callback function that needs to be connected to gin Router
Callback(db *sql.DB, c *gin.Context)
}
type GatewayRefundable ¶
type GatewayStatusFlag ¶
type GatewayStatusFlag uint32
const ( GATEWAY_NEEDCONFIG GatewayStatusFlag = 1 << iota // If set, the gateway is properly configured. Otherwise it needs to be configured before use. GATEWAY_BADCONFIG GATEWAY_GOOD )
type P ¶
type P map[string]interface{}
P stands for Parameters and is a shortcut for map[string]interface{}
var ( // Here's an example of gatewayConfigTemplate // the frontend should display a form as // specified by the template // For possible InputType, see as defined in types.go ExampleGatewayConfigTemplate P = P{ "api_user": P{ "FriendlyName": "API Username", "InputType": "text", "Default": "user", "Description": "Specify your API Username. Not your email address", "Optional": false, }, "api_token": P{ "FriendlyName": "API Token", "InputType": "password", }, "api_version": P{ "FriendlyName": "API Version", "InputType": "number", "Default": 3, }, "api_certificate": P{ "FriendlyName": "API Certificate", "InputType": "textarea", "Optional": true, }, "auth_mode": P{ "FriendlyName": "Auth Mode", "InputType": "radiogroup", "Items": P{ "auth_once": P{ "FriendlyName": "Auth Once", }, "auth_always": P{ "FriendlyName": "Auth Always", }, }, }, "vendor_select": P{ "FriendlyName": "Vendor Select", "InputType": "dropdown", "Items": P{ "tunnelwork": P{ "FriendlyName": "Tunnel.Work (Default)", }, "gaukaswang": P{ "FriendlyName": "Gaukas.Wang (50% Off!)", }, }, }, } // This is an example for gatewayConfig corresponding to the template // provided above. // Note that all types are string. ExampleGatewayConfig P = P{ "api_user": "user", "api_token": "THISISAFAKETOKENFORDEMONSTRATION", "apr_version": "3", "api_certificate": `mDMEYTlFghYJKwYBBAHaRw8BAQdA/uS2O1VY4krn4ocmQNcslLHCYPhk3/MaKoUh 3/QCMv20EkdhdWthcyA8aUBnYXVrLmFzPoiQBBMWCAA4FiEEBduM/AI5+aeDTX3t ni+Jhtdvi10FAmE5RYICGyMFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQni+J htdvi11TEAD/WuVpN/MwPZHrhdMfjy0vftvGqCeMxnMYOMqO7dqWu/EA/jgDsJO6 9tmLgWiGJFvp5q6C6/h2Z/h+dLEliBFvhyIJtBtHYXVrYXMgV2FuZyA8aUBnYXVr YXMud2FuZz6IkAQTFggAOBYhBAXbjPwCOfmng0197Z4viYbXb4tdBQJhOUWwAhsj BQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJEJ4viYbXb4tdtHcA/jinVl583X5H /uqWntniOVP/H/Y8BIGKA7VKixvpRoYrAQDHXgNudx55zBvxhs8uwbx50pFyKSJl pURMd+1CKNipD7g4BGE5RYISCisGAQQBl1UBBQEBB0Dwmfyi3YWai/M9HnGN42LX R+mvWH3695DHZQwzm87FZwMBCAeIeAQYFggAIBYhBAXbjPwCOfmng0197Z4viYbX b4tdBQJhOUWCAhsMAAoJEJ4viYbXb4tddukA/AgGRVfY8bnJJh/xfS6CzJHkvU20 GEO3wpxOrQHqIk7vAP9SQ4BDLnDjFrTyxNOWpWuHFcvlAbdGwrKmUjq2U74WAQ== =8i6d`, "auth_mode": "auth_once", "vendor_select": "tunnelwork", } ExampleOrderCreationParams P = P{ "ReferenceID": "TunnelWork-#109", "Amount": P{ "Value": "4.20", "Currency": "USD", }, "GatewayType": "GatewayBillable", } // Will not be parsed, used for debugging purposes. ExampleOrderDetails P = P{ "OrderID": "0xDEADC0DE", "ReferenceID": "TunnelWork-#109", "Amount": P{ "Value": "4.20", "Currency": "USD", }, "GatewaySpecificField1": "Some Data", "GatewaySpecificField2": "Some More Data", "GatewaySpecificField3": "Even More Data", } // Will be parsed and also recorded ExampleOrderStatus P = P{ "OrderID": "0xDEADC0DE", "ReferenceID": "TunnelWork-#109", "Status": "Unpaid", "PayerIdentifier": "i@gaukas.wang", } ExampleOrderFormTemplate P = P{ "Type": "OnSite", "OnSiteParams": P{ "card_holder": P{ "FriendlyName": "Card Holder", "InputType": "text", "Description": "Name on card", }, "card_number": P{ "FriendlyName": "Card Number", "InputType": "text", }, "cvv": P{ "FriendlyName": "CVV", "InputType": "password", "Description": "The 3-digit security number on your card", }, "network_selection": P{ "FriendlyName": "CC Network Selection", "InputType": "dropdown", "Items": P{ "mastercard": P{ "FriendlyName": "MasterCard", }, "visa": P{ "FriendlyName": "VISA", }, "jcb": P{ "FriendlyName": "JCB", }, }, }, }, "ButtomParams": P{ "btn_type": "text", "image_url": "./assets/img/paynow.png", "btn_target_attr": "_blank", "btn_href": "https://example.com/pay?id=0xDEADC0DE&merchant=0x12345678", }, } ExampleOnSiteOrderForm P = P{ "OrderID": "0xDEADC0DE", "OrderForm": P{ "card_holder": "Gaukas Wang", "card_number": "4800333344445555", "cvv": "123", "network_selection": "visa", }, } ExampleOrderRefundParams P = P{ "OrderID": "0xDEADC0DE", "Amount": P{ "Value": "0.69", "Currency": "USD", }, } )
Examples
Click to show internal directories.
Click to hide internal directories.