-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A first pass at setting up the content for the page and saving the user's answer about how they'd like to pay. The copy cards fee depends on a different PR being merged in (#139). For now we've got a temporary holding value.
- Loading branch information
1 parent
9d35fd0
commit 6b690d2
Showing
7 changed files
with
152 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
class PaymentSummaryForm < BaseForm | ||
# TODO: Define accessible attributes, eg attr_accessor :field | ||
attr_accessor :temp_payment_method, :type_change, :registration_cards, :registration_card_charge, :total_charge | ||
|
||
def initialize(transient_registration) | ||
super | ||
# TODO: Define params to get from transient_registration, eg self.field = @transient_registration.field | ||
self.temp_payment_method = @transient_registration.temp_payment_method | ||
|
||
self.type_change = @transient_registration.registration_type_changed? | ||
# TODO: Uncomment this once https://github.com/DEFRA/waste-carriers-renewals/pull/139/ is merged in | ||
# self.registration_cards = @transient_registration.temp_cards || 0 | ||
self.registration_cards = 2 # Temp value for testing | ||
self.registration_card_charge = determine_registration_card_charge | ||
self.total_charge = determine_total_charge | ||
end | ||
|
||
def submit(params) | ||
# Assign the params for validation and pass them to the BaseForm method for updating | ||
# TODO: Define allowed params, eg self.field = params[:field] | ||
# TODO: Include attributes to update in the attributes hash, eg { field: field } | ||
attributes = {} | ||
self.temp_payment_method = params[:temp_payment_method] | ||
attributes = { temp_payment_method: temp_payment_method } | ||
|
||
super(attributes, params[:reg_identifier]) | ||
end | ||
|
||
validates :temp_payment_method, inclusion: { in: %w[card bank_transfer] } | ||
|
||
private | ||
|
||
def determine_total_charge | ||
charges = [Rails.configuration.renewal_charge] | ||
charges << Rails.configuration.type_change_charge if type_change | ||
charges << registration_card_charge | ||
charges.sum | ||
end | ||
|
||
def determine_registration_card_charge | ||
registration_cards * 5 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters