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:
parent
939927fb73
commit
7c59d44785
@ -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
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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')
|
||||
|
5
db/migrate/20220826091819_add_payment_method_to_order.rb
Normal file
5
db/migrate/20220826091819_add_payment_method_to_order.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddPaymentMethodToOrder < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :orders, :payment_method, :string
|
||||
end
|
||||
end
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user