mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add payment method fees to order during checkout
The fee is displayed as "Transaction fee".
This commit is contained in:
@@ -62,8 +62,11 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
|
||||
shippingPrice: ->
|
||||
@shippingMethod()?.price || 0.0
|
||||
|
||||
paymentPrice: ->
|
||||
@paymentMethod()?.price || 0.0
|
||||
|
||||
paymentMethod: ->
|
||||
PaymentMethods.payment_methods_by_id[@order.payment_method_id]
|
||||
|
||||
cartTotal: ->
|
||||
@shippingPrice() + @order.display_total
|
||||
@order.display_total + @shippingPrice() + @paymentPrice()
|
||||
|
||||
@@ -4,5 +4,6 @@ Darkswarm.factory "PaymentMethods", (paymentMethods)->
|
||||
payment_methods_by_id: {}
|
||||
constructor: ->
|
||||
for method in @payment_methods
|
||||
method.price = parseFloat(method.price)
|
||||
@payment_methods_by_id[method.id] = method
|
||||
|
||||
|
||||
@@ -94,4 +94,13 @@ module CheckoutHelper
|
||||
current_order.tokenized_permission.save!
|
||||
session[:access_token] = token
|
||||
end
|
||||
|
||||
def payment_method_price(method, order)
|
||||
price = method.compute_amount(order)
|
||||
if price == 0
|
||||
t('checkout_method_free')
|
||||
else
|
||||
"{{ #{price} | localizeCurrency }}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
module Spree
|
||||
Payment.class_eval do
|
||||
has_one :adjustment, as: :source, dependent: :destroy
|
||||
|
||||
after_save :ensure_correct_adjustment, :update_order
|
||||
|
||||
def ensure_correct_adjustment
|
||||
if adjustment
|
||||
adjustment.originator = payment_method
|
||||
adjustment.label = adjustment_label
|
||||
adjustment.save
|
||||
else
|
||||
payment_method.create_adjustment(adjustment_label, order, self, true)
|
||||
reload
|
||||
end
|
||||
end
|
||||
|
||||
def adjustment_label
|
||||
I18n.t('payment_method_fee')
|
||||
end
|
||||
|
||||
# Pin payments lacks void and credit methods, but it does have refund
|
||||
# Here we swap credit out for refund and remove void as a possible action
|
||||
def actions_with_pin_payment_adaptations
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
class Api::PaymentMethodSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description, :id, :method_type
|
||||
attributes :name, :description, :id, :method_type,
|
||||
:price
|
||||
|
||||
def price
|
||||
object.compute_amount(options[:current_order])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
name: "order.payment_method_id",
|
||||
"ng-model" => "order.payment_method_id"
|
||||
= method.name
|
||||
= "(#{payment_method_price(method, @order)})"
|
||||
|
||||
%small.error.medium.input-text{"ng-show" => "!fieldValid('order.payment_method_id')"}
|
||||
= "{{ fieldErrors('order.payment_method_id') }}"
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
= t :checkout_shipping_price
|
||||
%td.shipping.text-right {{ Checkout.shippingPrice() | localizeCurrency }}
|
||||
|
||||
%tr
|
||||
%th
|
||||
= t :payment_method_fee
|
||||
%td.text-right {{ Checkout.paymentPrice() | localizeCurrency }}
|
||||
|
||||
%tr
|
||||
%th
|
||||
= t :checkout_total_price
|
||||
|
||||
@@ -1038,6 +1038,7 @@ Please follow the instructions there to make your enterprise visible on the Open
|
||||
properties: "Properties"
|
||||
shipping_methods: "Shipping Methods"
|
||||
payment_methods: "Payment Methods"
|
||||
payment_method_fee: "Transaction fee"
|
||||
enterprise_fees: "Enterprise Fees"
|
||||
inventory_settings: "Inventory Settings"
|
||||
tag_rules: "Tag Rules"
|
||||
|
||||
@@ -48,7 +48,7 @@ feature %q{
|
||||
visit spree.admin_orders_path
|
||||
page.find('td.actions a.icon-edit').click
|
||||
click_link 'Adjustments'
|
||||
page.find('td.actions a.icon-edit').click
|
||||
page.find('tr', text: 'Shipping').find('a.icon-edit').click
|
||||
|
||||
# Then I should see the uneditable included tax and our tax rate as the default
|
||||
page.should have_field :adjustment_included_tax, with: '10.00', disabled: true
|
||||
@@ -72,7 +72,7 @@ feature %q{
|
||||
visit spree.admin_orders_path
|
||||
page.find('td.actions a.icon-edit').click
|
||||
click_link 'Adjustments'
|
||||
page.find('td.actions a.icon-edit').click
|
||||
page.find('tr', text: 'Shipping').find('a.icon-edit').click
|
||||
|
||||
# Then I should see the uneditable included tax and 'Remove tax' as the default tax rate
|
||||
page.should have_field :adjustment_included_tax, with: '0.00', disabled: true
|
||||
|
||||
Reference in New Issue
Block a user