Documentation ¶
Index ¶
- Constants
- func CancelSubscription(c *Client, subscriptionID string, cancelAtePeriodEnd bool) error
- func DeleteCard(c *Client, customerID, cardID string) error
- func DeleteCustomer(c *Client, id string) error
- func DeletePlan(c *Client, id string) error
- type Card
- type CardInscriptionResponse
- type CardInscriptionState
- type Client
- type Customer
- func CreateCustomer(c *Client, name, email string) (Customer, error)
- func GetCustomer(c *Client, id string) (Customer, error)
- func ListCustomers(c *Client, page, perPage int, where map[string]map[string]interface{}, ...) ([]Customer, error)
- func UpdateCustomer(c *Client, id, name, email, defaultPaymentMethodID string) (Customer, error)
- type Event
- type Filter
- type GatewayResponse
- type Payment
- type Plan
- type Refund
- type Subscription
- func CreateSubscription(c *Client, customerID, planID, taxName string, taxPercent float64, ...) (Subscription, error)
- func GetSubscription(c *Client, subscriptionID string) (Subscription, error)
- func ListSubscriptions(c *Client, page, perPage int, where map[string]map[string]interface{}, ...) ([]Subscription, error)
- func UpdateSubscription(c *Client, subscriptionID, planID string) (Subscription, error)
- type Transaction
- type WebpayResponse
- type Withdrawal
Constants ¶
const ( Succeeded string = "succeeded" Failed string = "failed" )
Status constants
const ( CustomerCreated string = "customer.created" CustomerUpdated string = "customer.updated" CustomerDeleted string = "customer.deleted" PlanCreated string = "plan.created" PlanUpdated string = "plan.updated" PlanDeleted string = "plan.deleted" CustomerCardCreated string = "customer.card.created" CustomerCardDeleted string = "customer.card.deleted" CustomerSubscriptionCreated string = "customer.subscription.created" CustomerSubscriptionUpdated string = "customer.subscription.updated" CustomerSubscriptionDeleted string = "customer.subscription.deleted" TransactionPaymentSucceeded string = "transaction.payment_succeeded" TransactionPaymentFailed string = "transaction.payment_failed" TransactionPRefunded string = "transaction.refunded" TransactionResponseTimeout string = "transaction.response_timeout" )
Event types
const ( Successful string = "successful" Rejected string = "rejected" Unable string = "unable_to_charge" Refunded string = "refunded" WaitingForResponse string = "waiting_for_response" WaitingResponse string = "waiting_response" Timeout string = "response?timeout" )
Status constants
const ( WebpayPlus string = "webpay_plus" WebpayOneclick string = "webpay_oneclick" Olpays string = "olpays" )
Gateway constants
Variables ¶
This section is empty.
Functions ¶
func CancelSubscription ¶
CancelSubscription cancels a subscription. Depending on cancelAtPeriodEnd, it'll be canceled when the current period end is reached (if true), or immediately (if false). If subscription was ianctive, it'll be canceled immediately anyway.
func DeleteCard ¶
DeleteCard deletes a card for a given customer.
func DeleteCustomer ¶
DeleteCustomer deletes a customer given its id.
func DeletePlan ¶
DeletePlan deletes a plan given its id.
Types ¶
type Card ¶
type Card struct { ID string `json:"id"` Lats4Digits string `json:"last_4_digits"` CardType string `json:"card_type"` //VISA or MASTERCARD PaymentType string `json:"payment_type"` //CD (credit) or DB (debit) FailureCount int32 `json:"failure_count"` CreatedAt time.Time `json:"created_at"` }
Card struct to represent a qvo card object.
type CardInscriptionResponse ¶
type CardInscriptionResponse struct { InscriptionUID string `json:"inscription_uid"` RedirectURL string `json:"redirect_url"` ExpirationDate time.Time `json:"expiration_date"` }
CardInscriptionResponse struct holds the answer from qvo for a card inscription response.
func CreateCardInscription ¶
func CreateCardInscription(c *Client, customerID, returnURL string) (CardInscriptionResponse, error)
CreateCardInscription begins a card inscription request. If everything's ok, it'll return an inscription uid, the redirect url to send the customer to, and the expiration date for this transaction.
type CardInscriptionState ¶
type CardInscriptionState struct { UID string `json:"uid"` Status string `json:"status"` Card *Card `json:"card"` Error *errorWrapper `json:"error"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
CardInscriptionState holds the state of a card inscription request.
func GetCardInscription ¶
func GetCardInscription(c *Client, customerID, inscriptionUID string) (CardInscriptionState, error)
GetCardInscription returns the inscription's state and a card (if successful).
type Client ¶
Client represent the qvo api client. It holds the auth token and sandbox/production mode and offers request methods.
func NewClient ¶
NewClient initializes the api client with a token and a sandbox/production mode. Default log level is info.
func (*Client) SetLogLevel ¶
SetLogLevel allows to set the log level.
type Customer ¶
type Customer struct { ID string `json:"id"` DefaultPaymentMethod Card `json:"default_payment_method"` Name string `json:"name"` Email string `json:"email"` Subscriptions []Subscription `json:"subscriptions"` Cards []Card `json:"cards"` Transactions []Transaction `json:"transactions"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Customer struct to represent a qvo customer object.
func CreateCustomer ¶
CreateCustomer creates a customer at the QVO account.
func GetCustomer ¶
GetCustomer retrieves a customer given its id.
type Event ¶
type Event struct { ID string `json:"id"` Type string `json:"type"` Data map[string]interface{} `json:"data"` //API sends a "hash", so we are limited to an interfaces map. Previous *map[string]interface{} `json:"previous,omitempty"` //API sends a "hash", so we are limited to an interfaces map. Also, it's nullable, so it's a pointer. CreatedAt time.Time `json:"created_at"` }
Event struct to represent a qvo event object.
type GatewayResponse ¶
GatewayResponse struct to deal with gateway response from transactions.
type Payment ¶
type Payment struct { Amount int64 `json:"amount"` Gateway string `json:"gateway"` //One of: webpay_plus, webpay_oneclick, olpays. PaymentType string `json:"payment_type"` //credit or debit. Fee int64 `json:"fee"` Installments int32 `json:"installments"` PaymentMethod Card `json:"payment_method"` }
Payment struct to represent a qvo payment object.
type Plan ¶
type Plan struct { ID string `json:"id"` Name string `json:"name"` Price string `json:"price"` //An int or float string. Currency string `json:"currency"` //CLP or UF. Interval string `json:"interval"` //One of: day, week, month, year. IntervalCount int32 `json:"interval_count"` TrialPeriodDays int32 `json:"trial_period_days"` DefaultCycleCount int32 `json:"default_cycle_count"` Status string `json:"status"` //active or inactive. Subscription []Subscription `json:"subscriptions"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Plan struct to represent a qvo plan object.
func CreatePlan ¶
CreatePlan creates a plan at QVOs end. Returns a copy of the plan if successful, and an error if not. Price is a string as it may be an int or a float string representation DEPENDING on the currency (int for CLP, float for UF).
type Subscription ¶
type Subscription struct { ID string `json:"id"` Status string `json:"status"` //One of: active, canceled, trialing, retrying, inactive, unpaid. Debt int64 `json:"debt"` Start time.Time `json:"start"` End time.Time `json:"end"` CycleCount int32 `json:"cycle_count"` CurrentPeriodStart time.Time `json:"current_period_start"` CurrentPeriodEnd time.Time `json:"current_period_end"` Customer Customer `json:"customer"` Plan Plan `json:"plan"` Transactions []Transaction `json:"transactions"` TaxName string `json:"tax_name"` TaxPercent string `json:"tax_percent"` //A float string. CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Subscription struct to represent a qvo subscription object.
func CreateSubscription ¶
func CreateSubscription(c *Client, customerID, planID, taxName string, taxPercent float64, cycleCount int64, start *time.Time) (Subscription, error)
CreateSubscription creates a subscription for a customer and plan. Returns a copy of the subscription if successful, and an error if not. customerID and planID are required. cycleCount <= 0 will be omitted. If taxName is "" or taxPercent isn´t in [0.0, 100.0], they'll be omitted. start is a pointer to a time.Time, so a nil pointer will be omitted.
func GetSubscription ¶
func GetSubscription(c *Client, subscriptionID string) (Subscription, error)
GetSubscription returns the subscription or an error.
func ListSubscriptions ¶
func ListSubscriptions(c *Client, page, perPage int, where map[string]map[string]interface{}, orderBy string) ([]Subscription, error)
ListSubscriptions retrieves a list of subscriptions with given pages, filters and order.
func UpdateSubscription ¶
func UpdateSubscription(c *Client, subscriptionID, planID string) (Subscription, error)
UpdateSubscription updates a subscription's plan given its id.
type Transaction ¶
type Transaction struct { ID string `json:"id"` Amount int64 `json:"amount"` Currency string `json:"currency"` //CLP or USD. Description string `json:"description"` Gateway string `json:"gateway"` //One of: webpay_plus, webpay_oneclick, olpays. Credits int64 `json:"credits"` Status string `json:"status"` //One of: successful, rejected, unable_to_charge, refunded, waiting_for_response, response_timeout. Customer Customer `json:"customer"` Payment *Payment `json:"payment"` //Nullable, so it's a pointer. Refund *Refund `json:"refund"` //Nullable, so it's a pointer. Transable *map[string]interface{} //API sends a "hash", so we are limited to an interfaces map. Also, it's nullable, so it's a pointer. For now, it's supposed to be a subscription. GatewayResponse GatewayResponse `json:"gateway_response"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Transaction struct to represent a qvo transaction object.
func ChargeCard ¶
func ChargeCard(c *Client, customerID, cardID, description string, amount int64) (Transaction, error)
ChargeCard creates a charge for given customer and card.
func GetTransaction ¶
func GetTransaction(c *Client, id string) (Transaction, error)
GetTransaction retrieves a transaction by id.
func ListTransactions ¶
func ListTransactions(c *Client, page, perPage int, where map[string]map[string]interface{}, orderBy string) ([]Transaction, error)
ListTransactions retrieves a list of transactions with given pages, filters and order.
type WebpayResponse ¶
type WebpayResponse struct { TransactionID string `json:"transaction_id"` RedirectURL string `json:"redirect_url"` ExpirationDate time.Time `json:"expiration_date"` }
WebpayResponse struct holds the answer from qvo for a webpay transaction request.
func WebpayTransaction ¶
func WebpayTransaction(c *Client, customerID, returnURL, description string, amount int64) (WebpayResponse, error)
WebpayTransaction begins a webpay transaction. If everything's ok, it'll return a transaction id (for later check), the redirect url to send the customer to, and the expiration date for this transaction.
type Withdrawal ¶
type Withdrawal struct { ID string `json:"id"` Amount int64 `json:"amount"` Status string `json:"status"` //One of: processing, rejected, transfered. CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Withdrawal struct to represent a qvo withdraw object.
func CreateWithdrawal ¶
func CreateWithdrawal(c *Client, amount int64) (Withdrawal, error)
CreateWithdrawal creates a withdrawal of the given amount. Return a Withdrawal object or an error.
func GetWithdrawal ¶
func GetWithdrawal(c *Client, id string) (Withdrawal, error)
GetWithdrawal retrieves a withdrawal given its id.
func ListWithdrawals ¶
func ListWithdrawals(c *Client, page, perPage int, where map[string]map[string]interface{}, orderBy string) ([]Withdrawal, error)
ListWithdrawals retrieves a list of withdrawals with given pages, filters and order.