mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
rename order amount to total
This commit is contained in:
parent
885db68b51
commit
97ee15cf78
@ -9,9 +9,7 @@ class API::CartController < API::ApiController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
authorize :cart, :create?
|
authorize :cart, :create?
|
||||||
p '-----------------'
|
@order = Order.find_by(token: order_token, state: 'cart')
|
||||||
p current_user
|
|
||||||
@order = Order.find_by(token: order_token)
|
|
||||||
if @order.nil?
|
if @order.nil?
|
||||||
if current_user&.member?
|
if current_user&.member?
|
||||||
@order = Order.where(statistic_profile_id: current_user.statistic_profile.id,
|
@order = Order.where(statistic_profile_id: current_user.statistic_profile.id,
|
||||||
|
@ -9,7 +9,7 @@ module API::OrderConcern
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_order
|
def current_order
|
||||||
@current_order = Order.find_by(token: order_token)
|
@current_order = Order.find_by(token: order_token, state: 'cart')
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_order
|
def ensure_order
|
||||||
|
@ -72,8 +72,8 @@ const StoreCart: React.FC<StoreCartProps> = ({ onError, currentUser }) => {
|
|||||||
* Open/closes the payment modal
|
* Open/closes the payment modal
|
||||||
*/
|
*/
|
||||||
const handlePaymentSuccess = (data: Order): void => {
|
const handlePaymentSuccess = (data: Order): void => {
|
||||||
console.log(data);
|
|
||||||
setPaymentModal(false);
|
setPaymentModal(false);
|
||||||
|
window.location.href = '/#!/store';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,8 +118,8 @@ const StoreCart: React.FC<StoreCartProps> = ({ onError, currentUser }) => {
|
|||||||
</FabButton>
|
</FabButton>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{cart && !cartIsEmpty() && <CouponInput user={cart.user} amount={cart.amount} />}
|
{cart && !cartIsEmpty() && <CouponInput user={cart.user} amount={cart.total} />}
|
||||||
{cart && !cartIsEmpty() && <p>Totale: {FormatLib.price(cart.amount)}</p>}
|
{cart && !cartIsEmpty() && <p>Totale: {FormatLib.price(cart.total)}</p>}
|
||||||
{cart && !cartIsEmpty() && isPrivileged() && <MemberSelect defaultUser={cart.user} onSelected={handleChangeMember} />}
|
{cart && !cartIsEmpty() && isPrivileged() && <MemberSelect defaultUser={cart.user} onSelected={handleChangeMember} />}
|
||||||
{cart && !cartIsEmpty() &&
|
{cart && !cartIsEmpty() &&
|
||||||
<FabButton className="checkout-btn" onClick={checkout} disabled={!cart.user || cart.order_items_attributes.length === 0}>
|
<FabButton className="checkout-btn" onClick={checkout} disabled={!cart.user || cart.order_items_attributes.length === 0}>
|
||||||
|
@ -114,7 +114,7 @@ export const AbstractPaymentModal: React.FC<AbstractPaymentModalProps> = ({ isOp
|
|||||||
if (order && order?.user?.id) {
|
if (order && order?.user?.id) {
|
||||||
WalletAPI.getByUser(order.user.id).then((wallet) => {
|
WalletAPI.getByUser(order.user.id).then((wallet) => {
|
||||||
setWallet(wallet);
|
setWallet(wallet);
|
||||||
const p = { price: order.amount, price_without_coupon: order.amount };
|
const p = { price: order.total, price_without_coupon: order.total };
|
||||||
setPrice(p);
|
setPrice(p);
|
||||||
setRemainingPrice(new WalletLib(wallet).computeRemainingPrice(p.price));
|
setRemainingPrice(new WalletLib(wallet).computeRemainingPrice(p.price));
|
||||||
setReady(true);
|
setReady(true);
|
||||||
|
@ -47,7 +47,7 @@ export const PaymentModal: React.FC<PaymentModalProps> = ({ isOpen, toggleModal,
|
|||||||
// refresh the price when the cart changes
|
// refresh the price when the cart changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (order) {
|
if (order) {
|
||||||
setPrice({ price: order.amount, price_without_coupon: order.amount });
|
setPrice({ price: order.total, price_without_coupon: order.total });
|
||||||
} else {
|
} else {
|
||||||
PriceAPI.compute(cart).then(price => {
|
PriceAPI.compute(cart).then(price => {
|
||||||
setPrice(price);
|
setPrice(price);
|
||||||
|
@ -48,7 +48,6 @@ export const StripeForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, on
|
|||||||
if (res.payment) {
|
if (res.payment) {
|
||||||
await handleServerConfirmation(res.payment as PaymentConfirmation);
|
await handleServerConfirmation(res.payment as PaymentConfirmation);
|
||||||
} else {
|
} else {
|
||||||
res.order.total = res.order.amount;
|
|
||||||
await handleServerConfirmation(res.order);
|
await handleServerConfirmation(res.order);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -92,7 +91,6 @@ export const StripeForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, on
|
|||||||
try {
|
try {
|
||||||
if (order) {
|
if (order) {
|
||||||
const confirmation = await CheckoutAPI.confirmPayment(order.token, result.paymentIntent.id);
|
const confirmation = await CheckoutAPI.confirmPayment(order.token, result.paymentIntent.id);
|
||||||
confirmation.order.total = confirmation.order.amount;
|
|
||||||
await handleServerConfirmation(confirmation.order);
|
await handleServerConfirmation(confirmation.order);
|
||||||
} else {
|
} else {
|
||||||
const confirmation = await StripeAPI.confirmIntent(result.paymentIntent.id, cart);
|
const confirmation = await StripeAPI.confirmIntent(result.paymentIntent.id, cart);
|
||||||
|
@ -11,7 +11,6 @@ export interface Order {
|
|||||||
operator_id?: number,
|
operator_id?: number,
|
||||||
reference?: string,
|
reference?: string,
|
||||||
state?: string,
|
state?: string,
|
||||||
amount?: number,
|
|
||||||
total?: number,
|
total?: number,
|
||||||
created_at?: TDateISO,
|
created_at?: TDateISO,
|
||||||
order_items_attributes: Array<{
|
order_items_attributes: Array<{
|
||||||
|
@ -15,7 +15,7 @@ class Cart::AddItemService
|
|||||||
else
|
else
|
||||||
item.quantity += quantity.to_i
|
item.quantity += quantity.to_i
|
||||||
end
|
end
|
||||||
order.amount += (orderable.amount * quantity.to_i)
|
order.total += (orderable.amount * quantity.to_i)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
item.save
|
item.save
|
||||||
order.save
|
order.save
|
||||||
|
@ -7,7 +7,7 @@ class Cart::CreateService
|
|||||||
order_param = {
|
order_param = {
|
||||||
token: token,
|
token: token,
|
||||||
state: 'cart',
|
state: 'cart',
|
||||||
amount: 0
|
total: 0
|
||||||
}
|
}
|
||||||
if user
|
if user
|
||||||
order_param[:statistic_profile_id] = user.statistic_profile.id if user.member?
|
order_param[:statistic_profile_id] = user.statistic_profile.id if user.member?
|
||||||
|
@ -7,7 +7,7 @@ class Cart::RemoveItemService
|
|||||||
|
|
||||||
raise ActiveRecord::RecordNotFound if item.nil?
|
raise ActiveRecord::RecordNotFound if item.nil?
|
||||||
|
|
||||||
order.amount -= (item.amount * item.quantity.to_i)
|
order.total -= (item.amount * item.quantity.to_i)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
item.destroy!
|
item.destroy!
|
||||||
order.save
|
order.save
|
||||||
|
@ -12,7 +12,7 @@ class Cart::SetQuantityService
|
|||||||
raise ActiveRecord::RecordNotFound if item.nil?
|
raise ActiveRecord::RecordNotFound if item.nil?
|
||||||
|
|
||||||
different_quantity = quantity.to_i - item.quantity
|
different_quantity = quantity.to_i - item.quantity
|
||||||
order.amount += (orderable.amount * different_quantity)
|
order.total += (orderable.amount * different_quantity)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
item.update(quantity: quantity.to_i)
|
item.update(quantity: quantity.to_i)
|
||||||
order.save
|
order.save
|
||||||
|
@ -8,7 +8,7 @@ class Checkout::PaymentService
|
|||||||
def payment(order, operator, payment_id = '')
|
def payment(order, operator, payment_id = '')
|
||||||
raise Cart::OutStockError unless Orders::OrderService.new.in_stock?(order, 'external')
|
raise Cart::OutStockError unless Orders::OrderService.new.in_stock?(order, 'external')
|
||||||
|
|
||||||
raise Cart::InactiveProductError unless Orders::OrderService.new.all_products_is_active?
|
raise Cart::InactiveProductError unless Orders::OrderService.new.all_products_is_active?(order)
|
||||||
|
|
||||||
if operator.member?
|
if operator.member?
|
||||||
if Stripe::Helper.enabled?
|
if Stripe::Helper.enabled?
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
# Provides methods for Check if the product is in stock
|
|
||||||
class Cart::SetQuantityService
|
|
||||||
def call(order)
|
|
||||||
|
|
||||||
return order if quantity.to_i.zero?
|
|
||||||
|
|
||||||
raise Cart::OutStockError if quantity.to_i > orderable.stock['external']
|
|
||||||
|
|
||||||
item = order.order_items.find_by(orderable: orderable)
|
|
||||||
|
|
||||||
raise ActiveRecord::RecordNotFound if item.nil?
|
|
||||||
|
|
||||||
different_quantity = quantity.to_i - item.quantity
|
|
||||||
order.amount += (orderable.amount * different_quantity)
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
item.update(quantity: quantity.to_i)
|
|
||||||
order.save
|
|
||||||
end
|
|
||||||
order.reload
|
|
||||||
end
|
|
||||||
end
|
|
@ -10,7 +10,7 @@ module Payments::PaymentConcern
|
|||||||
end
|
end
|
||||||
|
|
||||||
def debit_amount(order)
|
def debit_amount(order)
|
||||||
total = order.amount
|
total = order.total
|
||||||
wallet_debit = get_wallet_debit(order.statistic_profile.user, total)
|
wallet_debit = get_wallet_debit(order.statistic_profile.user, total)
|
||||||
total - wallet_debit
|
total - wallet_debit
|
||||||
end
|
end
|
||||||
|
@ -75,15 +75,13 @@ class WalletService
|
|||||||
|
|
||||||
##
|
##
|
||||||
# Compute the amount decreased from the user's wallet, if applicable
|
# Compute the amount decreased from the user's wallet, if applicable
|
||||||
# @param payment {Invoice|PaymentSchedule}
|
# @param payment {Invoice|PaymentSchedule|Order}
|
||||||
# @param user {User} the customer
|
# @param user {User} the customer
|
||||||
# @param coupon {Coupon|String} Coupon object or code
|
# @param coupon {Coupon|String} Coupon object or code
|
||||||
##
|
##
|
||||||
def self.wallet_amount_debit(payment, user, coupon = nil)
|
def self.wallet_amount_debit(payment, user, coupon = nil)
|
||||||
total = if payment.is_a? PaymentSchedule
|
total = if payment.is_a? PaymentSchedule
|
||||||
payment.payment_schedule_items.first.amount
|
payment.payment_schedule_items.first.amount
|
||||||
elsif payment.is_a? Order
|
|
||||||
payment.amount
|
|
||||||
else
|
else
|
||||||
payment.total
|
payment.total
|
||||||
end
|
end
|
||||||
@ -95,7 +93,7 @@ class WalletService
|
|||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Subtract the amount of the payment document (Invoice|PaymentSchedule) from the customer's wallet
|
# Subtract the amount of the payment document (Invoice|PaymentSchedule|Order) from the customer's wallet
|
||||||
# @param transaction, if false: the wallet is not debited, the transaction is only simulated on the payment document
|
# @param transaction, if false: the wallet is not debited, the transaction is only simulated on the payment document
|
||||||
##
|
##
|
||||||
def self.debit_user_wallet(payment, user, transaction: true)
|
def self.debit_user_wallet(payment, user, transaction: true)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
json.extract! order, :id, :token, :statistic_profile_id, :operator_id, :reference, :state, :created_at
|
json.extract! order, :id, :token, :statistic_profile_id, :operator_id, :reference, :state, :created_at
|
||||||
json.amount order.amount / 100.0 if order.amount.present?
|
json.total order.total / 100.0 if order.total.present?
|
||||||
if order&.statistic_profile&.user
|
if order&.statistic_profile&.user
|
||||||
json.user do
|
json.user do
|
||||||
json.id order.statistic_profile.user.id
|
json.id order.statistic_profile.user.id
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class RenameAmountToTotalInOrder < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
rename_column :orders, :amount, :total
|
||||||
|
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_22_081222) do
|
ActiveRecord::Schema.define(version: 2022_08_26_074619) 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"
|
||||||
@ -464,7 +464,7 @@ ActiveRecord::Schema.define(version: 2022_08_22_081222) do
|
|||||||
t.string "token"
|
t.string "token"
|
||||||
t.string "reference"
|
t.string "reference"
|
||||||
t.string "state"
|
t.string "state"
|
||||||
t.integer "amount"
|
t.integer "total"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "payment_state"
|
t.string "payment_state"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user