Class: Epaybg::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/epaybg/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) {|_self| ... } ⇒ Transaction

Returns a new instance of Transaction.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
16
17
# File 'lib/epaybg/transaction.rb', line 10

def initialize(args = {})
  set_defaults!
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
  yield self if block_given?
  validate!
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def amount
  @amount
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def description
  @description
end

#encodingObject

Returns the value of attribute encoding.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def encoding
  @encoding
end

#expires_onObject

Returns the value of attribute expires_on.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def expires_on
  @expires_on
end

#invoiceObject

Returns the value of attribute invoice.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def invoice
  @invoice
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def url
  @url
end

#url_cancelObject

Returns the value of attribute url_cancel.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def url_cancel
  @url_cancel
end

#url_idnObject

Returns the value of attribute url_idn.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def url_idn
  @url_idn
end

#url_okObject

Returns the value of attribute url_ok.



7
8
9
# File 'lib/epaybg/transaction.rb', line 7

def url_ok
  @url_ok
end

Instance Method Details

#checksumObject



33
34
35
# File 'lib/epaybg/transaction.rb', line 33

def checksum
  Epaybg::hmac(encoded)
end


51
52
53
# File 'lib/epaybg/transaction.rb', line 51

def credit_card_link
  base_link "credit_paydirect"
end

#encodedObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/epaybg/transaction.rb', line 19

def encoded
  exp_time = self.expires_on.strftime("%d.%m.%Y")

  data = <<-DATA
    MIN=#{Epaybg.config["min"]}
    LANG=bg
    INVOICE=#{self.invoice}
    AMOUNT=#{self.amount}
    EXP_TIME=#{exp_time}
  DATA

  Base64.strict_encode64(data)
end


47
48
49
# File 'lib/epaybg/transaction.rb', line 47

def epay_link
  base_link "paylogin"
end

#register_paymentObject



37
38
39
40
41
42
43
44
45
# File 'lib/epaybg/transaction.rb', line 37

def register_payment
  uri = URI("#{self.url_idn}/?ENCODED=#{self.encoded}&CHECKSUM=#{self.checksum}")

  http             = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl     = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  res              = http.get(uri.request_uri)
  res.body
end