moneytree-rails 0.1.5 → 0.1.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2006000e7eb666a0edd1d8e035330c00804f41460dcca1a7e73d75f855dcd254
4
- data.tar.gz: 1a36220066504521f1d9d4b477d9eeca1fb5ddd7dce1abc37daefe0a4412001f
3
+ metadata.gz: 82a73ef1112fc456b1f7418cad362291d5817be5a4c1ab0d37a315418087584f
4
+ data.tar.gz: b31da6ae5001a28d162b6db90627654ccaa0adb74271aad2160357c971da2c33
5
5
  SHA512:
6
- metadata.gz: 72fbbd0d1f6dd0e144e6d72a412aa7313487afa0d92c2bbb5213925a4d3e4eaebdcb1369a64060183d7b073de41823f97d1f978f8751151c82799a8565324530
7
- data.tar.gz: 296df5c1b71b78acd51639d49caca1964bf8260c156ddc7ea68aa648dcf47a6fe8e1e0b9887e1cf20236365a8436dd9b76f45c7e1a5f18fdb74d537a3944d8bf
6
+ metadata.gz: d8de210345c2d0e8c813eb46b1d4f8f6e332df0b9013b6ced5b770886bc4a3246535f9cf9ad8ead5bcaef4c5cb40c24f20a383310a0407288f08e9dd34a3605e
7
+ data.tar.gz: 1a133c019d8e1a1cfb64b21ea7d2f05a675660b81f6802213072fb38da9ce2c5b7f983be58c8bdb399b62a94916703712bba81c478805c17dbaa91c796ca8e58
data/README.md CHANGED
@@ -95,6 +95,11 @@ class Merchant < ApplicationRecord
95
95
  def website
96
96
  'https://www.boomtown.com'
97
97
  end
98
+
99
+ # Optional, will be called by Moneytree after authenticating with the PSP
100
+ def moneytree_oauth_callback
101
+ puts "Hurray, I just got associated with a Moneytree gateway!"
102
+ end
98
103
  end
