From 6a99d2a3c89883bfc270563831bd0cded0b3c5da Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 6 Mar 2026 13:13:54 +1100 Subject: [PATCH] Add transaction origin in descriptiopn --- ...customer_account_transaction_controller.rb | 12 +++++------ .../customer_account_transaction_schema.rb | 5 ++--- ...customer_account_transaction_serializer.rb | 2 +- config/locales/en.yml | 1 + .../v1/customer_account_transaction_spec.rb | 4 +--- swagger/v1.yaml | 20 ------------------- 6 files changed, 10 insertions(+), 34 deletions(-) diff --git a/app/controllers/api/v1/customer_account_transaction_controller.rb b/app/controllers/api/v1/customer_account_transaction_controller.rb index c5fc4db29f..e172fd72b3 100644 --- a/app/controllers/api/v1/customer_account_transaction_controller.rb +++ b/app/controllers/api/v1/customer_account_transaction_controller.rb @@ -6,13 +6,11 @@ module Api def create authorize! :create, CustomerAccountTransaction - # We only allow using the api customer credit payment method default_params = { - currency: CurrentConfig.get(:currency), payment_method_id:, created_by: current_api_user + currency: CurrentConfig.get(:currency), created_by: current_api_user } - transaction = CustomerAccountTransaction.new( - default_params.merge(customer_account_transaction_params) - ) + parameters = default_params.merge(customer_account_transaction_params).merge(description: ) + transaction = CustomerAccountTransaction.new(parameters) if transaction.save render json: Api::V1::CustomerAccountTransactionSerializer.new(transaction), @@ -28,8 +26,8 @@ module Api params.require(:customer_account_transaction).permit(:customer_id, :amount, :description) end - def payment_method_id - Spree::PaymentMethod.api_customer_credit&.id + def description + I18n.t(".api_customer_credit", description: params[:description]) end end end diff --git a/app/json_schemas/customer_account_transaction_schema.rb b/app/json_schemas/customer_account_transaction_schema.rb index 4f5f1c5b76..0155e14346 100644 --- a/app/json_schemas/customer_account_transaction_schema.rb +++ b/app/json_schemas/customer_account_transaction_schema.rb @@ -11,7 +11,6 @@ class CustomerAccountTransactionSchema < JsonApiSchema customer_id: { type: :integer, example: 10 }, amount: { type: :decimal, example: 10.50 }, currency: { type: :string, example: "AUD" }, - payment_method_id: { type: :integer, example: 100 }, description: { type: :string, nullable: true, example: "Payment processed by POS" }, balance: { type: :decimal, example: 10.50 }, } @@ -22,10 +21,10 @@ class CustomerAccountTransactionSchema < JsonApiSchema end def self.writable_attributes - attributes.except(:id, :balance, :payment_method_id, :currency) + attributes.except(:id, :balance, :currency) end def self.relationships - [:customer, :payment_method] + [:customer] end end diff --git a/app/serializers/api/v1/customer_account_transaction_serializer.rb b/app/serializers/api/v1/customer_account_transaction_serializer.rb index 7f2031b82d..9a3dde737d 100644 --- a/app/serializers/api/v1/customer_account_transaction_serializer.rb +++ b/app/serializers/api/v1/customer_account_transaction_serializer.rb @@ -3,7 +3,7 @@ module Api module V1 class CustomerAccountTransactionSerializer < Api::V1::BaseSerializer - attributes :id, :customer_id, :payment_method_id, :amount, :currency, :description, :balance + attributes :id, :customer_id, :amount, :currency, :description, :balance end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index e1663f12a4..04418876ab 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5195,6 +5195,7 @@ en: invisible_captcha: sentence_for_humans: "Please leave empty" timestamp_error_message: "Please try again after 5 seconds." + api_customer_credit: "API credit: %{description}" api_payment_method: name: API customer credit description: Used to credit customer via customer account transactions endpoint diff --git a/spec/requests/api/v1/customer_account_transaction_spec.rb b/spec/requests/api/v1/customer_account_transaction_spec.rb index 3bfa44475e..65f9249357 100644 --- a/spec/requests/api/v1/customer_account_transaction_spec.rb +++ b/spec/requests/api/v1/customer_account_transaction_spec.rb @@ -4,7 +4,6 @@ require "swagger_helper" RSpec.describe "CustomerAccountTransactions", swagger_doc: "v1.yaml", feature: :api_v1 do let!(:enterprise) { create(:enterprise) } - let!(:payment_method) { create(:api_customer_credit_payment_method) } let(:customer) { create(:customer) } before do @@ -36,10 +35,9 @@ RSpec.describe "CustomerAccountTransactions", swagger_doc: "v1.yaml", feature: : run_test! do expect(json_response[:data][:attributes]).to include( customer_id: customer.id, - payment_method_id: payment_method.id, amount: "10.25", currency: "AUD", - description: "Payment processed by POS", + description: "API credit: Payment processed by POS", balance: "10.25", ) diff --git a/swagger/v1.yaml b/swagger/v1.yaml index 65410c4222..8c8d02baea 100644 --- a/swagger/v1.yaml +++ b/swagger/v1.yaml @@ -310,9 +310,6 @@ components: currency: type: string example: AUD - payment_method_id: - type: integer - example: 100 description: type: string nullable: true @@ -325,7 +322,6 @@ components: - customer_id - amount - currency - - payment_method_id - description - balance relationships: @@ -347,22 +343,6 @@ components: properties: related: type: string - payment_method: - type: object - properties: - data: - type: object - properties: - id: - type: string - type: - type: string - example: payment_method - links: - type: object - properties: - related: - type: string meta: type: object links: