moneytree-rails 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +29 -6
  4. data/Rakefile +30 -4
  5. data/app/assets/config/moneytree_manifest.js +1 -0
  6. data/app/assets/stylesheets/moneytree/application.css +15 -0
  7. data/app/controllers/moneytree/application_controller.rb +9 -0
  8. data/app/controllers/moneytree/oauth/square_controller.rb +14 -0
  9. data/app/controllers/moneytree/oauth/stripe_controller.rb +43 -0
  10. data/app/controllers/moneytree/webhooks/square_controller.rb +9 -0
  11. data/app/controllers/moneytree/webhooks/stripe_controller.rb +9 -0
  12. data/app/helpers/moneytree/application_helper.rb +4 -0
  13. data/app/helpers/moneytree/oauth/stripe_helper.rb +6 -0
  14. data/app/jobs/moneytree/application_job.rb +4 -0
  15. data/app/mailers/moneytree/application_mailer.rb +6 -0
  16. data/app/models/moneytree/application_record.rb +5 -0
  17. data/app/models/moneytree/payment_gateway.rb +52 -0
  18. data/app/views/layouts/moneytree/application.html.erb +15 -0
  19. data/config/routes.rb +4 -0
  20. data/db/migrate/20200914151648_create_moneytree_payment_gateways.rb +11 -0
  21. data/lib/moneytree.rb +9 -16
  22. data/lib/moneytree/account.rb +3 -34
  23. data/lib/moneytree/engine.rb +5 -0
  24. data/lib/moneytree/payment_provider/base.rb +5 -2
  25. data/lib/moneytree/payment_provider/stripe.rb +34 -0
  26. data/lib/moneytree/version.rb +1 -1
  27. data/lib/tasks/moneytree_tasks.rake +4 -0
  28. metadata +39 -32
  29. data/.github/workflows/ruby.yml +0 -33
  30. data/.gitignore +0 -12
  31. data/.rspec +0 -3
  32. data/.travis.yml +0 -6
  33. data/CHANGELOG.md +0 -7
  34. data/CODE_OF_CONDUCT.md +0 -74
  35. data/Gemfile +0 -15
  36. data/Gemfile.lock +0 -248
  37. data/Guardfile +0 -70
  38. data/LICENSE.txt +0 -21
  39. data/app/controllers/moneytree/oauth_controller.rb +0 -18
  40. data/bin/console +0 -14
  41. data/bin/setup +0 -8
  42. data/config.ru +0 -9
  43. data/lib/generators/moneytree/activerecord_generator.rb +0 -41
  44. data/lib/generators/moneytree/base_generator.rb +0 -13
  45. data/lib/generators/moneytree/install_generator.rb +0 -43
  46. data/lib/generators/moneytree/templates/active_record_event_model.rb.tt +0 -10
  47. data/lib/generators/moneytree/templates/active_record_migration.rb.tt +0 -62
  48. data/lib/generators/moneytree/templates/active_record_visit_model.rb.tt +0 -6
  49. data/lib/generators/moneytree/templates/base_store_initializer.rb.tt +0 -20
  50. data/lib/generators/moneytree/templates/moneytree_initializer.rb.tt +0 -15
  51. data/lib/moneytree/transaction.rb +0 -9
  52. data/moneytree.gemspec +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac0effde5b67728b209c237fcd5eb32f1bfaf682396d6dd65b3bbef29614c880
4
- data.tar.gz: 48b468a83dfd1a2099a04c3d137538d90444be660e281cbcf9fbb502469b28e7
3
+ metadata.gz: 5d3cb24c4e2a58def5e8f26fdd8ec1bce493b0deea44320eb30eed239a16f470
4
+ data.tar.gz: c8d266821266b5b886777afd8f45ed0bb19af5fb11b74de5145f77e25dd10b18
5
5
  SHA512:
