openpay

package module
v0.0.0-...-4190b33 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: MIT Imports: 8 Imported by: 0

README

Openpay Go API Wrapper

GoDoc

Este package es un wrapper de la API de Openpay.

Instrucciones de Uso

Para interactuar con la API de Openpay se debe crear una instancia de Merchant (la cual es segura para uso concurrente). Posteriormente, todas las instancias de Customer obtenidas a través de peticiones a la API tendrán una referencia al Merchant al que pertenecen. Esta referencia es necesaria para hacer operaciones en cuentas de clientes; si una instancia de Customer no se obtiene a través de la API, es necesario proveer una referencia a un Merchant manualmente. Para más información, ver la documentación de GoDoc.

import (
	"github.com/ElPincheTopo/openpay"
)

func main() {
	merchant := openpay.NewMerchant("myMerchantID", "myPrivateKey")

	customer, err := merchant.AddCustomer(&openpay.CustomerArgs{
		Name:     "Juan",
		LastName: "Perez",
		Email:    "juan@email.com",
		Address:  openpay.Address{
			// etc.
		},
	})
	if err != nil {
		panic(err)
	}

	card, err := customer.AddCardWithToken(&openpay.CardTokenArgs{
		TokenID:         "aCardToken",
		DeviceSessionID: "aSessionID",
	})
	if err != nil {
		panic(err)
	}

	var dst openpay.Charge
	err = customer.ChargeCustomer(&openpay.ChargeArgs{
		Source_id:         "aCardToken",
		Method:            "card",
		Amount:            100.50,
		Currency:          "MXN",
		Description:       "Cargo inicial a mi cuenta",
		Order_id:          "oid-00051",
		Device_session_id: "aSessionID",
	}, &dst)

	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	ActiveStatus    SubscriptionStatus = "active"
	TrialStatus                        = "trial"
	PastDueStatus                      = "past_due"
	UnpaidStatus                       = "unpaid"
	CancelledStatus                    = "cancelled"
)

Available status options

Variables

View Source
var (
	ErrNilClient    = errors.New("nil client")
	ErrNilMerchant  = errors.New("this resource doesn't point to a merchant")
	ErrNoResourceID = errors.New("this resource has no ID")
)

standard errors

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Category    string   `json:"category"`
	ErrorCode   int      `json:"error_code"`
	Description string   `json:"description"`
	HTTPCode    int      `json:"http_code"`
	RequestID   string   `json:"request_id"`
	FraudRules  []string `json:"fraud_rules"`
}

APIError represents an error returned by the Openpay API

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface

type Address

type Address struct {
	Line1       string `json:"line1"`
	Line2       string `json:"line2"`
	Line3       string `json:"line3"`
	PostalCode  string `json:"postal_code"`
	State       string `json:"state"`
	City        string `json:"city"`
	CountryCode string `json:"country_code"`
}

Address represents a customer's address.

type Card

type Card struct {
	CardArgs
	CreationDate  time.Time `json:"creation_date,omitempty"`
	AllowsCharges bool      `json:"allows_charges"`
	AllowsPayouts bool      `json:"allows_payouts"`
	Brand         string    `json:"brand,omitempty"`
	Type          string    `json:"type"`
	BankName      string    `json:"bank_name"`
	BankCode      string    `json:"bank_code"`
	CustomerID    string    `json:"customer_id"`
	PointsCard    bool      `json:"points_card"`
}

Card represents a credit or debit card.

type CardArgs

type CardArgs struct {
	ID              string  `json:"id"`
	HolderName      string  `json:"holder_name"`
	CardNumber      string  `json:"card_number"`
	CVV2            string  `json:"cvv2,omitempty"`
	ExpirationMonth string  `json:"expiration_month"`
	ExpirationYear  string  `json:"expiration_year"`
	Address         Address `json:"address,omitempty"`
}

CardArgs represents the arguments sent to the Openpay API to create a new card.

type CardTokenArgs

type CardTokenArgs struct {
	TokenID         string `json:"token_id"`
	DeviceSessionID string `json:"device_session_id"`
}

