gpayments

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: MIT Imports: 15 Imported by: 0

README

💰 go-gpayments pipeline status coverage report

Modulo de Go para comunicarse con la API de 4GEEKS Payments.

Cómo usar

package main

import (
    "fmt"
    "gitlab.com/esavara/gpayments"
    "context"
)

func main() {
    c, _ := gpayments.NewClient("cliente-id", "cliente-secret", context.Background())

    me, _ := c.Me()

    fmt.Printf("%#v", me)
}

Documentation

Index

Constants

View Source
const (
	APIVersion         = "v1"
	ErrorMsjRequest    = "no se pudo crear solicitud: %v"
	ErrorMsjMarshal    = "no se pudo serializar: %v"
	ErrorMsjHTTPStatus = "respuesta inesperada HTTP STATUS %d - %s"
)
View Source
const (
	TimeLayoutWithTimezone = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func NewTestClient

func NewTestClient(fn RoundTripFunc) *http.Client

NewTestClient returns *http.Client with Transport replaced to avoid making real calls

Types

type AuthResponse

type AuthResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int64  `json:"expires_in"`
	Scope       string `json:"scope"`
}

type Card

type Card struct {
	LastDigits      string `json:"last4"`
	ExpirationYear  int    `json:"exp_year"`
	ExpirationMonth int    `json:"exp_month"`
	Brand           string `json:"brand"`
	CVC             string `json:"cvc"`
}

type Charge

type Charge struct {
	ID         string    `json:"charge_id"`
	Customer   *Customer `json:"customer"`
	ByCustomer bool      `json:"charge_by_customer"`
	Log        ChargeLog `json:"charge_log"`
	CreatedOn  Time      `json:"created_on"`
}

type ChargeLog

type ChargeLog struct {
	Status            string  `json:"status"`
	Description       string  `json:"description"`
	EntityDescription string  `json:"entity_description"`
	Currency          string  `json:"currency"`
	Amount            float32 `json:"amount"`
	Card              Card    `json:"card"`
}

type ChargeRequest

type ChargeRequest struct {
	CustomerID  string  `json:"customer_key"`
	Amount      float32 `json:"amount"`
	Description string  `json:"description"`
	EntityDesc  string  `json:"entity_description,omitempty"`
	Currency    string  `json:"currency,omitempty"`
}

type ChargeRequestOptional

type ChargeRequestOptional struct {
	EntityDesc string `json:"entity_description"`
	Currency   string `json:"currency"`
}

type ChargeSimpleRequest

type ChargeSimpleRequest struct {
	Amount      float32 `json:"amount"`
	Description string  `json:"description"`
	Currency    string  `json:"currency"`
	CreditCard  string  `json:"credit_card_number"`
	CVC         string  `json:"credit_card_security_code_number"`
	Month       int     `json:"month"`
	Year        int     `json:"year"`
	EntityDesc  string  `json:"entity_description"`
}

type ChargeSimpleRequestOptional

type ChargeSimpleRequestOptional struct {
	EntityDesc string `json:"entity_description"`
}

type Client

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

func NewClient

func NewClient(id, secret string, ctx context.Context) (*Client, error)

func (*Client) CreateCharge

func (c *Client) CreateCharge(customerID, description string, amount float32, opt *ChargeRequestOptional) error

CreateCharge crea un charge, en otras palabras, realiza un rebajo a la tarjeta del cliente, utilizando sus datos financieros.

func (*Client) CreateCustomer

func (c *Client) CreateCustomer(name, email, currency, credit_card_number, credit_card_cvc string, month, year int) (Customer, error)

CreateCustomer crea y asigna un customer a tu cuenta de 4Geeks payments.

func (*Client) CreatePlan

func (c *Client) CreatePlan(name, currency string, interval Interval, count int, opt *PlanRequestOptional) error

CreatePlan crea un plan de pago.

func (*Client) CreateRefund

func (c *Client) CreateRefund(amount float32, charge string, reason RefundReason) (Refund, error)

CreateRefund crea un reembolso y lo asocia con una transacción.

func (*Client) CreateSimpleCharge

func (c *Client) CreateSimpleCharge(amount float32, description, currency, creditCard, cvc string, month, year int, opt *ChargeSimpleRequestOptional) error

CreateSimpleCharge crea un simple charge, en otras palabras, realiza un rebajo a la tarjeta que venga en el POST, no esta asignada a ningun customer.

func (*Client) CreateSubscription

func (c *Client) CreateSubscription(customerID, planID string) error

CreateSubscription crea un y asigna una subscripción a un cliente.

func (*Client) Debug added in v1.0.1

func (c *Client) Debug()

Debug activa o desactiva la depuracion de solicitudes HTTP

func (*Client) DeleteCustomer

func (c *Client) DeleteCustomer(id string) error

DeleteCustomer elimina un customer en especifico por su ID.

func (*Client) DeletePlan

func (c *Client) DeletePlan(id string) error

DeletePlan elimina un plan que el key indicado.

func (*Client) DeleteSubscription

func (c *Client) DeleteSubscription(id string) error

DeleteSubscription elimina una subscripcion en especifico.

func (*Client) GetCharge

func (c *Client) GetCharge(id string) (Charge, error)

GetCharge retorna el log específico del charge seleccionado.

func (*Client) GetCustomer

