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:



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

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.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def amount
  @amount
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def description
  @description
end

#encodingObject

Returns the value of attribute encoding.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def encoding
  @encoding
end

#expires_onObject

Returns the value of attribute expires_on.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def expires_on
  @expires_on
end

#invoiceObject

Returns the value of attribute invoice.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def invoice
  @invoice
end

#minObject

Returns the value of attribute min.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def min
  @min
end

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def secret
  @secret
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def url
  @url
end

#url_cancelObject

Returns the value of attribute url_cancel.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def url_cancel
  @url_cancel
end

#url_idnObject

Returns the value of attribute url_idn.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def url_idn
  @url_idn
end

#url_okObject

Returns the value of attribute url_ok.



5
6
7
# File 'lib/epaybg/transaction.rb', line 5

def url_ok
  @url_ok
end

Instance Method Details

#checksumObject



31
32
33
# File 'lib/epaybg/transaction.rb', line 31

def checksum
  Epaybg.hmac(encoded, secret)
end


49
50
51
# File 'lib/epaybg/transaction.rb', line 49

def credit_card_link
  base_link 'credit_paydirect'
end

#encodedObject



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

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

  data = <<-DATA
MIN=#{min}
LANG=bg
INVOICE=#{invoice}
AMOUNT=#{amount}
EXP_TIME=#{exp_time}
  DATA

  Base64.strict_encode64(data)
end


45
46
47
# File 'lib/epaybg/transaction.rb', line 45

def epay_link
  base_link 'paylogin'
end

#register_paymentObject



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

def register_payment
  uri = URI("#{url_idn}/?ENCODED=#{encoded}&CHECKSUM=#{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