2021-04-30 16:07:19 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-05-31 15:39:56 +02:00
|
|
|
require 'stripe/helper'
|
|
|
|
require 'pay_zen/helper'
|
|
|
|
|
2021-04-30 16:07:19 +02:00
|
|
|
# create remote items on currently active payment gateway
|
|
|
|
class PaymentGatewayService
|
|
|
|
def initialize
|
2021-05-19 18:12:52 +02:00
|
|
|
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
|
2021-04-30 16:07:19 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_subscription(payment_schedule, gateway_object_id)
|
|
|
|
@gateway.create_subscription(payment_schedule, gateway_object_id)
|
|
|
|
end
|
|
|
|
|
2021-06-14 15:14:14 +02:00
|
|
|
def create_user(user_id)
|
|
|
|
@gateway.create_user(user_id)
|
|
|
|
end
|
|
|
|
|
2021-04-30 16:07:19 +02:00
|
|
|
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
|
2021-06-03 12:22:37 +02:00
|
|
|
|
|
|
|
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)
|
2021-06-04 18:26:20 +02:00
|
|
|
service = case payment_schedule.gateway_subscription.klass
|
2021-06-03 12:22:37 +02:00
|
|
|
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
|
2021-06-03 12:22:37 +02:00
|
|
|
end
|
2021-04-30 16:07:19 +02:00
|
|
|
end
|