1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/services/payment_gateway_service.rb

74 lines
2.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'stripe/helper'
require 'pay_zen/helper'
# create remote items on currently active payment gateway
class PaymentGatewayService
def initialize
service = if Stripe::Helper.enabled?
require 'stripe/service'
Stripe::Service
elsif PayZen::Helper.enabled?
require 'pay_zen/service'
PayZen::Service
else
require 'payment/service'
Payment::Service
end
@gateway = service.new
end
def create_subscription(payment_schedule, *args)
@gateway.create_subscription(payment_schedule, *args)
end
def cancel_subscription(payment_schedule)
gateway = service_for_payment_schedule(payment_schedule)
gateway.cancel_subscription(payment_schedule)
end
def create_user(user_id)
@gateway.create_user(user_id)
end
def create_coupon(coupon_id)
@gateway.create_coupon(coupon_id)
end
def delete_coupon(coupon_id)
@gateway.delete_coupon(coupon_id)
end
def create_or_update_product(klass, id)
@gateway.create_or_update_product(klass, id)
end
def process_payment_schedule_item(payment_schedule_item)
2021-06-03 16:25:42 +02:00
gateway = service_for_payment_schedule(payment_schedule_item.payment_schedule)
gateway.process_payment_schedule_item(payment_schedule_item)
end
def pay_payment_schedule_item(payment_schedule_item)
gateway = service_for_payment_schedule(payment_schedule_item.payment_schedule)
gateway.pay_payment_schedule_item(payment_schedule_item)
end
private
def service_for_payment_schedule(payment_schedule)
service = case payment_schedule.gateway_subscription&.klass
when /^PayZen::/
require 'pay_zen/service'
PayZen::Service
when /^Stripe::/
require 'stripe/service'
Stripe::Service
else
require 'payment/service'
Payment::Service
end
2021-06-03 16:25:42 +02:00
service.new
end
end