process payment fields

This commit is contained in:
Pete Matsyburka
2023-12-14 21:22:26 +02:00
parent af4cf7257f
commit 0e9343d9e2
25 changed files with 561 additions and 125 deletions
+15 -1
View File
@@ -22,6 +22,12 @@ module Submissions
VERIFIED_TEXT = 'Verified'
UNVERIFIED_TEXT = 'Unverified'
CURRENCY_SYMBOLS = {
'USD' => '$',
'EUR' => '€',
'GBP' => '£'
}.freeze
module_function
# rubocop:disable Metrics
@@ -200,7 +206,15 @@ module Submissions
composer.image(io, width:, height:, margin: [0, 0, 10, 0])
composer.formatted_text_box([{ text: '' }])
elsif field['type'] == 'file'
elsif field['type'].in?(%w[file payment])
if field['type'] == 'payment'
unit = CURRENCY_SYMBOLS[field['preferences']['currency']]
price = ApplicationController.helpers.number_to_currency(field['preferences']['price'], unit:)
composer.formatted_text_box([{ text: "Paid #{price}\n" }], padding: [0, 0, 10, 0])
end
composer.formatted_text_box(
Array.wrap(value).map do |uuid|
attachment = submitter.attachments.find { |a| a.uuid == uuid }
@@ -85,7 +85,7 @@ module Submissions
width: image.width * scale,
height: image.height * scale
)
when 'file'
when 'file', 'payment'
items = Array.wrap(value).each_with_object([]) do |uuid, acc|
attachment = submitter.attachments.find { |a| a.uuid == uuid }
+1 -1
View File
@@ -99,7 +99,7 @@ module Submitters
def replace_default_variables(value, attrs, template, with_time: false)
return if value.blank?
value.gsub(VARIABLE_REGEXP) do |e|
value.to_s.gsub(VARIABLE_REGEXP) do |e|
case key = ::Regexp.last_match(1)
when 'time'
if with_time