Class: MossGenerator::StripeChargeRow

Inherits:
Object
  • Object
show all
Defined in:
lib/moss_generator/stripe_charge_row.rb

Overview

Parse charge data from single Stripe charge

Defined Under Namespace

Classes: NoConsumptionCountryError, NoExchangeRateForCurrencyOrDateError, NoVatRateForCountryError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(charge, rates, vat_rate_service = MossGenerator::VatRate) ⇒ StripeChargeRow

Returns a new instance of StripeChargeRow.



19
20
21
22
23
# File 'lib/moss_generator/stripe_charge_row.rb', line 19

def initialize(charge, rates, vat_rate_service = MossGenerator::VatRate)
  @charge = charge
  @rates = rates
  @vat_rate_service = vat_rate_service
end

Instance Attribute Details

#chargeObject (readonly)

Returns the value of attribute charge.



17
18
19
# File 'lib/moss_generator/stripe_charge_row.rb', line 17

def charge
  @charge
end

#ratesObject (readonly)

Returns the value of attribute rates.



17
18
19
# File 'lib/moss_generator/stripe_charge_row.rb', line 17

def rates
  @rates
end

#vat_rate_serviceObject (readonly)

Returns the value of attribute vat_rate_service.



17
18
19
# File 'lib/moss_generator/stripe_charge_row.rb', line 17

def vat_rate_service
  @vat_rate_service
end

Instance Method Details

#amount_without_vatObject



31
32
33
# File 'lib/moss_generator/stripe_charge_row.rb', line 31

def amount_without_vat
  Money.new(amount_with_vat * percent_without_vat).dollars.to_f
end

#amount_without_vat_centsObject



35
36
37
# File 'lib/moss_generator/stripe_charge_row.rb', line 35

def amount_without_vat_cents
  Money.new(amount_with_vat * percent_without_vat).cents
end

#country_codeObject



25
26
27
28
29
# File 'lib/moss_generator/stripe_charge_row.rb', line 25

def country_code
  return fetch_country_code unless fetch_country_code.nil?

  raise NoConsumptionCountryError, "charge: #{charge}"
end

#skippable?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/moss_generator/stripe_charge_row.rb', line 49

def skippable?
  not_completed? ||
    company? ||
    fetch_country_code.nil? ||
    sold_outside_of_eu? ||
    swedish_charge? ||
    refunded?
end

#vat_amountObject



43
44
45
46
47
# File 'lib/moss_generator/stripe_charge_row.rb', line 43

def vat_amount
  Money.new(amount_without_vat_cents * vat_rate_calculatable_percent)
       .dollars
       .to_f
end

#vat_rateObject



39
40
41
# File 'lib/moss_generator/stripe_charge_row.rb', line 39

def vat_rate
  @vat_rate = special_vat_rate_for_2021_quarter_one
end