Class: Liqpay::Request
- Inherits:
-
SignedPayload
- Object
- SignedPayload
- Liqpay::Request
- Defined in:
- lib/liqpay/request.rb
Overview
Represends a request to the LiqPay API
Constant Summary collapse
- REQUIRED_FIELDS =
%i[public_key amount currency description order_id action].freeze
- OPTIONAL_FIELDS =
%i[result_url server_url].freeze
- REQUEST_FIELDS =
(REQUIRED_FIELDS + OPTIONAL_FIELDS + %i[version]).freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
REQUIRED = either Liqpay::ACTION_PAY or Liqpay::ACTION_DONATE.
-
#amount ⇒ Object
REQUIRED Amount of payment (Float), in :currency.
-
#currency ⇒ Object
REQUIRED Currency of payment - one of ‘Liqpay::SUPPORTED_CURRENCIES`.
-
#description ⇒ Object
REQUIRED Description to be displayed to the user.
-
#order_id ⇒ Object
REQUIRED Arbitrary but unique ID.
-
#result_url ⇒ Object
RECOMMENDED URL that the user will be redirected to after payment.
-
#server_url ⇒ Object
RECOMMENDED URL that’ll receive the order details in the background.
Attributes inherited from SignedPayload
Instance Method Summary collapse
- #data ⇒ Object
- #form_fields ⇒ Object
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #version ⇒ Object
Methods inherited from SignedPayload
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
28 29 30 31 32 33 34 35 |
# File 'lib/liqpay/request.rb', line 28 def initialize( = {}) super() (REQUIRED_FIELDS + OPTIONAL_FIELDS).each { |field| send("#{field}=", [field]) } @action ||= Liqpay::ACTION_PAY @kamikaze = [:kamikaze] end |
Instance Attribute Details
#action ⇒ Object
REQUIRED = either Liqpay::ACTION_PAY or Liqpay::ACTION_DONATE
22 23 24 |
# File 'lib/liqpay/request.rb', line 22 def action @action end |
#amount ⇒ Object
REQUIRED Amount of payment (Float), in :currency
14 15 16 |
# File 'lib/liqpay/request.rb', line 14 def amount @amount end |
#currency ⇒ Object
REQUIRED Currency of payment - one of ‘Liqpay::SUPPORTED_CURRENCIES`
16 17 18 |
# File 'lib/liqpay/request.rb', line 16 def currency @currency end |
#description ⇒ Object
REQUIRED Description to be displayed to the user
18 19 20 |
# File 'lib/liqpay/request.rb', line 18 def description @description end |
#order_id ⇒ Object
REQUIRED Arbitrary but unique ID
20 21 22 |
# File 'lib/liqpay/request.rb', line 20 def order_id @order_id end |
#result_url ⇒ Object
RECOMMENDED URL that the user will be redirected to after payment
24 25 26 |
# File 'lib/liqpay/request.rb', line 24 def result_url @result_url end |
#server_url ⇒ Object
RECOMMENDED URL that’ll receive the order details in the background.
26 27 28 |
# File 'lib/liqpay/request.rb', line 26 def server_url @server_url end |
Instance Method Details
#data ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/liqpay/request.rb', line 41 def data json_data = REQUEST_FIELDS .map { |field| [field, send(field)] } .to_h .reject { |_k, v| v.nil? } .transform_values(&:to_s) puts JSON.dump(json_data) @data ||= Base64.strict_encode64(JSON.dump(json_data)).strip end |
#form_fields ⇒ Object
51 52 53 54 |
# File 'lib/liqpay/request.rb', line 51 def form_fields validate! unless @kamikaze { data: data, signature: signature } end |
#version ⇒ Object
37 38 39 |
# File 'lib/liqpay/request.rb', line 37 def version Liqpay::LIQPAY_API_VERSION end |