gerencianet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +15 -3
  4. data/docs/all-in-one.md +92 -0
  5. data/docs/carnet-detailing.md +61 -0
  6. data/docs/carnet-update.md +55 -0
  7. data/docs/carnets.md +217 -0
  8. data/docs/charge-detailing.md +42 -0
  9. data/docs/charge-payment.md +145 -0
  10. data/docs/charge-update.md +52 -0
  11. data/docs/charge-with-marketplace.md +54 -0
  12. data/docs/charges.md +94 -0
  13. data/docs/examples/.gitignore +1 -0
  14. data/docs/examples/all_in_one.rb +57 -0
  15. data/docs/examples/cancel_charge.rb +15 -0
  16. data/docs/examples/cancel_subscription.rb +15 -0
  17. data/docs/examples/create_billet_payment.rb +33 -0
  18. data/docs/examples/create_card_payment.rb +39 -0
  19. data/docs/examples/create_carnet.rb +32 -0
  20. data/docs/examples/create_charge.rb +24 -0
  21. data/docs/examples/create_plan.rb +17 -0
  22. data/docs/examples/create_subscription.rb +31 -0
  23. data/docs/examples/create_subscription_payment.rb +38 -0
  24. data/docs/examples/credentials.rb +5 -0
  25. data/docs/examples/delete_plan.rb +15 -0
  26. data/docs/examples/detail_carnet.rb +15 -0
  27. data/docs/examples/detail_charge.rb +15 -0
  28. data/docs/examples/detail_subscription.rb +15 -0
  29. data/docs/examples/get_installments.rb +16 -0
  30. data/docs/examples/get_notification.rb +15 -0
  31. data/docs/examples/get_plans.rb +17 -0
  32. data/docs/examples/update_billet.rb +19 -0
  33. data/docs/examples/update_carnet_metadata.rb +20 -0
  34. data/docs/examples/update_charge_metadata.rb +20 -0
  35. data/docs/examples/update_parcel.rb +20 -0
  36. data/docs/examples/update_subscription_metadata.rb +20 -0
  37. data/docs/installments.md +108 -0
  38. data/docs/notifications.md +105 -0
  39. data/docs/subscription-detailing.md +56 -0
  40. data/docs/subscription-payment.md +100 -0
  41. data/docs/subscription-update.md +29 -0
  42. data/docs/subscriptions.md +69 -0
  43. data/lib/gerencianet/constants.rb +1 -1
  44. data/lib/gerencianet/endpoints.rb +14 -19
  45. data/lib/gerencianet/version.rb +1 -1
  46. metadata +41 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db0dc12a8bb152c33bb1386d2ead264880cf56c0
4
- data.tar.gz: 5e72412e908a0369f4cded139d779bea0159601b
3
+ metadata.gz: c51582bc8d3f69e20fd2ae7ddfeb364ca88395ed
4
+ data.tar.gz: 7a34a05694cc686bbc15486c443022dd3e584636
5
5
  SHA512:
