pagsego

package module
v0.0.0-...-c151150 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2014 License: MIT Imports: 12 Imported by: 0

README

pagsego

PagSeguro API in Go (golang) (WIP)

req := pagsego.NewPaymentRequest("TOKEN", "vendedor@email.com", "REFID", "REDIRECTURI", "NOTIFICATIONURI")
req.AddItem("ID", "DESCRIPTION", 23.56, 1)
req.SetBuyer("Nome do Comprador", "comprador@email.com").SetCPF("00000000000")
req.SetShipping(pagsego.ShippingSEDEX, 10.0).SetAddress("SP", "São Paulo", "00000000", "Bairro", "Rua Teste", "1040", "Apt 111")

fmt.Println(result.Success)
if result.Success {
	fmt.Println(result.CheckoutResponse.Code)
}

Documentation

Index

Constants

View Source
const (
	ShippingPAC     = 1
	ShippingSEDEX   = 2
	ShippingOther   = 3
	XMLHeader       = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`
	CheckoutURL     = "https://ws.pagseguro.uol.com.br/v2/checkout"
	TransactionsURL = "https://ws.pagseguro.uol.com.br/v2/transactions/notifications"

	TransactionTypePayment = 1

	TransactionStatusAwaitingPayment = 1
	TransactionStatusInAnalysis      = 2
	TransactionStatusPaid            = 3
	TransactionStatusAvailable       = 4
	TransactionStatusInDispute       = 5
	TransactionStatusReturned        = 6
	TransactionStatusCanceled        = 7

	PaymentMethodCreditCardVisa             = 101
	PaymentMethodCreditCardMasterCard       = 102
	PaymentMethodCreditCardAMEX             = 103
	PaymentMethodCreditCardDiners           = 104
	PaymentMethodCreditCardHipercard        = 105
	PaymentMethodCreditCardAura             = 106
	PaymentMethodCreditCardElo              = 107
	PaymentMethodCreditCardPLENOCard        = 108
	PaymentMethodCreditCardPersonalCard     = 109
	PaymentMethodCreditCardJCB              = 110
	PaymentMethodCreditCardDiscover         = 111
	PaymentMethodCreditCardBrasilCard       = 112
	PaymentMethodCreditCardFORTBRASIL       = 113
	PaymentMethodCreditCardCARDBAN          = 114
	PaymentMethodCreditCardVALECARD         = 115
	PaymentMethodCreditCardCabal            = 116
	PaymentMethodCreditCardMais             = 117
	PaymentMethodCreditCardAvista           = 118
	PaymentMethodCreditCardGRANDCARD        = 119
	PaymentMethodBoletoBradesco             = 201
	PaymentMethodBoletoSantander            = 202
	PaymentMethodDebitoOnlineBradesco       = 301
	PaymentMethodDebitoOnlineItau           = 302
	PaymentMethodDebitoOnlineUnibanco       = 303
	PaymentMethodDebitoOnlineBancoDoBrasil  = 304
	PaymentMethodDebitoOnlineBancoReal      = 305
	PaymentMethodDebitoOnlineBanrisul       = 306
	PaymentMethodDebitoOnlineHSBC           = 307
	PaymentMethodSaldoPagSeguro             = 401
	PaymentMethodOiPaggo                    = 501
	PaymentMethodDepositoContaBancoDoBrasil = 701
	PaymentMethodDepositoContaHSBC          = 702
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buyer

type Buyer struct {
	Email     string           `xml:"email"`
	Name      string           `xml:"name"`
	Phone     *Phone           `xml:"phone,omitempty"`
	Documents []*BuyerDocument `xml:"documents>document,omitempty"`
	BornDate  string           `xml:"bornDate,omitempty"` //dd/MM/yyyy optional
}

func (*Buyer) SetCPF

func (r *Buyer) SetCPF(cpf string) *Buyer

func (*Buyer) SetPhone

func (r *Buyer) SetPhone(areaCode string, phone string) *Buyer

type BuyerDocument

type BuyerDocument struct {
	Type  string `xml:"type"` // It's always "CPF" ¯\_(ツ)_/¯
	Value string `xml:"value"`
}

type ErrorResponse

type ErrorResponse struct {
	Errors []XMLError `xml:"errors"`
}

type Metadata

type Metadata struct {
	Key   string     `xml:"key"`
	Value string     `xml:"value,omitempty"`
	Group []Metadata `xml:"group,omitempty"`
}

type PaymentItem

type PaymentItem struct {
	XMLName      xml.Name `xml:"item"`
	Id           string   `xml:"id"`
	Description  string   `xml:"description"`
	PriceAmount  string   `xml:"amount"`
	Quantity     string   `xml:"quantity"`
	ShippingCost string   `xml:"shippingCost,omitempty"`
	Weight       string   `xml:"weight,omitempty"`
}

func (*PaymentItem) SetAmount

func (r *PaymentItem) SetAmount(amount float64) *PaymentItem

func (*PaymentItem) SetQuantity

func (r *PaymentItem) SetQuantity(quantity int) *PaymentItem

func (*PaymentItem) SetShippingCost

func (r *PaymentItem) SetShippingCost(cost float64) *PaymentItem

func (*PaymentItem) SetWeight

func (r *PaymentItem) SetWeight(grams int) *PaymentItem

type PaymentPreResponse

type PaymentPreResponse struct {
	XMLName xml.Name `xml:"checkout"`
	Code    string   `xml:"code"`
	Data    string   `xml:"data"`
}

type PaymentPreSubmitResult

type PaymentPreSubmitResult struct {
	CheckoutResponse *PaymentPreResponse
	Error            *ErrorResponse
	Success          bool
}

type PaymentRequest

type PaymentRequest struct {
	XMLName         xml.Name       `xml:"checkout"`
	Email           string         `xml:"email"`
	Token           string         `xml:"token"`
	Currency        string         `xml:"currency"`
	Items           []*PaymentItem `xml:"items>item"`
	ReferenceID     string         `xml:"reference"`
	Buyer           *Buyer         `xml:"sender"`
	Shipping        *Shipping      `xml:"shipping"`
	ExtraAmount     string         `xml:"extraAmount,omitempty"` // use this for discounts or taxes
	RedirectURL     string         `xml:"redirectURL,omitempty"`
	NotificationURL string         `xml:"notificationURL,omitempty"`
	MaxUses         string         `xml:"maxUses,omitempty"`  // from 0 to 999 (the amount of tries a user can do with the same reference ID)
	MaxAge          string         `xml:"maxAge,omitempty"`   // time (in seconds) that the returned payment code is valid (30-999999999)
	Metadata        []*Metadata    `xml:"metadata,omitempty"` // https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-pagamentos.html#v2-item-api-de-pagamentos-parametros-http
	IsSandbox       bool           `xml:"-"`                  // o PagSeguro não tem um modo sandbox no momento (╯°□°)╯︵ ┻━┻
}

func NewPaymentRequest

func NewPaymentRequest(sellerToken, sellerEmail, referenceID, redirectURL, notificationURL string) *PaymentRequest

func (*PaymentRequest) AddItem

func (r *PaymentRequest) AddItem(id string, description string, amount float64, quantity int) *PaymentItem

func (*PaymentRequest) SetBuyer

func (r *PaymentRequest) SetBuyer(name, email string) *Buyer

func (*PaymentRequest) SetShipping

func (r *PaymentRequest) SetShipping(shippingType int, shippingCost float64) *Shipping

func (*PaymentRequest) Submit

func (r *PaymentRequest) Submit() (result *PaymentPreSubmitResult)

type Phone

type Phone struct {
	AreaCode    string `xml:"areaCode,omitempty"` // optional
	PhoneNumber string `xml:"number,omitempty"`   // optional
}

type Shipping

type Shipping struct {
	Type    string           `xml:"type"`
	Cost    string           `xml:"cost"`
	Address *ShippingAddress `xml:"address,omitempty"`
}

func (*Shipping) SetAddress

func (r *Shipping) SetAddress(state, city, postalCode, district, street, number, complement string) *Shipping

func (*Shipping) SetAddressCountry

func (r *Shipping) SetAddressCountry(country string) *Shipping

func (*Shipping) SetAddressStateCity

func (r *Shipping) SetAddressStateCity(state, city string) *Shipping

type ShippingAddress

type ShippingAddress struct {
	Country    string `xml:"country"`              // It's always "BRA" ¯\_(ツ)_/¯
	State      string `xml:"state,omitempty"`      // "SP"
	City       string `xml:"city,omitempty"`       // max 60 min 2
	PostalCode string `xml:"postalCode,omitempty"` // XXXXXXXX
	District   string `xml:"district,omitempty"`   // Bairro | max chars: 60
	Street     string `xml:"street,omitempty"`     // max: 80
	Number     string `xml:"number,omitempty"`     // max: 20
	Complement string `xml:"complement,omitempty"` // max: 40
}

type Transaction

type Transaction struct {
	XMLName            xml.Name                  `xml:"transaction"`
	Date               string                    `xml:"date,omitempty"`
	Code               string                    `xml:"code,omitempty"`
	Reference          string                    `xml:"reference,omitempty"`
	Type               int                       `xml:"type,omitempty"`
	Status             int                       `xml:"status,omitempty"`
	LastEventDate      string                    `xml:"lastEventDate,omitempty"`
	PaymentMethod      *TransactionPaymentMethod `xml:"paymentMethod,omitempty"`
	GrossAmount        string                    `xml:"grossAmount,omitempty"`
	DiscountAmount     string                    `xml:"discountAmount,omitempty"`
	FeeAmount          string                    `xml:"feeAmount,omitempty"`
	NetAmount          string                    `xml:"netAmount,omitempty"`
	EscrowEndDate      string                    `xml:"escrowEndDate,omitempty"`
	ExtraAmount        string                    `xml:"extraAmount,omitempty"`
	InstallmentCount   int                       `xml:"installmentCount,omitempty"`
	ItemCount          int                       `xml:"itemCount,omitempty"`
	Items              []*PaymentItem            `xml:"items>item,omitempty"`
	Buyer              *Buyer                    `xml:"sender,omitempty"`
	Shipping           *Shipping                 `xml:"shipping,omitempty"`
	CancellationSource string                    `xml:"cancellationSource,omitempty"`
}

func FetchTransactionInfo

func FetchTransactionInfo(sellerToken, sellerEmail, notificationCode string) (result *Transaction, err error)

type TransactionPaymentMethod

type TransactionPaymentMethod struct {
	Type int `xml:"type"`
	Code int `xml:"code"`
}

type XMLError

type XMLError struct {
	XMLName xml.Name `xml:"error"`
	Code    int      `xml:"code"`
	Message string   `xml:"message"`
}

Jump to

Keyboard shortcuts

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