mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Pass amount to payment mailer
We now include the refunded amount in the email to the customer. When voiding a payment, it's the full amount of the payment. When giving back credit then it's only the money that has been paid too much.
This commit is contained in:
@@ -22,10 +22,10 @@ class PaymentMailer < ApplicationMailer
|
||||
end
|
||||
end
|
||||
|
||||
def refund_available(payment, taler_order_status_url)
|
||||
def refund_available(amount, payment, taler_order_status_url)
|
||||
@order = payment.order
|
||||
@shop = @order.distributor.name
|
||||
@amount = payment.display_amount
|
||||
@amount = amount
|
||||
@taler_order_status_url = taler_order_status_url
|
||||
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
|
||||
@@ -65,16 +65,18 @@ module Spree
|
||||
end
|
||||
|
||||
def credit(money, gateway_options)
|
||||
amount = money / 100 # called with cents
|
||||
payment = gateway_options[:payment]
|
||||
taler_order = taler_order(id: payment.response_code)
|
||||
status = taler_order.fetch("order_status")
|
||||
|
||||
raise "Unsupported action" if status != "paid"
|
||||
|
||||
amount = "KUDOS:#{money}"
|
||||
taler_order.refund(refund: amount, reason: "credit")
|
||||
taler_amount = "KUDOS:#{amount}"
|
||||
taler_order.refund(refund: taler_amount, reason: "credit")
|
||||
|
||||
PaymentMailer.refund_available(payment, taler_order.status_url).deliver_later
|
||||
spree_money = Spree::Money.new(amount, currency: payment.currency).to_s
|
||||
PaymentMailer.refund_available(spree_money, payment, taler_order.status_url).deliver_later
|
||||
|
||||
ActiveMerchant::Billing::Response.new(true, "Refund initiated")
|
||||
end
|
||||
@@ -93,7 +95,8 @@ module Spree
|
||||
amount = taler_order.fetch("contract_terms")["amount"]
|
||||
taler_order.refund(refund: amount, reason: "void")
|
||||
|
||||
PaymentMailer.refund_available(payment, taler_order.status_url).deliver_later
|
||||
spree_money = payment.money.to_s
|
||||
PaymentMailer.refund_available(spree_money, payment, taler_order.status_url).deliver_later
|
||||
|
||||
ActiveMerchant::Billing::Response.new(true, "Refund initiated")
|
||||
end
|
||||
|
||||
@@ -56,7 +56,7 @@ RSpec.describe PaymentMailer do
|
||||
payment = build(:payment)
|
||||
payment.order.distributor = build(:enterprise, name: "Carrot Castle")
|
||||
link = "https://taler.example.com/order/1"
|
||||
mail = PaymentMailer.refund_available(payment, link)
|
||||
mail = PaymentMailer.refund_available(payment.money.to_s, payment, link)
|
||||
|
||||
expect(mail.subject).to eq "Refund from Carrot Castle"
|
||||
expect(mail.body).to include "Your payment of $45.75 to Carrot Castle is being refunded."
|
||||
|
||||
Reference in New Issue
Block a user