Code Monkey home page Code Monkey logo

pagarme-go's Introduction

pagarme-go

Go Report Card

Installation

go get github.com/luk4z7/pagarme-go
export PAGARME_APIKEY=YOUR_APYKEY

Usage

Create a Bank:

package main

import (
	"net/url"
	"encoding/json"
	"os"
	"github.com/luk4z7/pagarme-go/auth"
	"github.com/luk4z7/pagarme-go/lib/bank"
)

var bankAccount bank.Account

func main() {
	data := []byte(`{
		"bank_code": "184",
		"agencia": "0809",
		"agencia_dv": "9",
		"conta": "08809",
		"conta_dv": "8",
		"document_number": "80802694594",
		"legal_name": "JORGER MENDES"
	}`)
	create, err, errorsApi := bankAccount.Create(data, url.Values{}, auth.Headers{})
	if err != nil {
		response, _ := json.MarshalIndent(errorsApi, "", "  ")
		os.Stdout.Write(response)
	}
	responseCreate, _ := json.MarshalIndent(create, "", " ")
	os.Stdout.Write(responseCreate)
}

Example Response

{
     "agencia": "0809",
     "agencia_dv": "9",
     "bank_code": "184",
     "conta": "08809",
     "conta_dv": "8",
     "date_created": "2016-09-14T06:45:19.395Z",
     "document_number": "80802694594",
     "document_type": "cpf",
     "id": 16740182,
     "legal_name": "JORGER MENDES",
     "object": "bank_account"
}

Create a Card:

package main

import (
	"net/url"
	"encoding/json"
	"os"
	"github.com/luk4z7/pagarme-go/auth"
	"github.com/luk4z7/pagarme-go/lib/card"
)

var creditCard card.Card

func main() {
	data2 := []byte(`{
		"card_number": "4242424242424242",
		"card_holder_name": "Marcos Mendes Teste API Create",
		"card_expiration_date": "1018"
	}`)
	create2, err, errorsApi := creditCard.Create(data2, url.Values{}, auth.Headers{})
	if err != nil {
		response, _ := json.MarshalIndent(errorsApi, "", "  ")
		os.Stdout.Write(response)
	} else {
		responseCreate2, _ := json.MarshalIndent(create2, "", " ")
		os.Stdout.Write(responseCreate2)
	}
}

Example Response

{
     "brand": "visa",
     "country": "US",
     "customer": "",
     "date_created": "2016-09-04T20:47:36.701Z",
     "date_updated": "2016-09-04T20:47:36.83Z",
     "fingerprint": "1fSoeUfMRR/V",
     "first_digits": "424242",
     "holder_name": "Marcos Mendes Teste API Create",
     "id": "card_cisp3at4s00fowm6egw1kgit1",
     "last_digits": "4242",
     "object": "card",
     "valid": true
}

Create a transaction:

package main

import (
	"encoding/json"
	"os"
	"net/url"
	"github.com/luk4z7/pagarme-go/auth"
	"github.com/luk4z7/pagarme-go/lib/transaction"
)

var transactionRecord transaction.Transaction

func main() {
	data := []byte(`{
		"amount": 100,
		"card_id": "card_cisp3at4s00fowm6egw1kgit1",
		"customer": {
			"name":"Name",
			"email":"[email protected]",
			"document_number":"80802694594",
			"gender":"M",
			"born_at":"09-22-2015",
			"address": {
				"street":"Rua de exemplo",
				"street_number":"808",
				"neighborhood":"Bairro de exemplo",
				"complementary":"Apartamento 8",
				"city":"Cidade",
				"state":"Lordaeron",
				"zipcode":"47850000",
				"country":"Lordaeron"
			},
			"phone": {
				"ddi":"88",
				"ddd":"88",
				"number":"808080808"
			}
		},
		"postback_url": "http://requestb.in/pkt7pgpk",
		"metadata": {
			"idProduto": "10"
		}
	}`)
	create, err, errorsApi := transactionRecord.Create(data, url.Values{}, auth.Headers{})
	if err != nil {
		response, _ := json.MarshalIndent(errorsApi, "", "  ")
		os.Stdout.Write(response)
	} else {
		responseCreate, _ := json.MarshalIndent(create, "", " ")
		os.Stdout.Write(responseCreate)
	}
}

For more example:

in the folder examples exist several examples how you can use, for api reference consult https://github.com/pagarme/api-reference

pagarme-go's People

Contributors

luk4z7 avatar

Watchers

Andrey Andrade avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.