getnet

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 12 Imported by: 0

README

getnet

Build Status Coverage Status Go Report Card

SDK golang para integração com a API Getnet.

Consulte a documentação oficial da API Getnet https://developers.getnet.com.br/api para maiores detalhes sobre os campos.

Funcionalidades

  • Autenticação

    • Geração do token de acesso
  • Tokenização

    • Geração do token do cartão
  • Pagamento

    • Verificação de cartão
    • Pagamento com cartão de crédito

Usando

go get "github.com/martinusso/getnet"
Autenticação - Geração do token de acesso
var err error

credentials := getnet.ClientCredentials{
	ID:     "ecb847f2-e423-40c0-808c-55d2098a92ab",
	Secret: "1386f27e-0f2e-45f7-9efd-c8fdc1657426"}
credentials.AccessToken, err = credentials.NewAccessToken()
if err != nil {
	log.Fatal(err)
}
Tokenização - Geração do token do cartão
var err error

card := getnet.Card{
	CardNumber:      "5155901222280001",
	CardHolderName:  "JOAO DA SILVA",
	SecurityCode:    "123",
	Brand:           "Mastercard",
	ExpirationMonth: "12",
	ExpirationYear:  "20",
}
card.NumberToken, err = card.Token(credentials)
if err != nil {
	log.Fatal(err)
}
Cartão de Crédito
Pagamento com cartão de crédito
payment := getnet.Payment{
	Amount:   1.00,
	Currency: "BRL",
	Order: getnet.Order{
		OrderID:     "ea3dae62-1125-4eb4-b3ef-dcb720e8899d",
		SalesTax:    0,
		ProductType: Service,
	},
	Customer: getnet.Customer{
		CustomerID:     "customer_id",
		FirstName:      "João",
		LastName:       "da Silva",
		Email:          "customer@email.com.br",
		DocumentType:   "CPF",
		DocumentNumber: "12345678912",
		PhoneNumber:    "27987654321",
		BillingAddress: getnet.BillingAddress{
			Street:     "Av. Brasil",
			Number:     "1000",
			Complement: "Sala 1",
			District:   "São Geraldo",
			City:       "Porto Alegre",
			State:      "RS",
			Country:    "Brasil",
			PostalCode: "90230060",
		},
	},
	Credit: getnet.Credit{
		Delayed:            false,
		Authenticated:      false,
		PreAuthorization:   false,
		SaveCardData:       false,
		TransactionType:    Full,
		NumberInstallments: 1,
		SoftDescriptor:     "Texto exibido na fatura do cartão do comprador",
		DynamicMCC:         1799,
		Card: card, // Tokenização - Geração do token do cartão
	},
}

// credentials obtido em Autenticação - Geração do token de acesso
response, error := payment.Pay(credentials)

Documentation

Index

Constants

View Source
const (
	Mastercard Brand = "Mastercard"
	Visa       Brand = "Visa"
	Amex       Brand = "Amex"
	Elo        Brand = "Elo"
	Hipercard  Brand = "Hipercard"

	Verified    = "VERIFIED"
	NotVerified = "NOT VERIFIED"
	Denied      = "DENIED"
	Error       = "ERROR"
)
View Source
const (

	// Identificador do tipo de produto vendido dentre as opções (product_type)
	CashCarry       ProductType = "cash_carry"
	DigitalContent  ProductType = "digital_content"
	DigitalGoods    ProductType = "digital_goods"
	DigitalPhysical ProductType = "digital_physical"
	GiftCard        ProductType = "gift_card"
	PhysicalGoods   ProductType = "physical_goods"
	RenewSubs       ProductType = "renew_subs"
	Shareware       ProductType = "shareware"
	Service         ProductType = "service"

	// Tipo de transação (transaction_type)
	// Pagamento completo à vista, parcelado sem juros, parcelado com juros.
	Full                TransactionType = "FULL"
	InstallNoInterest   TransactionType = "INSTALL_NO_INTEREST"
	InstallWithInterest TransactionType = "INSTALL_WITH_INTEREST"

	// Status da transação (status)
	PaymentCanceled   = "CANCELED"
	PaymentApproved   = "APPROVED"
	PaymentDenied     = "DENIED"
	PaymentAuthorized = "AUTHORIZED"
	PaymentConfirmed  = "CONFIRMED"

	RealBrazilian Currency = "BRL"
	DollarUS      Currency = "USD"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Token     string `json:"access_token"`
	TokenType string `json:"token_type"`
	ExpiresIn int    `json:"expires_in"`
	Scope     string `json:"scope"`
	// contains filtered or unexported fields
}

