├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── auth ├── auth.go └── auth_test.go ├── bootstrap.go ├── config ├── apikey.go └── apikey_test.go ├── error └── error.go ├── examples ├── balance │ ├── balance.go │ └── operation │ │ └── operation.go ├── bank │ └── bank.go ├── card │ └── card.go ├── customer │ └── customer.go ├── payable │ └── payable.go ├── plan │ └── plan.go ├── recipient │ ├── balance │ │ ├── balance.go │ │ └── operation │ │ │ └── operation.go │ └── recipient.go ├── search │ └── search.go ├── subscription │ └── subscription.go ├── transaction │ ├── antifraudanalysis │ │ └── antifraudanalysis.go │ ├── capture │ │ └── capture.go │ ├── cardhashkey │ │ └── cardhashkey.go │ ├── collectpayment │ │ └── collectpayment.go │ ├── event │ │ └── event.go │ ├── operation │ │ └── operation.go │ ├── payable │ │ └── payable.go │ ├── postback │ │ └── postback.go │ ├── splitrule │ │ └── splitrule.go │ └── transaction.go └── transfer │ └── transfer.go ├── lib ├── balance │ ├── balance.go │ └── operation │ │ └── operation.go ├── bank │ └── account.go ├── card │ └── card.go ├── customer │ └── customer.go ├── event │ └── event.go ├── operation │ └── operation.go ├── payable │ └── payable.go ├── plan │ └── plan.go ├── postback │ └── postback.go ├── recipient │ ├── balance │ │ ├── balance.go │ │ └── operation │ │ │ └── operation.go │ └── recipient.go ├── search │ └── search.go ├── subscription │ ├── event │ │ └── event.go │ ├── postback │ │ └── postback.go │ ├── subscription.go │ └── transaction │ │ └── transaction.go ├── transaction │ ├── antifraudanalysis │ │ └── antifraudanalysis.go │ ├── capture │ │ └── capture.go │ ├── cardhashkey │ │ └── cardhashkey.go │ ├── collectpayment │ │ └── collectpayment.go │ ├── event │ │ └── event.go │ ├── operation │ │ └── operation.go │ ├── payable │ │ └── payable.go │ ├── postback │ │ └── postback.go │ ├── splitrule │ │ └── splitrule.go │ └── transaction.go ├── transfer │ └── transfer.go ├── validation │ └── validation.go └── zipcode │ └── zipcode.go └── repository ├── repository.go └── repository_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.DS_Store 3 | src 4 | bin 5 | pkg -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # pagarme-go Changelog 2 | ---------------- 3 | 4 | 5 | ## v0.0.3 (2016-09-15) 6 | 7 | * Include Go Report Card 8 | * Ignore folders: src, bin, pkg 9 | * Analyze files with go vet 10 | 11 | 12 | ## v0.0.2 (2016-09-14) 13 | 14 | * Implemented Gofmt (formats Go programs) 15 | 16 | 17 | ## v0.0.1 (2016-09-14) 18 | 19 | * Initial commit 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Lucas Alves Author. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Lucas Alves. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pagarme-go 2 | 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/luk4z7/pagarme-go)](https://goreportcard.com/report/github.com/luk4z7/pagarme-go) 4 | 5 | ## Installation 6 | 7 | ```bash 8 | go get github.com/luk4z7/pagarme-go 9 | ``` 10 | 11 | ```bash 12 | export PAGARME_APIKEY=YOUR_APYKEY 13 | ``` 14 | 15 | ## Usage 16 | 17 | 18 | Create a Bank: 19 | 20 | ```go 21 | package main 22 | 23 | import ( 24 | "net/url" 25 | "encoding/json" 26 | "os" 27 | "github.com/luk4z7/pagarme-go/auth" 28 | "github.com/luk4z7/pagarme-go/lib/bank" 29 | ) 30 | 31 | var bankAccount bank.Account 32 | 33 | func main() { 34 | data := []byte(`{ 35 | "bank_code": "184", 36 | "agencia": "0809", 37 | "agencia_dv": "9", 38 | "conta": "08809", 39 | "conta_dv": "8", 40 | "document_number": "80802694594", 41 | "legal_name": "JORGER MENDES" 42 | }`) 43 | create, err, errorsApi := bankAccount.Create(data, url.Values{}, auth.Headers{}) 44 | if err != nil { 45 | response, _ := json.MarshalIndent(errorsApi, "", " ") 46 | os.Stdout.Write(response) 47 | } 48 | responseCreate, _ := json.MarshalIndent(create, "", " ") 49 | os.Stdout.Write(responseCreate) 50 | } 51 | ``` 52 | 53 | Example Response 54 | 55 | ```json 56 | { 57 | "agencia": "0809", 58 | "agencia_dv": "9", 59 | "bank_code": "184", 60 | "conta": "08809", 61 | "conta_dv": "8", 62 | "date_created": "2016-09-14T06:45:19.395Z", 63 | "document_number": "80802694594", 64 | "document_type": "cpf", 65 | "id": 16740182, 66 | "legal_name": "JORGER MENDES", 67 | "object": "bank_account" 68 | } 69 | ``` 70 | 71 | 72 | Create a Card: 73 | 74 | ```go 75 | package main 76 | 77 | import ( 78 | "net/url" 79 | "encoding/json" 80 | "os" 81 | "github.com/luk4z7/pagarme-go/auth" 82 | "github.com/luk4z7/pagarme-go/lib/card" 83 | ) 84 | 85 | var creditCard card.Card 86 | 87 | func main() { 88 | data2 := []byte(`{ 89 | "card_number": "4242424242424242", 90 | "card_holder_name": "Marcos Mendes Teste API Create", 91 | "card_expiration_date": "1018" 92 | }`) 93 | create2, err, errorsApi := creditCard.Create(data2, url.Values{}, auth.Headers{}) 94 | if err != nil { 95 | response, _ := json.MarshalIndent(errorsApi, "", " ") 96 | os.Stdout.Write(response) 97 | } else { 98 | responseCreate2, _ := json.MarshalIndent(create2, "", " ") 99 | os.Stdout.Write(responseCreate2) 100 | } 101 | } 102 | ``` 103 | 104 | Example Response 105 | 106 | ```json 107 | { 108 | "brand": "visa", 109 | "country": "US", 110 | "customer": "", 111 | "date_created": "2016-09-04T20:47:36.701Z", 112 | "date_updated": "2016-09-04T20:47:36.83Z", 113 | "fingerprint": "1fSoeUfMRR/V", 114 | "first_digits": "424242", 115 | "holder_name": "Marcos Mendes Teste API Create", 116 | "id": "card_cisp3at4s00fowm6egw1kgit1", 117 | "last_digits": "4242", 118 | "object": "card", 119 | "valid": true 120 | } 121 | ``` 122 | 123 | 124 | Create a transaction: 125 | 126 | ```go 127 | package main 128 | 129 | import ( 130 | "encoding/json" 131 | "os" 132 | "net/url" 133 | "github.com/luk4z7/pagarme-go/auth" 134 | "github.com/luk4z7/pagarme-go/lib/transaction" 135 | ) 136 | 137 | var transactionRecord transaction.Transaction 138 | 139 | func main() { 140 | data := []byte(`{ 141 | "amount": 100, 142 | "card_id": "card_cisp3at4s00fowm6egw1kgit1", 143 | "customer": { 144 | "name":"Name", 145 | "email":"example@example.com", 146 | "document_number":"80802694594", 147 | "gender":"M", 148 | "born_at":"09-22-2015", 149 | "address": { 150 | "street":"Rua de exemplo", 151 | "street_number":"808", 152 | "neighborhood":"Bairro de exemplo", 153 | "complementary":"Apartamento 8", 154 | "city":"Cidade", 155 | "state":"Lordaeron", 156 | "zipcode":"47850000", 157 | "country":"Lordaeron" 158 | }, 159 | "phone": { 160 | "ddi":"88", 161 | "ddd":"88", 162 | "number":"808080808" 163 | } 164 | }, 165 | "postback_url": "http://requestb.in/pkt7pgpk", 166 | "metadata": { 167 | "idProduto": "10" 168 | } 169 | }`) 170 | create, err, errorsApi := transactionRecord.Create(data, url.Values{}, auth.Headers{}) 171 | if err != nil { 172 | response, _ := json.MarshalIndent(errorsApi, "", " ") 173 | os.Stdout.Write(response) 174 | } else { 175 | responseCreate, _ := json.MarshalIndent(create, "", " ") 176 | os.Stdout.Write(responseCreate) 177 | } 178 | } 179 | ``` 180 | 181 | For more example: 182 | 183 | in the folder `examples` exist several examples how you can use, for api reference consult 184 | https://github.com/pagarme/api-reference 185 | 186 | -------------------------------------------------------------------------------- /auth/auth.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package auth 6 | 7 | import ( 8 | "encoding/base64" 9 | "github.com/luk4z7/pagarme-go/config" 10 | liberr "github.com/luk4z7/pagarme-go/error" 11 | "net/http" 12 | ) 13 | 14 | var key config.ApiKey 15 | 16 | type Headers map[string]string 17 | 18 | // encoded username + password for base64 for http basic access authentRequestication 19 | func BasicAuth(username, password string) string { 20 | auth := username + ":" + password 21 | return base64.StdEncoding.EncodeToString([]byte(auth)) 22 | } 23 | 24 | // Authentication with API and return Response 25 | func Init(uri string, h Headers) *http.Response { 26 | // Create new request with endPoint passed 27 | req, err := http.NewRequest("GET", uri, nil) 28 | liberr.Check(err, "Return error of the new Request given a method of NewRequest - method: Init") 29 | // add more headers configurations 30 | if len(h) > 0 { 31 | q := req.URL.Query() 32 | for k, v := range h { 33 | q.Add(k, v) 34 | } 35 | req.URL.RawQuery = q.Encode() 36 | } 37 | // Authentication using basic http 38 | req.Header.Add("Authorization", "Basic "+BasicAuth(key.GetApiKey(), "x")) 39 | cli := &http.Client{} 40 | resp, err := cli.Do(req) 41 | liberr.Check(err, "Return error HTTP response of Do - method: Init") 42 | 43 | return resp 44 | } 45 | -------------------------------------------------------------------------------- /auth/auth_test.go: -------------------------------------------------------------------------------- 1 | package auth 2 | 3 | import ( 4 | "net/http" 5 | _ "net/http" 6 | _ "net/http/httptest" 7 | "os" 8 | "testing" 9 | ) 10 | 11 | func TestBasicAuth(t *testing.T) { 12 | setPagarmeAPIKey() 13 | 14 | encode := BasicAuth("user", "12345") 15 | if encode != "dXNlcjoxMjM0NQ==" { 16 | t.Fatal("error") 17 | } 18 | err := requireInMethodBasicAuthReturn(encode) 19 | if err != nil { 20 | t.Fatal("error") 21 | } 22 | } 23 | 24 | func TestInit(t *testing.T) { 25 | setPagarmeAPIKey() 26 | 27 | resp := Init("https://google.com", Headers{ 28 | "page": "1", 29 | "count": "10", 30 | }) 31 | _, err := requireInMethodInitReturn(resp) 32 | if err != nil { 33 | t.Fatal("error") 34 | } 35 | 36 | if resp.StatusCode == 400 { 37 | t.Fatal("error") 38 | } 39 | } 40 | 41 | func requireInMethodInitReturn(d *http.Response) (*http.Response, error) { 42 | return d, nil 43 | } 44 | 45 | func requireInMethodBasicAuthReturn(s string) error { 46 | return nil 47 | } 48 | 49 | func setPagarmeAPIKey() { 50 | os.Setenv("PAGARME_APIKEY", "TEST_VALUE") 51 | } 52 | -------------------------------------------------------------------------------- /bootstrap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | func main() {} 8 | -------------------------------------------------------------------------------- /config/apikey.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package config 6 | 7 | import ( 8 | "syscall" 9 | ) 10 | 11 | type Config interface { 12 | GetApiKey() string 13 | } 14 | 15 | type ApiKey struct { 16 | Key string 17 | } 18 | 19 | func (c *ApiKey) GetApiKey() string { 20 | v, f := syscall.Getenv("PAGARME_APIKEY") 21 | if f != true { 22 | panic("configure sua variavel de ambiente") 23 | } 24 | return v 25 | } 26 | -------------------------------------------------------------------------------- /config/apikey_test.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | func TestGetApiKeyPanic(t *testing.T) { 9 | defer func() { 10 | if r := recover(); r == nil { 11 | t.Errorf("The code did not panic") 12 | } 13 | }() 14 | 15 | apiKey := ApiKey{} 16 | apiKey.GetApiKey() 17 | } 18 | 19 | func TestGetApiKey(t *testing.T) { 20 | os.Setenv("PAGARME_APIKEY", "test") 21 | 22 | apiKey := ApiKey{} 23 | if apiKey.GetApiKey() != "test" { 24 | t.Errorf("GetApiKey was expecting %s but given %s", "test", apiKey.GetApiKey()) 25 | } 26 | 27 | os.Unsetenv("PAGARME_APIKEY") 28 | } 29 | -------------------------------------------------------------------------------- /error/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package error 6 | 7 | type ErrorsAPI struct { 8 | Errors []Errors `json:"errors"` 9 | Url string `json:"url"` 10 | Method string `json:"method"` 11 | } 12 | 13 | type Errors struct { 14 | ParameterName string `json:"parameter_name"` 15 | Type string `json:"type"` 16 | Message string `json:"message"` 17 | } 18 | 19 | type Err struct { 20 | Name string 21 | } 22 | 23 | func (e *Err) Error() string { 24 | return e.Name 25 | } 26 | 27 | // Return panic when error != nil 28 | func Check(e error, m string) { 29 | if e != nil { 30 | if m == "" { 31 | panic(m) 32 | } else { 33 | panic(e) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/balance/balance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/balance" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var balanceAmount balance.BalanceAmount 16 | 17 | func main() { 18 | // Get a Balance Amount 19 | getall, err, errorsApi := balanceAmount.GetAll(url.Values{}, auth.Headers{}) 20 | if err != nil { 21 | response, _ := json.MarshalIndent(errorsApi, "", " ") 22 | os.Stdout.Write(response) 23 | } else { 24 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 25 | os.Stdout.Write(responseGetAll) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/balance/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/balance/operation" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var balanceOperation operation.BalanceOperation 16 | 17 | func main() { 18 | // Get a Balance Operation 19 | get, err, errorsApi := balanceOperation.Get(url.Values{"id": {"0"}}, auth.Headers{}) 20 | if err != nil { 21 | response, _ := json.MarshalIndent(errorsApi, "", " ") 22 | os.Stdout.Write(response) 23 | } else { 24 | responseGet, _ := json.MarshalIndent(get, "", " ") 25 | os.Stdout.Write(responseGet) 26 | } 27 | 28 | // Get all Balance Operation 29 | getall, err, errorsApi := balanceOperation.GetAll(url.Values{}, auth.Headers{ 30 | "page": "1", 31 | "count": "10", 32 | }) 33 | if err != nil { 34 | response, _ := json.MarshalIndent(errorsApi, "", " ") 35 | os.Stdout.Write(response) 36 | } else { 37 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 38 | os.Stdout.Write(responseGetAll) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/bank/bank.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/bank" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var bankAccount bank.Account 16 | 17 | func main() { 18 | // Create a Card 19 | data := []byte(`{ 20 | "bank_code": "184", 21 | "agencia": "0808", 22 | "agencia_dv": "8", 23 | "conta": "08808", 24 | "conta_dv": "8", 25 | "document_number": "80802694594", 26 | "legal_name": "Lucas Alves" 27 | }`) 28 | create, err, errorsApi := bankAccount.Create(data, url.Values{}, auth.Headers{}) 29 | if err != nil { 30 | response, _ := json.MarshalIndent(errorsApi, "", " ") 31 | os.Stdout.Write(response) 32 | } 33 | responseCreate, _ := json.MarshalIndent(create, "", " ") 34 | os.Stdout.Write(responseCreate) 35 | 36 | // Get a Card 37 | get, err, errorsApi := bankAccount.Get(url.Values{"id": {"15897336"}}, auth.Headers{}) 38 | if err != nil { 39 | response, _ := json.MarshalIndent(errorsApi, "", " ") 40 | os.Stdout.Write(response) 41 | } 42 | responseGet, _ := json.MarshalIndent(get, "", " ") 43 | os.Stdout.Write(responseGet) 44 | 45 | // Get a Balance Operation 46 | getall, err, errorsApi := bankAccount.GetAll(url.Values{}, auth.Headers{ 47 | "page": "1", 48 | "count": "10", 49 | }) 50 | if err != nil { 51 | response, _ := json.MarshalIndent(errorsApi, "", " ") 52 | os.Stdout.Write(response) 53 | } 54 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 55 | os.Stdout.Write(responseGetAll) 56 | } 57 | -------------------------------------------------------------------------------- /examples/card/card.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/card" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var creditCard card.Card 16 | 17 | func main() { 18 | 19 | // Create a Card with card hash 20 | data := []byte(`{ 21 | "card_hash": "your_card_hash" 22 | }`) 23 | create, err, errorsApi := creditCard.Create(data, url.Values{}, auth.Headers{}) 24 | if err != nil { 25 | response, _ := json.MarshalIndent(errorsApi, "", " ") 26 | os.Stdout.Write(response) 27 | } else { 28 | responseCreate, _ := json.MarshalIndent(create, "", " ") 29 | os.Stdout.Write(responseCreate) 30 | } 31 | 32 | // Create a Card 33 | data2 := []byte(`{ 34 | "card_number": "4242424242424242", 35 | "card_holder_name": "Marcos Mendes Teste API Create", 36 | "card_expiration_date": "1018" 37 | }`) 38 | create2, err, errorsApi := creditCard.Create(data2, url.Values{}, auth.Headers{}) 39 | if err != nil { 40 | response, _ := json.MarshalIndent(errorsApi, "", " ") 41 | os.Stdout.Write(response) 42 | } else { 43 | responseCreate2, _ := json.MarshalIndent(create2, "", " ") 44 | os.Stdout.Write(responseCreate2) 45 | } 46 | 47 | // Get a Card 48 | 49 | get, err, errorsApi := creditCard.Get(url.Values{ 50 | "id": {"card_cisb66pu000po4x6ez7hbim8s"}, 51 | }, auth.Headers{}) 52 | if err != nil { 53 | response, _ := json.MarshalIndent(errorsApi, "", " ") 54 | os.Stdout.Write(response) 55 | } else { 56 | responseGet, _ := json.MarshalIndent(get, "", " ") 57 | os.Stdout.Write(responseGet) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/customer/customer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/customer" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var customerRecord customer.Customer 16 | 17 | func main() { 18 | data := []byte(`{ 19 | "name":"Name", 20 | "email":"example@example.com", 21 | "document_number":"80802694594", 22 | "gender":"M", 23 | "born_at":"09-22-2015", 24 | "address": { 25 | "street":"Rua de exemplo", 26 | "street_number":"808", 27 | "neighborhood":"Bairro de exemplo", 28 | "complementary":"Apartamento 8", 29 | "city":"Cidade", 30 | "state":"Lordaeron", 31 | "zipcode":"80808080", 32 | "country":"Lordaeron" 33 | }, 34 | "phone": { 35 | "ddi":"88", 36 | "ddd":"88", 37 | "number":"808080808" 38 | } 39 | }`) 40 | create, err, errorsApi := customerRecord.Create(data, url.Values{}, auth.Headers{}) 41 | if err != nil { 42 | response, _ := json.MarshalIndent(errorsApi, "", " ") 43 | os.Stdout.Write(response) 44 | } else { 45 | responseCreate, _ := json.MarshalIndent(create, "", " ") 46 | os.Stdout.Write(responseCreate) 47 | } 48 | 49 | get, err, errorsApi := customerRecord.Get(url.Values{"id": {"90456"}}, auth.Headers{}) 50 | if err != nil { 51 | response, _ := json.MarshalIndent(errorsApi, "", " ") 52 | os.Stdout.Write(response) 53 | } else { 54 | responseGet, _ := json.MarshalIndent(get, "", " ") 55 | os.Stdout.Write(responseGet) 56 | } 57 | 58 | getall, err, errorsApi := customerRecord.GetAll(url.Values{}, auth.Headers{ 59 | "page": "1", 60 | "count": "10", 61 | }) 62 | if err != nil { 63 | response, _ := json.MarshalIndent(errorsApi, "", " ") 64 | os.Stdout.Write(response) 65 | } else { 66 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 67 | os.Stdout.Write(responseGetAll) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /examples/payable/payable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/recipient" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var payableRecord recipient.Recipient 16 | 17 | func main() { 18 | get, err, errorsApi := payableRecord.Get(url.Values{"id": {"25786"}}, auth.Headers{}) 19 | if err != nil { 20 | response, _ := json.MarshalIndent(errorsApi, "", " ") 21 | os.Stdout.Write(response) 22 | } else { 23 | responseGet, _ := json.MarshalIndent(get, "", " ") 24 | os.Stdout.Write(responseGet) 25 | } 26 | 27 | getall, err, errorsApi := payableRecord.GetAll(url.Values{}, auth.Headers{ 28 | "page": "1", 29 | "count": "10", 30 | }) 31 | if err != nil { 32 | response, _ := json.MarshalIndent(errorsApi, "", " ") 33 | os.Stdout.Write(response) 34 | } else { 35 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 36 | os.Stdout.Write(responseGetAll) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/plan/plan.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/plan" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var planRecord plan.Plan 16 | 17 | func main() { 18 | // Criando um plano 19 | data := []byte(`{ 20 | "amount": "100", 21 | "days": "30", 22 | "name": "Plano de teste de 14 dias", 23 | "payment_methods": [ 24 | "credit_card" 25 | ], 26 | "trial_days": "14" 27 | }`) 28 | create, err, errorsApi := planRecord.Create(data, url.Values{}, auth.Headers{}) 29 | if err != nil { 30 | response, _ := json.MarshalIndent(errorsApi, "", " ") 31 | os.Stdout.Write(response) 32 | } else { 33 | responseCreate, _ := json.MarshalIndent(create, "", " ") 34 | os.Stdout.Write(responseCreate) 35 | } 36 | 37 | // Criando um plano anual válido por 3 anos com boleto 38 | data2 := []byte(`{ 39 | "amount":"8000", 40 | "days": 365, 41 | "name": "Plano de três anos", 42 | "payment_methods": [ 43 | "boleto" 44 | ], 45 | "installments": 1, 46 | "charges": 3 47 | }`) 48 | create2, err, errorsApi := planRecord.Create(data2, url.Values{}, auth.Headers{}) 49 | if err != nil { 50 | response, _ := json.MarshalIndent(errorsApi, "", " ") 51 | os.Stdout.Write(response) 52 | } else { 53 | responseCreate2, _ := json.MarshalIndent(create2, "", " ") 54 | os.Stdout.Write(responseCreate2) 55 | } 56 | 57 | // Criando um plano anual parcelado válido por 3 anos com boleto 58 | data3 := []byte(`{ 59 | "amount":"8000", 60 | "days": 365, 61 | "name": "Plano Anual Parcelado por três anos com boleto", 62 | "payment_methods": [ 63 | "boleto" 64 | ], 65 | "installments": 12, 66 | "charges": 3 67 | }`) 68 | create3, err, errorsApi := planRecord.Create(data3, url.Values{}, auth.Headers{}) 69 | if err != nil { 70 | response, _ := json.MarshalIndent(errorsApi, "", " ") 71 | os.Stdout.Write(response) 72 | } else { 73 | responseCreate3, _ := json.MarshalIndent(create3, "", " ") 74 | os.Stdout.Write(responseCreate3) 75 | } 76 | 77 | get, err, errorsApi := planRecord.Get(url.Values{"id": {"62535"}}, auth.Headers{}) 78 | if err != nil { 79 | response, _ := json.MarshalIndent(errorsApi, "", " ") 80 | os.Stdout.Write(response) 81 | } else { 82 | responseGet, _ := json.MarshalIndent(get, "", " ") 83 | os.Stdout.Write(responseGet) 84 | } 85 | 86 | getall, err, errorsApi := planRecord.GetAll(url.Values{}, auth.Headers{ 87 | "page": "1", 88 | "count": "10", 89 | }) 90 | if err != nil { 91 | response, _ := json.MarshalIndent(errorsApi, "", " ") 92 | os.Stdout.Write(response) 93 | } else { 94 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 95 | os.Stdout.Write(responseGetAll) 96 | } 97 | 98 | // Atualizando um plano 99 | data4 := []byte(`{ 100 | "name": "Plano de Teste de Teste", 101 | "trial_days": "8" 102 | }`) 103 | update, err, errorsApi := planRecord.Update(data4, url.Values{"id": {"40648"}}, auth.Headers{}) 104 | if err != nil { 105 | response, _ := json.MarshalIndent(errorsApi, "", " ") 106 | os.Stdout.Write(response) 107 | } else { 108 | responseUpdate, _ := json.MarshalIndent(update, "", " ") 109 | os.Stdout.Write(responseUpdate) 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /examples/recipient/balance/balance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/recipient/balance" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var balanceRecipient balance.BalanceRecipient 16 | 17 | func main() { 18 | // Get a Balance Amount 19 | get, err, errorsApi := balanceRecipient.Get(url.Values{"id": {"re_ciflm3dq9008r116ds3o8afvt"}}, auth.Headers{}) 20 | if err != nil { 21 | response, _ := json.MarshalIndent(errorsApi, "", " ") 22 | os.Stdout.Write(response) 23 | } else { 24 | responseGet, _ := json.MarshalIndent(get, "", " ") 25 | os.Stdout.Write(responseGet) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/recipient/balance/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/recipient/balance/operation" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var balanceRecipient operation.OperationRecipient 16 | 17 | func main() { 18 | // Get a Balance Amount 19 | get, err, errorsApi := balanceRecipient.Get(url.Values{ 20 | "id_recipient": {"re_ciflm3dq9008r116ds3o8afvt"}, 21 | "id_operation": {"10"}, 22 | }, auth.Headers{}) 23 | if err != nil { 24 | response, _ := json.MarshalIndent(errorsApi, "", " ") 25 | os.Stdout.Write(response) 26 | } else { 27 | responseGet, _ := json.MarshalIndent(get, "", " ") 28 | os.Stdout.Write(responseGet) 29 | } 30 | 31 | getAll, err, errorsApi := balanceRecipient.GetAll(url.Values{ 32 | "id_recipient": {"re_ciflm3dq9008r116ds3o8afvt"}, 33 | }, auth.Headers{ 34 | "page": "1", 35 | "count": "10", 36 | }) 37 | if err != nil { 38 | response, _ := json.MarshalIndent(errorsApi, "", " ") 39 | os.Stdout.Write(response) 40 | } else { 41 | responseGetAll, _ := json.MarshalIndent(getAll, "", " ") 42 | os.Stdout.Write(responseGetAll) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/recipient/recipient.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/recipient" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var recipientRecord recipient.Recipient 16 | 17 | func main() { 18 | // Criando um recebedor com uma conta bancária existente 19 | data := []byte(`{ 20 | "transfer_interval":"monthly", 21 | "transfer_day": 8, 22 | "transfer_enabled": true, 23 | "bank_account_id": 15897336 24 | }`) 25 | create, err, errorsApi := recipientRecord.Create(data, url.Values{}, auth.Headers{}) 26 | if err != nil { 27 | response, _ := json.MarshalIndent(errorsApi, "", " ") 28 | os.Stdout.Write(response) 29 | } else { 30 | responseCreate, _ := json.MarshalIndent(create, "", " ") 31 | os.Stdout.Write(responseCreate) 32 | } 33 | 34 | // Criando um recebedor com antecipação automática 35 | data2 := []byte(`{ 36 | "transfer_interval":"monthly", 37 | "transfer_day": 8, 38 | "transfer_enabled": true, 39 | "bank_account_id": 15897336, 40 | "automatic_anticipation_enabled": true, 41 | "anticipatable_volume_percentage": 88 42 | }`) 43 | create2, err, errorsApi := recipientRecord.Create(data2, url.Values{}, auth.Headers{}) 44 | if err != nil { 45 | response, _ := json.MarshalIndent(errorsApi, "", " ") 46 | os.Stdout.Write(response) 47 | } else { 48 | responseCreate2, _ := json.MarshalIndent(create2, "", " ") 49 | os.Stdout.Write(responseCreate2) 50 | } 51 | 52 | // Criando um recebedor com uma conta bancária nova 53 | data3 := []byte(`{ 54 | "transfer_interval":"weekly", 55 | "transfer_day": 1, 56 | "transfer_enabled": true, 57 | "bank_account": { 58 | "bank_code":"184", 59 | "agencia":"8", 60 | "conta":"08808", 61 | "conta_dv":"8", 62 | "document_number":"80802694594", 63 | "legal_name":"Lucas Alves" 64 | } 65 | }`) 66 | create3, err, errorsApi := recipientRecord.Create(data3, url.Values{}, auth.Headers{}) 67 | if err != nil { 68 | response, _ := json.MarshalIndent(errorsApi, "", " ") 69 | os.Stdout.Write(response) 70 | } else { 71 | responseCreate3, _ := json.MarshalIndent(create3, "", " ") 72 | os.Stdout.Write(responseCreate3) 73 | } 74 | 75 | // Retornando o saldo de um recebedor 76 | get, err, errorsApi := recipientRecord.Get(url.Values{"id": {"re_cishgtigt012zv86e859ajse4"}}, auth.Headers{}) 77 | if err != nil { 78 | response, _ := json.MarshalIndent(errorsApi, "", " ") 79 | os.Stdout.Write(response) 80 | } else { 81 | responseGet, _ := json.MarshalIndent(get, "", " ") 82 | os.Stdout.Write(responseGet) 83 | } 84 | 85 | getall, err, errorsApi := recipientRecord.GetAll(url.Values{}, auth.Headers{ 86 | "page": "1", 87 | "count": "10", 88 | }) 89 | if err != nil { 90 | response, _ := json.MarshalIndent(errorsApi, "", " ") 91 | os.Stdout.Write(response) 92 | } else { 93 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 94 | os.Stdout.Write(responseGetAll) 95 | } 96 | 97 | // Atualizando um recebedor com uma outra conta bancária existente 98 | data4 := []byte(`{ 99 | "bank_account_id": 6626431 100 | }`) 101 | update, err, errorsApi := recipientRecord.Update(data4, url.Values{"id": {"re_ciflm3dq9008r116ds3o8afvt"}}, auth.Headers{}) 102 | if err != nil { 103 | response, _ := json.MarshalIndent(errorsApi, "", " ") 104 | os.Stdout.Write(response) 105 | } else { 106 | responseUpdate, _ := json.MarshalIndent(update, "", " ") 107 | os.Stdout.Write(responseUpdate) 108 | } 109 | 110 | // Atualizando um recebedor para usar antecipação automática 111 | data5 := []byte(`{ 112 | "automatic_anticipation_enabled": true, 113 | "anticipatable_volume_percentage": 40 114 | }`) 115 | update2, err, errorsApi := recipientRecord.Update(data5, url.Values{"id": {"re_ciflm3dq9008r116ds3o8afvt"}}, auth.Headers{}) 116 | if err != nil { 117 | response, _ := json.MarshalIndent(errorsApi, "", " ") 118 | os.Stdout.Write(response) 119 | } else { 120 | responseUpdate2, _ := json.MarshalIndent(update2, "", " ") 121 | os.Stdout.Write(responseUpdate2) 122 | } 123 | 124 | // Atualizando um recebedor com novo dia para transferência 125 | data6 := []byte(`{ 126 | "transfer_day": 5, 127 | "transfer_interval": "weekly" 128 | }`) 129 | update3, err, errorsApi := recipientRecord.Update(data6, url.Values{"id": {"re_ciflm3dq9008r116ds3o8afvt"}}, auth.Headers{}) 130 | if err != nil { 131 | response, _ := json.MarshalIndent(errorsApi, "", " ") 132 | os.Stdout.Write(response) 133 | } else { 134 | responseUpdate3, _ := json.MarshalIndent(update3, "", " ") 135 | os.Stdout.Write(responseUpdate3) 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /examples/search/search.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/search" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var searchRecord search.Search 16 | 17 | func main() { 18 | get, err, errorsApi := searchRecord.Get(url.Values{}, auth.Headers{ 19 | "type": "transaction", 20 | "query": `{ 21 | "query": { 22 | "filtered": { 23 | "query": {"match_all": {}}, 24 | "filter": { 25 | "and": [ 26 | { 27 | "range": { 28 | "date_created": { 29 | "lte": "2016-01-31" 30 | } 31 | } 32 | }, 33 | { 34 | "or": [ 35 | {"term": {"status": "waiting_payment"}}, 36 | {"term": {"status": "paid"}} 37 | ] 38 | } 39 | ] 40 | } 41 | } 42 | }, 43 | "sort": [ 44 | { 45 | "date_created": {"order": "desc"} 46 | } 47 | ], 48 | "size": 5, 49 | "from": 0 50 | }`, 51 | }) 52 | if err != nil { 53 | response, _ := json.MarshalIndent(errorsApi, "", " ") 54 | os.Stdout.Write(response) 55 | } else { 56 | responseGet, _ := json.MarshalIndent(get, "", " ") 57 | os.Stdout.Write(responseGet) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/subscription/subscription.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/subscription" 11 | subscriptionEvent "github.com/luk4z7/pagarme-go/lib/subscription/event" 12 | subscriptionTransaction "github.com/luk4z7/pagarme-go/lib/subscription/transaction" 13 | "net/url" 14 | "os" 15 | ) 16 | 17 | var subscriptionRecord subscription.Subscription 18 | 19 | var subscriptionTransactions subscriptionTransaction.SubscriptionTransaction 20 | 21 | var subscriptionEvents subscriptionEvent.SubscriptionEvent 22 | 23 | func main() { 24 | // Criando uma subscription 25 | data := []byte(`{ 26 | "customer": { 27 | "email": "api@test.com" 28 | }, 29 | "plan_id": "62535", 30 | "card_id": "card_cisp3at4s00fowm6egw1kgit1", 31 | "postback_url": "http://requestb.in/zyn5obzy", 32 | "payment_method": "boleto" 33 | }`) 34 | create, err, errorsApi := subscriptionRecord.Create(data, url.Values{}, auth.Headers{}) 35 | if err != nil { 36 | response, _ := json.MarshalIndent(errorsApi, "", " ") 37 | os.Stdout.Write(response) 38 | } else { 39 | responseCreate, _ := json.MarshalIndent(create, "", " ") 40 | os.Stdout.Write(responseCreate) 41 | } 42 | 43 | // Retornando uma assinatura 44 | get, err, errorsApi := subscriptionRecord.Get(url.Values{"id": {"99815"}}, auth.Headers{}) 45 | if err != nil { 46 | response, _ := json.MarshalIndent(errorsApi, "", " ") 47 | os.Stdout.Write(response) 48 | } else { 49 | responseGet, _ := json.MarshalIndent(get, "", " ") 50 | os.Stdout.Write(responseGet) 51 | } 52 | 53 | // Retornando todas as assinaturas 54 | getall, err, errorsApi := subscriptionRecord.GetAll(url.Values{}, auth.Headers{ 55 | "page": "1", 56 | "count": "10", 57 | }) 58 | if err != nil { 59 | response, _ := json.MarshalIndent(errorsApi, "", " ") 60 | os.Stdout.Write(response) 61 | } else { 62 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 63 | os.Stdout.Write(responseGetAll) 64 | } 65 | 66 | // Atualizando um recebedor com uma outra conta bancária existente 67 | data4 := []byte(`{ 68 | "plan_id": "62544", 69 | "card_id": "card_cisp3at4s00fowm6egw1kgit1" 70 | }`) 71 | update, err, errorsApi := subscriptionRecord.Update(data4, url.Values{"id": {"99815"}}, auth.Headers{}) 72 | if err != nil { 73 | response, _ := json.MarshalIndent(errorsApi, "", " ") 74 | os.Stdout.Write(response) 75 | } else { 76 | responseUpdate, _ := json.MarshalIndent(update, "", " ") 77 | os.Stdout.Write(responseUpdate) 78 | } 79 | 80 | // Cancelando uma assinatura 81 | cancel, err, errorsApi := subscriptionRecord.Cancel(url.Values{ 82 | "id": {"99815"}, 83 | }, auth.Headers{}) 84 | if err != nil { 85 | response, _ := json.MarshalIndent(errorsApi, "", " ") 86 | os.Stdout.Write(response) 87 | } else { 88 | responseCancel, _ := json.MarshalIndent(cancel, "", " ") 89 | os.Stdout.Write(responseCancel) 90 | } 91 | 92 | // Transações de uma assinatura 93 | getTransactions, err, errorsApi := subscriptionTransactions.Get(url.Values{ 94 | "id": {"99815"}, 95 | }, auth.Headers{}) 96 | if err != nil { 97 | response, _ := json.MarshalIndent(errorsApi, "", " ") 98 | os.Stdout.Write(response) 99 | } else { 100 | responseTransactions, _ := json.MarshalIndent(getTransactions, "", " ") 101 | os.Stdout.Write(responseTransactions) 102 | } 103 | 104 | // Retornar um evento de uma assinatura 105 | getEvent, err, errorsApi := subscriptionEvents.Get(url.Values{ 106 | "subscription_id": {"99815"}, 107 | "id": {"99815"}, 108 | }, auth.Headers{}) 109 | if err != nil { 110 | response, _ := json.MarshalIndent(errorsApi, "", " ") 111 | os.Stdout.Write(response) 112 | } else { 113 | responseGetEvent, _ := json.MarshalIndent(getEvent, "", " ") 114 | os.Stdout.Write(responseGetEvent) 115 | } 116 | 117 | // Retornar todos os eventos de uma assinatura 118 | getallEvents, err, errorsApi := subscriptionEvents.GetAll(url.Values{ 119 | "subscription_id": {"99815"}, 120 | }, auth.Headers{}) 121 | if err != nil { 122 | response, _ := json.MarshalIndent(errorsApi, "", " ") 123 | os.Stdout.Write(response) 124 | } else { 125 | responseGetAllEvents, _ := json.MarshalIndent(getallEvents, "", " ") 126 | os.Stdout.Write(responseGetAllEvents) 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /examples/transaction/antifraudanalysis/antifraudanalysis.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/antifraudanalysis" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionAntifraudAnalysis antifraudanalysis.AntifraudAnalysis 16 | 17 | func main() { 18 | get, err, errorsApi := transactionAntifraudAnalysis.Get(url.Values{ 19 | "transaction_id": {"314578"}, 20 | "id": {"189164"}, 21 | }, auth.Headers{}) 22 | if err != nil { 23 | response, _ := json.MarshalIndent(errorsApi, "", " ") 24 | os.Stdout.Write(response) 25 | } else { 26 | responseGet, _ := json.MarshalIndent(get, "", " ") 27 | os.Stdout.Write(responseGet) 28 | } 29 | 30 | getall, err, errorsApi := transactionAntifraudAnalysis.GetAll(url.Values{"transaction_id": {"314578"}}, auth.Headers{}) 31 | if err != nil { 32 | response, _ := json.MarshalIndent(errorsApi, "", " ") 33 | os.Stdout.Write(response) 34 | } else { 35 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 36 | os.Stdout.Write(responseGetAll) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/transaction/capture/capture.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/capture" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionCapture capture.Capture 16 | 17 | func main() { 18 | data := []byte(`{"email": "seu@email.com"}`) 19 | create, err, errorsApi := transactionCapture.Create(data, url.Values{"transaction_id": {"700975"}}, auth.Headers{}) 20 | if err != nil { 21 | response, _ := json.MarshalIndent(errorsApi, "", " ") 22 | os.Stdout.Write(response) 23 | } else { 24 | responseCreate, _ := json.MarshalIndent(create, "", " ") 25 | os.Stdout.Write(responseCreate) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/transaction/cardhashkey/cardhashkey.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/cardhashkey" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionCardHashKey cardhashkey.CardHashKey 16 | 17 | func main() { 18 | get, err, errorsApi := transactionCardHashKey.Get(url.Values{}, auth.Headers{ 19 | "encryption_key": "ek_test_XZUwx9tUMr0l2GL1H6XjIsnc8X5nYg", 20 | }) 21 | if err != nil { 22 | response, _ := json.MarshalIndent(errorsApi, "", " ") 23 | os.Stdout.Write(response) 24 | } else { 25 | responseGet, _ := json.MarshalIndent(get, "", " ") 26 | os.Stdout.Write(responseGet) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/transaction/collectpayment/collectpayment.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/collectpayment" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionCollectPayment collectpayment.CollectPayment 16 | 17 | func main() { 18 | data := []byte(`{"email": "seu@email.com"}`) 19 | create, err, errorsApi := transactionCollectPayment.Create(data, url.Values{"transaction_id": {"700975"}}, auth.Headers{}) 20 | if err != nil { 21 | response, _ := json.MarshalIndent(errorsApi, "", " ") 22 | os.Stdout.Write(response) 23 | } else { 24 | responseCreate, _ := json.MarshalIndent(create, "", " ") 25 | os.Stdout.Write(responseCreate) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/transaction/event/event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/event" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionEvent event.TransactionEvent 16 | 17 | func main() { 18 | getall, err, errorsApi := transactionEvent.GetAll(url.Values{"transaction_id": {"683688"}}, auth.Headers{}) 19 | if err != nil { 20 | response, _ := json.MarshalIndent(errorsApi, "", " ") 21 | os.Stdout.Write(response) 22 | } else { 23 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 24 | os.Stdout.Write(responseGetAll) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/transaction/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/operation" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionOperation operation.TransactionOperation 16 | 17 | func main() { 18 | get, err, errorsApi := transactionOperation.Get(url.Values{ 19 | "transaction_id": {"683688"}, 20 | "id": {"go_cioau9den01nr633s9hlg8t9y"}, 21 | }, auth.Headers{}) 22 | if err != nil { 23 | response, _ := json.MarshalIndent(errorsApi, "", " ") 24 | os.Stdout.Write(response) 25 | } else { 26 | responseGet, _ := json.MarshalIndent(get, "", " ") 27 | os.Stdout.Write(responseGet) 28 | } 29 | 30 | getall, err, errorsApi := transactionOperation.GetAll(url.Values{"transaction_id": {"683688"}}, auth.Headers{}) 31 | if err != nil { 32 | response, _ := json.MarshalIndent(errorsApi, "", " ") 33 | os.Stdout.Write(response) 34 | } else { 35 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 36 | os.Stdout.Write(responseGetAll) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/transaction/payable/payable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/payable" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionPayable payable.TransactionPayable 16 | 17 | func main() { 18 | get, err, errorsApi := transactionPayable.Get(url.Values{ 19 | "transaction_id": {"192669"}, 20 | "id": {"1485"}, 21 | }, auth.Headers{}) 22 | if err != nil { 23 | response, _ := json.MarshalIndent(errorsApi, "", " ") 24 | os.Stdout.Write(response) 25 | } else { 26 | responseGet, _ := json.MarshalIndent(get, "", " ") 27 | os.Stdout.Write(responseGet) 28 | } 29 | 30 | getall, err, errorsApi := transactionPayable.GetAll(url.Values{"transaction_id": {"192669"}}, auth.Headers{}) 31 | if err != nil { 32 | response, _ := json.MarshalIndent(errorsApi, "", " ") 33 | os.Stdout.Write(response) 34 | } else { 35 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 36 | os.Stdout.Write(responseGetAll) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/transaction/postback/postback.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/postback" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionPostback postback.TransactionPostback 16 | 17 | func main() { 18 | get, err, errorsApi := transactionPostback.Get(url.Values{ 19 | "transaction_id": {"700975"}, 20 | "id": {"po_cissza9lk05h49r73lf4uww2z"}, 21 | }, auth.Headers{}) 22 | if err != nil { 23 | response, _ := json.MarshalIndent(errorsApi, "", " ") 24 | os.Stdout.Write(response) 25 | } else { 26 | responseGet, _ := json.MarshalIndent(get, "", " ") 27 | os.Stdout.Write(responseGet) 28 | } 29 | 30 | getall, err, errorsApi := transactionPostback.GetAll(url.Values{"transaction_id": {"700975"}}, auth.Headers{}) 31 | if err != nil { 32 | response, _ := json.MarshalIndent(errorsApi, "", " ") 33 | os.Stdout.Write(response) 34 | } else { 35 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 36 | os.Stdout.Write(responseGetAll) 37 | } 38 | 39 | // Reenviar um POSTback de uma transação 40 | redeliver, err, errorsApi := transactionPostback.Redeliver(url.Values{ 41 | "transaction_id": {"700975"}, 42 | "id": {"po_cissza9lk05h49r73lf4uww2z"}, 43 | }, auth.Headers{}) 44 | if err != nil { 45 | response, _ := json.MarshalIndent(errorsApi, "", " ") 46 | os.Stdout.Write(response) 47 | } else { 48 | responseRedeliver, _ := json.MarshalIndent(redeliver, "", " ") 49 | os.Stdout.Write(responseRedeliver) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/transaction/splitrule/splitrule.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction/splitrule" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var splitruleRecord splitrule.SplitRule 16 | 17 | func main() { 18 | get, err, errorsApi := splitruleRecord.Get(url.Values{ 19 | "transaction_id": {"0808"}, 20 | "id": {"184"}, 21 | }, auth.Headers{}) 22 | if err != nil { 23 | response, _ := json.MarshalIndent(errorsApi, "", " ") 24 | os.Stdout.Write(response) 25 | } else { 26 | responseGet, _ := json.MarshalIndent(get, "", " ") 27 | os.Stdout.Write(responseGet) 28 | } 29 | 30 | getall, err, errorsApi := splitruleRecord.GetAll(url.Values{"transaction_id": {"0808"}}, auth.Headers{}) 31 | if err != nil { 32 | response, _ := json.MarshalIndent(errorsApi, "", " ") 33 | os.Stdout.Write(response) 34 | } else { 35 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 36 | os.Stdout.Write(responseGetAll) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/transaction/transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transaction" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transactionRecord transaction.Transaction 16 | 17 | func main() { 18 | // Create 19 | data := []byte(`{ 20 | "amount": 100, 21 | "card_id": "card_cisb66pu000po4x6ez7hbim8s", 22 | "customer": { 23 | "name":"Name", 24 | "email":"example@example.com", 25 | "document_number":"80802694594", 26 | "gender":"M", 27 | "born_at":"09-22-2015", 28 | "address": { 29 | "street":"Rua de exemplo", 30 | "street_number":"808", 31 | "neighborhood":"Bairro de exemplo", 32 | "complementary":"Apartamento 8", 33 | "city":"Cidade", 34 | "state":"Lordaeron", 35 | "zipcode":"47850000", 36 | "country":"Lordaeron" 37 | }, 38 | "phone": { 39 | "ddi":"88", 40 | "ddd":"88", 41 | "number":"808080808" 42 | } 43 | }, 44 | "postback_url": "http://requestb.in/pkt7pgpk", 45 | "metadata": { 46 | "idProduto": "10" 47 | } 48 | }`) 49 | create, err, errorsApi := transactionRecord.Create(data, url.Values{}, auth.Headers{}) 50 | if err != nil { 51 | response, _ := json.MarshalIndent(errorsApi, "", " ") 52 | os.Stdout.Write(response) 53 | } else { 54 | responseCreate, _ := json.MarshalIndent(create, "", " ") 55 | os.Stdout.Write(responseCreate) 56 | } 57 | 58 | // Retornando o saldo de um recebedor 59 | get, err, errorsApi := transactionRecord.Get(url.Values{"id": {"700636"}}, auth.Headers{}) 60 | if err != nil { 61 | response, _ := json.MarshalIndent(errorsApi, "", " ") 62 | os.Stdout.Write(response) 63 | } else { 64 | responseGet, _ := json.MarshalIndent(get, "", " ") 65 | os.Stdout.Write(responseGet) 66 | } 67 | 68 | // Retornando todas as transações com paginação 69 | getall, err, errorsApi := transactionRecord.GetAll(url.Values{}, auth.Headers{ 70 | "page": "1", 71 | "count": "10", 72 | }) 73 | if err != nil { 74 | response, _ := json.MarshalIndent(errorsApi, "", " ") 75 | os.Stdout.Write(response) 76 | } else { 77 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 78 | os.Stdout.Write(responseGetAll) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /examples/transfer/transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/json" 9 | "github.com/luk4z7/pagarme-go/auth" 10 | "github.com/luk4z7/pagarme-go/lib/transfer" 11 | "net/url" 12 | "os" 13 | ) 14 | 15 | var transferRecord transfer.Transfer 16 | 17 | func main() { 18 | // Criando uma transferência a partir de um recebedor específico 19 | data := []byte(`{ 20 | "amount":"100", 21 | "bank_account_id": "15897336", 22 | "recipient_id": "re_cisv78zak000rbp6dx6rvyp6v" 23 | }`) 24 | create, err, errorsApi := transferRecord.Create(data, url.Values{}, auth.Headers{}) 25 | if err != nil { 26 | response, _ := json.MarshalIndent(errorsApi, "", " ") 27 | os.Stdout.Write(response) 28 | } else { 29 | responseCreate, _ := json.MarshalIndent(create, "", " ") 30 | os.Stdout.Write(responseCreate) 31 | } 32 | 33 | // Criando uma transferência a partir do recebedor padrão 34 | data2 := []byte(`{ 35 | "amount":"13000", 36 | "source_id": "re_cisv78zak000rbp6dx6rvyp6v", 37 | "target_id": "re_cisv78zak000rbp6dx6rvyp6v" 38 | }`) 39 | create2, err, errorsApi := transferRecord.Create(data2, url.Values{}, auth.Headers{}) 40 | if err != nil { 41 | response, _ := json.MarshalIndent(errorsApi, "", " ") 42 | os.Stdout.Write(response) 43 | } else { 44 | responseCreate2, _ := json.MarshalIndent(create2, "", " ") 45 | os.Stdout.Write(responseCreate2) 46 | } 47 | 48 | // Retornando uma transferência 49 | get, err, errorsApi := transferRecord.Get(url.Values{"id": {"7118"}}, auth.Headers{}) 50 | if err != nil { 51 | response, _ := json.MarshalIndent(errorsApi, "", " ") 52 | os.Stdout.Write(response) 53 | } else { 54 | responseGet, _ := json.MarshalIndent(get, "", " ") 55 | os.Stdout.Write(responseGet) 56 | } 57 | 58 | // Retornando todas as transferências 59 | getall, err, errorsApi := transferRecord.GetAll(url.Values{}, auth.Headers{ 60 | "page": "1", 61 | "count": "10", 62 | }) 63 | if err != nil { 64 | response, _ := json.MarshalIndent(errorsApi, "", " ") 65 | os.Stdout.Write(response) 66 | } else { 67 | responseGetAll, _ := json.MarshalIndent(getall, "", " ") 68 | os.Stdout.Write(responseGetAll) 69 | } 70 | 71 | // Cancelando uma transferência 72 | cancel, err, errorsApi := transferRecord.Cancel(url.Values{ 73 | "id": {"7118"}, 74 | }, auth.Headers{}) 75 | if err != nil { 76 | response, _ := json.MarshalIndent(errorsApi, "", " ") 77 | os.Stdout.Write(response) 78 | } else { 79 | responseCancel, _ := json.MarshalIndent(cancel, "", " ") 80 | os.Stdout.Write(responseCancel) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /lib/balance/balance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package balance 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | ) 13 | 14 | var repositoryBalance repository.Repository 15 | 16 | const ( 17 | endPoint = "https://api.pagar.me/1/balance" 18 | ) 19 | 20 | // amount Valor em centavos que você tem disponível em sua conta Pagar.me 21 | // object Nome do tipo do objeto criado/modificado. 22 | // amount Valor em centavos que você já transferiu para sua conta bancária (quanto já recebeu efetivamente) 23 | // amount Valor em centavos que você tem a receber do Pagar.me 24 | type BalanceAmount struct { 25 | Available int `json:"amount"` 26 | Object string `json:"object"` 27 | Transferred int `json:"amount"` 28 | WaitingFunds int `json:"amount"` 29 | } 30 | 31 | func (s *BalanceAmount) GetAll(p url.Values, h auth.Headers) (BalanceAmount, error, liberr.ErrorsAPI) { 32 | _, err, errApi := repositoryBalance.Get(url.Values{"route": {endPoint}}, s, h) 33 | return *s, err, errApi 34 | } 35 | -------------------------------------------------------------------------------- /lib/balance/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package operation 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryBalance repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/balance/operations" 19 | ) 20 | 21 | // amount Valor em centavos transacionado para a conta 22 | // date_created Data de criação da operação de saldo no formato ISODate 23 | // fee Valor em centavos que foi cobrado pela transação (taxa) 24 | // id Id da operação de saldo 25 | // movement_object Objeto da origem da operação de saldo 26 | // object Nome do tipo do objeto criado/modificado 27 | // status Estado do saldo da conta. Valores possíveis: waiting_funds, available e transferred 28 | // type Tipo de objeto que gerou a operação de saldo 29 | type BalanceOperation struct { 30 | Amount int `json:"amount"` 31 | DateCreated time.Time `json:"date_created"` 32 | Fee int `json:"fee"` 33 | Id int `json:"id"` 34 | BalanceMovement BalanceMovement `json:"movement_object"` 35 | Object string `json:"object"` 36 | Status string `json:"status"` 37 | Type string `json:"type"` 38 | } 39 | 40 | // amount Valor em centados do que foi pago 41 | // anticipation_fee Valor em centavos que foi cobrado pela antecipação (taxa) 42 | // bulk_anticipation_id 43 | // date_created Data de criação da operação no formato ISODate 44 | // fee Valor em centavos que foi cobrado pela transação (taxa) 45 | // id Id do recebível 46 | // installment Número da parcela 47 | // object Nome do tipo do objeto criado/modificado 48 | // original_payment_date Dia e hora da primeira data de pagamento no formato ISODate 49 | // payment_date Dia e hora do pagamento no formato ISODate 50 | // payment_method Forma de pagamento usada 51 | // recipient_id Id do recebedor ao qual esse recebível pertence 52 | // split_rule_id Id da regra de split, se houver alguma 53 | // status Estado atual do recebível. Valores possíveis: waiting_funds, paid e suspended 54 | // transaction_id Id da transação desse recebível 55 | // type Tipo do recebível. Valores possíveis: credit, refund, chargeback e chargeback_refund 56 | type BalanceMovement struct { 57 | Amount int `json:"amount"` 58 | AnticipationFee int `json:"anticipation_fee"` 59 | BulkAnticipationId int `json:"bulk_anticipation_id"` 60 | DateCreated time.Time `json:"date_created"` 61 | Fee int `json:"fee"` 62 | Id int `json:"id"` 63 | Installment int `json:"installment"` 64 | Object string `json:"object"` 65 | OriginalPaymentDate string `json:"original_payment_date"` 66 | PaymentDate time.Time `json:"payment_date"` 67 | PaymentMethod string `json:"payment_method"` 68 | RecipientId string `json:"recipient_id"` 69 | SplitRuleId string `json:"split_rule_id"` 70 | Status string `json:"status"` 71 | TransactionId int `json:"transaction_id"` 72 | Type string `json:"type"` 73 | } 74 | 75 | func (s *BalanceOperation) Get(p url.Values, h auth.Headers) (BalanceOperation, error, liberr.ErrorsAPI) { 76 | route := endPoint + "/" + p.Get("id") 77 | _, err, errApi := repositoryBalance.Get(url.Values{"route": {route}}, s, h) 78 | return *s, err, errApi 79 | } 80 | 81 | func (s *BalanceOperation) GetAll(p url.Values, h auth.Headers) ([]*BalanceOperation, error, liberr.ErrorsAPI) { 82 | res := []*BalanceOperation{} 83 | _, err, errApi := repositoryBalance.Get(url.Values{"route": {endPoint}}, res, h) 84 | return res, err, errApi 85 | } 86 | -------------------------------------------------------------------------------- /lib/bank/account.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bank 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryBank repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/bank_accounts" 19 | ) 20 | 21 | type Account struct { 22 | Agencia string `json:"agencia"` // Agência bancária 23 | AgenciaDv string `json:"agencia_dv"` // Dígito verificador da agência bancária 24 | BankCode string `json:"bank_code"` // Código do banco 25 | Conta string `json:"conta"` // Número da conta bancária 26 | ContaDv string `json:"conta_dv"` // Dígito verificador da conta bancária 27 | DateCreated time.Time `json:"date_created"` // Data de criação da conta no formato ISODate 28 | DocumentNumber string `json:"document_number"` // Documento identificador do titular da conta (CPF ou CNPJ) 29 | DocumentType string `json:"document_type"` // Tipo do documento identificador do titular da conta 30 | Id int `json:"id"` // Id da conta bancária 31 | LegalName string `json:"legal_name"` // Nome completo (se pessoa física) ou razão social (se pessoa jurídica) 32 | Object string `json:"object"` // Nome do tipo do objeto criado/modificado 33 | } 34 | 35 | func (s *Account) Create(d []byte, p url.Values, h auth.Headers) (Account, error, liberr.ErrorsAPI) { 36 | _, err, errApi := repositoryBank.Create(url.Values{"route": {endPoint}}, d, s) 37 | return *s, err, errApi 38 | } 39 | 40 | func (s *Account) Get(p url.Values, h auth.Headers) (Account, error, liberr.ErrorsAPI) { 41 | route := endPoint + "/" + p.Get("id") 42 | _, err, errApi := repositoryBank.Get(url.Values{"route": {route}}, s, h) 43 | return *s, err, errApi 44 | } 45 | 46 | func (s *Account) GetAll(p url.Values, h auth.Headers) ([]Account, error, liberr.ErrorsAPI) { 47 | res := []Account{} 48 | _, err, errApi := repositoryBank.Get(url.Values{"route": {endPoint}}, &res, h) 49 | return res, err, errApi 50 | } 51 | -------------------------------------------------------------------------------- /lib/card/card.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package card 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryCard repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/cards" 19 | ) 20 | 21 | type Card struct { 22 | Brand string `json:"brand"` // Bandeira do cartão 23 | Country string `json:"country"` // País do cartão 24 | Customer string `json:"customer"` // Cliente associado ao cartão 25 | DateCreated time.Time `json:"date_created"` // Data de criação do cartão no formato ISODate 26 | DateUpdated time.Time `json:"date_updated"` // Data de atualização cartão no formato ISODate 27 | Fingerprint string `json:"fingerprint"` // Identificador do cartão na nossa base 28 | FirstDigits string `json:"first_digits"` // Primeiros digitos do cartão 29 | HolderName string `json:"holder_name"` // Nome do portador do cartão 30 | Id string `json:"id"` // Id do cartão 31 | LastDigits string `json:"last_digits"` // Últimos digitos do cartão 32 | Object string `json:"object"` // Nome do tipo do objeto criado/modificado. 33 | Valid bool `json:"valid"` // Indicador de cartão válido 34 | } 35 | 36 | func (s *Card) Create(d []byte, p url.Values, h auth.Headers) (Card, error, liberr.ErrorsAPI) { 37 | _, err, errApi := repositoryCard.Create(url.Values{"route": {endPoint}}, d, s) 38 | return *s, err, errApi 39 | } 40 | 41 | func (s *Card) Get(p url.Values, h auth.Headers) (Card, error, liberr.ErrorsAPI) { 42 | route := endPoint + "/" + p.Get("id") 43 | _, err, errApi := repositoryCard.Get(url.Values{"route": {route}}, s, h) 44 | return *s, err, errApi 45 | } 46 | -------------------------------------------------------------------------------- /lib/customer/customer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package customer 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryCustomer repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/customers" 19 | ) 20 | 21 | type Customer struct { 22 | Addresses []Addresses `json:"addresses"` // Lista de endereços do Customere 23 | BornAt string `json:"born_at"` // Data de nascimento do Customere no formato ISODate 24 | DateCreated time.Time `json:"date_created"` // Data de criação do Customere no formato ISODate 25 | DocumentNumber string `json:"document_number"` // Número do CPF ou CNPJ do Customere 26 | DocumentType string `json:"document_type"` // Tipo do documento do Customere 27 | Email string `json:"email"` // E-mail do Customere 28 | Gender string `json:"gender"` // Gênero do Customere 29 | Id int `json:"id"` // Id do Customere 30 | Name string `json:"name"` // Data de nascimento do Customere 31 | Object string `json:"object"` // Nome do tipo do objeto criado/modificado. 32 | Phones []Phones `json:"phones"` 33 | } 34 | 35 | type Addresses struct { 36 | City string `json:"city"` // Nome do objeto criado 37 | Complementary string `json:"complementary"` // Complemento do endereço do Customere 38 | Country string `json:"country"` // País do endereço do Customere 39 | Id int `json:"id"` // Id do endereço 40 | Neighborhood string `json:"neighborhood"` // Bairro do Customere 41 | Object string `json:"object"` // Nome do objeto criado 42 | State string `json:"state"` // Estado do endereço do Customere 43 | Street string `json:"street"` // Logradouro do Customere 44 | StreetNumber string `json:"street_number"` // Numero do endereço do Customere 45 | Zipcode string `json:"zipcode"` // CEP do Customere 46 | } 47 | 48 | type Phones struct { 49 | DDD string `json:"ddd"` // Numero do DDD do telefone 50 | DDI string `json:"ddi"` // Número do DDI do telefone 51 | Id int `json:"id"` // Id gerado pelo sistema para o telefone criado 52 | Number string `json:"number"` // Numero do telefone do Customere 53 | Object string `json:"object"` // Nome do objeto criado 54 | } 55 | 56 | func (s *Customer) Create(d []byte, p url.Values, h auth.Headers) (Customer, error, liberr.ErrorsAPI) { 57 | _, err, errApi := repositoryCustomer.Create(url.Values{"route": {endPoint}}, d, s) 58 | return *s, err, errApi 59 | } 60 | 61 | func (s *Customer) Get(p url.Values, h auth.Headers) (Customer, error, liberr.ErrorsAPI) { 62 | route := endPoint + "/" + p.Get("id") 63 | _, err, errApi := repositoryCustomer.Get(url.Values{"route": {route}}, s, h) 64 | return *s, err, errApi 65 | } 66 | 67 | func (s *Customer) GetAll(p url.Values, h auth.Headers) ([]Customer, error, liberr.ErrorsAPI) { 68 | res := []Customer{} 69 | _, err, errApi := repositoryCustomer.Get(url.Values{"route": {endPoint}}, &res, h) 70 | return res, err, errApi 71 | } 72 | -------------------------------------------------------------------------------- /lib/event/event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package event 6 | 7 | type Event struct { 8 | Id string `json:"id"` // Id do evento 9 | Model string `json:"model"` // Objeto associado a esse evento 10 | ModelId string `json:"model_id"` // Id do objeto associado a esse evento 11 | Name string `json:"name"` // Nome do evento 12 | Object string `json:"object"` // Nome do tipo do objeto criado/modificado 13 | Payload Payload `json:"payload"` // Objeto com status dos eventos 14 | } 15 | 16 | type Payload struct { 17 | CurrentStatus string `json:"current_status"` 18 | DesiredStatus string `json:"desired_status"` 19 | OldStatus string `json:"old_status"` 20 | } 21 | -------------------------------------------------------------------------------- /lib/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package operation 6 | 7 | import "time" 8 | 9 | // date_created Data de criação da operação no formato ISODate 10 | // date_updated Data de atualização da operação no formato ISODate 11 | // ended_at Data de termíno do processamento da operação no formato Unix Timestamp 12 | // fail_reason Motivo da falha da operação 13 | // group_id Id do grupo de operações que essa operação pertence 14 | // id Id da operação 15 | // metadata Informações sobre o ambiente da operação 16 | // model Modelo da operação 17 | // model_id Id do modelo da transação 18 | // next_group_id Id do próximo grupo de operações 19 | // processor Adquirente que processou essa operação 20 | // processor_response_code Código de resposta retornado pelo adquirente 21 | // request_id Id da requisição interna que disparou essa operação 22 | // rollbacked Indicador de operação desfeita 23 | // started_at Data de início do processamento da operação no formato Unix Timestamp 24 | // status Status da operação. Valores possíveis: waiting, processing, deferred, failed, success e dropped 25 | // type Tipo da operação. Valores possíveis: analyze, authorize, capture, issue, conciliate e refund 26 | type Operation struct { 27 | DateCreated time.Time `json:"date_created"` 28 | DateUpdated time.Time `json:"date_updated"` 29 | EndedAt int `json:"ended_at"` 30 | FailReason string `json:"fail_reason"` 31 | GroupId string `json:"group_id"` 32 | Id string `json:"id"` 33 | Metadata Metadata `json:"metadata"` 34 | Model string `json:"model"` 35 | ModelId string `json:"model_id"` 36 | NextGroupId string `json:"next_group_id"` 37 | Processor string `json:"processor"` 38 | ProcessorResponseCode string `json:"processor_response_code"` 39 | RequestId string `json:"request_id"` 40 | Rollbacked bool `json:"rollbacked"` 41 | StartedAt int `json:"started_at"` 42 | Status string `json:"status"` 43 | Type string `json:"type"` 44 | } 45 | 46 | type Metadata struct { 47 | Environment Environment `json:"environment"` 48 | } 49 | 50 | type Environment struct { 51 | CapturedAmount int `json:"captured_amount"` 52 | AuthorizationCode string `json:"authorization_code"` 53 | AuthorizedAmount int `json:"authorized_amount"` 54 | Nsu int `json:"nsu"` 55 | ResponseCode string `json:"response_code"` 56 | Tid int `json:"tid"` 57 | } 58 | -------------------------------------------------------------------------------- /lib/payable/payable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package payable 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryRecipient repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/payables" 19 | ) 20 | 21 | type Payable struct { 22 | Object string `json:"object"` 23 | Id int `json:"id"` 24 | Status string `json:"status"` 25 | Amount int `json:"amount"` 26 | Fee int `json:"fee"` 27 | Installment string `json:"installment"` 28 | TransactionId int `json:"transaction_id"` 29 | SplitRuleId string `json:"split_rule_id"` 30 | PaymentDate time.Time `json:"payment_date"` 31 | Type string `json:"type"` 32 | PaymentMethod string `json:"payment_method"` 33 | DateCreated time.Time `json:"date_created"` 34 | } 35 | 36 | func (s *Payable) Get(p url.Values, h auth.Headers) (Payable, error, liberr.ErrorsAPI) { 37 | route := endPoint + "/" + p.Get("id") 38 | _, err, errApi := repositoryRecipient.Get(url.Values{"route": {route}}, s, h) 39 | return *s, err, errApi 40 | } 41 | 42 | func (s *Payable) GetAll(p url.Values, h auth.Headers) ([]Payable, error, liberr.ErrorsAPI) { 43 | res := []Payable{} 44 | _, err, errApi := repositoryRecipient.Get(url.Values{"route": {endPoint}}, &res, h) 45 | return res, err, errApi 46 | } 47 | -------------------------------------------------------------------------------- /lib/plan/plan.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package plan 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryRecipient repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/plans" 19 | ) 20 | 21 | // object Nome do tipo do objeto criado/modificado 22 | // id Id do plano 23 | // amount Valor do plano em centavos 24 | // days Dias para efetuação da próxima cobrança da assinatura atrelada ao plano 25 | // name Nome do plano 26 | // trial_days Dias que o usuário poderá testar o serviço gratuitamente 27 | // date_created Data da criação do plano (ISODate) 28 | // payment_methods Formas de pagamento aceitas no plano 29 | // charges Número de cobranças que podem ser feitas em uma assinatura 30 | // installments Informa em quantas vezes o pagamento será parcelado entre cada cobrança 31 | type Plan struct { 32 | Object string `json:"object"` 33 | Id int `json:"id"` 34 | Amount int `json:"amount"` 35 | Days int `json:"days"` 36 | Name string `json:"name"` 37 | TrialDays int `json:"trial_days"` 38 | DateCreated time.Time `json:"date_created"` 39 | PaymentMethods interface{} `json:"payment_methods"` 40 | Charges int `json:"charges"` 41 | Installments int `json:"installments"` 42 | } 43 | 44 | func (s *Plan) Create(d []byte, p url.Values, headers auth.Headers) (Plan, error, liberr.ErrorsAPI) { 45 | _, err, errApi := repositoryRecipient.Create(url.Values{"route": {endPoint}}, d, s) 46 | return *s, err, errApi 47 | } 48 | 49 | func (s *Plan) Get(p url.Values, h auth.Headers) (Plan, error, liberr.ErrorsAPI) { 50 | route := endPoint + "/" + p.Get("id") 51 | _, err, errApi := repositoryRecipient.Get(url.Values{"route": {route}}, s, h) 52 | return *s, err, errApi 53 | } 54 | 55 | func (s *Plan) GetAll(p url.Values, h auth.Headers) ([]Plan, error, liberr.ErrorsAPI) { 56 | res := []Plan{} 57 | _, err, errApi := repositoryRecipient.Get(url.Values{"route": {endPoint}}, &res, h) 58 | return res, err, errApi 59 | } 60 | 61 | func (s *Plan) Update(d []byte, p url.Values, h auth.Headers) (Plan, error, liberr.ErrorsAPI) { 62 | route := endPoint + "/" + p.Get("id") 63 | _, err, errApi := repositoryRecipient.Update(url.Values{"route": {route}}, d, s) 64 | return *s, err, errApi 65 | } 66 | -------------------------------------------------------------------------------- /lib/postback/postback.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package postback 6 | 7 | import "time" 8 | 9 | type Postback struct { 10 | DateCreated time.Time `json:"date_created"` 11 | DateUpdated time.Time `json:"date_updated"` 12 | Deliveries []Deliveries `json:"deliveries"` 13 | Headers string `json:"headers"` 14 | Id string `json:"id"` 15 | Model string `json:"model"` 16 | ModelId string `json:"model_id"` 17 | NextRetry string `json:"next_retry"` 18 | Object string `json:"object"` 19 | Payload string `json:"payload"` 20 | RequestUrl string `json:"request_url"` 21 | Retries int `json:"retries"` 22 | Signature string `json:"signature"` 23 | Status string `json:"status"` 24 | } 25 | 26 | type Deliveries struct { 27 | DateCreated time.Time `json:"date_created"` 28 | DateUpdated time.Time `json:"date_updated"` 29 | Id string `json:"id"` 30 | Object string `json:"object"` 31 | ResponseBody string `json:"response_body"` 32 | ResponseHeaders string `json:"response_headers"` 33 | ResponseTime int `json:"response_time"` 34 | Status string `json:"status"` 35 | StatusCode string `json:"status_code"` 36 | StatusReason string `json:"status_reason"` 37 | } 38 | -------------------------------------------------------------------------------- /lib/recipient/balance/balance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package balance 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/balance" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryBalance repository.Repository 16 | 17 | type BalanceRecipient struct { 18 | recipient balance.BalanceAmount 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/recipients" 23 | ) 24 | 25 | func (s *BalanceRecipient) Get(p url.Values, h auth.Headers) (balance.BalanceAmount, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("id") + "/balance" 27 | _, err, errApi := repositoryBalance.Get(url.Values{"route": {route}}, &s.recipient, h) 28 | return s.recipient, err, errApi 29 | } 30 | -------------------------------------------------------------------------------- /lib/recipient/balance/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package operation 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/balance/operation" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryBalance repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/recipients" 19 | ) 20 | 21 | type OperationRecipient struct { 22 | recipient operation.BalanceOperation 23 | } 24 | 25 | func (s *OperationRecipient) Get(p url.Values, h auth.Headers) (operation.BalanceOperation, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("id_recipient") + "/balance/operations/" + p.Get("id_operation") 27 | _, err, errApi := repositoryBalance.Get(url.Values{"route": {route}}, &s.recipient, h) 28 | return s.recipient, err, errApi 29 | } 30 | 31 | func (s *OperationRecipient) GetAll(p url.Values, h auth.Headers) ([]*operation.BalanceOperation, error, liberr.ErrorsAPI) { 32 | res := []*operation.BalanceOperation{} 33 | route := endPoint + "/" + p.Get("id_recipient") + "/balance/operations" 34 | _, err, errApi := repositoryBalance.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | -------------------------------------------------------------------------------- /lib/recipient/recipient.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package recipient 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/bank" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | "time" 14 | ) 15 | 16 | var repositoryRecipient repository.Repository 17 | 18 | const ( 19 | endPoint = "https://api.pagar.me/1/recipients" 20 | ) 21 | 22 | type Recipient struct { 23 | AnticipatableVolumePercentage int `json:"anticipatable_volume_percentage"` 24 | AutomaticAnticipationEnabled bool `json:"automatic_anticipation_enabled"` 25 | BankAccount bank.Account `json:"bank_account"` 26 | DateCreated time.Time `json:"date_created"` 27 | DateUpdated time.Time `json:"date_updated"` 28 | Id string `json:"id"` 29 | LastTransfer string `json:"last_transfer"` 30 | Object string `json:"object"` 31 | TransferDay int `json:"transfer_day"` 32 | TransferEnabled bool `json:"transfer_enabled"` 33 | TransferInnterval string `json:"transfer_interval"` 34 | } 35 | 36 | func (s *Recipient) Create(d []byte, p url.Values, h auth.Headers) (Recipient, error, liberr.ErrorsAPI) { 37 | _, err, errApi := repositoryRecipient.Create(url.Values{"route": {endPoint}}, d, s) 38 | return *s, err, errApi 39 | } 40 | 41 | func (s *Recipient) Get(p url.Values, h auth.Headers) (Recipient, error, liberr.ErrorsAPI) { 42 | route := endPoint + "/" + p.Get("id") 43 | _, err, errApi := repositoryRecipient.Get(url.Values{"route": {route}}, s, h) 44 | return *s, err, errApi 45 | } 46 | 47 | func (s *Recipient) GetAll(p url.Values, h auth.Headers) ([]Recipient, error, liberr.ErrorsAPI) { 48 | res := []Recipient{} 49 | _, err, errApi := repositoryRecipient.Get(url.Values{"route": {endPoint}}, &res, h) 50 | return res, err, errApi 51 | } 52 | 53 | func (s *Recipient) Update(d []byte, p url.Values, h auth.Headers) (Recipient, error, liberr.ErrorsAPI) { 54 | route := endPoint + "/" + p.Get("id") 55 | _, err, errApi := repositoryRecipient.Update(url.Values{"route": {route}}, d, s) 56 | return *s, err, errApi 57 | } 58 | -------------------------------------------------------------------------------- /lib/search/search.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package search 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | ) 13 | 14 | var repositorySearch repository.Repository 15 | 16 | const ( 17 | endPoint = "https://api.pagar.me/1/search" 18 | ) 19 | 20 | type Search struct { 21 | Took int `json:"took"` 22 | TimedOut bool `json:"timed_out"` 23 | Shards Shards `json:"_shards"` 24 | Hits Hits `json:"hits"` 25 | } 26 | 27 | type Shards struct { 28 | Total int `json:"total"` 29 | Successful int `json:"successful"` 30 | Failed int `json:"failed"` 31 | } 32 | 33 | type Hits struct { 34 | Total int `json:"total"` 35 | MaxScore int `json:"max_score"` 36 | HitsInto []HitsInto `json:"hits"` 37 | } 38 | 39 | type HitsInto struct { 40 | Index string `json:"_index"` 41 | Type string `json:"_type"` 42 | Id string `json:"_id"` 43 | Score string `json:"_score"` 44 | Source interface{} `json:"_source"` 45 | } 46 | 47 | func (s *Search) Get(p url.Values, h auth.Headers) (Search, error, liberr.ErrorsAPI) { 48 | _, err, errApi := repositorySearch.Get(url.Values{"route": {endPoint}}, s, h) 49 | return *s, err, errApi 50 | } 51 | -------------------------------------------------------------------------------- /lib/subscription/event/event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package subscription 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/event" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositorySubscriptionEvent repository.Repository 16 | 17 | type SubscriptionEvent struct { 18 | event event.Event 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/subscriptions" 23 | ) 24 | 25 | func (s *SubscriptionEvent) Get(p url.Values, h auth.Headers) (event.Event, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("subscription_id") + "/events/" + p.Get("id") 27 | _, err, errApi := repositorySubscriptionEvent.Get(url.Values{"route": {route}}, &s.event, h) 28 | return s.event, err, errApi 29 | } 30 | 31 | func (s *SubscriptionEvent) GetAll(p url.Values, h auth.Headers) ([]event.Event, error, liberr.ErrorsAPI) { 32 | res := []event.Event{} 33 | route := endPoint + "/" + p.Get("subscription_id") + "/events" 34 | _, err, errApi := repositorySubscriptionEvent.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | -------------------------------------------------------------------------------- /lib/subscription/postback/postback.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package subscription 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/postback" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryPostback repository.Repository 16 | 17 | type SubscriptionPostback struct { 18 | postback postback.Postback 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/subscriptions" 23 | ) 24 | 25 | func (s *SubscriptionPostback) Get(p url.Values, h auth.Headers) (postback.Postback, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("transaction_id") + "/postbacks/" + p.Get("id") 27 | _, err, errApi := repositoryPostback.Get(url.Values{"route": {route}}, &s.postback, h) 28 | return s.postback, err, errApi 29 | } 30 | 31 | func (s *SubscriptionPostback) GetAll(p url.Values, h auth.Headers) ([]postback.Postback, error, liberr.ErrorsAPI) { 32 | res := []postback.Postback{} 33 | route := endPoint + "/" + p.Get("transaction_id") + "/postbacks" 34 | _, err, errApi := repositoryPostback.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | 38 | func (s *SubscriptionPostback) Redeliver(p url.Values, h auth.Headers) (postback.Postback, error, liberr.ErrorsAPI) { 39 | route := endPoint + "/" + p.Get("transaction_id") + "/postbacks/" + p.Get("id") + "/redeliver" 40 | _, err, errApi := repositoryPostback.Create(url.Values{"route": {route}}, []byte(`{}`), s) 41 | return s.postback, err, errApi 42 | } 43 | -------------------------------------------------------------------------------- /lib/subscription/subscription.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package subscription 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/card" 11 | "github.com/luk4z7/pagarme-go/lib/customer" 12 | "github.com/luk4z7/pagarme-go/lib/plan" 13 | "github.com/luk4z7/pagarme-go/lib/transaction" 14 | "github.com/luk4z7/pagarme-go/repository" 15 | "net/url" 16 | "time" 17 | ) 18 | 19 | var repositorySubscription repository.Repository 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/subscriptions" 23 | ) 24 | 25 | // object Nome do tipo de objeto criado ou modificado. Valor retornado: subscription 26 | // plan Objeto com os dados do plano que a assinatura está associada 27 | // id Número do identificador do plano 28 | // current_transaction Objeto com os dados da ultima transação realizada pela assinatura 29 | // postback_url Endpoint da aplicação integrada ao Pagar.me que irá receber os jsons de resposta a 30 | // cada atualização dos processos 31 | // 32 | // payment_method Método de pagamento associado a essa assinatura 33 | // current_period_start Início do periodo de cobrança da assinatura 34 | // current_period_end Término do periodo de cobrança da assinatura 35 | // charges Numero de cobranças que foram efetuadas na assinatura, sem contar a cobrança inicial da 36 | // assinatura no caso de cartão de crédito. 37 | // 38 | // status Possíveis estados da transaçãov ou assinatura. Valores possíveis: trialing, paid, 39 | // pending_payment, unpaid, canceled e ended 40 | // 41 | // date_created Data de criação da assinatura 42 | // phone Objeto com dados do telefone do cliente 43 | // address Objeto com dados do endereço do cliente 44 | // custormer Objeto com dados do cliente 45 | // card Objeto com dados do cartão do cliente 46 | // metadata Objeto com dados adicionais do cliente ou produto ou serviço vendido 47 | type Subscription struct { 48 | Object string `json:"object"` 49 | Plan plan.Plan `json:"plan"` 50 | Id int `json:"id"` 51 | CurrentTransaction transaction.Transaction `json:"current_transaction"` 52 | PostbackUrl string `json:"postback_url"` 53 | PaymentMethod string `json:"payment_method"` 54 | CurrentPeriodStart string `json:"current_period_start"` 55 | CurrentPeriodEnd string `json:"current_period_end"` 56 | Charges int `json:"charges"` 57 | Status string `json:"status"` 58 | DateCreated time.Time `json:"date_created"` 59 | Phone customer.Phones `json:"phone"` 60 | Address customer.Addresses `json:"address"` 61 | Custormer customer.Customer `json:"custormer"` 62 | Card card.Card `json:"card"` 63 | Metadata Metadata `json:"metadata"` 64 | } 65 | 66 | type Metadata struct{} 67 | 68 | func (s *Subscription) Cancel(p url.Values, h auth.Headers) (Subscription, error, liberr.ErrorsAPI) { 69 | route := endPoint + "/" + p.Get("id") + "/cancel" 70 | _, err, errApi := repositorySubscription.Create(url.Values{"route": {route}}, []byte(`{}`), s) 71 | return *s, err, errApi 72 | } 73 | 74 | func (s *Subscription) Create(d []byte, p url.Values, h auth.Headers) (Subscription, error, liberr.ErrorsAPI) { 75 | _, err, errApi := repositorySubscription.Create(url.Values{"route": {endPoint}}, d, s) 76 | return *s, err, errApi 77 | } 78 | 79 | func (s *Subscription) Get(p url.Values, h auth.Headers) (Subscription, error, liberr.ErrorsAPI) { 80 | route := endPoint + "/" + p.Get("id") 81 | _, err, errApi := repositorySubscription.Get(url.Values{"route": {route}}, s, h) 82 | return *s, err, errApi 83 | } 84 | 85 | func (s *Subscription) GetAll(p url.Values, h auth.Headers) ([]Subscription, error, liberr.ErrorsAPI) { 86 | res := []Subscription{} 87 | _, err, errApi := repositorySubscription.Get(url.Values{"route": {endPoint}}, &res, h) 88 | return res, err, errApi 89 | } 90 | 91 | func (s *Subscription) Update(d []byte, p url.Values, h auth.Headers) (Subscription, error, liberr.ErrorsAPI) { 92 | route := endPoint + "/" + p.Get("id") 93 | _, err, errApi := repositorySubscription.Update(url.Values{"route": {route}}, d, s) 94 | return *s, err, errApi 95 | } 96 | -------------------------------------------------------------------------------- /lib/subscription/transaction/transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package subscription 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/transaction" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositorySubscription repository.Repository 16 | 17 | type SubscriptionTransaction struct { 18 | transaction transaction.Transaction 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/subscriptions" 23 | ) 24 | 25 | func (s *SubscriptionTransaction) Get(p url.Values, h auth.Headers) ([]transaction.Transaction, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("id") + "/transactions" 27 | res := []transaction.Transaction{} 28 | _, err, errApi := repositorySubscription.Get(url.Values{"route": {route}}, &res, h) 29 | return res, err, errApi 30 | } 31 | -------------------------------------------------------------------------------- /lib/transaction/antifraudanalysis/antifraudanalysis.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package antifraudanalysis 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryAntifraudAnalysis repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/transactions" 19 | ) 20 | 21 | type AntifraudAnalysis struct { 22 | Object string `json:"object"` 23 | Name string `json:"name"` 24 | Score string `json:"score"` 25 | Cost string `json:"cost"` 26 | Status string `json:"status"` 27 | DateCreated time.Time `json:"date_created"` 28 | DateUpdated time.Time `json:"date_updated"` 29 | Id int `json:"id"` 30 | } 31 | 32 | func (s *AntifraudAnalysis) Get(p url.Values, h auth.Headers) (AntifraudAnalysis, error, liberr.ErrorsAPI) { 33 | route := endPoint + "/" + p.Get("transaction_id") + "/antifraud_analyses/" + p.Get("id") 34 | _, err, errApi := repositoryAntifraudAnalysis.Get(url.Values{"route": {route}}, s, h) 35 | return *s, err, errApi 36 | } 37 | 38 | func (s *AntifraudAnalysis) GetAll(p url.Values, h auth.Headers) ([]AntifraudAnalysis, error, liberr.ErrorsAPI) { 39 | res := []AntifraudAnalysis{} 40 | route := endPoint + "/" + p.Get("transaction_id") + "/antifraud_analyses" 41 | _, err, errApi := repositoryAntifraudAnalysis.Get(url.Values{"route": {route}}, &res, h) 42 | return res, err, errApi 43 | } 44 | -------------------------------------------------------------------------------- /lib/transaction/capture/capture.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package capture 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/transaction" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryCapture repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/transactions" 19 | ) 20 | 21 | type Capture struct { 22 | capture transaction.Transaction 23 | } 24 | 25 | func (s *Capture) Create(d []byte, p url.Values, h auth.Headers) (transaction.Transaction, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("transaction_id") + "/capture" 27 | _, err, errApi := repositoryCapture.Create(url.Values{"route": {route}}, d, &s.capture) 28 | return s.capture, err, errApi 29 | } 30 | -------------------------------------------------------------------------------- /lib/transaction/cardhashkey/cardhashkey.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cardhashkey 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositoryCardHashKey repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/transactions/card_hash_key" 19 | ) 20 | 21 | type CardHashKey struct { 22 | DateCreated time.Time `json:"date_created"` 23 | Id int `json:"id"` 24 | Ip string `json:"ip"` 25 | PublicKey string `json:"public_key"` 26 | } 27 | 28 | func (s *CardHashKey) Get(p url.Values, h auth.Headers) (CardHashKey, error, liberr.ErrorsAPI) { 29 | _, err, errApi := repositoryCardHashKey.Get(url.Values{"route": {endPoint}}, s, h) 30 | return *s, err, errApi 31 | } 32 | -------------------------------------------------------------------------------- /lib/transaction/collectpayment/collectpayment.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package collectpayment 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | ) 13 | 14 | var repositoryCollectPayment repository.Repository 15 | 16 | const ( 17 | endPoint = "https://api.pagar.me/1/transactions" 18 | ) 19 | 20 | type CollectPayment struct{} 21 | 22 | func (s *CollectPayment) Create(d []byte, p url.Values, h auth.Headers) (CollectPayment, error, liberr.ErrorsAPI) { 23 | route := endPoint + "/" + p.Get("transaction_id") + "/collect_payment" 24 | _, err, errApi := repositoryCollectPayment.Create(url.Values{"route": {route}}, d, s) 25 | return *s, err, errApi 26 | } 27 | -------------------------------------------------------------------------------- /lib/transaction/event/event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package event 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/event" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryEvent repository.Repository 16 | 17 | type TransactionEvent struct { 18 | event event.Event 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/transactions" 23 | ) 24 | 25 | func (s *TransactionEvent) Get(p url.Values, h auth.Headers) (event.Event, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("transaction_id") + "/events/" + p.Get("id") 27 | _, err, errApi := repositoryEvent.Get(url.Values{"route": {route}}, &s.event, h) 28 | return s.event, err, errApi 29 | } 30 | 31 | func (s *TransactionEvent) GetAll(p url.Values, h auth.Headers) ([]event.Event, error, liberr.ErrorsAPI) { 32 | res := []event.Event{} 33 | route := endPoint + "/" + p.Get("transaction_id") + "/events" 34 | _, err, errApi := repositoryEvent.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | -------------------------------------------------------------------------------- /lib/transaction/operation/operation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package operation 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/operation" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryOperation repository.Repository 16 | 17 | type TransactionOperation struct { 18 | operation operation.Operation 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/transactions" 23 | ) 24 | 25 | func (s *TransactionOperation) Get(p url.Values, h auth.Headers) (operation.Operation, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("transaction_id") + "/operations/" + p.Get("id") 27 | _, err, errApi := repositoryOperation.Get(url.Values{"route": {route}}, &s.operation, h) 28 | return s.operation, err, errApi 29 | } 30 | 31 | func (s *TransactionOperation) GetAll(p url.Values, h auth.Headers) ([]operation.Operation, error, liberr.ErrorsAPI) { 32 | res := []operation.Operation{} 33 | route := endPoint + "/" + p.Get("transaction_id") + "/operations" 34 | _, err, errApi := repositoryOperation.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | -------------------------------------------------------------------------------- /lib/transaction/payable/payable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package payable 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/payable" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryPayable repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/transactions" 19 | ) 20 | 21 | type TransactionPayable struct { 22 | payable payable.Payable 23 | } 24 | 25 | func (s *TransactionPayable) Get(p url.Values, h auth.Headers) (payable.Payable, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("transaction_id") + "/payables/" + p.Get("id") 27 | _, err, errApi := repositoryPayable.Get(url.Values{"route": {route}}, &s.payable, h) 28 | return s.payable, err, errApi 29 | } 30 | 31 | func (s *TransactionPayable) GetAll(p url.Values, h auth.Headers) ([]payable.Payable, error, liberr.ErrorsAPI) { 32 | res := []payable.Payable{} 33 | route := endPoint + "/" + p.Get("transaction_id") + "/payables" 34 | _, err, errApi := repositoryPayable.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | -------------------------------------------------------------------------------- /lib/transaction/postback/postback.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package postback 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/postback" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | ) 14 | 15 | var repositoryPostback repository.Repository 16 | 17 | type TransactionPostback struct { 18 | postback postback.Postback 19 | } 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/transactions" 23 | ) 24 | 25 | func (s *TransactionPostback) Get(p url.Values, h auth.Headers) (postback.Postback, error, liberr.ErrorsAPI) { 26 | route := endPoint + "/" + p.Get("transaction_id") + "/postbacks/" + p.Get("id") 27 | _, err, errApi := repositoryPostback.Get(url.Values{"route": {route}}, &s.postback, h) 28 | return s.postback, err, errApi 29 | } 30 | 31 | func (s *TransactionPostback) GetAll(p url.Values, h auth.Headers) ([]postback.Postback, error, liberr.ErrorsAPI) { 32 | res := []postback.Postback{} 33 | route := endPoint + "/" + p.Get("transaction_id") + "/postbacks" 34 | _, err, errApi := repositoryPostback.Get(url.Values{"route": {route}}, &res, h) 35 | return res, err, errApi 36 | } 37 | 38 | func (s *TransactionPostback) Redeliver(p url.Values, h auth.Headers) (postback.Postback, error, liberr.ErrorsAPI) { 39 | route := endPoint + "/" + p.Get("transaction_id") + "/postbacks/" + p.Get("id") + "/redeliver" 40 | _, err, errApi := repositoryPostback.Create(url.Values{"route": {route}}, []byte(`{}`), s) 41 | return s.postback, err, errApi 42 | } 43 | -------------------------------------------------------------------------------- /lib/transaction/splitrule/splitrule.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package splitrule 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | "time" 13 | ) 14 | 15 | var repositorySplitRule repository.Repository 16 | 17 | const ( 18 | endPoint = "https://api.pagar.me/1/transactions" 19 | ) 20 | 21 | type SplitRule struct { 22 | Object string `json:"object"` 23 | Id int `json:"id"` 24 | RecipientId string `json:"recipient_id"` 25 | ChargeProcessingFee bool `json:"charge_processing_fee"` 26 | Liable bool `json:"liable"` 27 | Percentage int `json:"percentage"` 28 | Amount int `json:"amount"` 29 | DateCreated time.Time `json:"date_created"` 30 | DateUpdated time.Time `json:"date_updated"` 31 | Route string `json:"route"` 32 | } 33 | 34 | func (s *SplitRule) Get(p url.Values, h auth.Headers) (SplitRule, error, liberr.ErrorsAPI) { 35 | route := endPoint + "/" + p.Get("transaction_id") + "/split_rules/" + p.Get("id") 36 | _, err, errApi := repositorySplitRule.Get(url.Values{"route": {route}}, s, h) 37 | return *s, err, errApi 38 | } 39 | 40 | func (s *SplitRule) GetAll(p url.Values, h auth.Headers) ([]SplitRule, error, liberr.ErrorsAPI) { 41 | res := []SplitRule{} 42 | route := endPoint + "/" + p.Get("transaction_id") + "/split_rules" 43 | _, err, errAPi := repositorySplitRule.Get(url.Values{"route": {route}}, &res, h) 44 | return res, err, errAPi 45 | } 46 | -------------------------------------------------------------------------------- /lib/transaction/transaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package transaction 6 | 7 | import ( 8 | "net/url" 9 | "time" 10 | 11 | "github.com/luk4z7/pagarme-go/auth" 12 | liberr "github.com/luk4z7/pagarme-go/error" 13 | "github.com/luk4z7/pagarme-go/lib/card" 14 | "github.com/luk4z7/pagarme-go/lib/customer" 15 | "github.com/luk4z7/pagarme-go/lib/transaction/splitrule" 16 | "github.com/luk4z7/pagarme-go/repository" 17 | ) 18 | 19 | var repositoryTransaction repository.Repository 20 | 21 | const ( 22 | endPoint = "https://api.pagar.me/1/transactions" 23 | ) 24 | 25 | // object Nome do tipo do objeto criado/modificado. Valor retornado: transaction 26 | // status Para cada atualização no processamento da transação, esta propriedade será alterada, e o 27 | // objeto transaction retornado como resposta através da sua URL de postback ou após o término 28 | // do processamento da ação atual. Valores possíveis: processing, authorized, paid, refunded, 29 | // waiting_payment, pending_refund, refused 30 | // 31 | // refuse_reason Motivo/agente responsável pela validação ou anulação da transação. Valores possíveis: 32 | // acquirer, antifraud, internal_error, no_acquirer, acquirer_timeout 33 | // 34 | // status_reason Adquirente responsável pelo processamento da transação. Valores possíveis: development 35 | // (em ambiente de testes), pagarme (adquirente Pagar.me), stone, cielo, rede, mundipagg 36 | // 37 | // acquirer_response_code Mensagem de resposta do adquirente referente ao status da transação. 38 | // acquirer_name 39 | // authorization_code Código de autorização retornado pela bandeira. 40 | // soft_descriptor Texto que irá aparecer na fatura do cliente depois do nome da loja. OBS: Limite de 13 41 | // caracteres, apenas letras e números. 42 | // 43 | // tid Código que identifica a transação no adquirente. 44 | // nsu Código que identifica a transação no adquirente. 45 | // date_created Data de criação da transação no formato ISODate 46 | // date_updated Data de última atualização da transação no formato ISODate 47 | // amount Valor em centados do que foi pago 48 | // authorized_amount 49 | // paid_amount 50 | // refunded_amount 51 | // installments Número de parcelas/prestações a serem cobradas 52 | // id Código de identificação da transação 53 | // cost 54 | // card_holder_name Nome do portador do cartão. Usado quando o cartão a ser configurado na assinatura ainda não 55 | // está salvo no nosso banco de dados 56 | // 57 | // card_last_digits 58 | // card_first_digits 59 | // card_brand 60 | // card_hash 61 | // postback_url URL para onde são enviadas as notificações de alteração de status 62 | // payment_method Método de pagamento possíveis: credit_card e boleto 63 | // capture_method 64 | // antifraud_score 65 | // boleto_url URL do boleto para ser impresso 66 | // boleto_barcode Código de barras do boleto gerado na transação 67 | // boleto_expiration_date Data de vencimento do boleto no formato ISODate 68 | // referer Mostra de onde a transação foi criada. Valores : api_key ou encryption_key 69 | // ip IP de origem que criou a transção, podendo ser ou do seu cliente (quando criado via checkout 70 | // ou utilizando card_hash) ou do servidor. 71 | // 72 | // subscription_id Código da assinatura 73 | // phone Objeto do tipo phone 74 | // address Objeto do tipo address 75 | // customer Objeto do tipo customer 76 | // card Objeto do tipo card 77 | // split_rules 78 | // metadata 79 | // antifraud_metadata 80 | type Transaction struct { 81 | Object string `json:"object"` 82 | Status string `json:"status"` 83 | RefuseReason string `json:"refuse_reason"` 84 | StatusReason string `json:"status_reason"` 85 | AcquirerResponseCode string `json:"acquirer_response_code"` 86 | AcquirerName string `json:"acquirer_name"` 87 | AuthorizationCode string `json:"authorization_code"` 88 | SoftDescriptor string `json:"soft_descriptor"` 89 | Tid interface{} `json:"tid"` 90 | Nsu interface{} `json:"nsu"` 91 | DateCreated time.Time `json:"date_created"` 92 | DateUpdated time.Time `json:"date_updated"` 93 | Amount int `json:"amount"` 94 | AuthorizedAmount int `json:"authorized_amount"` 95 | PaidAmount int `json:"paid_amount"` 96 | RefundedAmount int `json:"refunded_amount"` 97 | Installments int `json:"installments"` 98 | Id int `json:"id"` 99 | Cost float64 `json:"cost"` 100 | CardHolderName string `json:"card_holder_name"` 101 | CardLastDigits string `json:"card_last_digits"` 102 | CardFirstDigits string `json:"card_first_digits"` 103 | CardBrand string `json:"card_brand"` 104 | CardHash string `json:"card_hash"` 105 | PostbackUrl string `json:"postback_url"` 106 | PaymentMethod string `json:"payment_method"` 107 | CaptureMethod string `json:"capture_method"` 108 | AntifraudScore string `json:"antifraud_score"` 109 | BoletoUrl string `json:"boleto_url"` 110 | BoletoBarcode string `json:"boleto_barcode"` 111 | BoletoExpirationDate string `json:"boleto_expiration_date"` 112 | Referer string `json:"referer"` 113 | Ip string `json:"ip"` 114 | SubscriptionId int `json:"subscription_id"` 115 | Phones customer.Phones `json:"phone"` 116 | Addresses customer.Addresses `json:"address"` 117 | Customer customer.Customer `json:"customer"` 118 | Card card.Card `json:"card"` 119 | SplitRules []splitrule.SplitRule `json:"split_rules"` 120 | Metadata Metadata `json:"metadata"` 121 | AntifraudMetadata AntifraudMetadata `json:"antifraud_metadata"` 122 | } 123 | 124 | type Metadata struct { 125 | IdProduto string `json:"id_produto"` 126 | } 127 | 128 | type AntifraudMetadata struct{} 129 | 130 | func (s *Transaction) Create(d []byte, p url.Values, h auth.Headers) (Transaction, error, liberr.ErrorsAPI) { 131 | _, err, errApi := repositoryTransaction.Create(url.Values{"route": {endPoint}}, d, s) 132 | return *s, err, errApi 133 | } 134 | 135 | func (s *Transaction) Get(p url.Values, h auth.Headers) (Transaction, error, liberr.ErrorsAPI) { 136 | route := endPoint + "/" + p.Get("id") 137 | _, err, errApi := repositoryTransaction.Get(url.Values{"route": {route}}, s, h) 138 | return *s, err, errApi 139 | } 140 | 141 | func (s *Transaction) GetAll(p url.Values, h auth.Headers) ([]Transaction, error, liberr.ErrorsAPI) { 142 | res := []Transaction{} 143 | _, err, errApi := repositoryTransaction.Get(url.Values{"route": {endPoint}}, &res, h) 144 | return res, err, errApi 145 | } 146 | -------------------------------------------------------------------------------- /lib/transfer/transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package transfer 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/lib/bank" 11 | "github.com/luk4z7/pagarme-go/repository" 12 | "net/url" 13 | "time" 14 | ) 15 | 16 | var repositoryTransfer repository.Repository 17 | 18 | const ( 19 | endPoint = "https://api.pagar.me/1/transfers" 20 | ) 21 | 22 | // object Nome do tipo do objeto criado/modificado 23 | // id Id da transferência 24 | // amount Valor em centavos transferido 25 | // type Tipo de transferência. Valores possíveis: ted, doc e credito_em_conta 26 | // status Estado da transferência. Valores possíveis: pending_transfer, transferred, failed, processing 27 | // e canceled 28 | // 29 | // source_type O tipo de origem da qual irá ser transferido o valor 30 | // source_id O id da origem da transferencia 31 | // target_type O tipo de destino da transferencia 32 | // target_id O id do destino da transferencia 33 | // fee Taxa em centavos cobrada pela transferência 34 | // funding_date Data ocorrência da transferência no formato ISODate 35 | // funding_estimated_date Data estimada para efetivação da transferência no formato ISODate 36 | // transaction_id Id da transação estornada no caso de estorno de boleto 37 | // date_created Data de criação da transferência no formato ISODate 38 | // bank_account Objeto da conta bancária 39 | type Transfer struct { 40 | Object string `json:"object"` 41 | Id int `json:"id"` 42 | Amount int `json:"amount"` 43 | Type string `json:"type"` 44 | Status string `json:"status"` 45 | SourceType string `json:"source_type"` 46 | SourceId string `json:"source_id"` 47 | TargetType string `json:"target_type"` 48 | TargetId string `json:"target_id"` 49 | Fee int `json:"fee"` 50 | FundingDate time.Time `json:"funding_date"` 51 | FundingEstimatedDate time.Time `json:"funding_estimated_date"` 52 | TransactionId int `json:"transaction_id"` 53 | DateCreated time.Time `json:"date_created"` 54 | BankAccount bank.Account `json:"bank_account"` 55 | } 56 | 57 | func (s *Transfer) Create(d []byte, p url.Values, h auth.Headers) (Transfer, error, liberr.ErrorsAPI) { 58 | _, err, errApi := repositoryTransfer.Create(url.Values{"route": {endPoint}}, d, s) 59 | return *s, err, errApi 60 | } 61 | 62 | func (s *Transfer) Get(p url.Values, h auth.Headers) (Transfer, error, liberr.ErrorsAPI) { 63 | route := endPoint + "/" + p.Get("id") 64 | _, err, errApi := repositoryTransfer.Get(url.Values{"route": {route}}, s, h) 65 | return *s, err, errApi 66 | } 67 | 68 | func (s *Transfer) GetAll(p url.Values, h auth.Headers) ([]Transfer, error, liberr.ErrorsAPI) { 69 | res := []Transfer{} 70 | _, err, errApi := repositoryTransfer.Get(url.Values{"route": {endPoint}}, &res, h) 71 | return res, err, errApi 72 | } 73 | 74 | func (s *Transfer) Update(d []byte, p url.Values, h auth.Headers) (Transfer, error, liberr.ErrorsAPI) { 75 | route := endPoint + "/" + p.Get("id") 76 | _, err, errApi := repositoryTransfer.Update(url.Values{"route": {route}}, d, s) 77 | return *s, err, errApi 78 | } 79 | 80 | func (s *Transfer) Cancel(p url.Values, h auth.Headers) (Transfer, error, liberr.ErrorsAPI) { 81 | route := endPoint + "/" + p.Get("id") + "/cancel" 82 | _, err, errApi := repositoryTransfer.Create(url.Values{"route": {route}}, []byte(`{}`), s) 83 | return *s, err, errApi 84 | } 85 | -------------------------------------------------------------------------------- /lib/validation/validation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package validation 6 | 7 | import ( 8 | liberr "github.com/luk4z7/pagarme-go/error" 9 | "net/url" 10 | ) 11 | 12 | // Check the values the map passed 13 | func MustBeNotEmpty(values url.Values, require func() []string) (bool, error) { 14 | 15 | required := require() 16 | 17 | valid := make(map[int]string) 18 | for k1, v := range required { 19 | for k, v2 := range values { 20 | if k == v { 21 | if len(v2[0]) == 0 { 22 | return false, &liberr.Err{Name: "Parametros invalidos"} 23 | } 24 | valid[k1] = k 25 | } 26 | } 27 | } 28 | 29 | if len(valid) != len(required) { 30 | return false, &liberr.Err{Name: "Parametros invalidos"} 31 | } 32 | 33 | return true, nil 34 | } 35 | 36 | func IsEmpty(values url.Values) error { 37 | _, err := MustBeNotEmpty(values, func() []string { 38 | return []string{""} 39 | }) 40 | return err 41 | } 42 | -------------------------------------------------------------------------------- /lib/zipcode/zipcode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zipcode 6 | 7 | import ( 8 | "github.com/luk4z7/pagarme-go/auth" 9 | liberr "github.com/luk4z7/pagarme-go/error" 10 | "github.com/luk4z7/pagarme-go/repository" 11 | "net/url" 12 | ) 13 | 14 | var repositoryZipcode repository.Repository 15 | 16 | const ( 17 | endPoint = "https://api.pagar.me/1/zipcodes" 18 | ) 19 | 20 | type Zipcode struct { 21 | Neighborhood string `json:"object"` // Bairro 22 | Street string `json:"street"` // Rua 23 | City string `json:"city"` // Cidade 24 | State string `json:"state"` // Estado 25 | Zipcode string `json:"zipcode"` // Código postal (CEP) 26 | } 27 | 28 | func (s *Zipcode) Get(p url.Values, h auth.Headers) (Zipcode, error, liberr.ErrorsAPI) { 29 | route := endPoint + "/" + p.Get("id") 30 | _, err, errApi := repositoryZipcode.Get(url.Values{"route": {route}}, s, h) 31 | return *s, err, errApi 32 | } 33 | -------------------------------------------------------------------------------- /repository/repository.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Lucas Alves Author. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package repository 6 | 7 | import ( 8 | "bytes" 9 | "encoding/json" 10 | "github.com/luk4z7/pagarme-go/auth" 11 | "github.com/luk4z7/pagarme-go/config" 12 | liberr "github.com/luk4z7/pagarme-go/error" 13 | "io/ioutil" 14 | "net/http" 15 | "net/url" 16 | ) 17 | 18 | var key config.ApiKey 19 | 20 | var errApi = liberr.ErrorsAPI{} 21 | 22 | // Repository is a object type for abstract methods for API 23 | // Get, Create, Getall, etc ... 24 | type Repository struct { 25 | } 26 | 27 | // params expected data for route settings and access should be as follows: 28 | // _, err := repositoryCard.Get(url.Values{"route": {route}}, struct, headers) 29 | // 30 | // structure expected by default a struct for unmarshall data eg: 31 | // type Card struct { 32 | // Brand string `json:"brand"` 33 | // Country string `json:"country"` 34 | // 35 | // headers expected data type for the header configuration http headers, eg: 36 | // Accept: application/json 37 | // Content-Type: application/json 38 | // Authorization: Basic 39 | // 40 | func (r *Repository) Get(p url.Values, i interface{}, h auth.Headers) (interface{}, error, liberr.ErrorsAPI) { 41 | // mount the route 42 | resp := auth.Init(string(p.Get("route")), h) 43 | // Read the response 44 | body, err := ioutil.ReadAll(resp.Body) 45 | liberr.Check(err, "Cannot read this resource - method: Get") 46 | 47 | if resp.StatusCode == 400 { 48 | err, errApi := checkError([]byte(body)) 49 | if err != nil { 50 | return i, err, errApi 51 | } 52 | } 53 | err = json.Unmarshal([]byte(body), &i) 54 | liberr.Check(err, "Cannot unmarshal data - method: Get") 55 | 56 | return i, nil, errApi 57 | } 58 | 59 | // params and structure also works to the method described above 60 | // data expected []byte for create/update any services 61 | func (r *Repository) Create(p url.Values, d []byte, i interface{}) (interface{}, error, liberr.ErrorsAPI) { 62 | req, err, errApi := request("POST", p.Get("route"), d, i) 63 | return req, err, errApi 64 | } 65 | 66 | func (s *Repository) Update(p url.Values, d []byte, i interface{}) (interface{}, error, liberr.ErrorsAPI) { 67 | req, err, errApi := request("PUT", p.Get("route"), d, i) 68 | return req, err, errApi 69 | } 70 | 71 | // Create a new connection with the endPoint last and return the response of the server 72 | func request(m, p string, d []byte, i interface{}) (interface{}, error, liberr.ErrorsAPI) { 73 | req, err := http.NewRequest(m, p, bytes.NewBuffer(d)) 74 | // Format the header 75 | req.Header.Set("Accept", "application/json") 76 | req.Header.Set("Content-Type", "application/json") 77 | req.Header.Add("Authorization", "Basic "+auth.BasicAuth(key.GetApiKey(), "x")) 78 | 79 | client := &http.Client{} 80 | resp, err := client.Do(req) 81 | liberr.Check(err, "Return error HTTP response of Do - method: request") 82 | defer resp.Body.Close() 83 | 84 | body, err := ioutil.ReadAll(resp.Body) 85 | liberr.Check(err, "Cannot read this resource - method: request") 86 | 87 | if resp.StatusCode == 400 { 88 | err, errApi := checkError([]byte(body)) 89 | if err != nil { 90 | return i, err, errApi 91 | } 92 | } 93 | err = json.Unmarshal([]byte(body), &i) 94 | liberr.Check(err, "Cannot unmarshal data - method: request") 95 | 96 | return i, nil, errApi 97 | } 98 | 99 | // Check the error of API return and return the json and liberr.Err 100 | func checkError(d []byte) (error, liberr.ErrorsAPI) { 101 | err := json.Unmarshal(d, &errApi) 102 | liberr.Check(err, "Cannot unmarshal data - method: checkError") 103 | 104 | if len(errApi.Errors) == 1 { 105 | return &liberr.Err{Name: "errosapi"}, errApi 106 | } 107 | return nil, errApi 108 | } 109 | -------------------------------------------------------------------------------- /repository/repository_test.go: -------------------------------------------------------------------------------- 1 | package repository 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "net/url" 7 | "os" 8 | "testing" 9 | 10 | "github.com/luk4z7/pagarme-go/auth" 11 | ) 12 | 13 | type MockedModel struct { 14 | value string `json:"value"` 15 | } 16 | 17 | func setupMockedHttpServer(body []byte, mockedUrl string, mockedMethod string) *httptest.Server { 18 | os.Setenv("PAGARME_APIKEY", "test") 19 | 20 | return httptest.NewServer( 21 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 22 | 23 | if r.URL.Path == mockedUrl && r.Method == mockedMethod { 24 | w.Header().Add("Content-Type", "application/json") 25 | w.Write(body) 26 | } 27 | }), 28 | ) 29 | } 30 | 31 | func TestGet(t *testing.T) { 32 | ts := setupMockedHttpServer([]byte(`{"value": "testing ok"}`), "/mocked_url/1", "GET") 33 | 34 | var mockedModel *MockedModel 35 | 36 | repository := Repository{} 37 | getResponse, _, _ := repository.Get(url.Values{"route": {ts.URL + "/mocked_url/1"}}, mockedModel, auth.Headers{}) 38 | 39 | model := getResponse.(map[string]interface{}) 40 | 41 | if model["value"] != "testing ok" { 42 | t.Errorf("invalid response data") 43 | } 44 | } 45 | 46 | func TestCreate(t *testing.T) { 47 | ts := setupMockedHttpServer([]byte(`{"status": "created"}`), "/mocked_url", "POST") 48 | 49 | repository := Repository{} 50 | 51 | requestBody := []byte(`{ 52 | "bank_code": "184", 53 | "agencia": "0808", 54 | "agencia_dv": "8", 55 | "conta": "08808", 56 | "conta_dv": "8", 57 | "document_number": "80802694594", 58 | "legal_name": "Hober Mallow" 59 | }`) 60 | 61 | getResponse, _, _ := repository.Create(url.Values{"route": {ts.URL + "/mocked_url"}}, requestBody, auth.Headers{}) 62 | 63 | model := getResponse.(map[string]interface{}) 64 | 65 | if model["status"] != "created" { 66 | t.Errorf("invalid response data") 67 | } 68 | } 69 | 70 | func TestUpdate(t *testing.T) { 71 | ts := setupMockedHttpServer([]byte(`{"status": "updated"}`), "/mocked_url", "PUT") 72 | 73 | repository := Repository{} 74 | 75 | requestBody := []byte(`{"legal_name": "Hober Mallow"}`) 76 | 77 | getResponse, _, _ := repository.Update(url.Values{"route": {ts.URL + "/mocked_url"}}, requestBody, auth.Headers{}) 78 | 79 | model := getResponse.(map[string]interface{}) 80 | 81 | if model["status"] != "updated" { 82 | t.Errorf("invalid response data") 83 | } 84 | } 85 | --------------------------------------------------------------------------------