You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/WalterPaes/go-pagseguro

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/WalterPaes/go-pagseguro

v1.0.0
Source
Go
Version published
Created
Source

License: MIT

GoPagSeguro

This Lib was developed for implement some features of the new PagSeguro's api using Go Lang

Usage

import "github.com/WalterPaes/GoPagSeguro"

Create a New Integration

integration := pagseguro.NewIntegration(
    {PAGSEG_URL}, 
    {PAGSEG_TOKEN}, 
    {PAGSEG_API_VERSION}
)

Generating a Boleto Charge

// Create a boleto charge struct to payload
boleto := pagseguro.NewBoletoCharge(
"ex-10001", 
"Charge reason", 
&pagseguro.Amount{
	Value:    100,
	Currency: "BRL",
}, &pagseguro.Boleto{
    DueDate:          "2021-05-01",
    InstructionLines: &pagseguro.BoletoInstructionLines{
        Line1: "Instruction One",
        Line2: "Instruction Two",
    },
    Holder: &pagseguro.Holder{
        Name:    "Walter Paes",
        TaxID:   "65763916093",
        Email:   "email@email.com",
        Address: &pagseguro.Address{
            Country:    "Brasil",
            Region:     "São Paulo",
            RegionCode: "SP",
            City:       "São Paulo",
            PostalCode: "88025011",
            Street:     "Rua Teste",
            Number:     "123",
            Locality:   "Pinheiros",
        },
    },
}, nil)

// Call function to do request
newCharge, err := integration.GenerateBoleto(boleto)

Create a credit card Authorization

// Create a credit card charge struct to payload
card := pagseguro.NewCardCharge(
    "ex-10001",
    "charge reason",
    1,
    false,
    nil,
    &pagseguro.Amount{
        Value:    1000,
        Currency: "BRL",
    },
    &pagseguro.Card{
        Number:       "5306941322840724",
        ExpMonth:     "11",
        ExpYear:      "2022",
        SecurityCode: "123",
        Holder:       &pagseguro.Holder{
            Name:    "Walter Paes",
        },
}, nil)

// Call function to do request
newCharge, err := integration.Authorization(card)

Do a Capture after Pre-Authorization

chargeID := "CHAR_344a0907-8aa6-4b7a-943c-897383adf45f"
amount := &pagseguro.Amount{
    Value: 1000,
    Currency: "BRL",
}

// Call function to do request
newCapture, err := integration.Capture(chargeID, amount)

Get a charge

chargeID := "CHAR_344a0907-8aa6-4b7a-943c-897383adf45f"

// Call function to do request
newCapture, err := integration.GetCharge(chargeID)

Refund and Cancel

chargeID := "CHAR_344a0907-8aa6-4b7a-943c-897383adf45f"
amount := &pagseguro.Amount{
    Value:    1000,
    Currency: "BRL",
}

// Call function to do request
charge, err := integration.RefundAndCancel(chargeID, amount)

:rocket: Technologies

This project was developed with the following technologies:

Made by Walter Junior

FAQs

Package last updated on 09 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts