Class: Paymaster::UrlGenerator

Inherits:
BaseRequest show all
Defined in:
lib/paymaster/url_generator.rb

Instance Attribute Summary collapse

Attributes inherited from BaseRequest

#client

Instance Method Summary collapse

Methods inherited from BaseRequest

#initialize, #perform, #sign

Constructor Details

This class inherits a constructor from Paymaster::BaseRequest

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



4
5
6
# File 'lib/paymaster/url_generator.rb', line 4

def amount
  @amount
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/paymaster/url_generator.rb', line 6

def description
  @description
end

#emailObject

Returns the value of attribute email.



9
10
11
# File 'lib/paymaster/url_generator.rb', line 9

def email
  @email
end

#expiresObject

Returns the value of attribute expires.



7
8
9
# File 'lib/paymaster/url_generator.rb', line 7

def expires
  @expires
end

#fail_urlObject

Returns the value of attribute fail_url.



12
13
14
# File 'lib/paymaster/url_generator.rb', line 12

def fail_url
  @fail_url
end

#fail_url_methodObject

Returns the value of attribute fail_url_method.



13
14
15
# File 'lib/paymaster/url_generator.rb', line 13

def fail_url_method
  @fail_url_method
end

#localeObject

Returns the value of attribute locale.



3
4
5
# File 'lib/paymaster/url_generator.rb', line 3

def locale
  @locale
end

#numberObject

Returns the value of attribute number.



5
6
7
# File 'lib/paymaster/url_generator.rb', line 5

def number
  @number
end

#payment_systemObject

Returns the value of attribute payment_system.



14
15
16
# File 'lib/paymaster/url_generator.rb', line 14

def payment_system
  @payment_system
end

#phone_numberObject

Returns the value of attribute phone_number.



8
9
10
# File 'lib/paymaster/url_generator.rb', line 8

def phone_number
  @phone_number
end

#sim_modeObject

Returns the value of attribute sim_mode.



15
16
17
# File 'lib/paymaster/url_generator.rb', line 15

def sim_mode
  @sim_mode
end

#success_urlObject

Returns the value of attribute success_url.



10
11
12
# File 'lib/paymaster/url_generator.rb', line 10

def success_url
  @success_url
end

#success_url_methodObject

Returns the value of attribute success_url_method.



11
12
13
# File 'lib/paymaster/url_generator.rb', line 11

def success_url_method
  @success_url_method
end

Instance Method Details

#datetime(value) ⇒ Object



49
50
51
52
# File 'lib/paymaster/url_generator.rb', line 49

def datetime(value)
  return unless value
  value.strftime("%Y-%m-%d %H:%M:%S")
end

#endpointObject



17
18
19
# File 'lib/paymaster/url_generator.rb', line 17

def endpoint
  "https://lmi.paymaster.ua/#{fetch_locale}/index/get"
end

#generateObject



40
41
42
# File 'lib/paymaster/url_generator.rb', line 40

def generate
  "#{endpoint}?#{params_as_string}"
end

#methods(method) ⇒ Object



44
45
46
47
# File 'lib/paymaster/url_generator.rb', line 44

def methods(method)
  return unless method
  method.to_s == "post" ? 1 : 0
end

#paramsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/paymaster/url_generator.rb', line 21

def params
  {
    LMI_MERCHANT_ID: client.merchant_id,
    LMI_PAYMENT_AMOUNT: amount,
    LMI_PAYMENT_NO: number,
    LMI_PAYMENT_DESC: description,
    LMI_EXPIRES: datetime(expires),
    LMI_PAYER_PHONE_NUMBER: phone_number,
    LMI_PAYER_EMAIL: email,
    LMI_SUCCESS_URL: success_url,
    LMI_SUCCESS_METHOD: methods(success_url_method),
    LMI_FAIL_URL: fail_url,
    LMI_FAIL_METHOD: methods(fail_url_method),
    LMI_PAYMENT_SYSTEM: payment_system,
    LMI_SIM_MODE: sim_mode,
    LMI_HASH: signature,
  }.compact
end

#params_as_stringObject



60
61
62
# File 'lib/paymaster/url_generator.rb', line 60

def params_as_string
  params.map { |k, v| "#{k}=#{v}" }.join("&")
end

#signatureObject



54
55
56
57
58
# File 'lib/paymaster/url_generator.rb', line 54

def signature
  return unless client.secret_key
  string = "#{client.merchant_id}#{number}#{amount}#{client.secret_key}"
  Digest::SHA256.hexdigest(string).upcase
end