6
- metadata.gz: 076b82eac8e238d2115de2c38254b899fa47d2a15dd8d9cf0bc1b8484189a44b70ca5e73974960f3a130b3e99a19c7be43d5a706845ee111d5f10a5ec40afe76
7
- data.tar.gz: 518f72c4a4e0a794bd3c0e7b203dde35d6c1865f45ec0eefa3e7b94affb1906f96b9dd9ba205be9410d5b3e847835e0a354139ed925c11fdff1587b7804ce0ce
6
+ metadata.gz: 8c6ca03e6e20f3d1b2377f74f41f4a83afa9d4944ae737ad2dada29d2fd1103a649cba9479a3b93047514828a88411f5baf833d8c9f3fb663977fcbe2bb1f2c0
7
+ data.tar.gz: 00269412bb8ee22c3bd481162d4cc920884a0b73786c3cc9d29ed61712c97cecded6c7123e6cd546439d4dcad71283849b97a7073ba2e17594424f045e8976cc
@@ -0,0 +1,8 @@
1
+ # 0.0.2
2
+
3
+ - Changed: Functions now receive a single hash param like `{params: params, body: body}` instead of receiving two params `params, body` as before.
4
+ - Added: Docs and examples
5
+
6
+ # 0.0.1
7
+
8
+ - Initial release
data/README.md CHANGED
@@ -6,6 +6,7 @@ provided by [Gerencianet](http://gerencianet.com.br).
6
6
  [![Build Status](https://travis-ci.org/gerencianet/gn-api-sdk-ruby.svg)](https://travis-ci.org/gerencianet/gn-api-sdk-ruby)
7
7
  [![Coverage Status](https://coveralls.io/repos/gerencianet/gn-api-sdk-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/gerencianet/gn-api-sdk-ruby?branch=master)
8
8
  [![Code Climate](https://codeclimate.com/github/gerencianet/gn-api-sdk-ruby/badges/gpa.svg)](https://codeclimate.com/github/gerencianet/gn-api-sdk-ruby)
9
+ [![Gem Version](https://badge.fury.io/rb/gerencianet.svg)](https://badge.fury.io/rb/gerencianet)
9
10
 
10
11
  :warning: **Gerencianet API is under BETA version, meaning that it's not available for all users right now. If you're interested, you can always send an email to
11
12
  desenvolvedores@gerencianet.com.br and we'll enable it for your account**
@@ -23,6 +24,7 @@ And then execute:
23
24
  ```bash
24
25
  $ bundle
25
26
  ```
27
+
26
28
  Or install it yourself as:
27
29
 
28
30
  ```bash
@@ -40,9 +42,9 @@ options = {
40
42
  sandbox: true
41
43
  }
42
44
 
43
- gerencianet = Gerencianet.new(@options)
45
+ gerencianet = Gerencianet.new(options)
44
46
 
45
- input = {
47
+ charge = {
46
48
  items: [{
47
49
  name: "Product A",
48
50
  value: 1000,
@@ -50,9 +52,19 @@ input = {
50
52
  }]
51
53
  }
52
54
 
53
- response = gerencianet.create_charge(input)
55
+ response = gerencianet.create_charge(body: charge)
54
56
  ```
55
57
 
58
+ ## Examples
59
+
60
+ You can run the examples inside `docs/examples` with `$ ruby docs/examples/example.rb`:
61
+
62
+ ```bash
63
+ $ ruby docs/examples/create_charge.rb
64
+ ```
65
+
66
+ Just remember to set the correct credentials inside `docs/examples/credentials.rb` before running.
67
+
56
68
  ## Tests
57
69
 
58
70
  To run the tests, just run *rspec*:
@@ -0,0 +1,92 @@
1
+ ## Create charge and payment
2
+
3
+ The most common case scenarios consist of the two steps mentioned in the title. The other examples show each part separately. Here goes the most used endpoints grouped in one example.
4
+
5
+ Create the inputs for the three endpoints:
6
+
7
+ ```ruby
8
+ charge = {
9
+ items: [{
10
+ name: "Product 1",
11
+ value: 1000,
12
+ amount: 2
13
+ }],
14
+ shippings: [{
15
+ name: "Default Shipping Cost",
16
+ value: 100
17
+ }, {
18
+ name: "Adicional Shipping Cost",
19
+ value: 150
20
+ }]
21
+ }
22
+
23
+ payment = {
24
+ payment: {
25
+ credit_card: {
26
+ installments: 1,
27
+ payment_token: "88faabaa35f9d9ff29c315e03255c5644554a771",
28
+ billing_address: {
29
+ street: "Av. JK",
30
+ number: 909,
31
+ neighborhood: "Bauxita",
32
+ zipcode: "35400000",
33
+ city: "Ouro Preto",
34
+ state: "MG"
35
+ },
36
+ customer: {
37
+ name: "Gorbadoc Oldbuck",
38
+ email: "oldbuck@gerencianet.com.br",
39
+ cpf: "04267484171",
40
+ birth: "1977-01-15",
41
+ phone_number: "5144916523"
42
+ }
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ Call the endpoints:
49
+
50
+ ```ruby
51
+ require "gerencianet"
52
+
53
+ options = {
54
+ client_id: "client_id",
55
+ client_secret: "client_secret",
56
+ sandbox: true
57
+ }
58
+
59
+ gerencianet = Gerencianet.new(options)
60
+
61
+ charge = gerencianet.create_charge(body: charge)
62
+
63
+ params = {
64
+ id: charge["data"]["charge_id"]
65
+ }
66
+
67
+ puts gerencianet.pay_charge(params: params, body: payment)
68
+ ```
69
+
70
+ Response:
71
+
72
+ ```ruby
73
+ { "code": 200,
74
+ "data": {
75
+ "charge_id": 260,
76
+ "total": 2250,
77
+ "status": 'new',
78
+ "custom_id": null,
79
+ "created_at": "2015-05-18"
80
+ }
81
+ } #charge created
82
+
83
+ { "code": 200,
84
+ "data": {
85
+ "charge_id": 260,
86
+ "total": 2400,
87
+ "payment": "credit_card",
88
+ "installments": 1,
89
+ "installment_value": 2400
90
+ }
91
+ } #payment created
92
+ ```
@@ -0,0 +1,61 @@
1
+ ## Detailing carnets
2
+
3
+ In order to retrieve carnets, just provide the id:
4
+
5
+ ```ruby
6
+ params = {
7
+ id: 1000
8
+ }
9
+
10
+ gerencianet = Gerencianet.new(options)
11
+ puts gerencianet.detail_carnet(params: params)
12
+ ```
13
+
14
+ The response you'll receive contains all the information about the carnet:
15
+
16
+ ```ruby
17
+ {
18
+ "code": 200,
19
+ "data": {
20
+ "carnet_id": 6,
21
+ "status": "active",
22
+ "repeats": 4,
23
+ "cover": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CC-28333-61428-LEENA9/28333-61428-LEENA9",
24
+ "value": 4000,
25
+ "split_items": false,
26
+ "charges": [{
27
+ "charge_id": 357,
28
+ "parcel": "1",
29
+ "status": "waiting",
30
+ "value": 2000,
31
+ "expire_at": '2015-06-01',
32
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61428-LEENA9",
33
+ "barcode": "00190.00009 01523.894002 00061.428181 1 64780000002000"
34
+ }, {
35
+ "charge_id": 358,
36
+ "parcel": "2",
37
+ "status": "waiting",
38
+ "value": 2000,
39
+ "expire_at": '2015-07-01',
40
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61429-CORZE4",
41
+ "barcode": "00190.00009 01523.894002 00061.428181 8 65090000002000"
42
+ }, {
43
+ "charge_id": 359,
44
+ "parcel": "3",
45
+ "status": "waiting",
46
+ "value": 2000,
47
+ "expire_at": '2015-08-01',
48
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61430-HIRRA4",
49
+ "barcode": "00190.00009 01523.894002 00061.428181 7 65400000002000"
50
+ }, {
51
+ "charge_id": 360,
52
+ "parcel": "4",
53
+ "status": "waiting",
54
+ "value": 2000,
55
+ "expire_at": '2015-09-01',
56
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61431-HIRRA4",
57
+ "barcode": "00190.00009 01523.894002 00061.428181 5 65400000002000"
58
+ }
59
+ ]
60
+ }
61
+ }
@@ -0,0 +1,55 @@
1
+ ## Updating carnets
2
+
3
+ ### Changing the metadata
4
+
5
+ You can update the `custom_id` and the `notification_url` of a carnet at any time.
6
+
7
+ It's important to keep in mind that all the charges of the carnet will be updated. If you want to update only one charge, check [Updating charges](/docs/charge-update.md).
8
+
9
+ ```ruby
10
+ params = {
11
+ id: 1004
12
+ }
13
+
14
+ body = {
15
+ notification_url: "http://yourdomain.com",
16
+ custom_id: "my_new_id"
17
+ }
18
+
19
+ gerencianet = Gerencianet.new(options)
20
+ puts gerencianet.update_carnet_metadata(params: params, body: body)
21
+ ```
22
+
23
+ If everything goes well, the response will be:
24
+
25
+ ```ruby
26
+ {
27
+ "code": 200
28
+ }
29
+ ```
30
+
31
+ ### Updating the expiration date of a parcel
32
+
33
+ Only parcels with status `waiting` or `unpaid` can have expiration date set or updated:
34
+
35
+ ```ruby
36
+ params = {
37
+ id: 1008
38
+ }
39
+
40
+ body = {
41
+ parcel: 1,
42
+ expire_at: "2020-12-12"
43
+ }
44
+
45
+ gerencianet = Gerencianet.new(options)
46
+ puts gerencianet.update_parcel(params: params, body: body)
47
+ ```
48
+
49
+ If everything goes well, the response will be:
50
+
51
+ ```ruby
52
+ {
53
+ "code": 200
54
+ }
55
+ ```
@@ -0,0 +1,217 @@
1
+ ## Creating carnet billets
2
+
3
+ Carnet is a payment method that generates a bundle of charges with the same payment information and customer.
4
+
5
+ In order to generate a carnet, you'll need the items, the customer and the number of repeats (or parcels).
6
+
7
+ The carnets can also be generated with the `metadata` attribute, just like in the banking billet, containing the `notification_url` and/or `custom_id`
8
+
9
+ There are other optional params:
10
+
11
+ - `expiration date` of the first charge
12
+ - `post_office_service`, which tells if the carnet must be sent via post office service (to you or to your clients)
13
+ - `split_items`, identifying if the total value must be splitted among the charges (defaults to `false`)
14
+ - The carnet `instructions`
15
+
16
+ ### Required properties:
17
+
18
+ ```ruby
19
+ body = {
20
+ expire_at: tomorrow.strftime,
21
+ items: [{
22
+ name: "Carnet Item 1",
23
+ value: 1000,
24
+ amount: 2
25
+ }],
26
+ customer: {
27
+ name: "Gorbadoc Oldbuck",
28
+ email: "oldbuck@gerencianet.com.br",
29
+ cpf: "04267484171",
30
+ birth: "1977-01-15",
31
+ phone_number: "5144916523"
32
+ },
33
+ repeats: 12,
34
+ split_items: false
35
+ }
36
+ ```
37
+
38
+ ### Required properties plus metadata **(optional)**:
39
+
40
+ ```ruby
41
+ body = {
42
+ expire_at: tomorrow.strftime,
43
+ items: [{
44
+ name: "Carnet Item 1",
45
+ value: 1000,
46
+ amount: 2
47
+ }],
48
+ customer: {
49
+ name: "Gorbadoc Oldbuck",
50
+ email: "oldbuck@gerencianet.com.br",
51
+ cpf: "04267484171",
52
+ birth: "1977-01-15",
53
+ phone_number: "5144916523"
54
+ },
55
+ repeats: 12,
56
+ metadata: {
57
+ custom_id: "my_id",
58
+ notification_url: "http://yourdomain.com"
59
+ }
60
+ }
61
+ ```
62
+
63
+ 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 carnet.
64
+
65
+ ### Required properties plus expiration date of the first charge **(optional)**:
66
+
67
+ If you don't provide the expiration date of the first charge, the defaut value will be the current day + 8.
68
+
69
+ ```ruby
70
+ body = {
71
+ items: [{
72
+ name: "Carnet Item 1",
73
+ value: 1000,
74
+ amount: 2
75
+ }],
76
+ customer: {
77
+ name: "Gorbadoc Oldbuck",
78
+ email: "oldbuck@gerencianet.com.br",
79
+ cpf: "04267484171",
80
+ birth: "1977-01-15",
81
+ phone_number: "5144916523"
82
+ },
83
+ repeats: 4,
84
+ expire_at: "2020-12-12"
85
+ }
86
+ ```
87
+
88
+ ### Required properties plus post office service information **(optional)**:
89
+
90
+ If you want the carnet 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:
91
+
92
+ ```ruby
93
+ body = {
94
+ items: [{
95
+ name: "Carnet Item 1",
96
+ value: 1000,
97
+ amount: 2
98
+ }],
99
+ customer: {
100
+ name: "Gorbadoc Oldbuck",
101
+ email: "oldbuck@gerencianet.com.br",
102
+ cpf: "04267484171",
103
+ birth: "1977-01-15",
104
+ phone_number: "5144916523"
105
+ },
106
+ repeats: 4,
107
+ post_office_service: {
108
+ send_to: "customer"
109
+ }
110
+ }
111
+ ```
112
+
113
+ If `send_to` is set to *customer*, the carnet arrives at you customer's. If it is set to *seller*, just wait for it to arrive at your place!
114
+
115
+
116
+ ### split_items attribute **(optional)**
117
+
118
+ By default, each parcel has the total value of the carnet. If you want to divide the total value among the parcels, change `split_items` property to *true*.
119
+
120
+ ```ruby
121
+ var body = {
122
+ items: [{
123
+ name: "Carnet Item 1",
124
+ value: 1000,
125
+ amount: 2
126
+ }],
127
+ customer: {
128
+ name: "Gorbadoc Oldbuck",
129
+ email: "oldbuck@gerencianet.com.br",
130
+ cpf: "04267484171",
131
+ birth: "1977-01-15",
132
+ phone_number: "5144916523"
133
+ },
134
+ repeats: 4,
135
+ split_items: true
136
+ }
137
+ ```
138
+
139
+ ### Setting instructions **(optional)**
140
+
141
+ If you want the carnet 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:
142
+
143
+ ```ruby
144
+ body = {
145
+ items: [{
146
+ name: "Carnet Item 1",
147
+ value: 1000,
148
+ amount: 2
149
+ }],
150
+ customer: {
151
+ name: "Gorbadoc Oldbuck",
152
+ email: "oldbuck@gerencianet.com.br",
153
+ cpf: "04267484171",
154
+ birth: "1977-01-15",
155
+ phone_number: "5144916523"
156
+ },
157
+ repeats: 4,
158
+ instructions: [
159
+ "Pay only with money",
160
+ "Do not pay with gold"
161
+ ]
162
+ }
163
+ ```
164
+
165
+ ### Finally, create the carnet:
166
+
167
+ ```ruby
168
+ gerencianet.create_carnet(body: body)
169
+ ```
170
+
171
+ Check out the response:
172
+
173
+ ```ruby
174
+ {
175
+ "code": 200,
176
+ "data": {
177
+ "carnet_id": 6,
178
+ "cover": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CC-28333-61428-LEENA9/28333-61428-LEENA9",
179
+ "charges": [{
180
+ "charge_id": 357,
181
+ "parcel": "1",
182
+ "status": "waiting",
183
+ "value": 2000,
184
+ "expire_at": "2015-06-01",
185
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61428-LEENA9",
186
+ "barcode": "00190.00009 01523.894002 00061.428181 1 64780000002000"
187
+ }, {
188
+ "charge_id": 358,
189
+ "parcel": "2",
190
+ "status": "waiting",
191
+ "value": 2000,
192
+ "expire_at": "2015-07-01",
193
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61429-CORZE4",
194
+ "barcode": "00190.00009 01523.894002 00061.428181 8 65090000002000"
195
+ }, {
196
+ "charge_id": 359,
197
+ "parcel": "3",
198
+ "status": "waiting",
199
+ "value": 2000,
200
+ "expire_at": "2015-08-01",
201
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61430-HIRRA4",
202
+ "barcode": "00190.00009 01523.894002 00061.428181 7 65400000002000"
203
+ }, {
204
+ "charge_id": 360,
205
+ "parcel": "4",
206
+ "status": "waiting",
207
+ "value": 2000,
208
+ "expire_at": "2015-09-01",
209
+ "url": "https://visualizacao.gerencianet.com.br/emissao/28333_2385_ZEMAL5/A5CL-28333-61428-LEENA9/28333-61431-HIRRA4",
210
+ "barcode": "00190.00009 01523.894002 00061.428181 5 65400000002000"
211
+ }
212
+ ]
213
+ }
214
+ }
215
+ ```
216
+
217
+ Notice that, as the `repeats` were set to 4, the output contains 4 charges with `waiting` status. The value of each charge is the sum of the items values, because the `split_items` property was set to *false*. Also notice that `expire_at` increases monthly.