Documentation ¶
Index ¶
- Constants
- type Client
- func (c Client) CancelRefund(token string) (*RefundStatus, error)
- func (c Client) CreateEmailOrder(or OrderRequest) (orderID int, token string, err error)
- func (c Client) CreateOrder(or OrderRequest) (*OrderResponse, error)
- func (c Client) CreateRefund(r Refund) (*RefundStatus, error)
- func (c Client) GetOrder(token string) (*Order, error)
- func (c Client) GetOrderByCommerceID(commerceID string) (*Order, error)
- func (c Client) GetOrderByFlowID(flowOrderID int) (*Order, error)
- func (c Client) GetRefundStatus(token string) (*RefundStatus, error)
- func (c *Client) GinOrderConfirmationCallback(onAccepted func(*Order)) gin.HandlerFunc
- func (c *Client) GinRefundConfirmationCallback(onAccepted func(*RefundStatus)) gin.HandlerFunc
- func (c *Client) HTTPOrderConfirmationCallback(onAccepted func(*Order)) http.HandlerFunc
- func (c *Client) HTTPRefundConfirmationCallback(onAccepted func(*RefundStatus)) http.HandlerFunc
- func (c *Client) SetProduction()
- func (c *Client) SetSandbox()
- type Optional
- type Order
- type OrderRequest
- type OrderResponse
- type PaymentData
- type PendingInfo
- type Refund
- type RefundStatus
Constants ¶
const ( ProductionURL = "https://www.flow.cl/api" SandboxURL = "https://sandbox.flow.cl/api" )
const ( // OrderStatusAwaitingPayment indicates that the order's payment is still pending. OrderStatusAwaitingPayment = iota + 1 // OrderStatusPayed indicates that the order has been successfully payed and should be accepted. OrderStatusPayed // OrderStatusRejected indicates that the payment failed because it was rejected. OrderStatusRejected // OrderStatusCanceled indicates that some party canceled the order before it was fulfilled. OrderStatusCanceled )
const ( // RefundStatusCreated is a refund created and awaiting processing. RefundStatusCreated = "created" // RefundStatusAccepted is a refund accepted and ready to be transferred. RefundStatusAccepted = "accepted" // RefundStatusRejected is a refund that was not accepted. RefundStatusRejected = "rejected" // RefundStatusRefunded is a refund that was accepted and transferred. RefundStatusRefunded = "refunded" // RefundStatusCanceled is a refund that was canceled by one of the parties. RefundStatusCanceled = "canceled" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // APIKey is the access key provided by Flow. APIKey string // SecretKey is uses to sign the API requests. SecretKey string // URL is the base URL to be used in the requests. Can be ProductionURL or SandboxURL. URL string }
Client contains the authentication data and the canonical URL used for requests to the Flow API/
func NewClient ¶
NewClient creates a *Client with the given keys. By default it's set to sandbox mode.
func (Client) CancelRefund ¶
func (c Client) CancelRefund(token string) (*RefundStatus, error)
CancelRefund cancels a refund request.
func (Client) CreateEmailOrder ¶
func (c Client) CreateEmailOrder(or OrderRequest) (orderID int, token string, err error)
CreateEmailOrder creates an Order to be sent by email and returns its ID and token.
func (Client) CreateOrder ¶
func (c Client) CreateOrder(or OrderRequest) (*OrderResponse, error)
CreateOrder creates a new order and returns its ID and token.
func (Client) CreateRefund ¶
func (c Client) CreateRefund(r Refund) (*RefundStatus, error)
CreateRefund starts a new refund request.
func (Client) GetOrderByCommerceID ¶
GetOrderByCommerceID fetches the an Order based on the provided commerce identifier.
func (Client) GetOrderByFlowID ¶
GetOrderByFlowID fetches the an Order based on the provided Flow identifier.
func (Client) GetRefundStatus ¶
func (c Client) GetRefundStatus(token string) (*RefundStatus, error)
GetRefundStatus fetches the status of a refund request.
func (*Client) GinOrderConfirmationCallback ¶
func (c *Client) GinOrderConfirmationCallback(onAccepted func(*Order)) gin.HandlerFunc
GinOrderConfirmationCallback returns a gin.HandlerFunc that processes the Flow callback request. It validates the provided token, and if the token matches a accepted order, the onAccepted function gets called.
func (*Client) GinRefundConfirmationCallback ¶
func (c *Client) GinRefundConfirmationCallback(onAccepted func(*RefundStatus)) gin.HandlerFunc
GinRefundConfirmationCallback returns a gin.HandlerFunc that processes the Flow callback request. It validates the provided token, and if the token matches an accepted refund, the onAccepted function gets called.
func (*Client) HTTPOrderConfirmationCallback ¶
func (c *Client) HTTPOrderConfirmationCallback(onAccepted func(*Order)) http.HandlerFunc
HTTPOrderConfirmationCallback returns a http.HandlerFunc that processes the Flow callback request. It validates the provided token, and if the token matches a accepted order, the onAccepted function gets called.
func (*Client) HTTPRefundConfirmationCallback ¶
func (c *Client) HTTPRefundConfirmationCallback(onAccepted func(*RefundStatus)) http.HandlerFunc
HTTPRefundConfirmationCallback returns a http.HandlerFunc that processes the Flow callback request. It validates the provided token, and if the token matches an accepted refund, the onAccepted function gets called.
func (*Client) SetProduction ¶
func (c *Client) SetProduction()
SetProduction sets the Client's URL to the production base URL.
func (*Client) SetSandbox ¶
func (c *Client) SetSandbox()
SetProduction sets the Client's URL to the sandbox base URL.
type Optional ¶
type Optional struct { // RUT or Rol Unico Tributario is a unique national identifier RUT string `json:"RUT,omitempty"` // ID is the ID of the transaction. ID string `json:"ID,omitempty"` }
Optional contains optional fields like RUT and ID.
type Order ¶
type Order struct { // FlowOrder is the ID provided by Flow. FlowOrder int `json:"flowOrder,omitempty"` // CommerceOrder is an optional ID created by the commerce. CommerceOrder string `json:"commerceOrder,omitempty"` // RequestDate is the date the order was created. If none is set, the current date is used. It follows the format // yyyy-mm-dd hh:mm:ss RequestDate string `json:"requestDate,omitempty"` // Status is the current status of an order it might be one of the following: // 1 Awaiting payment - OrderStatusAwaitingPayment // 2 Payed - OrderStatusPayed // 3 Rejected - OrderStatusRejected // 4 Canceled - OrderStatusCanceled Status int `json:"status,omitempty"` // Subject is the reason for the payment. It might be the items or service being bought. Subject string `json:"subject,omitempty"` // Currency is optionally set to define the currency of the transaction. Currency string `json:"currency,omitempty"` // Amount represents the amount of money being charged. Amount string `json:"amount,omitempty"` // PayerEmail is the email of the payer. PayerEmail string `json:"payer,omitempty"` // Optional contains optional fields like RUT and ID. Optional Optional `json:"optional,omitempty"` // PendingInfo reports if a media is still waiting on the payment, and the date since it's waiting. PendingInfo PendingInfo `json:"pending_info,omitempty"` // PaymentData contains additional information about the payment. PaymentData PaymentData `json:"paymentData,omitempty"` // MerchantID will be set if a merchant is being a middleman in the payment. MerchantID string `json:"merchantId,omitempty"` }
Order represents a payment order.
type OrderRequest ¶
type OrderRequest struct { // CommerceOrder is an optional ID created by the commerce. CommerceOrder string `structs:"commerceOrder"` // Subject is the reason for the payment. It might be the items or service being bought. Subject string `structs:"subject"` // Currency is optionally set to define the currency of the transaction. Currency string `structs:"currency,omitempty"` // Amount represents the amount of money being charged. Amount uint64 `structs:"amount"` // PayerEmail is the email of the payer. PayerEmail string `structs:"email"` // PaymentMethod can be set to define the allowed payment methods. It default to 9: all payment methods. PaymentMethod int `structs:"paymentMethod,omitempty"` // ConfirmationURL is the URL to which Flow will send the order details after the payment is made. This URL must // implement the confirmation logic. See GinOrderConfirmationCallback and HTTPOrderConfirmationCallback. ConfirmationURL string `structs:"urlConfirmation,omitempty"` // ReturnURL is the URL to which the user will be sent after the payment is made and confirmed. Usually on this // URL a boucher or confirmation message will be showed. ReturnURL string `structs:"urlReturn,omitempty"` // TimeoutSeconds is the number of seconds the order should stay active for. TimeoutSeconds uint64 `structs:"timeout,omitempty"` // MerchantID will be set if a merchant is being a middleman in the payment. MerchantID string `structs:"merchantId,omitempty"` // PaymentCurrency is optionally set to force the payer to pay in an specific currency. PaymentCurrency string `structs:"payment_currency,omitempty"` }
OrderRequest is the data needed to start a payment order.
type OrderResponse ¶
type OrderResponse struct { // FlowID is the Flow identifier for the order. FlowID int `json:"flowOrder"` // Token is the token used to buildPOST the payment URL. Token string `json:"token"` // URL is the base URL to redirect for payment. URL string `json:"url"` }
OrderResponse is the values sent by Flow if an order is successfully created.
func (OrderResponse) GetPaymentURL ¶
func (or OrderResponse) GetPaymentURL() string
GetPaymentURL parses the payment URL of an order
type PaymentData ¶
type PaymentData struct { // Date is the date of the payment. Date string `json:"date,omitempty"` // Media refers to a payment entity. Media string `json:"media,omitempty"` // ConversionDate is the date of the conversion between currencies if more than one was involved in the payment. // The format is yyyy-mm-dd hh:mm:ss ConversionDate string `json:"conversionDate,omitempty"` // ConversionRate is the rate used to convert between currencies if more than one was involved in the payment. ConversionRate float64 `json:"conversionRate,omitempty"` // Amount is the payed amount. Amount string `json:"amount,omitempty"` // Currency is the payment in which the payment was made. Currency string `json:"currency,omitempty"` // Fee is the fee applied to the transaction. Fee string `json:"fee,omitempty"` // Balance is the Amount minus the Fee Balance int64 `json:"balance,omitempty"` // TransferDate is the date in which the transfer was made. It format the format yyyy-mm-dd hh:mm:ss TransferDate string `json:"transferDate,omitempty"` }
PaymentData contains additional information about the payment.
type PendingInfo ¶
type PendingInfo struct { // Media refers to a payment entity. Media string `json:"media,omitempty"` // Date is the date since the payment is pending. It format the format yyyy-mm-dd hh:mm:ss Date string `json:"date,omitempty"` }
PendingInfo reports if a media is still waiting on the payment, and the date since it's waiting.
type Refund ¶
type Refund struct { // OrderID is the ID of the order being refunded. OrderID string `structs:"refundCommerceOrder"` // ReceiverEmail is the email of the refunded payer. ReceiverEmail string `structs:"receiverEmail"` // Amount is the amount of money the refund is for. Amount uint64 `structs:"amount"` // CallbackURL is where Flow will notify the server about the refund status. CallbackURL string `structs:"urlCallBack"` }
Refund represents a request for a refund.
type RefundStatus ¶
type RefundStatus struct { // Token is an identifier for the refund. Token string `json:"token"` // RefundOrder is the OrderID of the order being refunded. RefundOrder string `json:"flowRefundOrder"` // Date is the date on which the refund request was created. It format the format yyyy-mm-dd hh:mm:ss Date string `json:"date"` // Status is the status of the refund. It might be one of: // created, accepted, rejected, refunded, canceled Status string `json:"status"` // Amount is the amount of money being refunded. Amount uint64 `json:"amount"` // Fee is the fee being charged for the refund. Fee uint64 `json:"fee"` }
RefundStatus is the data related to a refund.