mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Add transaction origin for internal credit payments
This commit is contained in:
@@ -33,7 +33,6 @@ module Spree
|
||||
customer = Customer.find_by(id: options[:customer_id])
|
||||
return error_response("customer_not_found") if customer.nil?
|
||||
return error_response("missing_payment") if options[:payment_id].nil?
|
||||
return error_response("credit_payment_method_missing") if payment_method.nil?
|
||||
|
||||
available_credit = customer.customer_account_transactions.last&.balance
|
||||
return error_response("no_credit_available") if available_credit.nil?
|
||||
@@ -49,7 +48,6 @@ module Spree
|
||||
customer.customer_account_transactions.create(
|
||||
amount: -calculated_amount,
|
||||
currency:,
|
||||
payment_method:,
|
||||
payment_id: options[:payment_id],
|
||||
description:
|
||||
)
|
||||
@@ -69,7 +67,6 @@ module Spree
|
||||
customer = Customer.find_by(id: options[:customer_id])
|
||||
return error_response("customer_not_found") if customer.nil?
|
||||
return error_response("missing_payment") if options[:payment_id].nil?
|
||||
return error_response("credit_payment_method_missing") if payment_method.nil?
|
||||
|
||||
customer.with_lock do
|
||||
description = I18n.t(
|
||||
@@ -80,7 +77,6 @@ module Spree
|
||||
customer.customer_account_transactions.create(
|
||||
amount: calculated_amount,
|
||||
currency:,
|
||||
payment_method:,
|
||||
payment_id: options[:payment_id],
|
||||
description:,
|
||||
created_by_id: options[:user_id]
|
||||
@@ -101,10 +97,6 @@ module Spree
|
||||
|
||||
private
|
||||
|
||||
def payment_method
|
||||
Spree::PaymentMethod.customer_credit
|
||||
end
|
||||
|
||||
def error_response(translation_key)
|
||||
message = I18n.t(translation_key, scope: "credit_payment_method.errors")
|
||||
ActiveMerchant::Billing::Response.new(false, message)
|
||||
|
||||
@@ -5204,8 +5204,8 @@ en:
|
||||
description: Allow customer to pay with credit
|
||||
success: Payment with credit was sucessful
|
||||
void_success: Credit void was sucessful
|
||||
order_payment_description: "Payment for order: %{order_number}"
|
||||
order_void_description: "Refund for order: %{order_number}"
|
||||
order_payment_description: "Customer credit: Payment for order: %{order_number}"
|
||||
order_void_description: "Customer credit: Refund for order: %{order_number}"
|
||||
errors:
|
||||
customer_not_found: Customer not found
|
||||
missing_payment: Missing payment
|
||||
|
||||
@@ -43,9 +43,8 @@ RSpec.describe Spree::PaymentMethod::CustomerCredit do
|
||||
|
||||
transaction = customer.customer_account_transactions.last
|
||||
expect(transaction.amount).to eq(-10.00)
|
||||
expect(transaction.payment_method).to be_a(Spree::PaymentMethod::CustomerCredit)
|
||||
expect(transaction.payment).to eq(payment)
|
||||
expect(transaction.description).to eq("Payment for order: R023075164")
|
||||
expect(transaction.description).to eq("Customer credit: Payment for order: R023075164")
|
||||
end
|
||||
|
||||
context "when not enough credit is available" do
|
||||
@@ -95,15 +94,6 @@ RSpec.describe Spree::PaymentMethod::CustomerCredit do
|
||||
expect(response.message).to eq("Missing payment")
|
||||
end
|
||||
end
|
||||
|
||||
context "when credit payment method is not configured" do
|
||||
let!(:credit_payment_method) { nil }
|
||||
|
||||
it "returns an error" do
|
||||
expect(response.success?).to be(false)
|
||||
expect(response.message).to eq("Credit payment method is missing")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#void" do
|
||||
@@ -131,9 +121,8 @@ RSpec.describe Spree::PaymentMethod::CustomerCredit do
|
||||
|
||||
transaction = customer.customer_account_transactions.last
|
||||
expect(transaction.amount).to eq(15.00)
|
||||
expect(transaction.payment_method).to be_a(Spree::PaymentMethod::CustomerCredit)
|
||||
expect(transaction.payment).to eq(payment)
|
||||
expect(transaction.description).to eq("Refund for order: R023075164")
|
||||
expect(transaction.description).to eq("Customer credit: Refund for order: R023075164")
|
||||
end
|
||||
|
||||
context "when user_id provided" do
|
||||
@@ -182,14 +171,5 @@ RSpec.describe Spree::PaymentMethod::CustomerCredit do
|
||||
expect(response.message).to eq("Missing payment")
|
||||
end
|
||||
end
|
||||
|
||||
context "when credit payment method is not configured" do
|
||||
let!(:credit_payment_method) { nil }
|
||||
|
||||
it "returns an error" do
|
||||
expect(response.success?).to be(false)
|
||||
expect(response.message).to eq("Credit payment method is missing")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user