{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Go","type":"basic","slug":"instalacao-sdk-go","excerpt":"Saiba como instalar e configurar nossa SDK em Go para API Pix e API Boletos (Bolix)","body":"[block:html]\n{\n  \"html\": \"<p>Nossa API é <a href=\\\"https://en.wikipedia.org/wiki/Representational_state_transfer\\\" target=\\\"_blank\\\" title=\\\"Link Externo\\\">RESTful</a> e responde em <a href=\\\"http://www.json.org/\\\" target=\\\"_blank\\\" title=\\\"Link Externo\\\">JSON</a>. A Gerencianet utiliza <a href=\\\"http://oauth.net/\\\" target=\\\"_blank\\\" title=\\\"Link Externo\\\">OAuth</a> para fornecer acesso autorizado à <abbr title=\\\"Application Programming Interface\\\">API</abbr>. Nossa SDK de Go já está preparada para realizar essa autenticação automaticamente.</p>\"\n}\n[/block]\nA seguir, confira os procedimentos para instalação da SDK da Gerencianet em Go para boletos e para o Pix:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ go get github.com/gerencianet/gn-api-sdk-go/gerencianet\",\n      \"language\": \"go\"\n    },\n    {\n      \"code\": \"go get github.com/gerencianet/gn-api-sdk-go-pix/gerencianet\",\n      \"language\": \"go\",\n      \"name\": \"Go Pix\"\n    }\n  ]\n}\n[/block]\n# Testado com\n\n- <code>Go 1.16</code>\n\n\n# Uso básico\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import (\\n    \\\"github.com/gerencianet/gn-api-sdk-go/gerencianet\\\"\\n)\\n\\ncredentials := map[string]interface{} {\\n    \\\"client_id\\\": \\\"client_id\\\",\\n    \\\"client_secret\\\": \\\"client_secret\\\",\\n    \\\"sandbox\\\": true,\\n    \\\"timeout\\\": 10,\\n}\\n\\ngn := gerencianet.NewGerencianet(credentials)\\n\\nbody = {\\n    \\\"items\\\": [{\\n        \\\"name\\\": \\\"Product 1\\\",\\n        \\\"value\\\": 1000,\\n        \\\"amount\\\": 2,\\n    }],\\n    \\\"shippings\\\": [{\\n        \\\"name\\\": \\\"Default Shipping Cost\\\",\\n        \\\"value\\\": 100,\\n    }]\\n}\\n\\nres, err := gn.CreateCharge(body)\",\n      \"language\": \"go\"\n    },\n    {\n      \"code\": \"import (\\n\\t\\\"fmt\\\"\\n\\t\\\"github.com/gerencianet/gn-api-sdk-go-pix/gerencianet\\\"\\n\\t\\\"github.com/gerencianet/gn-api-sdk-go-pix/_examples/configs\\\"\\n)\\n\\ncredentials := map[string]interface{} {\\n    \\\"client_id\\\": \\\"Your Client_Id\\\",\\n\\t\\\"client_secret\\\": \\\"Your Client_Secret\\\",\\n\\t\\\"sandbox\\\": true,\\n\\t\\\"timeout\\\": 20,\\n\\t\\\"CA\\\" : \\\"Path to your public key\\\",\\n\\t\\\"Key\\\" : \\\"Path to your private key\\\",\\n}\\n\\ngn := gerencianet.NewGerencianet(credentials)\\n\\nbody := map[string]interface{} {\\n\\t\\t\\n\\t\\t\\\"calendario\\\": map[string]interface{} {\\n\\t\\t\\t\\t\\\"expiracao\\\": 3600,\\n\\t\\t\\t},\\n\\t\\t\\\"devedor\\\": map[string]interface{}{\\n\\t\\t\\t\\n\\t\\t\\t\\t\\\"cpf\\\": \\\"12345678909\\\",\\n\\t\\t\\t\\t\\\"nome\\\": \\\"Francisco da Silva\\\",\\n\\t\\t\\t\\n\\t\\t},\\n\\t\\t\\\"valor\\\": map[string]interface{} {\\n\\t\\t\\t\\n\\t\\t\\t\\t\\\"original\\\": \\\"00.01\\\",\\n\\t\\t\\t\\n\\t\\t},\\n\\t\\t\\\"chave\\\": \\\"47e7e515-44d3-42cc-8e1f-ef529b4ba4d1\\\",\\n\\t\\t\\\"solicitacaoPagador\\\": \\\"Teste.\\\",\\n\\t\\t\\\"infoAdicionais\\\": []map[string]interface{} {\\n\\t\\t\\t{\\n\\t\\t\\t\\t\\\"nome\\\": \\\"Campo 1\\\",\\n\\t\\t\\t\\t\\\"valor\\\": \\\"Informação Adicional1 do PSP-Recebedor\\\",\\n\\t\\t\\t},\\n\\t\\t},\\n\\t}\\n\\nres, err := gn.CreateImmediateCharge(body)\",\n      \"language\": \"go\",\n      \"name\": \"Go Pix\"\n    }\n  ]\n}\n[/block]\n<br>\n\n# Exemplos\n\nVocê pode rodar os exemplos dentro de <code>_examples</code> com <code>$ go run example.go</code>:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ go run charge/create_charge.go\",\n      \"language\": \"go\"\n    },\n    {\n      \"code\": \"$ go run chargecreateImmediateCharge.go\",\n      \"language\": \"go\",\n      \"name\": \"Go Pix\"\n    }\n  ]\n}\n[/block]\nBasta lembrar de definir as credenciais corretas dentro de <code>_examples/configs.go</code> antes de serem executadas.\n\n# Testes\n\nPara executar os testes, basta executar:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ go test\",\n      \"language\": \"go\"\n    }\n  ]\n}\n[/block]","updates":[],"order":11,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"606f2ca7c5ba91007878348e","project":"575aeffae12cf20e002f306c","version":{"version":"1.1.0","version_clean":"1.1.0","codename":"2021","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["606f2ca6c5ba91007878342b","575af039a083950e004487f7","575af5c7ba4ed70e000ca288","606f2ca6c5ba91007878342c","606f2ca6c5ba91007878342d","606f2ca6c5ba91007878342e","606f2ca6c5ba91007878342f","5761a63d207db7170022fc14","5761b9a2b65324200072d79e","576832939f0bf4190014ffdf","576832c09f0bf4190014ffe1","576832cba151c10e004316f0","576832d5bb15f40e00a288ec","576832e107b1f30e0039c645","606f2ca6c5ba910078783430","606f2ca6c5ba910078783431","5783f78c5cbce30e0074e2b7","606f2ca6c5ba910078783432","606f2ca6c5ba910078783433","606f2ca6c5ba910078783434","606f2ca6c5ba910078783435","606f2ca6c5ba910078783436","606f2ca6c5ba910078783437","578529f887c9280e0090394b","606f2ca6c5ba910078783438","606f2ca6c5ba910078783439","606f2ca6c5ba91007878343a","606f2ca6c5ba91007878343b","606f2ca6c5ba91007878343c","606f2ca6c5ba91007878343d","606f2ca6c5ba91007878343e","606f2ca6c5ba91007878343f","606f2ca6c5ba910078783440","606f2ca6c5ba910078783441","60d61f026ddc3901a32ee5f1","60ec37c637005f015e54174e","61473375119247002a9c14d7"],"_id":"606f2ca7c5ba9100787834c6","project":"575aeffae12cf20e002f306c","createdAt":"2016-06-10T16:51:06.080Z","releaseDate":"2016-06-10T16:51:06.080Z","__v":3,"forked_from":"575aeffae12cf20e002f306f"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Instalação da API (SDK's)","slug":"instalação-da-api-sdks","order":7,"from_sync":false,"reference":false,"_id":"606f2ca6c5ba91007878343d","createdAt":"2017-03-10T12:37:05.075Z","project":"575aeffae12cf20e002f306c","version":"606f2ca7c5ba9100787834c6","__v":0},"user":"57601a13af3e090e00108059","createdAt":"2017-11-14T11:28:34.714Z","githubsync":"","__v":0,"parentDoc":null}

Go

Saiba como instalar e configurar nossa SDK em Go para API Pix e API Boletos (Bolix)

[block:html] { "html": "<p>Nossa API é <a href=\"https://en.wikipedia.org/wiki/Representational_state_transfer\" target=\"_blank\" title=\"Link Externo\">RESTful</a> e responde em <a href=\"http://www.json.org/\" target=\"_blank\" title=\"Link Externo\">JSON</a>. A Gerencianet utiliza <a href=\"http://oauth.net/\" target=\"_blank\" title=\"Link Externo\">OAuth</a> para fornecer acesso autorizado à <abbr title=\"Application Programming Interface\">API</abbr>. Nossa SDK de Go já está preparada para realizar essa autenticação automaticamente.</p>" } [/block] A seguir, confira os procedimentos para instalação da SDK da Gerencianet em Go para boletos e para o Pix: [block:code] { "codes": [ { "code": "$ go get github.com/gerencianet/gn-api-sdk-go/gerencianet", "language": "go" }, { "code": "go get github.com/gerencianet/gn-api-sdk-go-pix/gerencianet", "language": "go", "name": "Go Pix" } ] } [/block] # Testado com - <code>Go 1.16</code> # Uso básico [block:code] { "codes": [ { "code": "import (\n \"github.com/gerencianet/gn-api-sdk-go/gerencianet\"\n)\n\ncredentials := map[string]interface{} {\n \"client_id\": \"client_id\",\n \"client_secret\": \"client_secret\",\n \"sandbox\": true,\n \"timeout\": 10,\n}\n\ngn := gerencianet.NewGerencianet(credentials)\n\nbody = {\n \"items\": [{\n \"name\": \"Product 1\",\n \"value\": 1000,\n \"amount\": 2,\n }],\n \"shippings\": [{\n \"name\": \"Default Shipping Cost\",\n \"value\": 100,\n }]\n}\n\nres, err := gn.CreateCharge(body)", "language": "go" }, { "code": "import (\n\t\"fmt\"\n\t\"github.com/gerencianet/gn-api-sdk-go-pix/gerencianet\"\n\t\"github.com/gerencianet/gn-api-sdk-go-pix/_examples/configs\"\n)\n\ncredentials := map[string]interface{} {\n \"client_id\": \"Your Client_Id\",\n\t\"client_secret\": \"Your Client_Secret\",\n\t\"sandbox\": true,\n\t\"timeout\": 20,\n\t\"CA\" : \"Path to your public key\",\n\t\"Key\" : \"Path to your private key\",\n}\n\ngn := gerencianet.NewGerencianet(credentials)\n\nbody := map[string]interface{} {\n\t\t\n\t\t\"calendario\": map[string]interface{} {\n\t\t\t\t\"expiracao\": 3600,\n\t\t\t},\n\t\t\"devedor\": map[string]interface{}{\n\t\t\t\n\t\t\t\t\"cpf\": \"12345678909\",\n\t\t\t\t\"nome\": \"Francisco da Silva\",\n\t\t\t\n\t\t},\n\t\t\"valor\": map[string]interface{} {\n\t\t\t\n\t\t\t\t\"original\": \"00.01\",\n\t\t\t\n\t\t},\n\t\t\"chave\": \"47e7e515-44d3-42cc-8e1f-ef529b4ba4d1\",\n\t\t\"solicitacaoPagador\": \"Teste.\",\n\t\t\"infoAdicionais\": []map[string]interface{} {\n\t\t\t{\n\t\t\t\t\"nome\": \"Campo 1\",\n\t\t\t\t\"valor\": \"Informação Adicional1 do PSP-Recebedor\",\n\t\t\t},\n\t\t},\n\t}\n\nres, err := gn.CreateImmediateCharge(body)", "language": "go", "name": "Go Pix" } ] } [/block] <br> # Exemplos Você pode rodar os exemplos dentro de <code>_examples</code> com <code>$ go run example.go</code>: [block:code] { "codes": [ { "code": "$ go run charge/create_charge.go", "language": "go" }, { "code": "$ go run chargecreateImmediateCharge.go", "language": "go", "name": "Go Pix" } ] } [/block] Basta lembrar de definir as credenciais corretas dentro de <code>_examples/configs.go</code> antes de serem executadas. # Testes Para executar os testes, basta executar: [block:code] { "codes": [ { "code": "$ go test", "language": "go" } ] } [/block]