mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +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
|
include Payments::PaymentConcern
|
||||||
|
|
||||||
def payment(order)
|
def payment(order)
|
||||||
o = payment_success(order)
|
o = payment_success(order, 'local')
|
||||||
{ order: o }
|
{ order: o }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,10 +15,10 @@ module Payments::PaymentConcern
|
|||||||
total - wallet_debit
|
total - wallet_debit
|
||||||
end
|
end
|
||||||
|
|
||||||
def payment_success(order)
|
def payment_success(order, payment_method = '')
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
WalletService.debit_user_wallet(order, order.statistic_profile.user)
|
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|
|
order.order_items.each do |item|
|
||||||
ProductService.update_stock(item.orderable, 'external', 'sold', -item.quantity, item.id)
|
ProductService.update_stock(item.orderable, 'external', 'sold', -item.quantity, item.id)
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ class Payments::PayzenService
|
|||||||
payzen_order = client.get(payment_id, operation_type: 'DEBIT')
|
payzen_order = client.get(payment_id, operation_type: 'DEBIT')
|
||||||
|
|
||||||
if payzen_order['answer']['transactions'].any? { |transaction| transaction['status'] == 'PAID' }
|
if payzen_order['answer']['transactions'].any? { |transaction| transaction['status'] == 'PAID' }
|
||||||
o = payment_success(order)
|
o = payment_success(order, 'card')
|
||||||
{ order: o }
|
{ order: o }
|
||||||
else
|
else
|
||||||
order.update(payment_state: 'failed')
|
order.update(payment_state: 'failed')
|
||||||
|
@ -23,7 +23,7 @@ class Payments::StripeService
|
|||||||
)
|
)
|
||||||
|
|
||||||
if intent&.status == 'succeeded'
|
if intent&.status == 'succeeded'
|
||||||
o = payment_success(order)
|
o = payment_success(order, 'card')
|
||||||
return { order: o }
|
return { order: o }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ class Payments::StripeService
|
|||||||
def confirm_payment(order, payment_id)
|
def confirm_payment(order, payment_id)
|
||||||
intent = Stripe::PaymentIntent.confirm(payment_id, {}, { api_key: Setting.get('stripe_secret_key') })
|
intent = Stripe::PaymentIntent.confirm(payment_id, {}, { api_key: Setting.get('stripe_secret_key') })
|
||||||
if intent&.status == 'succeeded'
|
if intent&.status == 'succeeded'
|
||||||
o = payment_success(order)
|
o = payment_success(order, 'card')
|
||||||
{ order: o }
|
{ order: o }
|
||||||
else
|
else
|
||||||
order.update(payment_state: 'failed')
|
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.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "fuzzystrmatch"
|
enable_extension "fuzzystrmatch"
|
||||||
@ -470,6 +470,7 @@ ActiveRecord::Schema.define(version: 2022_08_26_090821) do
|
|||||||
t.string "payment_state"
|
t.string "payment_state"
|
||||||
t.integer "wallet_amount"
|
t.integer "wallet_amount"
|
||||||
t.integer "wallet_transaction_id"
|
t.integer "wallet_transaction_id"
|
||||||
|
t.string "payment_method"
|
||||||
t.index ["statistic_profile_id"], name: "index_orders_on_statistic_profile_id"
|
t.index ["statistic_profile_id"], name: "index_orders_on_statistic_profile_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user