Class: WebpayBy::Form
- Inherits:
-
Object
- Object
- WebpayBy::Form
- Defined in:
- lib/webpay_by/form.rb
Constant Summary collapse
- SANDBOX_URL =
'https://securesandbox.webpay.by'- LIVE_URL =
'https://payment.webpay.by'- APP_VERSION =
2- LANGUAGE_LIST =
%w( russian english )
- REQUEST_METHOD =
'post'- ENCTYPE =
'application/x-www-form-urlencoded'
Instance Attribute Summary collapse
-
#enctype ⇒ Object
readonly
Returns the value of attribute enctype.
-
#language_id ⇒ Object
readonly
Returns the value of attribute language_id.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #action_url ⇒ Object
- #fields ⇒ Object
-
#initialize(request:, language_id: nil) ⇒ Form
constructor
A new instance of Form.
Constructor Details
#initialize(request:, language_id: nil) ⇒ Form
Returns a new instance of Form.
33 34 35 36 37 38 39 40 41 |
# File 'lib/webpay_by/form.rb', line 33 def initialize(request:, language_id: nil) @request = request @language_id ||= LANGUAGE_LIST.first @version = APP_VERSION @request_method = REQUEST_METHOD @enctype = ENCTYPE raise "Unsupported language, must be one of #{LANGUAGE_LIST.join ', '}" unless LANGUAGE_LIST.include? @language_id end |
Instance Attribute Details
#enctype ⇒ Object (readonly)
Returns the value of attribute enctype.
31 32 33 |
# File 'lib/webpay_by/form.rb', line 31 def enctype @enctype end |
#language_id ⇒ Object (readonly)
Returns the value of attribute language_id.
31 32 33 |
# File 'lib/webpay_by/form.rb', line 31 def language_id @language_id end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
31 32 33 |
# File 'lib/webpay_by/form.rb', line 31 def request @request end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
31 32 33 |
# File 'lib/webpay_by/form.rb', line 31 def request_method @request_method end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
31 32 33 |
# File 'lib/webpay_by/form.rb', line 31 def version @version end |
Instance Method Details
#action_url ⇒ Object
43 44 45 |
# File 'lib/webpay_by/form.rb', line 43 def action_url @request.client.debug_mode? ? SANDBOX_URL : LIVE_URL end |
#fields ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/webpay_by/form.rb', line 47 def fields fields_with_values = { '*scart': '', wsb_version: @version, wsb_language_id: @language_id, wsb_storeid: @request.client.billing_id, wsb_order_num: @request.order_id, wsb_test: @request.test_mode, wsb_currency_id: @request.currency_id, wsb_seed: @request.seed, wsb_total: @request.total, wsb_signature: @request.signature, wsb_return_url: @request.back_url, wsb_notify_url: @request.notify_url } @request.items.each_with_index do |item, i| fields_with_values.merge!( "wsb_invoice_item_name[#{i}]": item.name, "wsb_invoice_item_quantity[#{i}]": item.quantity, "wsb_invoice_item_price[#{i}]": item.price ) end fields_with_values.compact end |