99
104
  ```
100
105
 
@@ -1,6 +1,6 @@
1
1
  module Moneytree
2
2
  module Oauth
3
- class SquareController < ApplicationController
3
+ class SquareController < Moneytree::ApplicationController
4
4
  def new
5
5
  redirect_to current_account.oauth_link
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module Moneytree
2
2
  module Oauth
3
- class StripeController < ApplicationController
3
+ class StripeController < Moneytree::ApplicationController
4
4
  def new
5
5
  redirect_to stripe_oauth_url
6
6
  end
@@ -27,7 +27,7 @@ module Moneytree
27
27
  query: {
28
28
  response_type: :code,
29
29
  client_id: Moneytree.stripe_credentials[:client_id],
30
- scope: PaymentProvider::Stripe::PERMISSION,
30
+ scope: Moneytree::PaymentProvider::Stripe::PERMISSION,
31
31
  redirect_uri: oauth_stripe_callback_url,
32
32
  'stripe_user[email]': current_account.email,
33
33
  'stripe_user[url]': current_account.website,
@@ -1,6 +1,6 @@
1
1
  module Moneytree
2
2
  module Webhooks
3
- class SquareController < ApplicationController
3
+ class SquareController < Moneytree::ApplicationController
4
4
  def create
5
5
  # Do some callback magic here
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module Moneytree
2
2
  module Webhooks
3
- class StripeController < ApplicationController
3
+ class StripeController < Moneytree::ApplicationController
4
4
  skip_before_action :verify_authenticity_token
5
5
 
6
6
  def create
@@ -29,7 +29,7 @@ module Moneytree
29
29
  return if transaction.completed?
30
30
 
31
31
  transaction.process_response(
32
- TransactionResponse.new(:success, '', { charge_id: stripe_object.id })
32
+ Moneytree::TransactionResponse.new(:success, '', { charge_id: stripe_object.id })
33
33
  )
34
34
 
35
35
  if Moneytree.order_status_trigger_method
@@ -47,7 +47,7 @@ module Moneytree
47
47
  next if refund.completed?
48
48
 
49
49
  refund.process_response(
50
- TransactionResponse.new(:success, '')
50
+ Moneytree::TransactionResponse.new(:success, '')
51
51
  )
52
52
  if Moneytree.order_status_trigger_method
53
53
  transaction.order.send(Moneytree.order_status_trigger_method, transaction)
@@ -56,7 +56,7 @@ module Moneytree
56
56
  end
57
57
 
58
58
  def transaction
59
- @transaction ||= Transaction.find(stripe_object.metadata[:moneytree_transaction_id])
59
+ @transaction ||= Moneytree::Transaction.find(stripe_object.metadata[:moneytree_transaction_id])
60
60
  end
61
61
 
62
62
  def stripe_object
@@ -0,0 +1,15 @@
1
+ module Moneytree
2
+ class Card
3
+ include ActiveModel::Model
4
+
5
+ attr_accessor(
6
+ :last4,
7
+ :exp_month,
8
+ :exp_year,
9
+ :fingerprint,
10
+ :brand,
11
+ :address_zip,
12
+ :country
13
+ )
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  module Moneytree
2
- class Payment < Transaction
3
- has_many :refunds, class_name: 'Refund'
2
+ class Payment < Moneytree::Transaction
3
+ has_many :refunds, class_name: 'Moneytree::Refund'
4
4
 
5
5
  validates_absence_of :payment_id
6
6
 
@@ -8,13 +8,11 @@ module Moneytree
8
8
  # FIXME: enable https://github.com/ankane/lockbox
9
9
  delegate :oauth_link, :scope_correct?, :charge, :refund, to: :payment_provider
10
10
 
11
- # has_many :orders
12
- # has_many :transactions
13
- # has_many :customers
14
- # has_many :cards
11
+ has_many :transactions
15
12
 
16
13
  def oauth_callback(params)
17
14
  update! psp_credentials: payment_provider.get_access_token(params)
15
+ account.send(:moneytree_oauth_callback) if account.respond_to?(:moneytree_oauth_callback, true)
18
16
  end
19
17
 
20
18
  def psp_connected?
@@ -29,8 +27,6 @@ module Moneytree
29
27
  psp_credentials[:scope] == payment_provider.scope
30
28
  end
31
29
 
32
- private
33
-
34
30
  def payment_provider
35
31
  @payment_provider ||=
36
32
  case psp
@@ -1,5 +1,5 @@
1
1
  module Moneytree
2
- class Refund < Transaction
2
+ class Refund < Moneytree::Transaction
3
3
  belongs_to :payment, class_name: 'Moneytree::Payment'
4
4
 
5
5
  before_validation :set_order, :set_payment_gateway
@@ -1,5 +1,5 @@
1
1
  module Moneytree
2
- class Transaction < ApplicationRecord
2
+ class Transaction < Moneytree::ApplicationRecord
3
3
  belongs_to :payment_gateway
4
4
  belongs_to :order, polymorphic: true
5
5
 
@@ -9,8 +9,14 @@ module Moneytree
9
9
 
10
10
  serialize :details
11
11
 
12
+ delegate :payment_provider, to: :payment_gateway
13
+
12
14
  after_create_commit :execute_transaction
13
15
 
16
+ def card
17
+ payment_provider.card_for(self)
18
+ end
19
+
14
20
  def process_response(response)
15
21
  if response.success?
16
22
  update!(
@@ -9,7 +9,9 @@ module Moneytree
9
9
  end
10
10
 
11
11
  def new_payment(*args)
12
- moneytree_transactions << Payment.new(*args)
12
+ payment = Payment.new(*args)
13
+ moneytree_transactions << payment
14
+ payment
13
15
  end
14
16
  end
15
17
  end
@@ -43,7 +43,10 @@ module Moneytree
43
43
  TransactionResponse.new(
44
44
  { succeeded: :success, pending: :pending, failed: :failed }[response[:status].to_sym],
45
45
  response[:failure_message],
46
- { charge_id: response[:id] }
46
+ {
47
+ charge_id: response[:id],
48
+ card: response[:payment_method_details][:card]
49
+ }
47
50
  )
48
51
  rescue ::Stripe::StripeError => e
49
52
  TransactionResponse.new(:failed, e.message)
@@ -70,6 +73,18 @@ module Moneytree
70
73
  TransactionResponse.new(:failed, e.message)
71
74
  end
72
75
 
76
+ def card_for(transaction)
77
+ Card.new(
78
+ last4: transaction.details[:card][:last4],
79
+ exp_month: transaction.details[:card][:exp_month],
80
+ exp_year: transaction.details[:card][:exp_year],
81
+ fingerprint: transaction.details[:card][:fingerprint],
82
+ brand: transaction.details[:card][:brand],
83
+ address_zip: transaction.details[:card][:address_zip],
84
+ country: transaction.details[:card][:country]
85
+ )
86
+ end
87
+
73
88
  private
74
89
 
75
90
  def credentitals
@@ -1,3 +1,3 @@
1
1
  module Moneytree
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneytree-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Klaassen
@@ -59,6 +59,7 @@ files:
59
59
  - app/jobs/moneytree/application_job.rb
60
60
  - app/mailers/moneytree/application_mailer.rb
61
61
  - app/models/moneytree/application_record.rb
62
+ - app/models/moneytree/card.rb
62
63
  - app/models/moneytree/payment.rb
63
64
  - app/models/moneytree/payment_gateway.rb
64
65
  - app/models/moneytree/refund.rb