moneytree-rails 0.1.6 → 0.1.11

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: e93dc9ca7a7f7c33bb6866abec9c4ef68038d5c9c542a92ea20d890086ab4369
4
- data.tar.gz: ab099aef15f26a36c21934d1a70d39e8641db9fee2feb88107681b3f72b5f890
3
+ metadata.gz: 0a606a849682a4f6127da7dfbb4a9d0606f315c819207653084088a3b230c179
4
+ data.tar.gz: d682ed115c7159fbbb81276b63b5e9d94b8e43032a201cb088bb2cf1e8b495a9
5
5
  SHA512:
6
- metadata.gz: c76a4655eb8f63a3c7643b95b595e8cbe7484ff5a92642ca28e1947225ed6ebce4be3bf80cb620bc1ace05450b308a976901f4f3415fcfce2083dd4f475453fd
7
- data.tar.gz: ddb835e4f3a5113752ca9929a4fd0788565729a8881a7c917bbb13548bdc856e025e0b7def3c0647d6e5314bf4e0670ce70036355be1a21a77439002cb786699
6
+ metadata.gz: 6b9e27ae3746b2d400e3810ff71717e676d546aed60235fc3a1f0b0f81cce6b9fcaf70b5b3ccf0bdceb3f0b3070bfba018363a8b163ec2db311b687c4e259ed7
7
+ data.tar.gz: 9cd9a4892e98f7e6d4acad9fa9a026dda236215c3830576d3cd1ee3b779dfc4377c82226e333de0833272c962f39e8914b3aaa9f3789ce21945f5751d5e98a81
@@ -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,10 +8,7 @@ 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)
@@ -30,8 +27,6 @@ module Moneytree
30
27
  psp_credentials[:scope] == payment_provider.scope
31
28
  end
32
29
 
33
- private
34
-
35
30
  def payment_provider
36
31
  @payment_provider ||=
37
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
@@ -26,7 +26,7 @@ module Moneytree
26
26
  PERMISSION.to_s
27
27
  end
28
28
 
29
- def charge(amount, details, app_fee_amount: 0, description: "Charge for #{account.name}", metadata:)
29
+ def charge(amount, details, metadata:, app_fee_amount: 0, description: "Charge for #{account.name}")
30
30
  # `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token
31
31
  response = ::Stripe::Charge.create(
32
32
  {
@@ -43,7 +43,11 @@ 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
+ has_application_fee: !app_fee_amount.zero?
50
+ }
47
51
  )
48
52
  rescue ::Stripe::StripeError => e
49
53
  TransactionResponse.new(:failed, e.message)
@@ -55,7 +59,7 @@ module Moneytree
55
59
  charge: details[:charge_id],
56
60
  amount: (-amount * 100).to_i,
57
61
  metadata: metadata,
58
- refund_application_fee: Moneytree.refund_application_fee
62
+ refund_application_fee: details[:has_application_fee] && Moneytree.refund_application_fee
59
63
  },
60
64
  stripe_account: payment_gateway.psp_credentials[:stripe_user_id]
61
65
  )
@@ -70,6 +74,18 @@ module Moneytree
70
74
  TransactionResponse.new(:failed, e.message)
71
75
  end
72
76
 
77
+ def card_for(transaction)
78
+ Card.new(
79
+ last4: transaction.details[:card][:last4],
80
+ exp_month: transaction.details[:card][:exp_month],
81
+ exp_year: transaction.details[:card][:exp_year],
82
+ fingerprint: transaction.details[:card][:fingerprint],
83
+ brand: transaction.details[:card][:brand],
84
+ address_zip: transaction.details[:card][:address_zip],
85
+ country: transaction.details[:card][:country]
86
+ )
87
+ end
88
+
73
89
  private
74
90
 
75
91
  def credentitals
@@ -1,3 +1,3 @@
1
1
  module Moneytree
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.11'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneytree-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Klaassen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-27 00:00:00.000000000 Z
11
+ date: 2020-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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