Class: WebpayBy::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/webpay_by/response.rb

Constant Summary collapse

SUCCESSFUL_TYPE_INDEXES =
%w( 1 4 )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/webpay_by/response.rb', line 34

def initialize(options = {})
  @client           = options[:client]
  @batch_timestamp  = options[:batch_timestamp]
  @currency_id      = options[:currency_id]
  @amount           = options[:amount]
  @payment_method   = options[:payment_method]
  @order_id         = options[:order_id]
  @site_order_id    = options[:site_order_id]
  @transaction_id   = options[:transaction_id]
  @payment_type     = options[:payment_type]
  @rrn              = options[:rrn]
  @wsb_signature    = options[:wsb_signature]
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def amount
  @amount
end

#batch_timestampObject (readonly)

Returns the value of attribute batch_timestamp.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def batch_timestamp
  @batch_timestamp
end

#clientObject (readonly)

Returns the value of attribute client.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def client
  @client
end

#currency_idObject (readonly)

Returns the value of attribute currency_id.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def currency_id
  @currency_id
end

#order_idObject (readonly)

Returns the value of attribute order_id.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def order_id
  @order_id
end

#payment_methodObject (readonly)

Returns the value of attribute payment_method.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def payment_method
  @payment_method
end

#payment_typeObject (readonly)

Returns the value of attribute payment_type.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def payment_type
  @payment_type
end

#rrnObject (readonly)

Returns the value of attribute rrn.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def rrn
  @rrn
end

#site_order_idObject (readonly)

Returns the value of attribute site_order_id.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def site_order_id
  @site_order_id
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



31
32
33
# File 'lib/webpay_by/response.rb', line 31

def transaction_id
  @transaction_id
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/webpay_by/response.rb', line 48

def approved?
  valid_signature? && @payment_type.in?(SUCCESSFUL_TYPE_INDEXES)
end

#signatureObject



58
59
60
61
62
63
# File 'lib/webpay_by/response.rb', line 58

def signature
  signed_attrs = [@batch_timestamp, @currency_id, @amount, @payment_method, @order_id, @site_order_id,
                  @transaction_id, @payment_type, @rrn, @client.secret_key].join

  Digest::MD5.hexdigest signed_attrs
end

#valid_signature?Boolean

wsb_signature представляет собой hex-последовательность и является результатом выполнения функции MD 5. В качестве аргумента функции MD5 служит текстовая последовательность, полученная путем простой конкатенации

Returns:

  • (Boolean)


54
55
56
# File 'lib/webpay_by/response.rb', line 54

def valid_signature?
  @wsb_signature.to_s == signature
end