forked from foodcoops/foodsoft
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user-interface for payorder confirmation
Conflicts: lib/foodsoft_payorder/lib/foodsoft_payorder/update_group_order_articles.rb
- Loading branch information
Showing
10 changed files
with
109 additions
and
28 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
15 changes: 15 additions & 0 deletions
15
lib/foodsoft_payorder/app/controllers/payorders_controller.rb
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class PayordersController < GroupOrdersController | ||
|
||
def confirm | ||
# always confirm currently open orders | ||
GroupOrderArticleQuantity.confirm_open!(@current_user.ordergroup) | ||
# redirect to current orders or specified page | ||
return_to = params[:return_to] | ||
if return_to.present? and (return_to.starts_with?(root_path) or return_to.starts_with?(root_url)) | ||
redirect_to return_to | ||
else | ||
redirect_to group_order_path(:current) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
module PayorderHelper | ||
def order_payment_status_button(options={}) | ||
return unless @group_orders_sum > 0 | ||
unconfirmed = GroupOrderArticleQuantity.where(group_order_article_id: @goa_by_oa.values.map(&:id)).where(confirmed: [false,nil]) | ||
if unconfirmed.empty? | ||
link = my_ordergroup_path | ||
cls = "payment-status-btn #{options[:class]}" | ||
link_to glyph('ok')+' '+I18n.t('helpers.payorder.paid'), link, {style: 'color: green'}.merge(options).merge({class: cls}) | ||
else | ||
if order_needs? :payment | ||
# TODO use method to get link, and also support external urls | ||
payment_fee = FoodsoftConfig[:payorder_payment_fee] | ||
amount = -@ordergroup.get_available_funds + payment_fee.to_f | ||
return_to = group_order_path(@order_date || :current) | ||
link = FoodsoftPayorder.payment_link self, amount: amount, fixed: true, | ||
pay_link = FoodsoftPayorder.payment_link self, amount: amount, fixed: true, | ||
title: I18n.t('helpers.payorder.payment_prompt'), return_to: return_to | ||
link = confirm_group_orders_path(return_to: pay_link) | ||
cls = "payment-status-btn btn btn-primary #{options[:class]}" | ||
link_to glyph('chevron-right')+' '+I18n.t('helpers.payorder.payment'), link, options.merge({class: cls}) | ||
elsif order_needs? :confirmation | ||
link = confirm_group_orders_path | ||
cls = "payment-status-btn btn btn-primary #{options[:class]}" | ||
# @todo use button_to with Rails 4+ instead of this workaround | ||
form_tag link do | ||
button_tag glyph('chevron-right')+' '+I18n.t('helpers.payorder.confirm'), options.merge({class: cls}) | ||
end | ||
else | ||
link = my_ordergroup_path | ||
cls = "payment-status-btn #{options[:class]}" | ||
link_to glyph('ok')+' '+I18n.t('helpers.payorder.paid'), link, {style: 'color: green'}.merge(options).merge({class: cls}) | ||
end | ||
end | ||
|
||
# @param types [Symbol, Array<Symbol>] Which actions to check: +payment+ or +confirmation+; or +nil+ for any. | ||
# @return [Boolean] Whether the member order needs user action to go through | ||
def order_needs?(what=nil) | ||
@group_orders_sum > 0 or return false | ||
what = [what] unless what.nil? or what.is_a? Array | ||
if what.nil? or what.include? :payment | ||
return true if @ordergroup.get_available_funds < 0 | ||
end | ||
if what.nil? or what.include? :confirmation | ||
goaqs = GroupOrderArticleQuantity.where(group_order_article_id: @goa_by_oa.values.map(&:id)) | ||
return true if goaqs.where(confirmed: false).any? | ||
end | ||
return false | ||
end | ||
end |
3 changes: 1 addition & 2 deletions
3
...pp/overrides/current_orders/group_orders/_payment_bar/add_payment_button.html.haml.deface
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,4 +1,3 @@ | ||
/ insert_bottom '.pull-right' | ||
- if FoodsoftConfig[:payorder_payment] | ||
- if @articles_grouped_by_category.count > 0 and @ordergroup.get_available_funds < 0 | ||
= order_payment_status_button | ||
= order_payment_status_button if order_needs? |
20 changes: 10 additions & 10 deletions
20
...der/app/overrides/group_orders/_group_order_totals/payment_status_footer.html.haml.deface
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,24 +1,24 @@ | ||
/ insert_after 'erb[silent]:contains("<price_details_bottom_mark>")' | ||
- payment_fee = FoodsoftConfig[:payorder_payment_fee] | ||
- if FoodsoftPayorder.enabled? and @order_date == 'current' | ||
- if (payable = -@ordergroup.get_available_funds) > 0 | ||
- payable += payment_fee.to_f | ||
- if (sum = @ordergroup.account_balance - @ordergroup.value_of_finished_orders) != 0 | ||
%tr.price_details | ||
%td{colspan: cols} | ||
%tr.price_details | ||
%td{colspan: cols-colsright-1}= link_to I18n.t("group_orders.group_order_totals.previous_#{sum>0 ? 'surplus' : 'deficit'}"), my_ordergroup_path | ||
%td.price= number_to_currency(sum.abs) | ||
%td{colspan: colsright, style: 'text-align: left'}= '-' if sum > 0 | ||
- if order_needs? :payment | ||
- payable = -@ordergroup.get_available_funds + payment_fee.to_f | ||
%tr.price_details | ||
%td{colspan: cols} | ||
%tr.price_details | ||
%td{colspan: cols-colsright-1}= link_to I18n.t("group_orders.group_order_totals.previous_#{@group_orders_sum>0 ? 'surplus' : 'deficit'}"), my_ordergroup_path | ||
%td.price= number_to_currency(@group_orders_sum.abs) | ||
%td{colspan: colsright, style: 'text-align: left'}= '-' if @group_orders_sum > 0 | ||
- if payment_fee | ||
%tr.price_details | ||
%td{colspan: cols-colsright-1}= t '.payment_fee' | ||
%td.price= number_to_currency payment_fee | ||
%td{colspan: colsright} | ||
- if payable != sum | ||
- if payable != @group_orders_sum | ||
%tr.price_details | ||
%th{colspan: cols-colsright-1}= t '.payable' | ||
%th.price= number_to_currency payable | ||
%th{colspan: colsright} | ||
- if order_needs? | ||
%tr.price_details | ||
%td{colspan: cols, style: 'text-align: right'}= order_payment_status_button |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
Rails.application.routes.draw do | ||
scope '/:foodcoop' do | ||
post '/group_orders/current/confirm', controller: 'payorders', action: 'confirm', as: 'confirm_group_orders' | ||
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