gerencianet 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +15 -3
- data/docs/all-in-one.md +92 -0
- data/docs/carnet-detailing.md +61 -0
- data/docs/carnet-update.md +55 -0
- data/docs/carnets.md +217 -0
- data/docs/charge-detailing.md +42 -0
- data/docs/charge-payment.md +145 -0
- data/docs/charge-update.md +52 -0
- data/docs/charge-with-marketplace.md +54 -0
- data/docs/charges.md +94 -0
- data/docs/examples/.gitignore +1 -0
- data/docs/examples/all_in_one.rb +57 -0
- data/docs/examples/cancel_charge.rb +15 -0
- data/docs/examples/cancel_subscription.rb +15 -0
- data/docs/examples/create_billet_payment.rb +33 -0
- data/docs/examples/create_card_payment.rb +39 -0
- data/docs/examples/create_carnet.rb +32 -0
- data/docs/examples/create_charge.rb +24 -0
- data/docs/examples/create_plan.rb +17 -0
- data/docs/examples/create_subscription.rb +31 -0
- data/docs/examples/create_subscription_payment.rb +38 -0
- data/docs/examples/credentials.rb +5 -0
- data/docs/examples/delete_plan.rb +15 -0
- data/docs/examples/detail_carnet.rb +15 -0
- data/docs/examples/detail_charge.rb +15 -0
- data/docs/examples/detail_subscription.rb +15 -0
- data/docs/examples/get_installments.rb +16 -0
- data/docs/examples/get_notification.rb +15 -0
- data/docs/examples/get_plans.rb +17 -0
- data/docs/examples/update_billet.rb +19 -0
- data/docs/examples/update_carnet_metadata.rb +20 -0
- data/docs/examples/update_charge_metadata.rb +20 -0
- data/docs/examples/update_parcel.rb +20 -0
- data/docs/examples/update_subscription_metadata.rb +20 -0
- data/docs/installments.md +108 -0
- data/docs/notifications.md +105 -0
- data/docs/subscription-detailing.md +56 -0
- data/docs/subscription-payment.md +100 -0
- data/docs/subscription-update.md +29 -0
- data/docs/subscriptions.md +69 -0
- data/lib/gerencianet/constants.rb +1 -1
- data/lib/gerencianet/endpoints.rb +14 -19
- data/lib/gerencianet/version.rb +1 -1
- metadata +41 -2
@@ -0,0 +1,42 @@
|
|
1
|
+
## Detailing charges
|
2
|
+
|
3
|
+
It's very simple to get details from a charge. You just need the id:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
params = {
|
7
|
+
id: 1000
|
8
|
+
}
|
9
|
+
|
10
|
+
gerencianet = Gerencianet.new(options)
|
11
|
+
gerencianet.detail_charge(params: params)
|
12
|
+
```
|
13
|
+
|
14
|
+
As response, you will receive all the information about the charge (including if it belongs to a subscription or carnet):
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
{
|
18
|
+
"code": 200,
|
19
|
+
"data": {
|
20
|
+
"charge_id": 233,
|
21
|
+
"subscription_id": 12,
|
22
|
+
"total": 2000,
|
23
|
+
"status": "new",
|
24
|
+
"custom_id": null,
|
25
|
+
"created_at": "2015-05-14",
|
26
|
+
"notification_url": "http://yourdomain.com",
|
27
|
+
"items": [
|
28
|
+
{
|
29
|
+
"name": "Product 1",
|
30
|
+
"value": 1000,
|
31
|
+
"amount": 2
|
32
|
+
}
|
33
|
+
],
|
34
|
+
"history": [
|
35
|
+
{
|
36
|
+
"status": "new",
|
37
|
+
"created_at": "2015-05-14 15:39:14"
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
}
|
42
|
+
```
|
@@ -0,0 +1,145 @@
|
|
1
|
+
## Paying charges
|
2
|
+
|
3
|
+
There are two ways of giving sequence to a charge. You can generate a banking billet so it is payable until its due date, or can use the customer's credit card to submit the payment.
|
4
|
+
|
5
|
+
### 1. Banking billets
|
6
|
+
|
7
|
+
Setting banking billet as a charge's payment method is simple. You have to use `banking_billet` as the payment method and inform the `charge_id`.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "gerencianet"
|
11
|
+
require "date"
|
12
|
+
|
13
|
+
tomorrow = Date.today + 1
|
14
|
+
|
15
|
+
params = {
|
16
|
+
id: 2365
|
17
|
+
}
|
18
|
+
|
19
|
+
body = {
|
20
|
+
payment: {
|
21
|
+
banking_billet: {
|
22
|
+
expire_at: tomorrow.strftime,
|
23
|
+
customer: {
|
24
|
+
name: "Gorbadoc Oldbuck",
|
25
|
+
email: "oldbuck@gerencianet.com.br",
|
26
|
+
cpf: "04267484171",
|
27
|
+
birth: "1977-01-15",
|
28
|
+
phone_number: "5144916523"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
gerencianet = Gerencianet.new(options)
|
35
|
+
gerencianet.pay_charge(params: params, body: body)
|
36
|
+
```
|
37
|
+
|
38
|
+
If you don't set the `expire_at` attribute, the date will be the current day + 3.
|
39
|
+
|
40
|
+
You'll receive the payment info in the callback, such as the barcode and the billet link:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
{
|
44
|
+
"code": 200,
|
45
|
+
"data": {
|
46
|
+
"charge_id": 242,
|
47
|
+
"total": 1150,
|
48
|
+
"payment": "banking_billet",
|
49
|
+
"barcode": "00190.00009 01523.894002 00059.161182 9 64350000001150",
|
50
|
+
"link": "https://visualizacao.gerencianet.com.br/emissao/28333_2139_RRABRA7/A4XB-28333-59161-BRANAE4",
|
51
|
+
"expire_at": "2015-05-21"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
If you want the banking billet to have extra instructions, it's possible to send a maximum of 4 different instructions with a maximum of 90 caracters, just as follows:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
var body = {
|
60
|
+
payment: {
|
61
|
+
banking_billet: {
|
62
|
+
expire_at: tomorrow.strftime,
|
63
|
+
customer: {
|
64
|
+
name: "Gorbadoc Oldbuck",
|
65
|
+
email: "oldbuck@gerencianet.com.br",
|
66
|
+
cpf: "04267484171",
|
67
|
+
birth: "1977-01-15",
|
68
|
+
phone_number: "5144916523"
|
69
|
+
},
|
70
|
+
instructions: [
|
71
|
+
"Pay only with money",
|
72
|
+
"Do not pay with gold"
|
73
|
+
]
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
```
|
78
|
+
|
79
|
+
### 2. Credit card
|
80
|
+
|
81
|
+
The most common payment method is to use a credit card in order to make things happen faster. Paying a charge with a credit card in Gerencianet is as simples as generating a banking billet, as seen above.
|
82
|
+
|
83
|
+
The difference here is that we need to provide some extra information, as a `billing_address` and a `payment_token`. The former is used to make an anti-fraud analyze before accepting/appoving the payment, the latter identifies a credit card at Gerencianet, so that you don't need to bother about keeping track of credit card numbers. The `installments` attribute is self-explanatory.
|
84
|
+
|
85
|
+
We'll talk about getting payment tokens later. For now, let's take a look at the snipet that does the work we're aiming for:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
body = {
|
89
|
+
payment: {
|
90
|
+
credit_card: {
|
91
|
+
installments: 1,
|
92
|
+
payment_token: "5739b06925244dd1ab8e0afa62389d5fb4ea2945",
|
93
|
+
billing_address: {
|
94
|
+
street: "Av. JK",
|
95
|
+
number: 909,
|
96
|
+
neighborhood: "Bauxita",
|
97
|
+
zipcode: "35400000",
|
98
|
+
city: "Ouro Preto",
|
99
|
+
state: "MG"
|
100
|
+
},
|
101
|
+
customer: {
|
102
|
+
name: "Gorbadoc Oldbuck",
|
103
|
+
email: "oldbuck@gerencianet.com.br",
|
104
|
+
cpf: "04267484171",
|
105
|
+
birth: "1977-01-15",
|
106
|
+
phone_number: "5144916523"
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
params = {
|
113
|
+
id: 2366
|
114
|
+
}
|
115
|
+
|
116
|
+
gerencianet = Gerencianet.new(options)
|
117
|
+
gerencianet.pay_charge(params: params, body: body)
|
118
|
+
```
|
119
|
+
|
120
|
+
If everything went well, the response will come with the total value, installments number and the value of each installment:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
{
|
124
|
+
"code": 200,
|
125
|
+
"data": {
|
126
|
+
"charge_id": 223,
|
127
|
+
"total": 1150,
|
128
|
+
"payment": "credit_card",
|
129
|
+
"installments": 1,
|
130
|
+
"installment_value": 1150
|
131
|
+
}
|
132
|
+
}
|
133
|
+
```
|
134
|
+
|
135
|
+
##### Payment tokens
|
136
|
+
|
137
|
+
A `payment_token` represents a credit card number at Gerencianet.
|
138
|
+
|
139
|
+
For testing purposes, you can go to your application playground in your Gerencianet's account. At the payment endpoint you'll see a button that generates one token for you. This payment token will point to a random test credit card number.
|
140
|
+
|
141
|
+
When in production, it will depend if your project is a web app or a mobile app.
|
142
|
+
|
143
|
+
For web apps you should follow this [guide](https://api.gerencianet.com.br/checkout/card). It basically consists of copying/pasting a script tag in your checkout page.
|
144
|
+
|
145
|
+
For mobile apps you should use this [SDK for Android](https://github.com/gerencianet/gn-api-sdk-android) or this [SDK for iOS](https://github.com/gerencianet/gn-api-sdk-ios).
|
@@ -0,0 +1,52 @@
|
|
1
|
+
## Updating charges
|
2
|
+
|
3
|
+
### Changing the metadata
|
4
|
+
|
5
|
+
You can update the `custom_id` or the `notification_url` of a charge:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
params = {
|
9
|
+
id: 1008
|
10
|
+
}
|
11
|
+
|
12
|
+
body = {
|
13
|
+
notification_url: "http://yourdomain.com",
|
14
|
+
custom_id: "my_new_id"
|
15
|
+
}
|
16
|
+
|
17
|
+
gerencianet = Gerencianet.new(options)
|
18
|
+
gerencianet.update_charge_metadata(params: params, body: body)
|
19
|
+
```
|
20
|
+
|
21
|
+
If everything goes well, the return will be:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
{
|
25
|
+
"code": 200
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
### Updating the expiration date of a billet
|
30
|
+
|
31
|
+
Only charges with status `waiting` or `unpaid` and with payment method `banking_billet` can have the `expire_at` changed:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
params = {
|
35
|
+
id: 1008
|
36
|
+
}
|
37
|
+
|
38
|
+
body = {
|
39
|
+
expire_at: "2020-12-12"
|
40
|
+
}
|
41
|
+
|
42
|
+
gerencianet = Gerencianet.new(options)
|
43
|
+
gerencianet.update_billet(params: params, body: body)
|
44
|
+
```
|
45
|
+
|
46
|
+
If everything goes well, the return will be:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
{
|
50
|
+
"code": 200
|
51
|
+
}
|
52
|
+
```
|
@@ -0,0 +1,54 @@
|
|
1
|
+
## Creating charges with marketplace
|
2
|
+
|
3
|
+
What if your web store contains products from many different sellers from many different segments? The user can complete a single purchase with products from more than one seller, right? Here enters marketplace.
|
4
|
+
|
5
|
+
With some extra attributes, you can tell Gerencianet to pass on a percentage amount of the purchase total value to someone else.
|
6
|
+
|
7
|
+
Create the input data:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
body = {
|
11
|
+
items: [{
|
12
|
+
name: "Product A",
|
13
|
+
value: 1000,
|
14
|
+
amount: 1,
|
15
|
+
marketplace: {
|
16
|
+
repasses: [{
|
17
|
+
payee_code: "GEZTAMJYHA3DAMBQGAYDAMRYGMZTGM",
|
18
|
+
percentage: 2500
|
19
|
+
},{
|
20
|
+
payee_code: "AKSLJI3DAMBQGSKLJDYDAMRTGOPWKS",
|
21
|
+
percentage: 2500
|
22
|
+
}]
|
23
|
+
}
|
24
|
+
}],
|
25
|
+
metadata: {
|
26
|
+
notification_url: "http://yourdomain.com"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
Create the charge:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gerencianet.create_charge(body: body)
|
35
|
+
```
|
36
|
+
|
37
|
+
The attribute `payee_code` identifies a Gerencianet account, just like in [creating charges with shippings](https://github.com/gerencianet/gn-api-sdk-node/tree/master/docs/charge-with-shippings.md). In order to get someone else's `payee_code` you need to ask the account owner. There is no other way. To visualize yours, log in your Gerencianet account and search for *Identificador de Conta* under *Dados Cadastrais*.
|
38
|
+
|
39
|
+
In the example above, there are two repasses, both of 25%, but each one for a different account, whereas the `payee_code` differs. The integrator account will receive, at the end, 50% of the total value. Disregarding the rates, the integrator account would receive R$5,00. The other two accounts would receive R$ 2,50 each.
|
40
|
+
|
41
|
+
The response is the sames as usual:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
{
|
45
|
+
"code": 200,
|
46
|
+
"data": {
|
47
|
+
"charge_id": 254,
|
48
|
+
"total": 10000,
|
49
|
+
"status": "new",
|
50
|
+
"custom_id": null,
|
51
|
+
"created_at": "2015-05-18"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
```
|
data/docs/charges.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
## Creating charges
|
2
|
+
|
3
|
+
Charges have one or more items. That's it.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
body = {
|
7
|
+
items: [{
|
8
|
+
name: "Product 1",
|
9
|
+
value: 1000,
|
10
|
+
amount: 2
|
11
|
+
}]
|
12
|
+
}
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
### Adding shipping costs to a charge **(optional)**:
|
17
|
+
|
18
|
+
In order to be the most agnostic as possible about how the user handles shippings, the API just receives an array with the values. You can add as many as you want. Sometimes you'll want a shipping cost to be received by another person/account. In this case, you must provide the `payee_code`. The *Additional Shipping* in the example below will be passed on to the referenced account after the payment.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
body = {
|
22
|
+
items: [{
|
23
|
+
name: "Product A",
|
24
|
+
value: 1000,
|
25
|
+
amount: 2
|
26
|
+
}],
|
27
|
+
shippings: [{
|
28
|
+
name: "Default Shipping",
|
29
|
+
value: 100
|
30
|
+
}, {
|
31
|
+
name: "Additional Shipping",
|
32
|
+
value: 120,
|
33
|
+
payee_code: "GEZTAMJYHA3DAMBQGAYDAMRYGMZTGMBRGI"
|
34
|
+
}]
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
### Charge `metadata` attribute:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
body = {
|
42
|
+
items: [{
|
43
|
+
name: "Product A",
|
44
|
+
value: 1000,
|
45
|
+
amount: 2
|
46
|
+
}],
|
47
|
+
metadata: {
|
48
|
+
custom_id: "my_id",
|
49
|
+
notification_url: "http://yourdomain.com"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
```
|
53
|
+
|
54
|
+
The `notification_url` property will be used for sending notifications once things happen with charges statuses, as when it's payment was approved, for example. More about notifications [here](https://github.com/gerencianet/gn-api-sdk-node/tree/master/docs/notifications.md). The `custom_id` property can be used to set your own reference to the charge.
|
55
|
+
|
56
|
+
## Post office service:
|
57
|
+
|
58
|
+
If you want the charge to arrive at your house or at your client's house, you can count on Gerencianet's post office service. Just send an extra attribute:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
body = {
|
62
|
+
items: [{
|
63
|
+
name: "Product A",
|
64
|
+
value: 1000,
|
65
|
+
amount: 2
|
66
|
+
}],
|
67
|
+
post_office_service: {
|
68
|
+
send_to: "customer"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
```
|
72
|
+
|
73
|
+
If `send_to` is set to *customer*, the charge arrives at you customer's. If it is set to *seller*, just wait for it to arrive at your place. It's awesome!
|
74
|
+
|
75
|
+
### Finally, create the charge:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
gerencianet.create_charge(body: body)
|
79
|
+
```
|
80
|
+
|
81
|
+
Check out the response:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
{
|
85
|
+
"code": 200,
|
86
|
+
"data": {
|
87
|
+
"charge_id": 1253,
|
88
|
+
"total": 2000,
|
89
|
+
"status": "new",
|
90
|
+
"custom_id": null,
|
91
|
+
"created_at": "2015-05-18 14:56:39"
|
92
|
+
}
|
93
|
+
}
|
94
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
node_modules/
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "gerencianet"
|
2
|
+
require_relative "./credentials"
|
3
|
+
|
4
|
+
options = {
|
5
|
+
client_id: CREDENTIALS::CLIENT_ID,
|
6
|
+
client_secret: CREDENTIALS::CLIENT_SECRET,
|
7
|
+
sandbox: true
|
8
|
+
}
|
9
|
+
|
10
|
+
charge = {
|
11
|
+
items: [{
|
12
|
+
name: "Product 1",
|
13
|
+
value: 1000,
|
14
|
+
amount: 2
|
15
|
+
}],
|
16
|
+
shippings: [{
|
17
|
+
name: "Default Shipping Cost",
|
18
|
+
value: 100
|
19
|
+
}, {
|
20
|
+
name: "Adicional Shipping Cost",
|
21
|
+
value: 150
|
22
|
+
}]
|
23
|
+
}
|
24
|
+
|
25
|
+
payment = {
|
26
|
+
payment: {
|
27
|
+
credit_card: {
|
28
|
+
installments: 1,
|
29
|
+
payment_token: "88faabaa35f9d9ff29c315e03255c5644554a771",
|
30
|
+
billing_address: {
|
31
|
+
street: "Av. JK",
|
32
|
+
number: 909,
|
33
|
+
neighborhood: "Bauxita",
|
34
|
+
zipcode: "35400000",
|
35
|
+
city: "Ouro Preto",
|
36
|
+
state: "MG"
|
37
|
+
},
|
38
|
+
customer: {
|
39
|
+
name: "Gorbadoc Oldbuck",
|
40
|
+
email: "oldbuck@gerencianet.com.br",
|
41
|
+
cpf: "04267484171",
|
42
|
+
birth: "1977-01-15",
|
43
|
+
phone_number: "5144916523"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
gerencianet = Gerencianet.new(options)
|
50
|
+
|
51
|
+
charge = gerencianet.create_charge(body: charge)
|
52
|
+
|
53
|
+
params = {
|
54
|
+
id: charge["data"]["charge_id"]
|
55
|
+
}
|
56
|
+
|
57
|
+
puts gerencianet.pay_charge(params: params, body: payment)
|