6
- metadata.gz: f07412f98d4783a4e6b64316c1fe10300e0c47f6f008a9479b8df592e23a01c2d72697de61b53d5d495e504a64bdfdb79529bddc71af205ff1fa968a3742b420
7
- data.tar.gz: c04082cfb750538aa4ae3f9500c2d3b9fcae56ad546a81e326ae5994e7045c781ff4ac408b99b71492fef642dccd60d2c5ac851f17b55b957ed04ca780fb30d3
6
+ metadata.gz: ee2779c427433363015894190d09a801cb2cb8ecc3b7eb746cf067149b95486acd8c221ddbc074f0f943b7baf6bcd5845b3c22ccb59cb8464cac11fba5b4d760
7
+ data.tar.gz: 04de96735920050133081445ffae416e9248a08d0f33e6c1e806b0f9968a53a0dc8da60c2fa4d0274455a021fc251fb6662cfb567e712449e158bdccf71e6327
@@ -0,0 +1,20 @@
1
+ Copyright 2020 Kieran Klaassen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,16 +1,23 @@
1
1
  # 🚧 WORK IN PROGRESS 🚧
2
2
 
3
3
  - [ ] OAuth
4
- - [ ] Cards
5
- - [ ] Customers
6
- - [ ] Payments
7
- - [ ] Refunds
4
+ - [ ] Controller actions
5
+ - [ ] Scopes
6
+ - [ ] Square
7
+ - [ ] Stripe
8
+ - [ ] Braintree
9
+ - [ ] Moneytree models
10
+ - [ ] Payment gateway, belongs to account
11
+ - [ ] Cards
12
+ - [ ] Customers
13
+ - [ ] Payments
14
+ - [ ] Refunds
8
15
  - [ ] Notifications
9
16
 
10
17
  # Moneytree 💵 🌴
11
18
 