func (AccessToken) Expired

func (at AccessToken) Expired() bool

type Address

type Address struct {
	Street     string `json:"street,omitempty"`
	Number     string `json:"number,omitempty"`
	Complement string `json:"complement,omitempty"`
	District   string `json:"district,omitempty"`
	City       string `json:"city,omitempty"`
	State      string `json:"state,omitempty"`
	Country    string `json:"country,omitempty"`
	PostalCode string `json:"postal_code,omitempty"`
}

type BillingAddress

type BillingAddress struct {
	Street     string `json:"street,omitempty"`
	Number     string `json:"number,omitempty"`
	Complement string `json:"complement,omitempty"`
	District   string `json:"district,omitempty"`
	City       string `json:"city,omitempty"`
	State      string `json:"state,omitempty"`
	Country    string `json:"country,omitempty"`
	PostalCode string `json:"postal_code,omitempty"`
}

type Brand

type Brand string

type Card

type Card struct {
	CardNumber      string `json:"-"`
	NumberToken     string `json:"number_token"`
	Brand           Brand  `json:"brand"`
	CardHolderName  string `json:"cardholder_name"`
	ExpirationMonth string `json:"expiration_month"`
	ExpirationYear  string `json:"expiration_year"`
	SecurityCode    string `json:"security_code"`
	CustomerID      string `json:"-"`
}

func (Card) Token

func (c Card) Token(cc ClientCredentials) (string, error)

func (Card) Verify

func (c Card) Verify(cc ClientCredentials) (Verification, error)

type ClientCredentials

type ClientCredentials struct {
	ClientID     string
	ClientSecret string
	SellerID     string
	Sandbox      bool
	AccessToken  AccessToken
}

func (ClientCredentials) Basic

func (cc ClientCredentials) Basic() string

func (ClientCredentials) Bearer

func (cc ClientCredentials) Bearer() string

func (ClientCredentials) HasSeller

func (cc ClientCredentials) HasSeller() bool

func (ClientCredentials) NewAccessToken

func (cc ClientCredentials) NewAccessToken() (AccessToken, error)

func (ClientCredentials) URL

func (cc ClientCredentials) URL() string

type Credit

type Credit struct {
	Delayed            bool            `json:"delayed"`
	Authenticated      bool            `json:"authenticated"`
	PreAuthorization   bool            `json:"pre_authorization"`
	SaveCardData       bool            `json:"save_card_data"`
	TransactionType    TransactionType `json:"transaction_type"`
	NumberInstallments int             `json:"number_installments"`
	SoftDescriptor     string          `json:"soft_descriptor"`
	DynamicMCC         int             `json:"dynamic_mcc"`
	Card               Card            `json:"card"`
}

func (Credit) MarshalJSON

func (c Credit) MarshalJSON() ([]byte, error)

type CreditResponse

type CreditResponse struct {
	Delayed               bool      `json:"delayed"`
	AuthorizationCode     string    `json:"authorization_code"`
	AuthorizedAt          time.Time `json:"authorized_at"`
	ReasonCode            string    `json:"reason_code"`
	ReasonMessage         string    `json:"reason_message"`
	Acquirer              string    `json:"acquirer"`
	SoftDescriptor        string    `json:"soft_descriptor"`
	Brand                 Brand     `json:"brand"`
	TerminalNSU           string    `json:"terminal_nsu"`
	AcquirerTransactionID string    `json:"acquirer_transaction_id"`
	TransactionID         string    `json:"transaction_id"`
}

func (*CreditResponse) UnmarshalJSON

func (cr *CreditResponse) UnmarshalJSON(data []byte) error

type Currency

type Currency string

type Customer

type Customer struct {
	CustomerID     string         `json:"customer_id"`
	FirstName      string         `json:"first_name,omitempty"`
	LastName       string         `json:"last_name,omitempty"`
	Name           string         `json:"name,omitempty"`
	Email          string         `json:"email,omitempty"`
	DocumentType   string         `json:"document_type,omitempty"`
	DocumentNumber string         `json:"document_number,omitempty"`
	PhoneNumber    string         `json:"phone_number,omitempty"`
	BillingAddress BillingAddress `json:"billing_address,omitempty"`
}

type Debit

