Class: WebpayBy::Request

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

Constant Summary collapse

CURRENCIES =
%w( BYN USD EUR RUB )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, seed:, order_id:, back_url:, notify_url:, items:, currency_id: nil) ⇒ Request

Returns a new instance of Request.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/webpay_by/request.rb', line 30

def initialize(client:, seed:, order_id:, back_url:, notify_url:, items:, currency_id: nil)
  @client         = client
  @order_id       = order_id
  @seed           = seed
  @currency_id  ||= CURRENCIES.first
  @back_url       = back_url
  @notify_url     = notify_url
  @items          = items.map { |item| item.is_a?(WebpayBy::Item) ? item : WebpayBy::Item.new(item) }

  raise "Unsupported currency, must be one of #{CURRENCIES.join ', '}" unless CURRENCIES.include? @currency_id
end

Instance Attribute Details

#back_urlObject (readonly)

Returns the value of attribute back_url.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def back_url
  @back_url
end

#clientObject (readonly)

Returns the value of attribute client.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def client
  @client
end

#currency_idObject (readonly)

Returns the value of attribute currency_id.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def currency_id
  @currency_id
end

#itemsObject (readonly)

Returns the value of attribute items.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def items
  @items
end

#notify_urlObject (readonly)

Returns the value of attribute notify_url.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def notify_url
  @notify_url
end

#order_idObject (readonly)

Returns the value of attribute order_id.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def order_id
  @order_id
end

#seedObject (readonly)

Returns the value of attribute seed.



28
29
30
# File 'lib/webpay_by/request.rb', line 28

def seed
  @seed
end

Instance Method Details

#form(options = {}) ⇒ Object



58
59
60
# File 'lib/webpay_by/request.rb', line 58

def form(options = {})
  WebpayBy::Form.new options.merge request: self
end

#signatureObject

Электронная подпись формируется для предотвращения изменений в форме платежа и должна присутствовать в каждой форме заказа. Все заказы без электронной подписи не будут рассматриваться системой WebPay



52
53
54
55
56
# File 'lib/webpay_by/request.rb', line 52

def signature
  signed_attrs = [@seed, @client.billing_id, @order_id, test_mode, @currency_id, total, @client.secret_key].join

  Digest::SHA1.hexdigest signed_attrs
end

#test_modeObject



46
47
48
# File 'lib/webpay_by/request.rb', line 46

def test_mode
  @client.debug_mode? ? 1 : 0
end

#totalObject



42
43
44
# File 'lib/webpay_by/request.rb', line 42

def total
  @items.map(&:total).sum
end