Skip to content

Commit

Permalink
Merge pull request #1 from gerencianet/TZSD_729-SDK-com-Settle
Browse files Browse the repository at this point in the history
Tzsd 729 sdk com settle
  • Loading branch information
Thiagogresende authored Dec 27, 2018
2 parents 1daaeb6 + b262db0 commit d7cd6a2
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 88 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.0.3

- Added: new endpoint (settle charge)
- Added: new endpoint (settle parcel carnet)

# 1.0.2

- Added: new endpoint (create charge balance sheet)
Expand Down
167 changes: 81 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,81 @@
# gn-api-sdk-go

> A go library for integration of your backend with the payment services
provided by [Gerencianet](http://gerencianet.com.br).

[![Build Status](https://travis-ci.org/gerencianet/gn-api-sdk-go.svg)](https://travis-ci.org/gerencianet/gn-api-sdk-go)
[![Coverage Status](https://coveralls.io/repos/github/gerencianet/gn-api-sdk-go/badge.svg?branch=master)](https://coveralls.io/github/gerencianet/gn-api-sdk-go?branch=master)

## Installation

Install with:

```bash
$ go get github.com/gerencianet/gn-api-sdk-go/gerencianet
```
## Tested with
```
go 1.8
```
## Basic usage

```go

import (
"github.com/gerencianet/gn-api-sdk-go/gerencianet"
)

credentials := map[string]interface{} {
"client_id": "client_id",
"client_secret": "client_secret",
"sandbox": true,
"timeout": 10,
}

gn := gerencianet.NewGerencianet(credentials)

body = {
"items": [{
"name": "Product 1",
"value": 1000,
"amount": 2,
}],
"shippings": [{
"name": "Default Shipping Cost",
"value": 100,
}]
}

res, err := gn.CreateCharge(body)

```

## Examples

You can run the examples inside `_examples` with
`$ go run example.go`:

```bash
$ go run charge/create_charge.go
```

Just remember to set the correct credentials inside `examples/configs.go` before running.

## Tests

To run the tests, just run:

```bash
$ go test
```

## Additional documentation

The full documentation with all available endpoints is in https://dev.gerencianet.com.br/.

## Changelog

[CHANGELOG](CHANGELOG.md)

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gerencianet/gn-api-sdk-go. This project is intended to be a safe, welcoming space for collaboration.

## License

The library is available as open source under the terms of the [MIT License](LICENSE).
# gn-api-sdk-go

> A go library for integration of your backend with the payment services
provided by [Gerencianet](http://gerencianet.com.br).

[![Build Status](https://travis-ci.org/gerencianet/gn-api-sdk-go.svg)](https://travis-ci.org/gerencianet/gn-api-sdk-go)
[![Coverage Status](https://coveralls.io/repos/github/gerencianet/gn-api-sdk-go/badge.svg?branch=master)](https://coveralls.io/github/gerencianet/gn-api-sdk-go?branch=master)

## Installation

Install with:

```bash

$ go get github.com/gerencianet/gn-api-sdk-go/gerencianet
```
## Tested with
```
go 1.8 and 1.11.4
```
## Basic usage

```go

import (
"github.com/FilipeMata/gn-api-sdk-go/gerencianet"
)

credentials := map[string]interface{} {
"client_id": "client_id",
"client_secret": "client_secret",
"sandbox": true,
"timeout": 10,
}

gn := gerencianet.NewGerencianet(credentials)

body = {
"items": [{
"name": "Product 1",
"value": 1000,
"amount": 2,
}],
"shippings": [{
"name": "Default Shipping Cost",
"value": 100,
}]
}

res, err := gn.CreateCharge(body)

```

## Examples

You can run the examples inside `_examples` with
`$ go run example.go`:

```bash
$ go run charge/create_charge.go
```

Just remember to set the correct credentials inside `examples/configs.go` before running.

## Tests

To run the tests, just run:

```bash
$ go test
```

## Changelog

[CHANGELOG](CHANGELOG.md)


## License

The library is available as open source under the terms of the [MIT License](LICENSE).
21 changes: 21 additions & 0 deletions _examples/carnet/settle_parcel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"
"github.com/gerencianet/gn-api-sdk-go/gerencianet"
"github.com/gerencianet/gn-api-sdk-go/_examples/configs"
)

func main(){

credentials := configs.Credentials
gn := gerencianet.NewGerencianet(credentials)

res, err := gn.SettleCarnetParcel(1, 1) // no lugar dos 1s coloque o carnet_id e o numero da parcela respectivamente

if err != nil {
fmt.Println(err)
} else {
fmt.Println(res)
}
}
21 changes: 21 additions & 0 deletions _examples/charge/settle_charge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"fmt"
"github.com/gerencianet/gn-api-sdk-go/gerencianet"
"github.com/gerencianet/gn-api-sdk-go/_examples/configs"
)

func main(){

credentials := configs.Credentials
gn := gerencianet.NewGerencianet(credentials)

res, err := gn.SettleCharge(1) // no lugar do 1 coloque o charge_id certo

if err != nil {
fmt.Println(err)
} else {
fmt.Println(res)
}
}
2 changes: 1 addition & 1 deletion gerencianet/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gerencianet

var Version = "1.0.1"
var Version = "1.0.3"

const (
UrlSandbox = "https://sandbox.gerencianet.com.br/v1"
Expand Down
15 changes: 14 additions & 1 deletion gerencianet/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,17 @@ func (endpoints endpoints) UpdatePlan(planID int, body map[string]interface{}) (
func (endpoints endpoints) CreateChargeBalanceSheet(chargeID int, body map[string]interface{}) (string, error) {
params := map[string]string{ "id": strconv.Itoa(chargeID) }
return endpoints.requester.request("/charge/:id/balance-sheet", "POST", params, body)
}
}

func (endpoints endpoints) SettleCarnetParcel(carnetID int, parcel int) (string, error) {
params := map[string]string{
"id": strconv.Itoa(carnetID),
"parcel": strconv.Itoa(parcel),
}
return endpoints.requester.request("/carnet/:id/parcel/:parcel/settle", "PUT", params, nil)
}

func (endpoints endpoints) SettleCharge(chargeID int) (string, error) {
params := map[string]string{ "id": strconv.Itoa(chargeID) }
return endpoints.requester.request("/charge/:id/settle", "PUT", params, nil)
}
4 changes: 4 additions & 0 deletions gerencianet/endpoints_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ func Test_endpoints(t *testing.T) {
endpoints.UpdatePlan(1, nil)
endpoints.CreateSubscriptionHistory(1, nil)
endpoints.CreateChargeBalanceSheet(1, nil)
endpoints.SettleCarnetParcel(1, 1)
endpoints.SettleCharge(1)


t.Skip("skipping endpoints tests")
}

0 comments on commit d7cd6a2

Please sign in to comment.