pay-lago 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +27 -0
  3. data/.gitignore +28 -0
  4. data/.rspec +3 -0
  5. data/.standard.yml +3 -0
  6. data/CHANGELOG.md +2 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +25 -0
  9. data/Gemfile.lock +292 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +85 -0
  12. data/Rakefile +32 -0
  13. data/app/controllers/pay/webhooks/lago_controller.rb +41 -0
  14. data/app/models/concerns/pay/lago/pay_customer_extensions.rb +15 -0
  15. data/app/models/concerns/pay/lago/pay_extensions.rb +15 -0
  16. data/bin/console +15 -0
  17. data/bin/rails +16 -0
  18. data/bin/setup +8 -0
  19. data/config/routes.rb +5 -0
  20. data/docs/1_customers.md +18 -0
  21. data/docs/2_charges.md +72 -0
  22. data/docs/3_subscriptions.md +67 -0
  23. data/docs/4_webhooks.md +66 -0
  24. data/lib/pay/lago/attributes.rb +24 -0
  25. data/lib/pay/lago/billable.rb +148 -0
  26. data/lib/pay/lago/charge.rb +82 -0
  27. data/lib/pay/lago/engine.rb +27 -0
  28. data/lib/pay/lago/error.rb +9 -0
  29. data/lib/pay/lago/payment_method.rb +37 -0
  30. data/lib/pay/lago/subscription.rb +134 -0
  31. data/lib/pay/lago/version.rb +7 -0
  32. data/lib/pay/lago/webhook_extensions.rb +10 -0
  33. data/lib/pay/lago/webhooks/customer_payment_provider_created.rb +18 -0
  34. data/lib/pay/lago/webhooks/invoice_created.rb +15 -0
  35. data/lib/pay/lago/webhooks/invoice_drafted.rb +11 -0
  36. data/lib/pay/lago/webhooks/invoice_one_off_created.rb +15 -0
  37. data/lib/pay/lago/webhooks/invoice_payment_status_updated.rb +14 -0
  38. data/lib/pay/lago/webhooks/subscription_started.rb +12 -0
  39. data/lib/pay/lago/webhooks/subscription_terminated.rb +12 -0
  40. data/lib/pay/lago.rb +91 -0
  41. data/pay-lago.gemspec +27 -0
  42. data/sig/pay/lago.rbs +6 -0
  43. data/test/controllers/pay/webhooks/lago_controller_test.rb +37 -0
  44. data/test/dummy/.browserslistrc +1 -0
  45. data/test/dummy/Rakefile +6 -0
  46. data/test/dummy/app/assets/config/manifest.js +4 -0
  47. data/test/dummy/app/assets/images/.keep +0 -0
  48. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  49. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  50. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  51. data/test/dummy/app/controllers/application_controller.rb +4 -0
  52. data/test/dummy/app/controllers/concerns/.keep +0 -0
  53. data/test/dummy/app/controllers/main_controller.rb +4 -0
  54. data/test/dummy/app/controllers/payment_methods_controller.rb +5 -0
  55. data/test/dummy/app/helpers/application_helper.rb +2 -0
  56. data/test/dummy/app/helpers/current_helper.rb +9 -0
  57. data/test/dummy/app/javascript/application.js +9 -0
  58. data/test/dummy/app/javascript/controllers/application.js +10 -0
  59. data/test/dummy/app/javascript/controllers/index.js +11 -0
  60. data/test/dummy/app/jobs/application_job.rb +2 -0
  61. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  62. data/test/dummy/app/models/account.rb +3 -0
  63. data/test/dummy/app/models/application_record.rb +3 -0
  64. data/test/dummy/app/models/concerns/.keep +0 -0
  65. data/test/dummy/app/models/team.rb +10 -0
  66. data/test/dummy/app/models/user.rb +3 -0
  67. data/test/dummy/app/views/layouts/application.html.erb +36 -0
  68. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  69. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  70. data/test/dummy/app/webhooks/charge_succeeded.rb +5 -0
  71. data/test/dummy/bin/importmap +4 -0
  72. data/test/dummy/bin/rails +4 -0
  73. data/test/dummy/bin/rake +4 -0
  74. data/test/dummy/bin/setup +33 -0
  75. data/test/dummy/bin/webpack +18 -0
  76. data/test/dummy/bin/webpack-dev-server +18 -0
  77. data/test/dummy/config/application.rb +25 -0
  78. data/test/dummy/config/boot.rb +6 -0
  79. data/test/dummy/config/cable.yml +9 -0
  80. data/test/dummy/config/database.yml +3 -0
  81. data/test/dummy/config/environment.rb +5 -0
  82. data/test/dummy/config/environments/development.rb +70 -0
  83. data/test/dummy/config/environments/production.rb +86 -0
  84. data/test/dummy/config/environments/test.rb +60 -0
  85. data/test/dummy/config/importmap.rb +8 -0
  86. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  87. data/test/dummy/config/initializers/assets.rb +11 -0
  88. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  89. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  90. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  91. data/test/dummy/config/initializers/inflections.rb +16 -0
  92. data/test/dummy/config/initializers/mime_types.rb +4 -0
  93. data/test/dummy/config/initializers/pay.rb +11 -0
  94. data/test/dummy/config/initializers/session_store.rb +3 -0
  95. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/test/dummy/config/locales/en.yml +23 -0
  97. data/test/dummy/config/puma.rb +47 -0
  98. data/test/dummy/config/routes.rb +4 -0
  99. data/test/dummy/config/secrets.yml +22 -0
  100. data/test/dummy/config/spring.rb +6 -0
  101. data/test/dummy/config/storage.yml +34 -0
  102. data/test/dummy/config.ru +6 -0
  103. data/test/dummy/db/migrate/20170205000000_create_users.rb +22 -0
  104. data/test/dummy/db/schema.rb +125 -0
  105. data/test/dummy/lib/assets/.keep +0 -0
  106. data/test/dummy/log/.keep +0 -0
  107. data/test/dummy/public/404.html +67 -0
  108. data/test/dummy/public/422.html +67 -0
  109. data/test/dummy/public/500.html +66 -0
  110. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/test/dummy/public/apple-touch-icon.png +0 -0
  112. data/test/dummy/public/favicon.ico +0 -0
  113. data/test/dummy/vendor/javascript/.keep +0 -0
  114. data/test/fixtures/accounts.yml +2 -0
  115. data/test/fixtures/pay/customers.yml +7 -0
  116. data/test/fixtures/teams.yml +4 -0
  117. data/test/fixtures/users.yml +11 -0
  118. data/test/pay/lago/billable_test.rb +42 -0
  119. data/test/pay/lago/charge_test.rb +23 -0
  120. data/test/pay/lago/subscription_test.rb +48 -0
  121. data/test/support/fixtures/lago/invoice.one_off_created.json +120 -0
  122. data/test/support/vcr.rb +28 -0
  123. data/test/test_helper.rb +66 -0
  124. data/test/vcr_cassettes/test_add_payment_method_to_lago.yml +56 -0
  125. data/test/vcr_cassettes/test_can_get_lago_processor_customer.yml +56 -0
  126. data/test/vcr_cassettes/test_can_make_a_lago_processor_charge.yml +163 -0
  127. data/test/vcr_cassettes/test_generates_lago_processor_id.yml +107 -0
  128. data/test/vcr_cassettes/test_lago_cannot_change_quantity.yml +108 -0
  129. data/test/vcr_cassettes/test_lago_processor_cancel.yml +212 -0
  130. data/test/vcr_cassettes/test_lago_processor_charge.yml +325 -0
  131. data/test/vcr_cassettes/test_lago_processor_on_grace_period__is_always_false.yml +108 -0
  132. data/test/vcr_cassettes/test_lago_processor_pause_raises_an_error.yml +108 -0
  133. data/test/vcr_cassettes/test_lago_processor_paused__is_always_false.yml +108 -0
  134. data/test/vcr_cassettes/test_lago_processor_refund_with_premium.yml +378 -0
  135. data/test/vcr_cassettes/test_lago_processor_refund_without_premium.yml +375 -0
  136. data/test/vcr_cassettes/test_lago_processor_resume_raises_an_error.yml +108 -0
  137. data/test/vcr_cassettes/test_lago_processor_subscribe.yml +108 -0
  138. data/test/vcr_cassettes/test_lago_processor_subscription.yml +160 -0
  139. data/test/vcr_cassettes/test_lago_processor_swap.yml +212 -0
  140. metadata +212 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a9c2b824c5412e64bb1f0c2efed6c5532265b9ff4978c8368d98d3fc7cba2cc2
