diff --git a/app/models/order.rb b/app/models/order.rb index b1a70cc5d..dd2eb68d0 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -12,4 +12,9 @@ class Order < ApplicationRecord enum payment_state: PAYMENT_STATES.zip(PAYMENT_STATES).to_h validates :token, :state, presence: true + + def set_wallet_transaction(amount, transaction_id) + self.wallet_amount = amount + self.wallet_transaction_id = transaction_id + end end diff --git a/app/services/wallet_service.rb b/app/services/wallet_service.rb index 3e9bb2011..2d23ad77a 100644 --- a/app/services/wallet_service.rb +++ b/app/services/wallet_service.rb @@ -106,9 +106,9 @@ class WalletService # wallet debit success raise DebitWalletError unless wallet_transaction - payment.set_wallet_transaction(wallet_amount, wallet_transaction.id) unless payment.is_a? Order + payment.set_wallet_transaction(wallet_amount, wallet_transaction.id) else - payment.set_wallet_transaction(wallet_amount, nil) unless payment.is_a? Order + payment.set_wallet_transaction(wallet_amount, nil) end end end diff --git a/db/migrate/20220826090821_add_wallet_amount_and_wallet_transaction_id_to_order.rb b/db/migrate/20220826090821_add_wallet_amount_and_wallet_transaction_id_to_order.rb new file mode 100644 index 000000000..d07d7bd14 --- /dev/null +++ b/db/migrate/20220826090821_add_wallet_amount_and_wallet_transaction_id_to_order.rb @@ -0,0 +1,6 @@ +class AddWalletAmountAndWalletTransactionIdToOrder < ActiveRecord::Migration[5.2] + def change + add_column :orders, :wallet_amount, :integer + add_column :orders, :wallet_transaction_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index bc90d2784..bbe91f20a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_08_26_085923) do +ActiveRecord::Schema.define(version: 2022_08_26_090821) do # These are extensions that must be enabled in order to support this database enable_extension "fuzzystrmatch" @@ -468,6 +468,8 @@ ActiveRecord::Schema.define(version: 2022_08_26_085923) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "payment_state" + t.integer "wallet_amount" + t.integer "wallet_transaction_id" t.index ["statistic_profile_id"], name: "index_orders_on_statistic_profile_id" end