Sha256: 2bc91cc343f688a9e863db568e6c8e1dc18ad9d233941db701f57965805bd9ec

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

module Paytureman

  class PaymentDescription < Struct.new(:product, :total, :template_tag, :language)

    def to_h
      super.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-0.7.0 lib/payments/payment_new.rb