4
+ data.tar.gz: fee44626ac0dcc1082cc688f74d56c74146fa33b3ee001c35ce1b3a3f729991b
5
+ SHA512:
6
+ metadata.gz: 76cefb859ce9d0fed7736cf6a699517efbe36125d15be22334508fdd3daba204b9e283eae982889f2e68c0f35e88b258e3a5fdef856733f18ff6faff748d697c
7
+ data.tar.gz: 507d1b89c54951857c29f8d728d20ad902bd907943243a6349189197a1a56915a1309434c4efc24e3ee997e0905f0e245420341bfe38f46bd835c41a24073271
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '3.1.0'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ test/dummy/db/*.sqlite3*
11
+ test/dummy/log/*.log
12
+ test/dummy/tmp/
13
+ test/dummy/public/packs/
14
+ test/dummy/public/packs-test/
15
+ test/dummy/node_modules/
16
+ test/dummy/config/credentials.yml.enc
17
+ test/dummy/config/master.key
18
+
19
+ .DS_Store
20
+ .directory
21
+ .byebug_history
22
+ *.swp
23
+ *.swo
24
+ *.bak
25
+
26
+ # Releases
27
+ pay-lago-*.gem
28
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## [0.1.0] - 2023-10-23
2
+ - 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 moxvallix@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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pay-lago.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.20.0"
11
+
12
+ gem "standard", "~> 1.3"
13
+
14
+ # Gems from Pay for testing
15
+ gem "byebug"
16
+ gem "appraisal", github: "thoughtbot/appraisal"
17
+ gem "overcommit"
18
+ gem "mocha"
19
+ gem "vcr"
20
+ gem "receipts"
21
+ gem "webmock"
22
+ gem "matrix"
23
+
24
+ # Databases
25
+ gem "sqlite3", "~> 1.6.0.rc2"
data/Gemfile.lock ADDED
@@ -0,0 +1,292 @@
1
+ GIT
2
+ remote: https://github.com/thoughtbot/appraisal.git
3
+ revision: feb78bcc6177038399bff098cb6c2bd4bca4972a
4
+ specs:
5
+ appraisal (2.5.0)
6
+ bundler
7
+ rake
8
+ thor (>= 0.14.0)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ pay-lago (0.1.0)
14
+ lago-ruby-client (= 0.50.0.pre.beta)
15
+ pay (~> 6.8)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ actioncable (7.1.1)
21
+ actionpack (= 7.1.1)
22
+ activesupport (= 7.1.1)
23
+ nio4r (~> 2.0)
24
+ websocket-driver (>= 0.6.1)
25
+ zeitwerk (~> 2.6)
26
+ actionmailbox (7.1.1)
27
+ actionpack (= 7.1.1)
28
+ activejob (= 7.1.1)
29
+ activerecord (= 7.1.1)
30
+ activestorage (= 7.1.1)
31
+ activesupport (= 7.1.1)
32
+ mail (>= 2.7.1)
33
+ net-imap
34
+ net-pop
35
+ net-smtp
36
+ actionmailer (7.1.1)
37
+ actionpack (= 7.1.1)
38
+ actionview (= 7.1.1)
39
+ activejob (= 7.1.1)
40
+ activesupport (= 7.1.1)
41
+ mail (~> 2.5, >= 2.5.4)
42
+ net-imap
43
+ net-pop
44
+ net-smtp
45
+ rails-dom-testing (~> 2.2)
46
+ actionpack (7.1.1)
47
+ actionview (= 7.1.1)
48
+ activesupport (= 7.1.1)
49
+ nokogiri (>= 1.8.5)
50
+ rack (>= 2.2.4)
51
+ rack-session (>= 1.0.1)
52
+ rack-test (>= 0.6.3)
53
+ rails-dom-testing (~> 2.2)
54
+ rails-html-sanitizer (~> 1.6)
55
+ actiontext (7.1.1)
56
+ actionpack (= 7.1.1)
57
+ activerecord (= 7.1.1)
58
+ activestorage (= 7.1.1)
59
+ activesupport (= 7.1.1)
60
+ globalid (>= 0.6.0)
61
+ nokogiri (>= 1.8.5)
62
+ actionview (7.1.1)
63
+ activesupport (= 7.1.1)
64
+ builder (~> 3.1)
65
+ erubi (~> 1.11)
66
+ rails-dom-testing (~> 2.2)
67
+ rails-html-sanitizer (~> 1.6)
68
+ activejob (7.1.1)
69
+ activesupport (= 7.1.1)
70
+ globalid (>= 0.3.6)
71
+ activemodel (7.1.1)
72
+ activesupport (= 7.1.1)
73
+ activerecord (7.1.1)
74
+ activemodel (= 7.1.1)
75
+ activesupport (= 7.1.1)
76
+ timeout (>= 0.4.0)
77
+ activestorage (7.1.1)
78
+ actionpack (= 7.1.1)
79
+ activejob (= 7.1.1)
80
+ activerecord (= 7.1.1)
81
+ activesupport (= 7.1.1)
82
+ marcel (~> 1.0)
83
+ activesupport (7.1.1)
84
+ base64
85
+ bigdecimal
86
+ concurrent-ruby (~> 1.0, >= 1.0.2)
87
+ connection_pool (>= 2.2.5)
88
+ drb
89
+ i18n (>= 1.6, < 2)
90
+ minitest (>= 5.1)
91
+ mutex_m
92
+ tzinfo (~> 2.0)
93
+ addressable (2.8.5)
94
+ public_suffix (>= 2.0.2, < 6.0)
95
+ ast (2.4.2)
96
+ base64 (0.1.1)
97
+ bigdecimal (3.1.4)
98
+ builder (3.2.4)
99
+ byebug (11.1.3)
100
+ childprocess (4.1.0)
101
+ concurrent-ruby (1.2.2)
102
+ connection_pool (2.4.1)
103
+ crack (0.4.5)
104
+ rexml
105
+ crass (1.0.6)
106
+ date (3.3.3)
107
+ drb (2.1.1)
108
+ ruby2_keywords
109
+ erubi (1.12.0)
110
+ globalid (1.2.1)
111
+ activesupport (>= 6.1)
112
+ hashdiff (1.0.1)
113
+ i18n (1.14.1)
114
+ concurrent-ruby (~> 1.0)
115
+ iniparse (1.5.0)
116
+ io-console (0.6.0)
117
+ irb (1.8.3)
118
+ rdoc
119
+ reline (>= 0.3.8)
120
+ json (2.6.3)
121
+ jwt (2.7.1)
122
+ lago-ruby-client (0.50.0.pre.beta)
123
+ jwt
124
+ openssl
125
+ language_server-protocol (3.17.0.3)
126
+ lint_roller (1.1.0)
127
+ loofah (2.21.4)
128
+ crass (~> 1.0.2)
129
+ nokogiri (>= 1.12.0)
130
+ mail (2.8.1)
131
+ mini_mime (>= 0.1.1)
132
+ net-imap
133
+ net-pop
134
+ net-smtp
135
+ marcel (1.0.2)
136
+ matrix (0.4.2)
137
+ mini_mime (1.1.5)
138
+ minitest (5.20.0)
139
+ mocha (2.1.0)
140
+ ruby2_keywords (>= 0.0.5)
141
+ mutex_m (0.1.2)
142
+ net-imap (0.4.1)
143
+ date
144
+ net-protocol
145
+ net-pop (0.1.2)
146
+ net-protocol
147
+ net-protocol (0.2.1)
148
+ timeout
149
+ net-smtp (0.4.0)
150
+ net-protocol
151
+ nio4r (2.5.9)
152
+ nokogiri (1.15.4-x86_64-linux)
153
+ racc (~> 1.4)
154
+ openssl (3.2.0)
155
+ overcommit (0.60.0)
156
+ childprocess (>= 0.6.3, < 5)
157
+ iniparse (~> 1.4)
158
+ rexml (~> 3.2)
159
+ parallel (1.23.0)
160
+ parser (3.2.2.4)
161
+ ast (~> 2.4.1)
162
+ racc
163
+ pay (6.8.1)
164
+ rails (>= 6.0.0)
165
+ pdf-core (0.9.0)
166
+ prawn (2.4.0)
167
+ pdf-core (~> 0.9.0)
168
+ ttfunk (~> 1.7)
169
+ prawn-table (0.2.2)
170
+ prawn (>= 1.3.0, < 3.0.0)
171
+ psych (5.1.1.1)
172
+ stringio
173
+ public_suffix (5.0.3)
174
+ racc (1.7.1)
175
+ rack (3.0.8)
176
+ rack-session (2.0.0)
177
+ rack (>= 3.0.0)
178
+ rack-test (2.1.0)
179
+ rack (>= 1.3)
180
+ rackup (2.1.0)
181
+ rack (>= 3)
182
+ webrick (~> 1.8)
183
+ rails (7.1.1)
184
+ actioncable (= 7.1.1)
185
+ actionmailbox (= 7.1.1)
186
+ actionmailer (= 7.1.1)
187
+ actionpack (= 7.1.1)
188
+ actiontext (= 7.1.1)
189
+ actionview (= 7.1.1)
190
+ activejob (= 7.1.1)
191
+ activemodel (= 7.1.1)
192
+ activerecord (= 7.1.1)
193
+ activestorage (= 7.1.1)
194
+ activesupport (= 7.1.1)
195
+ bundler (>= 1.15.0)
196
+ railties (= 7.1.1)
197
+ rails-dom-testing (2.2.0)
198
+ activesupport (>= 5.0.0)
199
+ minitest
200
+ nokogiri (>= 1.6)
201
+ rails-html-sanitizer (1.6.0)
202
+ loofah (~> 2.21)
203
+ nokogiri (~> 1.14)
204
+ railties (7.1.1)
205
+ actionpack (= 7.1.1)
206
+ activesupport (= 7.1.1)
207
+ irb
208
+ rackup (>= 1.0.0)
209
+ rake (>= 12.2)
210
+ thor (~> 1.0, >= 1.2.2)
211
+ zeitwerk (~> 2.6)
212
+ rainbow (3.1.1)
213
+ rake (13.0.6)
214
+ rdoc (6.5.0)
215
+ psych (>= 4.0.0)
216
+ receipts (2.2.0)
217
+ prawn (>= 1.3.0, < 3.0.0)
218
+ prawn-table (~> 0.2.1)
219
+ regexp_parser (2.8.2)
220
+ reline (0.3.9)
221
+ io-console (~> 0.5)
222
+ rexml (3.2.6)
223
+ rubocop (1.56.4)
224
+ base64 (~> 0.1.1)
225
+ json (~> 2.3)
226
+ language_server-protocol (>= 3.17.0)
227
+ parallel (~> 1.10)
228
+ parser (>= 3.2.2.3)
229
+ rainbow (>= 2.2.2, < 4.0)
230
+ regexp_parser (>= 1.8, < 3.0)
231
+ rexml (>= 3.2.5, < 4.0)
232
+ rubocop-ast (>= 1.28.1, < 2.0)
233
+ ruby-progressbar (~> 1.7)
234
+ unicode-display_width (>= 2.4.0, < 3.0)
235
+ rubocop-ast (1.29.0)
236
+ parser (>= 3.2.1.0)
237
+ rubocop-performance (1.19.1)
238
+ rubocop (>= 1.7.0, < 2.0)
239
+ rubocop-ast (>= 0.4.0)
240
+ ruby-progressbar (1.13.0)
241
+ ruby2_keywords (0.0.5)
242
+ sqlite3 (1.6.6-x86_64-linux)
243
+ standard (1.31.2)
244
+ language_server-protocol (~> 3.17.0.2)
245
+ lint_roller (~> 1.0)
246
+ rubocop (~> 1.56.4)
247
+ standard-custom (~> 1.0.0)
248
+ standard-performance (~> 1.2)
249
+ standard-custom (1.0.2)
250
+ lint_roller (~> 1.0)
251
+ rubocop (~> 1.50)
252
+ standard-performance (1.2.1)
253
+ lint_roller (~> 1.1)
254
+ rubocop-performance (~> 1.19.1)
255
+ stringio (3.0.8)
256
+ thor (1.2.2)
257
+ timeout (0.4.0)
258
+ ttfunk (1.7.0)
259
+ tzinfo (2.0.6)
260
+ concurrent-ruby (~> 1.0)
261
+ unicode-display_width (2.5.0)
262
+ vcr (6.2.0)
263
+ webmock (3.19.1)
264
+ addressable (>= 2.8.0)
265
+ crack (>= 0.3.2)
266
+ hashdiff (>= 0.4.0, < 2.0.0)
267
+ webrick (1.8.1)
268
+ websocket-driver (0.7.6)
269
+ websocket-extensions (>= 0.1.0)
270
+ websocket-extensions (0.1.5)
271
+ zeitwerk (2.6.12)
272
+
273
+ PLATFORMS
274
+ x86_64-linux
275
+
276
+ DEPENDENCIES
277
+ appraisal!
278
+ byebug
279
+ matrix
280
+ minitest (~> 5.20.0)
281
+ mocha
282
+ overcommit
283
+ pay-lago!
284
+ rake (~> 13.0)
285
+ receipts
286
+ sqlite3 (~> 1.6.0.rc2)
287
+ standard (~> 1.3)
288
+ vcr
289
+ webmock
290
+
291
+ BUNDLED WITH
292
+ 2.4.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Moxvallix
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,85 @@
1
+ # Pay Lago Processor
2
+
3
+ Implements Lago support for the [Pay Gem](https://github.com/pay-rails/pay).
4
+
5
+ ## Installation
6
+ Before you use this gem, make sure you are familiar with the Pay Gem, and have followed
7
+ its [installation instructions](https://github.com/pay-rails/pay/blob/main/docs/1_installation.md).
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add pay-lago
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install pay-lago
16
+
17
+ ## Usage
18
+ ### Using Pay with Lago
19
+
20
+ Lago works somewhat differently than the other payment processors so it comes with some limitations and differences.
21
+
22
+ * Lago itself doesn't handle payments, but can be set up to trigger them through other services (Stripe etc.)
23
+ - Currently Pay doesn't provide an interface for setting up payment processors in Lago.
24
+ - Payment providers will have to be configured directly with the Lago API or UI.
25
+ * Lago subscriptions do not have trials etc.
26
+ * Charges are mapped to Lago invoices.
27
+ * Some features require [Lago Premium](https://www.getlago.com/pricing) to function correctly.
28
+ * Wherever Lago requires an external_id, Pay will use the [GlobalID](https://github.com/rails/globalid) of the corresponding Pay object.
29
+ - This is unless the object already has processor_id set, in which case it'll use that.
30
+
31
+ ### Configuration
32
+
33
+ Lago requires an API key for it's client to work. This can be found at [/developers]() on your Lago instance.
34
+
35
+ If you are using Lago self-hosted, you will also need to provide the url to your API instance.
36
+
37
+ ```yaml
38
+ # Configuration for Lago in Rails Credentials.
39
+ lago:
40
+ api_key: <YOUR API KEY>
41
+ api_url: <YOUR API URL>
42
+ ```
43
+
44
+ ```bash
45
+ # Configuration for Lago in Environment Variables
46
+ LAGO_API_URL="<YOUR API URL>" LAGO_API_KEY="<YOUR API KEY>" rails server
47
+ ```
48
+
49
+ If your configuration is correct, `Pay::Lago.valid_auth?` will be true.
50
+
51
+ ### Docs
52
+ See [Pay Gem](https://github.com/pay-rails/pay) for main pay docs.
53
+
54
+ - [Customer](docs/1_customers.md)
55
+ - [Charges](docs/2_charges.md)
56
+ - [Subscriptions](docs/3_subscriptions.md)
57
+ - [Webhooks](docs/4_webhooks.md)
58
+
59
+ ### Using the Lago API Client
60
+
61
+ Pay automatically configures an instance of the Lago Client for use across the module. However, the same client can be accessed
62
+ for direct use of the [Lago API](https://docs.getlago.com/api-reference/intro).
63
+
64
+ The client instance can be accessed from `Pay::Lago.client`.
65
+
66
+ #### Please Note:
67
+ For any API calls that would use a GET, the external_id must be [URI encoded](https://ruby-doc.org/current/stdlibs/uri/URI.html#method-c-encode_www_form_component), as the lago-ruby-client gem does not currently do this itself. See [this issue](https://github.com/getlago/lago-ruby-client/issues/136).
68
+
69
+ ## Development
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
72
+
73
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pay-lago. 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/[USERNAME]/pay-lago/blob/master/CODE_OF_CONDUCT.md).
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ ## Code of Conduct
84
+
85
+ Everyone interacting in the Pay::Lago project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pay-lago/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ require "bundler/gem_tasks"
8
+
9
+ require "rdoc/task"
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "Pay"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
17
+ end
18
+
19
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
20
+ load "rails/tasks/engine.rake"
21
+
22
+ load "rails/tasks/statistics.rake"
23
+
24
+ require "rake/testtask"
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << "test"
28
+ t.pattern = "test/**/*_test.rb"
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,41 @@
1
+ module Pay
2
+ module Webhooks
3
+ class LagoController < Pay::ApplicationController
4
+ if Rails.application.config.action_controller.default_protect_from_forgery
5
+ skip_before_action :verify_authenticity_token
6
+ end
7
+
8
+ def create
9
+ return head :bad_request unless (event = verified_event)
10
+ queue_event(event)
11
+ head :ok
12
+ end
13
+
14
+ private
15
+
16
+ def queue_event(event)
17
+ return unless Pay::Webhooks.delegator.listening?("lago.#{event["webhook_type"]}")
18
+
19
+ record = Pay::Webhook.create!(processor: :lago, event_type: event["webhook_type"], event: event)
20
+ Pay::Webhooks::ProcessJob.perform_later(record)
21
+ end
22
+
23
+ def verified_event
24
+ payload_json = JSON.parse(request.raw_post)
25
+ return false unless valid_signature?(request.headers["HTTP_X_LAGO_SIGNATURE"], payload_json)
26
+ payload_json
27
+ rescue JSON::ParserError
28
+ false
29
+ end
30
+
31
+ def valid_signature?(signature, payload)
32
+ public_key = Pay::Lago.webhook_public_key
33
+ Pay::Lago.client.webhooks.valid_signature?(signature, payload, public_key)
34
+ end
35
+
36
+ def verified_webhook?(signature, payload)
37
+ Pay::Lago.client.webhooks.valid_signature?(signature, payload_json, public_key)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ module Pay
2
+ module Lago
3
+ module PayCustomerExtensions
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ scope :lago, -> { where(processor: "lago") }
8
+ end
9
+
10
+ def lago?
11
+ processor == "lago"
12
+ end
13
+ end
14
+ end
15
+ end