12
19
  [![Actions Status](https://github.com/kieranklaassen/moneytree/workflows/build/badge.svg)](https://github.com/kieranklaassen/moneytree/actions)
13
- [![Gem Version](https://badge.fury.io/rb/moneytree.svg)](https://badge.fury.io/rb/moneytree)
20
+ [![Gem Version](https://badge.fury.io/rb/moneytree-rails.svg)](https://badge.fury.io/rb/moneytree-rails)
14
21
 
15
22
  🔥 A powerful, simple, and extendable payment engine for rails, centered around transactional payments. 💵 🌴
16
23
 
@@ -48,7 +55,7 @@ rails app:template LOCATION='https://railsbytes.com/script/Xg8sOv'
48
55
  Add the latest version of Moneytree to your gem Gemfile by running:
49
56
 
50
57
  ```bash
51
- $ bundle add moneytree
58
+ $ bundle add moneytree-rails
52
59
  $ bundle install
53
60
  $ bundle exec moneytree init
54
61
  ```
@@ -111,3 +118,19 @@ The gem is available as open source under the terms of the [MIT License](https:/
111
118
 
112
119
  Everyone interacting in the Moneytree project's codebases, issue trackers, chat rooms and mailing lists is expected to
113
120
  follow the [code of conduct](https://github.com/kieranklaassen/moneytree/blob/master/CODE_OF_CONDUCT.md).
121
+
122
+ rails g model payment_gateway psp_credentials:text moneytree_psp:integer account:references{polymorphic}
123
+
124
+ owner t.string :name t.text :psp_credentials t.integer :moneytree_psp
125
+
126
+ rails g model orders t.string :description t.string :remote_identifier t.references :customer t.references :account
127
+
128
+ rails g model transactions t.decimal :amount t.decimal :app_fee_amount t.integer :status t.integer :type t.string
129
+ :remote_identifier t.string :currency_code t.string :psp_error t.integer :moneytree_psp t.references :account
130
+ t.references :order t.references :card
131
+
132
+ rails g model customers t.string :first_name t.string :last_name t.string :email t.string :remote_identifier t.integer
133
+ :moneytree_psp t.references :account
134
+
135
+ rails g model cards t.string :card_brand t.string :last_4 t.integer :expiration_month t.integer :expiration_year
136
+ t.string :cardholder_name t.string :fingerprint t.integer :moneytree_psp t.references :customer t.references :account
data/Rakefile CHANGED
@@ -1,6 +1,32 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
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
3
6
 
4
- RSpec::Core::RakeTask.new(:spec)
7
+ require 'rdoc/task'
5
8
 
6
- task :default => :spec
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Moneytree'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
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 @@
1
+ //= link_directory ../stylesheets/moneytree .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,9 @@
1
+ module Moneytree
2
+ class ApplicationController < ::ApplicationController
3
+ protect_from_forgery with: :exception
4
+
5
+ # def current_account
6
+ # send(Moneytree.current_account)
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Moneytree
2
+ module Oauth
3
+ class SquareController < ApplicationController
4
+ def new
5
+ redirect_to current_account.oauth_link
6
+ end
7
+
8
+ def callback
9
+ current_account.oauth_callback(params)
10
+ render text: 'Boom'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ module Moneytree
2
+ module Oauth
3
+ class StripeController < ApplicationController
4
+ def new
5
+ redirect_to stripe_oauth_url
6
+ end
7
+
8
+ def callback
9
+ payment_gateway = PaymentGateway.create!(psp: 'stripe', account: current_account)
10
+ payment_gateway.oauth_callback(payment_gateway_params)
11
+ redirect_to '/', notice: 'Connected to Stripe'
12
+ end
13
+
14
+ private
15
+
16
+ def payment_gateway_params
17
+ params.permit :scope, :code
18
+ end
19
+
20
+ def stripe_oauth_url
21
+ # https://stripe.com/docs/connect/oauth-reference
22
+ # https://stripe.com/docs/connect/oauth-reference#get-authorize
23
+ URI::HTTPS.build(
24
+ host: 'connect.stripe.com',
25
+ path: '/oauth/authorize',
26
+ query: {
27
+ response_type: :code,
28
+ client_id: Moneytree.stripe_credentials[:client_id],
29
+ scope: PaymentProvider::Stripe::PERMISSION,
30
+ redirect_uri: oauth_stripe_callback_url, # FIXME: use rails url helper and add host
31
+ 'stripe_user[email]': current_account.email,
32
+ 'stripe_user[url]': current_account.website,
33
+ 'stripe_user[currency]': current_account.currency_code
34
+ }.to_query
35
+ ).to_s
36
+ end
37
+
38
+ def current_account
39
+ send(Moneytree.current_account)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ module Moneytree
2
+ module Webhooks
3
+ class SquareController < ApplicationController
4
+ def create
5
+ # Do some callback magic here
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Moneytree
2
+ module Webhooks
3
+ class StripeController < ApplicationController
4
+ def create
5
+ # Do some callback magic here
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module Moneytree
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Moneytree
2
+ module Oauth
3
+ module StripeHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Moneytree
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Moneytree
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Moneytree
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ module Moneytree
2
+ class PaymentGateway < ApplicationRecord
3
+ include Moneytree::Account
4
+
5
+ belongs_to :account, polymorphic: true
6
+
7
+ enum psp: Moneytree::PSPS
8
+ serialize :psp_credentials
9
+ # encrypts :psp_credentials
10
+ # FIXME: enable https://github.com/ankane/lockbox
11
+ delegate :oauth_link, :scope_correct?, to: :payment_provider
12
+
13
+ # has_many :orders
14
+ # has_many :transactions
15
+ # has_many :customers
16
+ # has_many :cards
17
+
18
+ def oauth_callback(params)
19
+ update! psp_credentials: payment_provider.get_access_token(params)
20
+ end
21
+
22
+ def psp_connected?
23
+ psp.present? && psp_credentials.present?
24
+ end
25
+
26
+ def needs_oauth?
27
+ !psp_connected? || !scope_correct?
28
+ end
29
+
30
+ def scope_correct?
31
+ psp_credentials[:scope] == payment_provider.scope
32
+ end
33
+
34
+ def charge; end
35
+
36
+ def refund; end
37
+
38
+ private
39
+
40
+ def payment_provider
41
+ @payment_provider ||=
42
+ case psp
43
+ when 'stripe'
44
+ Moneytree::PaymentProvider::Stripe.new(self)
45
+ # when 'square'
46
+ # Moneytree::PaymentProvider::Square.new(self)
47
+ else
48
+ raise 'BOOM'
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Moneytree</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "moneytree/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
@@ -0,0 +1,4 @@
1
+ Moneytree::Engine.routes.draw do
2
+ get 'oauth/stripe/new', to: 'oauth/stripe#new'
3
+ get 'oauth/stripe/callback', to: 'oauth/stripe#callback'
4
+ end
@@ -0,0 +1,11 @@
1
+ class CreateMoneytreePaymentGateways < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :moneytree_payment_gateways do |t|
4
+ t.text :psp_credentials
5
+ t.integer :psp, null: false
6
+ t.references :account, polymorphic: true, null: false, index: { name: 'index_moneytree_pg_account_type_and_account_id' }
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -1,31 +1,24 @@
1
1
  # dependencies
2
- require 'active_support'
3
- require 'active_support/core_ext'
2
+ # require 'rails'
3
+ # require 'active_support/core_ext'
4
4
 
5
5
  # modules
6
6
  # FIXME: autoload instead? https :/ / github.com / excid3 / noticed / blob / master / lib / noticed.rb
7
7
  require 'moneytree/version'
8
8
  require 'moneytree/account'
9
- require 'moneytree/transaction'
10
- require 'moneytree/payment_provider/square'
11
-
12
- require "'moneytree/engine" if defined?(Rails)
9
+ require 'moneytree/payment_provider/base'
10
+ require 'moneytree/payment_provider/stripe'
11
+ require 'moneytree/engine'
13
12
 
14
13
  module Moneytree
15
- PSPS = %i[square stripe braintree].freeze
14
+ PSPS = %i[stripe].freeze
16
15
 
17
16
  mattr_accessor :enabled_psps
18
- mattr_accessor :account_class
19
- mattr_accessor :order_class
20
- mattr_accessor :transaction_class
21
- mattr_accessor :square_credentials
17
+ mattr_accessor :stripe_credentials
22
18
  mattr_accessor :current_account
23
19
 
24
20
  @@enabled_psps = PSPS
25
- @@account_class = 'Account'
26
- @@order_class = 'Order'
27
- @@transaction_class = 'Transaction'
28
- @@current_account = 'current_account'
21
+ @@current_account = :current_account
29
22
 
30
23
  def self.setup
31
24
  yield self
@@ -35,7 +28,7 @@ module Moneytree
35
28
  class Error < StandardError; end
36
29
  end
37
30
 
38
- # FIXME: See if we need this, example: https://github.com/ankane/ahoy/blob/master/lib/ahoy/model.rb
31
+ # FIXME: See if we need this
39
32
  ActiveSupport.on_load(:action_controller) do
40
33
  # include Moneytree::Controller
41
34
  end
@@ -1,42 +1,11 @@
1
+ require 'active_support/concern'
2
+
1
3
  module Moneytree
2
4
  module Account
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  included do
6
- enum moneytree_psp: Moneytree::PSPS
7
- serialize :psp_credentials
8
- # encrypts :psp_credentials
9
- # FIXME: enable https://github.com/ankane/lockbox
10
- delegate :client, :oauth_link, to: :psp
11
- end
12
-
13
- def oauth_callback(params)
14
- update! psp_credentials: psp.oauth_callback(params)
15
- end
16
-
17
- def psp_connected?
18
- false
19
- # moneytree_psp && psp_credentials
20
- end
21
-
22
- def needs_oauth?
23
- true
24
- end
25
-
26
- def charge; end
27
-
28
- def refund; end
29
-
30
- private
31
-
32
- def psp
33
- @psp ||=
34
- case moneytree_psp
35
- when 'square'
36
- Moneytree::PaymentProvider::Square.new(self)
37
- else
38
- raise 'BOOM'
39
- end
8
+ has_one :moneytree_payment_gateway, class_name: 'Moneytree::PaymentGateway', foreign_key: 'account_id'
40
9
  end
41
10
  end
42
11
  end