2021-04-20 17:22:53 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'pay_zen/item'
|
|
|
|
require 'stripe/item'
|
|
|
|
|
|
|
|
# Payments module
|
|
|
|
module Payment; end
|
|
|
|
|
|
|
|
# Build the corresponding gateway item, according to the provided klass
|
|
|
|
class Payment::ItemBuilder
|
|
|
|
attr_reader :instance
|
|
|
|
|
2021-06-02 20:07:53 +02:00
|
|
|
def self.build(klass, *ids)
|
|
|
|
builder = new(klass, *ids)
|
2021-04-20 17:22:53 +02:00
|
|
|
builder.instance
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-06-02 20:07:53 +02:00
|
|
|
def initialize(klass, *ids)
|
2021-04-20 17:22:53 +02:00
|
|
|
@instance = case klass
|
|
|
|
when /^PayZen::/
|
2021-06-02 20:07:53 +02:00
|
|
|
PayZen::Item.new(klass, *ids)
|
2021-04-20 17:22:53 +02:00
|
|
|
when /^Stripe::/
|
2021-06-02 20:07:53 +02:00
|
|
|
Stripe::Item.new(klass, *ids)
|
2021-04-20 17:22:53 +02:00
|
|
|
else
|
|
|
|
raise TypeError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|