From fb2dfed6bf0f9a7bcde39255362fb67407369ef9 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 25 Feb 2026 14:01:00 +1100 Subject: [PATCH] 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. --- app/mailers/payment_mailer.rb | 4 ++-- app/models/spree/payment_method/taler.rb | 11 +++++++---- spec/mailers/payment_mailer_spec.rb | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/mailers/payment_mailer.rb b/app/mailers/payment_mailer.rb index b90d4c2191..0968224341 100644 --- a/app/mailers/payment_mailer.rb +++ b/app/mailers/payment_mailer.rb @@ -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 diff --git a/app/models/spree/payment_method/taler.rb b/app/models/spree/payment_method/taler.rb index 777b3f3090..2ee18757e6 100644 --- a/app/models/spree/payment_method/taler.rb +++ b/app/models/spree/payment_method/taler.rb @@ -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 diff --git a/spec/mailers/payment_mailer_spec.rb b/spec/mailers/payment_mailer_spec.rb index dcce998d6e..f5cdae6c21 100644 --- a/spec/mailers/payment_mailer_spec.rb +++ b/spec/mailers/payment_mailer_spec.rb @@ -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."