Sha256: 745131d09f317486a89eb70d9a4f64f4693fbdf70a37e9b300443b4e79834232

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module Paytureman

  VALID_OPTIONS = [
    :template_tag,
    :language,
    :url,
    :total,
    :product
  ]

  class PaymentDescription
    def initialize(description = {})
      @description = description.dup
      @description.assert_valid_keys(*VALID_OPTIONS)
    end

    def to_h
      @description.select { |_, v| v.present? }
    end
  end

  class PaymentNew < Payment

    def initialize(order_id, amount, ip, gateway = nil)
      super(order_id, amount, gateway)
      @ip = ip
    end

    def save_to_memento(memento)
      super
      memento.ip = ip
    end

    def self.new_from_memento(memento)
      new(memento.order_id, memento.amount, memento.ip, memento.gateway)
    end

    def prepare(description = PaymentDescription.new)
      session_id = payture.init(order_id, amount_in_cents, ip, description.to_h)
      if session_id
        PaymentPrepared.new(order_id, amount, session_id, gateway)
      else
        self
      end
    end

  protected

    attr_reader :ip

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paytureman-1.0.0 lib/payments/payment_new.rb