CardTokenArgs represents the data sent to the Openpay API to create a new card from previously tokenized information.

type Charge

type Charge struct {
	ID              string `json:"id"`
	Authorization   string `json:"authorization"`
	OperationType   string `json:"operation_type"`
	Method          string `json:"method"`
	TransactionType string `json:"transaction_type"`
	Card            struct {
		ID              string  `json:"id"`
		Type            string  `json:"type"`
		Brand           string  `json:"brand"`
		Address         Address `json:"address"`
		CardNumber      string  `json:"card_number"`
		HolderName      string  `json:"holder_name"`
		ExpirationYear  string  `json:"expiration_year"`
		ExpirationMonth string  `json:"expiration_month"`
		AllowsCharges   bool    `json:"allows_charges"`
		AllowsPayouts   bool    `json:"allows_payouts"`
		CreationDate    string  `json:"creation_date"`
		BankName        string  `json:"bank_name"`
		PointsType      string  `json:"points_type"`
		PointsCard      bool    `json:"points_card"`
		CustomerID      string  `json:"customer_id"`
		BankCode        string  `json:"bank_code"`
	} `json:"card"`
	Status        string  `json:"status"`
	Conciliated   bool    `json:"conciliated"`
	CreationDate  string  `json:"creation_date"`
	OperationDate string  `json:"operation_date"`
	Description   string  `json:"description"`
	ErrorMessage  *string `json:"error_message"`
	OrderID       string  `json:"order_id"`
	CustomerID    string  `json:"customer_id"`
	Amount        float64 `json:"amount"`
	Currency      string  `json:"currency"`
	Fee           struct {
		Amount float64 `json:"amount"`
		Tax    float64 `json:"tax"`
	} `json:"fee"`
}

type ChargeArgs

type ChargeArgs struct {
	Source_id         string  `json:"source_id"`
	Method            string  `json:"method"`
	Amount            float64 `json:"amount"`
	Currency          string  `json:"currency"`
	Description       string  `json:"description"`
	Order_id          string  `json:"order_id"`
	Device_session_id string  `json:"device_session_id"`
}

ChargeArgs is the object sent to the Openpay API when a new charge is made for a customer.

type Customer

type Customer struct {
	ID           string         `json:"id,omitempty"`
	CreationDate time.Time      `json:"creation_date"`
	Name         string         `json:"name"`
	LastName     string         `json:"last_name"`
	Email        string         `json:"email"`
	PhoneNumber  string         `json:"phone_number"`
	Status       string         `json:"status"`
	Balance      float64        `json:"balance"`
	CLABE        string         `json:"clabe"`
	Address      Address        `json:"address"`
	Store        StoreReference `json:"store"`

	// Merchant will be set automatically if obtained from through an API call.
	// Otherwise, you must set it yourself.
	Merchant *Merchant
}

Customer is an Openpay customer.

func (*Customer) AddCard

func (c *Customer) AddCard(args *CardArgs) (*Card, error)

AddCard saves a card to the customer's account.

func (*Customer) AddCardWithToken

func (c *Customer) AddCardWithToken(args *CardTokenArgs) (*Card, error)

AddCardWithToken saves a card to the customer's account, using a card token generated with the JavaScript library.

func (*Customer) AddSubscription

func (c *Customer) AddSubscription(args *SubscriptionArgs) (*Subscription, error)

AddSubscription subscribes a customer to a plan

func (*Customer) ChargeCustomer

func (c *Customer) ChargeCustomer(data interface{}) (*Charge, error)

func (*Customer) DeleteCard

func (c *Customer) DeleteCard(id string) error

DeleteCard removes a card saved on the customer's account

func (*Customer) DeleteSubscription

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

DeleteSubscription cancels a subscription immediately

func (*Customer) GetCard

func (c *Customer) GetCard(id string) (*Card, error)

GetCard gets a card saved on the customer's account.

func (*Customer) GetSubscription

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

GetSubscription retrieves a subscription with the specified ID

func (*Customer) GetSubscriptions