type Debit struct {
	CardHolderMobile string `json:"cardholder_mobile"`
	SoftDescriptor   string `json:"soft_descriptor"`
	DynamicMCC       int    `json:"dynamic_mcc"`
	Authenticated    bool   `json:"authenticated"`
	Card             Card   `json:"card"`
}

func (Debit) MarshalJSON

func (d Debit) MarshalJSON() ([]byte, error)

type Detail

type Detail struct {
	Status            string `json:"status"`
	ErroCode          string `json:"error_code"`
	Description       string `json:"description"`
	DescriptionDetail string `json:"description_detail"`
}

type Device

type Device struct {
	DeviceID  string `json:"device_id,omitempty"`
	IPAddress string `json:"ip_address,omitempty"`
}

type ErrorResponseSchemaV1

type ErrorResponseSchemaV1 struct {
	Message string   `json:"message"`
	Name    string   `json:"name"`
	Details []Detail `json:"details"`
}

func (ErrorResponseSchemaV1) String

func (e ErrorResponseSchemaV1) String() string

type ErrorResponseSchemaV2

type ErrorResponseSchemaV2 struct {
	Error       string `json:"error"`
	Description string `json:"error_description"`
}

type Order

type Order struct {
	OrderID     string      `json:"order_id"`
	SalesTax    int         `json:"sales_tax"`
	ProductType ProductType `json:"product_type"`
}

type Payment

type Payment struct {
	SellerID  string     `json:"seller_id,omitempty"`
	Amount    float64    `json:"amount"`
	Currency  Currency   `json:"currency"`
	Order     Order      `json:"order"`
	Customer  Customer   `json:"customer"`
	Device    Device     `json:"device,omitempty"`
	Shippings []Shipping `json:"shippings,omitempty"`
	Credit    Credit     `json:"credit,omitempty"`
	Debit     Debit      `json:"debit,omitempty"`
}

func (Payment) MarshalJSON

func (p Payment) MarshalJSON() ([]byte, error)

func (Payment) Pay

type PaymentResponse

type PaymentResponse struct {
	PaymentID  string         `json:"payment_id"`
	SellerID   string         `json:"seller_id"`
	Amount     float64        `json:"amount"`
	Currency   Currency       `json:"currency"`
	OrderID    string         `json:"order_id"`
	Status     string         `json:"status"`
	ReceivedAt time.Time      `json:"received_at"`
	Credit     CreditResponse `json:"credit"`
}

func (PaymentResponse) Approved

func (p PaymentResponse) Approved() bool

func (PaymentResponse) Authorized

func (p PaymentResponse) Authorized() bool

func (PaymentResponse) Canceled

func (p PaymentResponse) Canceled() bool

func (PaymentResponse) Confirmed

func (p PaymentResponse) Confirmed() bool

func (PaymentResponse) Denied

func (p PaymentResponse) Denied() bool

func (*PaymentResponse) UnmarshalJSON

func (p *PaymentResponse) UnmarshalJSON(data []byte) error

type ProductType

type ProductType string

type Response

type Response struct {
	Body []byte
	Code int
}

type RestClient

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

func NewRestClient

func NewRestClient(c ClientCredentials) RestClient

func (RestClient) AuthBasic

func (r RestClient) AuthBasic() RestClient

func (RestClient) FormData

func (r RestClient) FormData(endpoint string, form url.Values) (Response, error)

func (RestClient) Get

func (r RestClient) Get(endpoint string) (Response, error)

func (RestClient) Post

func (r RestClient) Post(endpoint string, value interface{}) (Response, error)

type Shipping

type Shipping struct {
	FirstName      string  `json:"first_name,omitempty"`
	Name           string  `json:"name,omitempty"`
	Email          string  `json:"email,omitempty"`
	PhoneNumber    string  `json:"phone_number,omitempty"`
	ShippingAmount float64 `json:"shipping_amount,omitempty"`
	Address        Address `json:"address,omitempty"`
}

func (Shipping) MarshalJSON

func (s Shipping) MarshalJSON() ([]byte, error)

type Token

type Token struct {
	NumberToken string `json:"number_token"`
}

type TransactionType

type TransactionType string

type Verification

type Verification struct {
	Status            string `json:"status"`
	VerificationID    string `json:"verification_id"`
	AuthorizationCode string `json:"authorization_code"`
}

func (Verification) Denied

func (v Verification) Denied() bool

func (Verification) NotVerified

func (v Verification) NotVerified() bool

func (Verification) Verified

func (v Verification) Verified() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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