class SKVReport::Stripe
Generate SKV CSV string from Stripe
charge
Attributes
charges[R]
company_information[R]
period[R]
rates[R]
year[R]
Public Class Methods
call(charges, period, year, company_information = {}, rates = {})
click to toggle source
# File lib/skv_report/stripe.rb, line 34 def self.call(charges, period, year, company_information = {}, rates = {}) new(charges, period, year, company_information, rates).call end
new(charges, period, year, company_information = {}, rates = {})
click to toggle source
company_information
needs to contain the following information {
vat_number: String, # vat number of the selling company name: String, # contact name on selling company phone: String, # phone to contact on selling company email: String, # optional email to contact on selling company type_of_sales: String, # one of the following three ['wares', 'third_party', 'services']
}
Send rates to ImportExchangeRates, and send the object to stripe charge row, and then call rate for in there? Nah…
# File lib/skv_report/stripe.rb, line 26 def initialize(charges, period, year, company_information = {}, rates = {}) @charges = charges @company_information = company_information @period = period @year = year @rates = rates end
Public Instance Methods
call()
click to toggle source
# File lib/skv_report/stripe.rb, line 38 def call CSV.generate(csv_options) do |csv| csv << first_row csv << second_row generate_charge_rows(csv) end end
Private Instance Methods
build_charge_rows()
click to toggle source
# File lib/skv_report/stripe.rb, line 75 def build_charge_rows group_charge_rows.map do |vat_number, charges| sales_row(vat_number, charges) end end
column_separator()
click to toggle source
# File lib/skv_report/stripe.rb, line 104 def column_separator ';' end
csv_options()
click to toggle source
# File lib/skv_report/stripe.rb, line 96 def csv_options { col_sep: column_separator, row_sep: row_separator } end
evaluate_amount_position(charges)
click to toggle source
# File lib/skv_report/stripe.rb, line 85 def evaluate_amount_position(charges) case company_information['type_of_sales'] when 'wares' then [charges.sum(&:sales_amount), nil, nil] when 'third_party' then [nil, charges.sum(&:sales_amount), nil] when 'services' then [nil, nil, charges.sum(&:sales_amount)] else raise UndefinedTypeOfSalesError, "#{company_information['type_of_sales']} is not valid" end end
exchange_rates()
click to toggle source
# File lib/skv_report/stripe.rb, line 120 def exchange_rates @exchange_rates ||= ExchangeRates.new(rates) end
first_row()
click to toggle source
# File lib/skv_report/stripe.rb, line 48 def first_row ['SKV574008'] end
generate_charge_rows(csv)
click to toggle source
# File lib/skv_report/stripe.rb, line 60 def generate_charge_rows(csv) build_charge_rows.each { |row| csv << row } end
group_charge_rows()
click to toggle source
# File lib/skv_report/stripe.rb, line 64 def group_charge_rows charge_rows = charges.map do |charge| charge_row = SKVReport::StripeChargeRow.new(charge, exchange_rates) next if charge_row.skippable? charge_row end.compact charge_rows.group_by(&:buyer_vat_number) end
row_separator()
click to toggle source
# File lib/skv_report/stripe.rb, line 100 def row_separator ";\r\n" end
sales_row(vat_number, charges)
click to toggle source
# File lib/skv_report/stripe.rb, line 81 def sales_row(vat_number, charges) [vat_number].concat(evaluate_amount_position(charges)) end
sanitized_phone()
click to toggle source
# File lib/skv_report/stripe.rb, line 116 def sanitized_phone company_information['phone'].gsub(/[^0-9\-+]/, '')[0...17] end
second_row()
click to toggle source
# File lib/skv_report/stripe.rb, line 52 def second_row [company_information['vat_number'], year_and_period, company_information['name'][0...35], sanitized_phone, company_information['email']] end
year_and_period()
click to toggle source
# File lib/skv_report/stripe.rb, line 108 def year_and_period "#{year_short}-#{period}" end
year_short()
click to toggle source
# File lib/skv_report/stripe.rb, line 112 def year_short Date.new(year).strftime('%y') end