vindi-hermes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cfeffedc8df5f4cfd1d2fc38730c15185bb9c454a30c8e9fbe3308168a7cda6f
4
+ data.tar.gz: 707dad5195dc739dc23a46953198bd084be58cbb0a95faef053231f39c9f264e
5
+ SHA512:
6
+ metadata.gz: 985bbbda160a2c67ae61896cdff47d4ab4e05284e3661cf3498821aa84223c920fc9c4fac6d204b513a7260fc03ff62de877e6f664d71ddf025a5c6d4c5d55b4
7
+ data.tar.gz: 6b8bf90607a8ba997ddb4273c7c24c07028fdafc46e1668be3750a89d8c2d6a7e0d318982f2c38bd3fc2861911ba4db6f83b7e673da7f78f851947a718db33b9
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-05-25
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at wedson.sousa.lima@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in vindi.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rubocop"
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vindi-hermes (0.0.1)
5
+ faraday (~> 1.4)
6
+ faraday_middleware (~> 1.0)
7
+ her (~> 1.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (6.1.3.2)
13
+ activesupport (= 6.1.3.2)
14
+ activesupport (6.1.3.2)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
20
+ ast (2.4.2)
21
+ concurrent-ruby (1.1.8)
22
+ diff-lcs (1.4.4)
23
+ faraday (1.4.2)
24
+ faraday-em_http (~> 1.0)
25
+ faraday-em_synchrony (~> 1.0)
26
+ faraday-excon (~> 1.1)
27
+ faraday-net_http (~> 1.0)
28
+ faraday-net_http_persistent (~> 1.1)
29
+ multipart-post (>= 1.2, < 3)
30
+ ruby2_keywords (>= 0.0.4)
31
+ faraday-em_http (1.0.0)
32
+ faraday-em_synchrony (1.0.0)
33
+ faraday-excon (1.1.0)
34
+ faraday-net_http (1.0.1)
35
+ faraday-net_http_persistent (1.1.0)
36
+ faraday_middleware (1.0.0)
37
+ faraday (~> 1.0)
38
+ her (1.1.1)
39
+ activemodel (>= 4.2.1)
40
+ faraday (>= 0.8)
41
+ multi_json (~> 1.7)
42
+ httplog (1.5.0)
43
+ rack (>= 1.0)
44
+ rainbow (>= 2.0.0)
45
+ i18n (1.8.10)
46
+ concurrent-ruby (~> 1.0)
47
+ minitest (5.14.4)
48
+ multi_json (1.15.0)
49
+ multipart-post (2.1.1)
50
+ parallel (1.20.1)
51
+ parser (3.0.1.1)
52
+ ast (~> 2.4.1)
53
+ rack (2.2.3)
54
+ rainbow (3.0.0)
55
+ rake (13.0.3)
56
+ regexp_parser (2.1.1)
57
+ rexml (3.2.5)
58
+ rspec (3.10.0)
59
+ rspec-core (~> 3.10.0)
60
+ rspec-expectations (~> 3.10.0)
61
+ rspec-mocks (~> 3.10.0)
62
+ rspec-core (3.10.1)
63
+ rspec-support (~> 3.10.0)
64
+ rspec-expectations (3.10.1)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.10.0)
67
+ rspec-mocks (3.10.2)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.10.0)
70
+ rspec-support (3.10.2)
71
+ rubocop (1.15.0)
72
+ parallel (~> 1.10)
73
+ parser (>= 3.0.0.0)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ regexp_parser (>= 1.8, < 3.0)
76
+ rexml
77
+ rubocop-ast (>= 1.5.0, < 2.0)
78
+ ruby-progressbar (~> 1.7)
79
+ unicode-display_width (>= 1.4.0, < 3.0)
80
+ rubocop-ast (1.6.0)
81
+ parser (>= 3.0.1.1)
82
+ ruby-progressbar (1.11.0)
83
+ ruby2_keywords (0.0.4)
84
+ tzinfo (2.0.4)
85
+ concurrent-ruby (~> 1.0)
86
+ unicode-display_width (2.0.0)
87
+ zeitwerk (2.4.2)
88
+
89
+ PLATFORMS
90
+ x86_64-linux
91
+
92
+ DEPENDENCIES
93
+ httplog
94
+ rake (~> 13.0)
95
+ rspec (~> 3.2)
96
+ rubocop
97
+ vindi-hermes!
98
+
99
+ BUNDLED WITH
100
+ 2.2.17
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Wedson Lima
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # **Vindi** **Her**mes - Let the god of trade help you
2
+
3
+ ActiveRecord-like way to interact with Vindi API
4
+
5
+ ## Vindi
6
+
7
+ [Vindi](https://vindi.com.br) is a brazilian fintech, that was recently acquired by [Locaweb](https://blog.vindi.com.br/agora-a-vindi-faz-parte-do-grupo-locaweb), that helps other companies to work with **recurring payments**.
8
+
9
+ ### API docs
10
+
11
+ * [Swagger sandbox](https://vindi.github.io/api-docs/dist/?url=https://sandbox-app.vindi.com.br/api/v1/docs#/)
12
+ * [Swagger prod](https://vindi.github.io/api-docs/dist)
13
+ *
14
+ [Vindi - Official Gem](https://github.com/vindi/vindi-ruby)
15
+
16
+ > You may ask: Why create another if there is already one that's official?
17
+ > *And I'll tell you, **little grasshopper**: Because I think this one could be more beautiful.*
18
+ >
19
+ > And you also may ask: Why the hell is the doc in english when all those interested are from the big banana republic?
20
+ > *And my answer to you would be: You ask a lot of questions, huh?*
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'vindi-hermes'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ $ bundle install
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install vindi-hermes
37
+
38
+ ## Usage
39
+
40
+ ### Config
41
+
42
+ ```ruby
43
+ # config/initializers/vindi.rb
44
+ Vindi.config do |c|
45
+ c.sandbox = true # default is false
46
+ c.api_key = 'YOUR API KEY'
47
+ c.webhook_name = 'BASIC AUTH NAME'
48
+ c.webhook_password = 'BASIC AUTH PASSWORD'
49
+ end
50
+ ```
51
+
52
+ ### Examples
53
+
54
+ #### Saruman creates a subscription business to rent his Palantir
55
+
56
+ ```ruby
57
+ # Let's say that Gandalf wants to borrow Saruman's Palantir
58
+ # promising he'll give it back before the end of the 3rd era.
59
+ #
60
+ # But Saruman is wise and he thinks he could make a good money
61
+ # charging a rent for the use of the magic ball.
62
+ #
63
+ # So, Saruman went on to Vindi and there created a product...
64
+ #
65
+ palantir = Vindi::Product.new.tap do |p|
66
+ p.code = "palantir"
67
+ p.name = "Palantir"
68
+ p.description = "The Twitch of Istari folk"
69
+ p.pricing_schema = { price: 42.42 }
70
+ p.save
71
+ end
72
+
73
+ # ...then created a recurring plan.
74
+ one_plan = Vindi::Plan.new.tap do |p|
75
+ p.code = "the-one-plan"
76
+ p.name = "Monthly Plan"
77
+ p.description = "The One Plan To Rule Them All"
78
+ p.period = "monthly"
79
+ p.recurring = true
80
+ p.plan_items = [
81
+ {
82
+ cycles: nil, # untill the end of time
83
+ product_id: palantir.id
84
+ }
85
+ ]
86
+ p.save
87
+ end
88
+
89
+ # Gandalf uses his fellow Bilbo's address to receive the invoices...
90
+ gandalf = Vindi::Customer.new.tap do |c|
91
+ c.code = 1
92
+ c.name = "Gandalf the Grey"
93
+ c.email = "mithrandir@middlearth.io"
94
+ c.address = {
95
+ street: "Bagshot Row",
96
+ number: "Bag End",
97
+ neighborhood: "Hobbiton",
98
+ city: "Shire"
99
+ }
100
+ c.save
101
+ end
102
+
103
+ # ...uses Elrond's credit card to create a payment profile...
104
+ pp = Vindi::PaymentProfile.new.tap do |pp|
105
+ pp.holder_name = "Elrond Half-elven"
106
+ pp.card_expiration = "12/3021"
107
+ pp.card_number = "5167454851671773"
108
+ pp.card_cvv = "123"
109
+ pp.customer_id = gandalf.id
110
+ pp.save
111
+ end
112
+
113
+ # ...subscribes and then get the palantir.
114
+ subscription = Vindi::Subscription.new.tap do |s|
115
+ s.plan_id = one_plan.id
116
+ s.customer_id = gandalf.id
117
+ s.payment_method_code = "credit_card"
118
+ s.save
119
+ end
120
+ ```
121
+
122
+ #### After some time he wants to know how the business is going
123
+
124
+ ```ruby
125
+ # Active customers
126
+ customers = Vindi::Customer.active
127
+
128
+ # Active subscriptions
129
+ subscriptions = Vindi::Subscriptions.active
130
+
131
+ # Subscriptions for the-one-plan
132
+ subscriptions = Vindi::Plan.find_by(code: "the-one-plan").subscriptions
133
+
134
+ # Filter Gandalf
135
+ gandalf = Vindi::Customer.find_by(email: "mithrandir@middlearth.io")
136
+
137
+ # All Gandalf's subscriptions
138
+ subscriptions = gandalf.subscriptions.active
139
+
140
+ # Cancel Gandalf's subscription
141
+ gandalf.subscriptions.active.last.cancel!
142
+
143
+ # Refund the last Gandalf's payment
144
+ gandalf.charges.last.refund!
145
+ ```
146
+
147
+ ## Webhooks
148
+
149
+ You must validate incoming data from Vindi.
150
+ * [Vindi Blog Post](https://atendimento.vindi.com.br/hc/pt-br/articles/203305800)
151
+
152
+ You can validate webhook calls using baisc auth.
153
+ Just configure a webhook call with something like this `https://NAME:PASSWORD@www.startupmassa.com/vindi/webhook`.
154
+
155
+ On Vindi admin dashboard
156
+
157
+ ```bash
158
+ https://vindi:123456@www.startupmassa.com/vindi/webhook
159
+ ```
160
+
161
+ On your project
162
+
163
+ ```ruby
164
+ # config/initializers/vindi.rb
165
+ Vindi.config do |c|
166
+ c.api_key = '123456'
167
+ c.webhook_name = 'vindi'
168
+ c.webhook_password = '123456'
169
+ end
170
+
171
+ # routes.rb
172
+ namespace :vindi do
173
+ post :webhook, to: "webhook#listener"
174
+ end
175
+
176
+ # vindi/webhook_controller.rb
177
+ class Vindi::Webhook < ActionController::Base
178
+ http_basic_authenticate_with name: Vindi.webhook_name, password: Vindi.webhook_password
179
+
180
+ # POST https://usuario:senha@www.startupmassa.com/vindi/webhook
181
+ def listener
182
+ case event_params[:type]
183
+ when "charge_rejected" # defaulting user?
184
+ when "bill_paid" # do the magic
185
+ else
186
+ head :ok
187
+ end
188
+ end
189
+
190
+ private
191
+ def event_params
192
+ params.require(:event).permit!
193
+ end
194
+ end
195
+ ```
196
+
197
+ ## Contributing
198
+
199
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wedsonlima/vindi-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/wedsonlima/vindi-ruby/blob/main/CODE_OF_CONDUCT.md).
200
+
201
+ ## License
202
+
203
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
204
+
205
+ ## Code of Conduct
206
+
207
+ Everyone interacting in the Vindi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wedsonlima/vindi-ruby/blob/main/CODE_OF_CONDUCT.md).