Class: LibertyReserveLink::Sci

Inherits:
Object
  • Object
show all
Defined in:
lib/liberty_reserve_link/sci.rb

Constant Summary collapse

ENDPOINT =
'https://sci.libertyreserve.com'
ALLOWED_OPTIONS =
%w{lr_acc_from lr_comments lr_success_url lr_success_url_method lr_fail_url lr_fail_url_method lr_status_url lr_status_url_method}

Instance Method Summary collapse

Constructor Details

#initialize(credential) ⇒ Sci

Returns a new instance of Sci.



8
9
10
11
# File 'lib/liberty_reserve_link/sci.rb', line 8

def initialize(credential)
  @credential = credential
  check_credential
end

Instance Method Details

#accountObject



17
18
19
# File 'lib/liberty_reserve_link/sci.rb', line 17

def 
  @credential.
end

#check_credentialObject



13
14
15
# File 'lib/liberty_reserve_link/sci.rb', line 13

def check_credential
  raise LibertyReserveLink::Client::InvalidCredentialException unless @credential.valid?
end

#escape_options(options) ⇒ Object



29
30
31
# File 'lib/liberty_reserve_link/sci.rb', line 29

def escape_options options
  options.reject {|k, v| !(ALLOWED_OPTIONS.include? k.to_s)}
end

#hash(input) ⇒ Object



43
44
45
# File 'lib/liberty_reserve_link/sci.rb', line 43

def hash(input)
  Digest::SHA256.new.digest(input).unpack('H*').first.upcase
end

#nameObject



21
22
23
# File 'lib/liberty_reserve_link/sci.rb', line 21

def name
  @credential.name
end

#payment_uri(amount, currency, order_id, item_name, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/liberty_reserve_link/sci.rb', line 33

def payment_uri(amount, currency, order_id, item_name, options={})
  endpoint = URI.parse ENDPOINT
  @query = {lr_acc: , lr_store: name, lr_amnt: amount,
            lr_currency: currency, lr_merchant_ref: order_id,
            item_name: item_name, order_id: order_id
            }.merge(escape_options(options))
  endpoint.query = @query.to_query
  endpoint.to_s
end

#prepare_string(params) ⇒ Object



47
48
49
# File 'lib/liberty_reserve_link/sci.rb', line 47

def prepare_string(params)
  "#{}:#{params[:lr_paidby]}:#{name.gsub(/\\\//, '')}:#{params[:lr_amnt]}:#{params[:lr_transfer]}:#{params[:lr_currency]}:#{secret}"
end

#secretObject



25
26
27
# File 'lib/liberty_reserve_link/sci.rb', line 25

def secret
  @credential.secret
end

#valid?(params) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/liberty_reserve_link/sci.rb', line 51

def valid?(params)
  params[:lr_encrypted] == hash(prepare_string(params)) && params[:lr_paidto] == 
end