1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/services/checkout/payment_service.rb
2022-09-07 17:24:14 +02:00

42 lines
1.4 KiB
Ruby

# frozen_string_literal: true
# Provides methods for pay cart
class Checkout::PaymentService
require 'pay_zen/helper'
require 'stripe/helper'
include Payments::PaymentConcern
def payment(order, operator, coupon_code, payment_id = '')
raise Cart::OutStockError unless Orders::OrderService.new.in_stock?(order, 'external')
raise Cart::InactiveProductError unless Orders::OrderService.new.all_products_is_active?(order)
CouponService.new.validate(coupon_code, order.statistic_profile.user.id)
amount = debit_amount(order)
if operator.privileged? || amount.zero?
Payments::LocalService.new.payment(order, coupon_code)
elsif operator.member?
if Stripe::Helper.enabled?
Payments::StripeService.new.payment(order, coupon_code, payment_id)
elsif PayZen::Helper.enabled?
Payments::PayzenService.new.payment(order, coupon_code)
else
raise Error('Bad gateway or online payment is disabled')
end
end
end
def confirm_payment(order, operator, coupon_code, payment_id = '')
if operator.member?
if Stripe::Helper.enabled?
Payments::StripeService.new.confirm_payment(order, coupon_code, payment_id)
elsif PayZen::Helper.enabled?
Payments::PayzenService.new.confirm_payment(order, coupon_code, payment_id)
else
raise Error('Bad gateway or online payment is disabled')
end
end
end
end