Module: UsageCredits::PayChargeExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/usage_credits/models/concerns/pay_charge_extension.rb

Overview

Extends Pay::Charge with credit pack functionality

Instance Method Summary collapse

Instance Method Details

#init_metadataObject



14
15
16
17
# File 'lib/usage_credits/models/concerns/pay_charge_extension.rb', line 14

def 
  self. ||= {}
  self.data ||= {}
end

#refunded?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/usage_credits/models/concerns/pay_charge_extension.rb', line 34

def refunded?
  return false unless amount_refunded
  amount_refunded > 0
end

#succeeded?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/usage_credits/models/concerns/pay_charge_extension.rb', line 19

def succeeded?
  case type
  when "Pay::Stripe::Charge"
    status = data["status"] || data[:status]
    return true if status == "succeeded"
    return true if data["amount_captured"].to_i == amount.to_i
  end

  # Are Pay::Charge objects guaranteed to be created only after a successful payment?
  # Is the existence of a Pay::Charge object in the database a guarantee that the payment went through?
  # I'm implementing this `succeeded?` method just out of precaution
  # TODO: Implement for more payment processors? Or just drop this method if it's unnecessary
  true
end