1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

add payment method in order after payment

This commit is contained in:
Du Peng 2022-08-26 11:24:42 +02:00
parent 939927fb73
commit 7c59d44785
6 changed files with 13 additions and 7 deletions

View File

@ -5,7 +5,7 @@ class Payments::LocalService
include Payments::PaymentConcern
def payment(order)
o = payment_success(order)
o = payment_success(order, 'local')
{ order: o }
end
end

View File

@ -15,10 +15,10 @@ module Payments::PaymentConcern
total - wallet_debit
end
def payment_success(order)
def payment_success(order, payment_method = '')
ActiveRecord::Base.transaction do
WalletService.debit_user_wallet(order, order.statistic_profile.user)
order.update(state: 'in_progress', payment_state: 'paid')
order.update(state: 'in_progress', payment_state: 'paid', payment_method: payment_method)
order.order_items.each do |item|
ProductService.update_stock(item.orderable, 'external', 'sold', -item.quantity, item.id)
end

View File

@ -28,7 +28,7 @@ class Payments::PayzenService
payzen_order = client.get(payment_id, operation_type: 'DEBIT')
if payzen_order['answer']['transactions'].any? { |transaction| transaction['status'] == 'PAID' }
o = payment_success(order)
o = payment_success(order, 'card')
{ order: o }
else
order.update(payment_state: 'failed')

View File

@ -23,7 +23,7 @@ class Payments::StripeService
)
if intent&.status == 'succeeded'
o = payment_success(order)
o = payment_success(order, 'card')
return { order: o }
end
@ -36,7 +36,7 @@ class Payments::StripeService
def confirm_payment(order, payment_id)
intent = Stripe::PaymentIntent.confirm(payment_id, {}, { api_key: Setting.get('stripe_secret_key') })
if intent&.status == 'succeeded'
o = payment_success(order)
o = payment_success(order, 'card')
{ order: o }
else
order.update(payment_state: 'failed')

View File

@ -0,0 +1,5 @@
class AddPaymentMethodToOrder < ActiveRecord::Migration[5.2]
def change
add_column :orders, :payment_method, :string
end
end

View File

@ -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_090821) do
ActiveRecord::Schema.define(version: 2022_08_26_091819) do
# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
@ -470,6 +470,7 @@ ActiveRecord::Schema.define(version: 2022_08_26_090821) do
t.string "payment_state"
t.integer "wallet_amount"
t.integer "wallet_transaction_id"
t.string "payment_method"
t.index ["statistic_profile_id"], name: "index_orders_on_statistic_profile_id"
end