pags

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: MIT Imports: 4 Imported by: 0

README

Golang PagSeguro v4 client

Build Status Go Report Card go.dev reference

PagSeguro v4 API golang client: docs

PagSeguro's dashboards:

Usage

client := pags.NewClient(<baseURL>, <token>, <retryCount>, <timeout>, <retryWait>, <retryMaxWait>)
Credit card
Authorize transaction
charge := pags.Charge{
    ReferenceID: "sample-reference-id",
    Description: "Sample description",
    Amount: pags.Amount{
        Value:    17000,
        Currency: "BRL",
    },
    PaymentMethod: &pags.PaymentMethod{
        Type:         "CREDIT_CARD",
        Installments: 1,
        Capture:      false,
        Card: pags.Card{
            Number:       "4111111111111111",
            ExpMonth:     "03",
            ExpYear:      "2026",
            SecurityCode: "123",
            Holder: &pags.Holder{
                Name: "Neil Armstrong",
            },
        },
    },
}

response, err := client.Charge(&charge)
Capture transaction
charge := pags.Charge{
    Amount: pags.Amount{
        Value: 17000,
    },
}

response, err := client.Capture(<tid>, &charge)
Cancel transaction
charge := pags.Charge{
    Amount: pags.Amount{
        Value: 15000,
    },
}

response, err := client.Cancel(<tid>, &charge)
Boleto
charge := pags.Charge{
    ReferenceID: "sample-reference-id",
    Description: "Sample charge",
    Amount: pags.Amount{
        Value:    17000,
        Currency: "BRL",
    },
    PaymentMethod: pags.PaymentMethod{
        Type: "BOLETO",
        Boleto: &pags.Boleto{
            DueDate: "1969-07-20",
            InstructionLines: pags.InstructionLines{
                Line1: "Sample line 1",
                Line2: "Sample line 2",
            },
            Holder: pags.Holder{
                Name:  "Neil Armstrong",
                TaxID: "46274361499",
                Email: "neil.armstrong@nasa.dev",
                Address: &pags.Address{
                    Country:    "Brazil",
                    Region:     "Rio Grande do Sul",
                    RegionCode: "RS",
                    City:       "Uruguaiana",
                    PostalCode: "97504000",
                    Street:     "Rua Marechal Floriano",
                    Number:     "835",
                    Locality:   "Rio Branco",
                },
            },
        },
    },
    NotificationUrls: []string{"https://sample.com"},
}

response, err := client.Charge(&charge)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Country    string `json:"country"`
	Region     string `json:"region"`
	RegionCode string `json:"region_code"`
	City       string `json:"city"`
	PostalCode string `json:"postal_code"`
	Street     string `json:"street"`
	Number     string `json:"number"`
	Locality   string `json:"locality"`
}

Address represents the charge payment method holder address.

type Amount

type Amount struct {
	Value    int      `json:"value"`
	Currency string   `json:"currency,omitempty"`
	Summary  *Summary `json:"summary,omitempty"`
}

Amount represents the charge amount.

type Boleto

type Boleto struct {
	ID               string            `json:"id"`
	Barcode          string            `json:"barcode"`
	FormattedBarcode string            `json:"formatted_barcode"`
	DueDate          string            `json:"due_date"`
	InstructionLines *InstructionLines `json:"instruction_lines"`
	Holder           Holder            `json:"holder"`
}

Boleto represents the charge payment method boleto.

type Card

type Card struct {
	ID           string  `json:"id,omitempty"`
	Store        bool    `json:"store,omitempty"`
	Number       string  `json:"number,omitempty"`
	SecurityCode string  `json:"security_code,omitempty"`
	Encrypted    string  `json:"encrypted,omitempty"`
	Brand        string  `json:"brand,omitempty"`
	FirstDigits  string  `json:"first_digits,omitempty"`
	LastDigits   string  `json:"last_digits,omitempty"`
	ExpMonth     string  `json:"exp_month,omitempty"`
	ExpYear      string  `json:"exp_year,omitempty"`
	Holder       *Holder `json:"holder,omitempty"`
}

Card represents the charge payment method card.

type Charge

type Charge struct {
	ID               string           `json:"id,omitempty"`
	ReferenceID      string           `json:"reference_id,omitempty"`
	Status           string           `json:"status,omitempty"`
	Description      string           `json:"description,omitempty"`
	Amount           Amount           `json:"amount"`
	PaymentMethod    *PaymentMethod   `json:"payment_method,omitempty"`
	PaymentResponse  *PaymentResponse `json:"payment_response,omitempty"`
	Links            []Links          `json:"links,omitempty"`
	NotificationUrls []string         `json:"notification_urls,omitempty"`
	CreatedAt        string           `json:"created_at,omitempty"`
	PaidAt           string           `json:"paid_at,omitempty"`
}

Charge represents the PagSeguro v4 API charge payload.

type Client

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

Client represents PagSeguro v4 API client.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient returns PagSeguro v4 API client.

func (Client) Cancel

func (c Client) Cancel(tid string, charge *Charge) (*Charge, error)

Cancel is responsible for canceling a transaction.

func (Client) Capture

func (c Client) Capture(tid string, charge *Charge) (*Charge, error)

Capture is responsible for capturing an authorized transaction.

func (Client) Charge

func (c Client) Charge(charge *Charge) (*Charge, error)

Charge is responsible for creating a new charge (credit card/boleto).

type Holder

type Holder struct {
	Name    string   `json:"name"`
	TaxID   string   `json:"tax_id"`
	Email   string   `json:"email"`
	Address *Address `json:"address"`
}

Holder represents the charge card payment method holder.

type InstructionLines

type InstructionLines struct {
	Line1 string `json:"line_1"`
	Line2 string `json:"line_2"`
}

InstructionLines represents the charge payment method boleto instruction lines.

type Links struct {
	Rel   string `json:"rel"`
	Href  string `json:"href"`
	Media string `json:"media"`
	Type  string `json:"type"`
}

Links represents the charge links response.

type PaymentMethod

type PaymentMethod struct {
	Type           string  `json:"type"`
	Installments   int     `json:"installments,omitempty"`
	Capture        bool    `json:"capture"`
	Card           *Card   `json:"card,omitempty"`
	CaptureBefore  string  `json:"capture_before,omitempty"`
	SoftDescriptor string  `json:"soft_descriptor,omitempty"`
	Boleto         *Boleto `json:"boleto,omitempty"`
}

PaymentMethod represents the charge payment method.

type PaymentResponse

type PaymentResponse struct {
	Code      string `json:"code"`
	Message   string `json:"message"`
	Reference string `json:"reference"`
}

PaymentResponse represents the charge payment method response.

type Summary

type Summary struct {
	Total    int `json:"total"`
	Paid     int `json:"paid"`
	Refunded int `json:"refunded"`
}

Summary represents the charge amount summary.

Jump to

Keyboard shortcuts

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