Class: TBK::Webpay::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/tbk/webpay/payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Payment

Returns a new instance of Payment.



13
14
15
16
17
18
19
20
21
22
# File 'lib/tbk/webpay/payment.rb', line 13

def initialize(options = {})
  self.commerce = options[:commerce] || TBK::Commerce.default_commerce
  self.request_ip = options[:request_ip]
  self.amount = options[:amount]
  self.order_id = options[:order_id]
  self.session_id = options[:session_id]
  self.confirmation_url = options[:confirmation_url]
  self.success_url = options[:success_url]
  self.failure_url = options[:failure_url]
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



6
7
8
# File 'lib/tbk/webpay/payment.rb', line 6

def amount
  @amount
end

#commerceObject

Returns the value of attribute commerce.



4
5
6
# File 'lib/tbk/webpay/payment.rb', line 4

def commerce
  @commerce
end

#confirmation_urlObject

Returns the value of attribute confirmation_url.



9
10
11
# File 'lib/tbk/webpay/payment.rb', line 9

def confirmation_url
  @confirmation_url
end

#failure_urlObject

Returns the value of attribute failure_url.



11
12
13
# File 'lib/tbk/webpay/payment.rb', line 11

def failure_url
  @failure_url
end

#order_idObject

Returns the value of attribute order_id.



7
8
9
# File 'lib/tbk/webpay/payment.rb', line 7

def order_id
  @order_id
end

#request_ipObject

Returns the value of attribute request_ip.



5
6
7
# File 'lib/tbk/webpay/payment.rb', line 5

def request_ip
  @request_ip
end

#session_idObject

Returns the value of attribute session_id.



8
9
10
# File 'lib/tbk/webpay/payment.rb', line 8

def session_id
  @session_id
end

#success_urlObject

Returns the value of attribute success_url.



10
11
12
# File 'lib/tbk/webpay/payment.rb', line 10

def success_url
  @success_url
end

Instance Method Details

#redirect_urlObject



29
30
31
# File 'lib/tbk/webpay/payment.rb', line 29

def redirect_url
  "#{ self.process_url }?TBK_VERSION_KCC=#{ TBK::VERSION::KCC }&TBK_TOKEN=#{ self.token }"
end

#to_html_form(options = {}, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tbk/webpay/payment.rb', line 33

def to_html_form(options = {}, &block)
  form = <<-EOF
    <form method="POST"
      class="#{ options[:class] || 'tbk_payment_form'}"
      id="#{ options[:id] }"
      action="#{ self.process_url }">
      <input type="hidden" name="TBK_PARAM" value="#{ self.param }">
      <input type="hidden" name="TBK_VERSION_KCC" value="#{ TBK::VERSION::KCC }">
      <input type="hidden" name="TBK_CODIGO_COMERCIO" value="#{ self.commerce.id }">
      <input type="hidden" name="TBK_KEY_ID" value="#{ self.commerce.webpay_key_id }">
      #{ yield if block_given? }
    </form>
  EOF

  form = form.html_safe if form.respond_to? :html_safe

  form
end

#tokenObject



52
53
54
55
56
57
58
59
# File 'lib/tbk/webpay/payment.rb', line 52

def token
  unless @token
    @token = fetch_token
    TBK::Webpay.logger.payment(self)
  end

  @token
end

#transaction_idObject



25
26
27
# File 'lib/tbk/webpay/payment.rb', line 25

def transaction_id
  @transaction_id ||= (rand * 10000000000).to_i
end