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
@@ -0,0 +1,20 @@
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
+ params = {
11
+ id: 1008
12
+ }
13
+
14
+ body = {
15
+ parcel: 1,
16
+ expire_at: "2020-12-12"
17
+ }
18
+
19
+ gerencianet = Gerencianet.new(options)
20
+ puts gerencianet.update_parcel(params: params, body: body)
@@ -0,0 +1,20 @@
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
+ params = {
11
+ id: 1009
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_subscription_metadata(params: params, body: body)
@@ -0,0 +1,108 @@
1
+ ## Listing installments
2
+
3
+ If you ever need to get the total value for a charge, including rates and interests, as well as each installment value, even before the payment itself, you can.
4
+
5
+ Why would I need this?
6
+
7
+ Sometimes you need to check the total for making a discount, or simple to show a combobox with the installments for your users.
8
+
9
+ Stop bragging about. Here is the code:
10
+
11
+ ```ruby
12
+ params = {
13
+ brand: "visa",
14
+ total: 5000
15
+ }
16
+
17
+ gerencianet = Gerencianet.new(options)
18
+ gerencianet.get_installments(params: params)
19
+ ```
20
+
21
+ And the response:
22
+
23
+ ```ruby
24
+ {
25
+ "code": 200,
26
+ "data": {
27
+ "rate": 150,
28
+ "interest_percentage": 0,
29
+ "name": "visa",
30
+ "installments": [
31
+ {
32
+ "installment": 1,
33
+ "has_interest": false,
34
+ "value": 5150,
35
+ "currency": "51,50"
36
+ },
37
+ {
38
+ "installment": 2,
39
+ "has_interest": true,
40
+ "value": 2679,
41
+ "currency": "26,79"
42
+ },
43
+ {
44
+ "installment": 3,
45
+ "has_interest": true,
46
+ "value": 1821,
47
+ "currency": "18,21"
48
+ },
49
+ {
50
+ "installment": 4,
51
+ "has_interest": true,
52
+ "value": 1393,
53
+ "currency": "13,93"
54
+ },
55
+ {
56
+ "installment": 5,
57
+ "has_interest": true,
58
+ "value": 1137,
59
+ "currency": "11,37"
60
+ },
61
+ {
62
+ "installment": 6,
63
+ "has_interest": true,
64
+ "value": 966,
65
+ "currency": "9,66"
66
+ },
67
+ {
68
+ "installment": 7,
69
+ "has_interest": true,
70
+ "value": 845,
71
+ "currency": "8,45"
72
+ },
73
+ {
74
+ "installment": 8,
75
+ "has_interest": true,
76
+ "value": 754,
77
+ "currency": "7,54"
78
+ },
79
+ {
80
+ "installment": 9,
81
+ "has_interest": true,
82
+ "value": 683,
83
+ "currency": "6,83"
84
+ },
85
+ {
86
+ "installment": 10,
87
+ "has_interest": true,
88
+ "value": 627,
89
+ "currency": "6,27"
90
+ },
91
+ {
92
+ "installment": 11,
93
+ "has_interest": true,
94
+ "value": 581,
95
+ "currency": "5,81"
96
+ },
97
+ {
98
+ "installment": 12,
99
+ "has_interest": true,
100
+ "value": 544,
101
+ "currency": "5,44"
102
+ }
103
+ ]
104
+ }
105
+ }
106
+ ```
107
+
108
+ Observe that the response comes with an installments array of 12 positions at maximum. Each position matches one possible option of installment number, containing its value in currency and integer forms. The number of installments will vary according to the selected brand. Use it any way that suits your needs.
@@ -0,0 +1,105 @@
1
+ ## Notifications
2
+
3
+ Any changes that happen in the charges will trigger an event that notifies the `notification_url` provided at creation time (see [creating charges](https://github.com/gerencianet/gn-api-sdk-node/tree/master/docs/charges.md)).
4
+
5
+ It's also possible to set or change the `notification_url` for existing charges, see [updating informations](https://github.com/gerencianet/gn-api-sdk-node/tree/master/docs/charge-update.md).
6
+
7
+ Given that a charge has a valid `notification_url`, when the notification time comes you'll receive a post with a `token`. This token must be used to get the notification payload data.
8
+
9
+ The example below assumes that you're using a **Rails** app. It's easier showing than explaining with words:
10
+
11
+ ```ruby
12
+ class TicketsController < ApplicationController
13
+ # this is a post route
14
+ def notification_route
15
+ params = {
16
+ token: params[:token]
17
+ }
18
+
19
+ gerencianet = Gerencianet.new(options)
20
+ gerencianet.get_notification(params: params)
21
+ end
22
+ end
23
+ ```
24
+
25
+ Response:
26
+
27
+ ```ruby
28
+ {
29
+ "code": 200,
30
+ "data": [{
31
+ "id": 1,
32
+ "type": "charge",
33
+ "custom_id": null,
34
+ "status": {
35
+ "current": "new",
36
+ "previous": null
37
+ },
38
+ "identifiers": {
39
+ "charge_id": 1002
40
+ }
41
+ }, {
42
+ "id": 2,
43
+ "type": "charge",
44
+ "custom_id": null,
45
+ "status": {
46
+ "current": "waiting",
47
+ "previous": "new"
48
+ },
49
+ "identifiers": {
50
+ "charge_id": 1002
51
+ }
52
+ }, {
53
+ "id": 3,
54
+ "type": "charge",
55
+ "custom_id": null,
56
+ "status": {
57
+ "current": "paid",
58
+ "previous": "waiting"
59
+ },
60
+ "identifiers": {
61
+ "charge_id": 1002
62
+ },
63
+ "value": 2000
64
+ }, {
65
+ "id": 4,
66
+ "type": "charge",
67
+ "custom_id": null,
68
+ "status": {
69
+ "current": "refunded",
70
+ "previous": "paid"
71
+ },
72
+ "identifiers": {
73
+ "charge_id": 1002
74
+ }
75
+ }]
76
+ }
77
+ ```
78
+
79
+ The response will be an array with all the changes of a certain token that happened within the past 6 months. It will have the following parameters:
80
+
81
+ * id: Each notification has its own sequence, starting from `1`. The `id` parameter identifies this sequence. This is useful if you need to keep track of what changes you have already processed.
82
+
83
+ * type: Available values are:
84
+ * `charge` - a charge have changed
85
+ * `subscription` - a subscription have changed
86
+ * `carnet` - a carnet have changed
87
+ * `subscription_charge` - one subscription's parcel have changed
88
+ * `carnet_charge` - one carnet's parcel have changed
89
+
90
+ * custom_id: your custom_id.
91
+
92
+ * status: Contains the `current` and `previous` (before the change) status of the transaction.
93
+
94
+ p.s.: if there is no `previous` status (i.e.: for new charges), the `previous` value will be null.
95
+
96
+ * identifiers: Identifiers related to the change. It may have one or more identifier, depending on the type:
97
+ * for `charge` type: identifiers will contain only `charge_id`.
98
+ * for `subscription` type: identifiers will contain only `subscription_id`.
99
+ * for `carnet` type: identifiers will contain only `carnet_id`.
100
+ * for `subscription_charge` type: identifiers will contain both `charge_id` and `subscription_id`.
101
+ * for `carnet_charge` type: identifiers will contain both `charge_id` and `carnet_id`.
102
+
103
+ * value: This parameter will only be shown when the status changes to paid.
104
+
105
+ For more informations about notifications, please refer to [Gerencianet](https://docs.gerencianet.com.br/#!/charges/notifications).
@@ -0,0 +1,56 @@
1
+ ## Detailing subscriptions
2
+
3
+ Works just like the charge detailing, but here you pass the subscription id:
4
+
5
+ ```ruby
6
+ params = {
7
+ id: 1120
8
+ }
9
+
10
+ gerencianet = Gerencianet.new(options)
11
+ gerencianet.detail_subscription(params: params)
12
+ ```
13
+
14
+ Response:
15
+
16
+ ```ruby
17
+ {
18
+ "code": 200,
19
+ "data": {
20
+ "subscription_id": 12,
21
+ "value": 2000,
22
+ "status": "new",
23
+ "payment_method": null,
24
+ "next_execution": null,
25
+ "next_expire_at": null,
26
+ "interval": 1,
27
+ "repeats": 2,
28
+ "processed_amount": 0,
29
+ "created_at": "2015-05-14 15:39:14",
30
+ "history": [
31
+ {
32
+ "charge_id": 233,
33
+ "status": "new",
34
+ "created_at": "2015-05-14 15:39:14"
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ ```
40
+
41
+ Note that if you [detail a charge](/docs/charge-detailing.md) that belongs to a subscription, the response will have a `subscription` block with data about it, including the `subscription_id`. If you need the subscription information, you can do this:
42
+
43
+ ```ruby
44
+ params = {
45
+ charge_id: 2332
46
+ }
47
+
48
+ gerencianet = Gerencianet.new(options)
49
+ charge = gerencianet.detail_charge(params: params)
50
+
51
+ params = {
52
+ id: charge["data"]["subscription_id"]
53
+ }
54
+
55
+ gerencianet.detail_subscription(params: params)
56
+ ```
@@ -0,0 +1,100 @@
1
+ ## Paying subscriptions
2
+
3
+ ### 1. Banking billets
4
+
5
+ ```ruby
6
+ params = {
7
+ id: 1113
8
+ }
9
+
10
+ var body = {
11
+ payment: {
12
+ banking_billet: {
13
+ expire_at: "2016-12-12",
14
+ customer: {
15
+ name: "Gorbadoc Oldbuck",
16
+ email: "oldbuck@gerencianet.com.br",
17
+ cpf: "04267484171",
18
+ birth: "1977-01-15",
19
+ phone_number: "5144916523"
20
+ }
21
+ }
22
+ }
23
+ }
24
+
25
+ gerencianet = Gerencianet.new(options)
26
+ gerencianet.pay_subscription(params: params, body: body)
27
+ ```
28
+
29
+ ### 2. Credit card
30
+
31
+ Here it's necessary to use the customer's *credit card* to submit the payment. A `payment_token` represents a credit card, as explained at the end of this page.
32
+
33
+ ```ruby
34
+ params = {
35
+ id: 1113
36
+ }
37
+
38
+ body = {
39
+ payment: {
40
+ credit_card: {
41
+ payment_token: "e0c210bb679fea225a586256234f8ce179fd16c5",
42
+ billing_address: {
43
+ street: "Av. JK",
44
+ number: 909,
45
+ neighborhood: "Bauxita",
46
+ zipcode: "35400000",
47
+ city: "Ouro Preto",
48
+ state: "MG"
49
+ },
50
+ customer: {
51
+ name: "Gorbadoc Oldbuck",
52
+ email: "oldbuck@gerencianet.com.br",
53
+ cpf: "04267484171",
54
+ birth: "1977-01-15",
55
+ phone_number: "5144916523"
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ gerencianet = Gerencianet.new(options)
62
+ gerencianet.pay_subscription(params: params, body: body)
63
+ ```
64
+
65
+ Response:
66
+
67
+ ```js
68
+ {
69
+ "code": 200,
70
+ "data": {
71
+ "subscription_id": 11,
72
+ "status": "active",
73
+ "plan": {
74
+ "id": 1000,
75
+ "interval": 2,
76
+ "repeats": null
77
+ },
78
+ "charge": {
79
+ "id": 1053,
80
+ "status": "waiting"
81
+ },
82
+ "total": 1150,
83
+ "payment": "credit_card"
84
+ }
85
+ }
86
+ ```
87
+
88
+ For getting installment values, including interests, check [Getting Installments](/docs/payment-data.md).
89
+
90
+ ##### Payment tokens
91
+
92
+ A `payment_token` represents a credit card number at Gerencianet.
93
+
94
+ 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.
95
+
96
+ When in production, it will depend if your project is a web app or a mobile app.
97
+
98
+ 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.
99
+
100
+ 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,29 @@
1
+ ## Updating subscriptions
2
+
3
+ ### Changing the metadata
4
+
5
+ You can update the `custom_id` or the `notification_url` of a subscription.
6
+
7
+ It is important to keep in mind that all the subscription charges will be updated. If you want to update only one, check [Updating charges](/docs/charge-update).
8
+
9
+ ```ruby
10
+ params = {
11
+ id: 1009
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_subscription_metadata(params: params, body: body)
21
+ ```
22
+
23
+ If everything goes well, the return will be:
24
+
25
+ ```ruby
26
+ {
27
+ "code": 200
28
+ }
29
+ ```
@@ -0,0 +1,69 @@
1
+ ## Creating subscriptions
2
+
3
+ If you ever have to recurrently charge your clients, you can create a different kind of charge, one that belongs to a subscription. This way, subsequent charges will be automatically created based on plan configuration and the charge value is charged in your customers' credit card, or the banking billet is generated and sent to the custumer, accoding to the plan’s configuration.
4
+
5
+ The plan configuration receive two params: `repeats` and `interval`:
6
+
7
+ The `repeats` parameter defines how many times the transaction will be repeated. If you don't provide it, the subscription will create charges indefinitely.
8
+
9
+ The `interval` parameter defines the interval, in months, that a charge has to be generated. The minimum value is 1, and the maximum is 24.
10
+
11
+ It's worth to mention that this mechanics is triggered only if the customer commits the subscription. In other words, it takes effect when the customer pays the first charge.
12
+
13
+ At last, it boils down to creating a plan and then the subscription. The plan can be reused for generating other subscriptions:
14
+
15
+ ```ruby
16
+ plan = {
17
+ name: "My first plan",
18
+ repeats: 24,
19
+ interval: 2
20
+ }
21
+
22
+ subscription = {
23
+ items: [{
24
+ name: "Product 1",
25
+ value: 1000,
26
+ amount: 2
27
+ }]
28
+ }
29
+
30
+ gerencianet = Gerencianet.new(options)
31
+ plan = gerencianet.create_plan(body: plan)
32
+
33
+ params = {
34
+ id: plan["data"]["plan_id"]
35
+ }
36
+
37
+ gerencianet.create_subscription(params: params, body: subscription)
38
+ ```
39
+
40
+ ### Deleting a plan:
41
+ *(works just for plans that doesn't have a subscription associated):*
42
+
43
+ ```ruby
44
+ params = {
45
+ id: 1
46
+ }
47
+
48
+ gerencianet = Gerencianet.new(options)
49
+ gerencianet.delete_plan(params: params)
50
+ ```
51
+
52
+ ### Canceling subscriptions
53
+
54
+ You can cancel active subscriptions at any time:
55
+
56
+ ```ruby
57
+ params = {
58
+ id: 1111
59
+ }
60
+
61
+ gerencianet = Gerencianet.new(options)
62
+ puts gerencianet.cancel_subscription(params: params)
63
+ ```
64
+
65
+ ```js
66
+ {
67
+ "code": 200
68
+ }
69
+ ```