func (c *Client) GetCustomer(id string) (Customer, error)

GetCustomer retorna un customer encontrado por el ID identificador.

func (*Client) GetPlan

func (c *Client) GetPlan(id string) (Plan, error)

GetPlan retorna un plan que el key indicado.

func (*Client) GetRefund

func (c *Client) GetRefund(id string) (Refund, error)

GetRefund retorna un reembolso.

func (*Client) GetSubscription

func (c *Client) GetSubscription(id string) (Subscription, error)

GetSubscription retorna un plan que el key indicado.

func (*Client) ListCharges

func (c *Client) ListCharges() ([]Charge, error)

ListCharges retorna todos los logs de los cargos creados a mis clientes.

func (*Client) ListCustomers

func (c *Client) ListCustomers() ([]Customer, error)

ListCustomers retorna la informacion de todos los customers asociados a mi cuenta en 4Geeks Payments.

func (*Client) ListPlans

func (c *Client) ListPlans() ([]Plan, error)

ListPlans retorna todos los planes que hayas creado.

func (*Client) ListRefunds

func (c *Client) ListRefunds() ([]Refund, error)

ListRefunds retorna todos los reembolsos activos.

func (*Client) ListSubscriptions

func (c *Client) ListSubscriptions() ([]Subscription, error)

ListSubscription retorna todos las subscripciones creadas.

func (*Client) Me

func (c *Client) Me() (Me, error)

Me retorna mi información como developer de 4geeks Payments.

func (*Client) UpdateCustomer

func (c *Client) UpdateCustomer(u CustomerRequest, id string) (Customer, error)

UpdateCustomer edita un customer en especifico.

type Customer

type Customer struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Currency string `json:"currency"`
	Test     bool   `json:"test"`
	ID       string `json:"key"`
	Card     Card   `json:"card"`
}

type CustomerRequest

type CustomerRequest struct {
	Name       string `json:"name"`
	Email      string `json:"email"`
	Currency   string `json:"currency"`
	CreditCard string `json:"credit_card_number"`
	CVC        string `json:"credit_card_security_code_number"`
	Month      int    `json:"exp_month"`
	Year       int    `json:"exp_year"`
}

type Interval

type Interval int
const (
	Day Interval = iota + 1
	Week
	Month
	Year
)

func (*Interval) MarshalText

func (i *Interval) MarshalText() (text []byte, err error)

func (Interval) String

func (i Interval) String() string

func (*Interval) UnmarshalText

func (i *Interval) UnmarshalText(text []byte) error

type Me

type Me struct {
	DeveloperKey      string `json:"developer_key"`
	Test              bool   `json:"test"`
	Page              string `json:"page"`
	BankName          string `json:"bank_name"`
	BankAccountNumber string `json:"bank_account_number"`
	BankSINPE         string `json:"bank_sinpe"`
}

type Plan

type Plan struct {
	ID          string          `json:"key"`
	Information PlanInformation `json:"information"`
}

type PlanInformation

type PlanInformation struct {
	Currency    string   `json:"currency"`
	Amount      float32  `json:"amount"`
	Name        string   `json:"name"`
	CreatedOn   Time     `json:"created"`
	Description string   `json:"credit_card_description"`
	TrialDays   int      `json:"trial_period_days"`
	Interval    Interval `json:"interval"`
	Count       int      `json:"interval_count"`
}

type PlanRequest

type PlanRequest struct {
	Name        string   `json:"name"`
	Currency    string   `json:"currency"`
	Interval    Interval `json:"interval"`
	Count       int      `json:"interval_count"`
	TrialDays   int      `json:"trial_period_days"`
	Description string   `json:"credit_card_description"`
}

type PlanRequestOptional

type PlanRequestOptional struct {
	TrialDays   int    `json:"trial_period_days"`
	Description string `json:"credit_card_description"`
}

type Refund

type Refund struct {
	ID       string       `json:"refund_id"`
	Charge   string       `json:"charge_id"`
	Amount   float32      `json:"amount,string"`
	Currency string       `json:"currency"`
	Reason   RefundReason `json:"reason"`
	Status   string       `json:"status"`
	Test     bool         `json:"test"`
}

type RefundReason

type RefundReason int
const (
	Duplicate RefundReason = iota + 1
	Fraudulent
	RequestedByCustomer
)

func (*RefundReason) MarshalJSON

func (r *RefundReason) MarshalJSON() (text []byte, err error)

func (RefundReason) String

func (r RefundReason) String() string

func (*RefundReason) UnmarshalJSON

func (r *RefundReason) UnmarshalJSON(text []byte) error

type RoundTripFunc

type RoundTripFunc func(req *http.Request) *http.Response

RoundTripFunc .

func (RoundTripFunc) RoundTrip

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip .

type SourceGPayments

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

func NewSourceToken

func NewSourceToken(id, secret string) *SourceGPayments

func (*SourceGPayments) Token

func (s *SourceGPayments) Token() (*oauth2.Token, error)

type Subscription

type Subscription struct {
	ID        int      `json:"id"`
	Key       string   `json:"subscription_id"`
	Developer Me       `json:"developer"`
	Customer  Customer `json:"customer"`
	Plan      Plan     `json:"plan"`
}

type Time

type Time struct {
	time.Time
}

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) (err error)

Jump to

Keyboard shortcuts

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