func (c *Customer) GetSubscriptions() ([]Subscription, error)

GetSubscriptions gets all of a customer's subscriptions

func (*Customer) UpdateSubscription

func (c *Customer) UpdateSubscription(id string, data *Subscription) (*Subscription, error)

UpdateSubscription updates a subscription with the provided data

type CustomerArgs

type CustomerArgs struct {
	ExternalID      string  `json:"external_id,omitempty"`
	Name            string  `json:"name"`
	LastName        string  `json:"last_name,omitempty"`
	Email           string  `json:"email"`
	RequiresAccount bool    `json:"requires_acount"`
	PhoneNumber     string  `json:"phone_number,omitempty"`
	Address         Address `json:"address,omitempty"`
}

CustomerArgs is the object sent to the Openpay API when a new customer is created.

type Merchant

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

Merchant represents your Openpay account

func NewMerchant

func NewMerchant(id, privateKey string, sandbox bool) *Merchant

NewMerchant initializes a merchant instance, which is at the same time an Openpay API consumer

func (*Merchant) AddCard

func (m *Merchant) AddCard(args *CardArgs) (*Card, error)

AddCard saves a card to your merchant account.

func (*Merchant) AddCardWithToken

func (m *Merchant) AddCardWithToken(args *CardTokenArgs) (*Card, error)

AddCardWithToken saves a card to your merchant account, using a card token generated with the JavaScript library.

func (*Merchant) AddCustomer

func (m *Merchant) AddCustomer(args *CustomerArgs) (*Customer, error)

AddCustomer creates a new customer on the Openpay API.

func (*Merchant) DeleteCard

func (m *Merchant) DeleteCard(id string) error

DeleteCard removes a card saved on your merchant account.

func (*Merchant) DeleteCustomer

func (m *Merchant) DeleteCustomer(id string) error

DeleteCustomer deletes an Openpay customer.

func (*Merchant) GetCard

func (m *Merchant) GetCard(id string) (*Card, error)

GetCard gets a card saved on your merchant account.

func (*Merchant) GetCustomer

func (m *Merchant) GetCustomer(id string) (*Customer, error)

GetCustomer gets an Openpay customer.

func (*Merchant) GetCustomers

func (m *Merchant) GetCustomers() ([]Customer, error)

GetCustomers lists all available customers.

func (*Merchant) UpdateCustomer

func (m *Merchant) UpdateCustomer(id string, data *Customer) (*Customer, error)

UpdateCustomer updates an existing Openpay customer.

type StoreReference

type StoreReference struct {
	Reference        string `json:"reference"`
	BarcodeURL       string `json:"barcode_url"`
	PaybinReference  string `json:"paybin_reference"`
	BarcodePaybinURL string `json:"barcode_paybin_url"`
}

StoreReference represents a customer's store reference.

type Subscription

type Subscription struct {
	ID                  string             `json:"id"`
	CreationDate        time.Time          `json:"creation_date"`
	CancelAtPeriodEnd   bool               `json:"cancel_at_period_end"`
	ChargeDate          time.Time          `json:"charge_date"`
	CurrentPeriodNumber int                `json:"current_period_number"`
	PerdiodEndDate      time.Time          `json:"period_end_date"`
	TrialEndDate        time.Time          `json:"trial_end_date"`
	PlanID              int                `json:"plan_id"`
	Status              SubscriptionStatus `json:"status"`
	CustomerID          int                `json:"customer_id"`
	Card                Card               `json:"card"`
}

Subscription represents a customer's subscription to a plan

type SubscriptionArgs

type SubscriptionArgs struct {
	PlanID       int    `json:"plan_id"`
	TrialEndDate string `json:"trial_end_date"`
	SourceID     string `json:"source_id,omitempty"`
	Card         Card   `json:"card,omitempty"`
}

SubscriptionArgs is the object sent to the Openpay API when a new subscription is created

type SubscriptionStatus

type SubscriptionStatus string

SubscriptionStatus is a subscription's current status

Jump to

Keyboard shortcuts

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