Class: LibertyReserveLink::Sci
- Inherits:
-
Object
- Object
- LibertyReserveLink::Sci
- 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
- #account ⇒ Object
- #check_credential ⇒ Object
- #escape_options(options) ⇒ Object
- #hash(input) ⇒ Object
-
#initialize(credential) ⇒ Sci
constructor
A new instance of Sci.
- #name ⇒ Object
- #payment_uri(amount, currency, order_id, item_name, options = {}) ⇒ Object
- #prepare_string(params) ⇒ Object
- #secret ⇒ Object
- #valid?(params) ⇒ Boolean
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
#account ⇒ Object
17 18 19 |
# File 'lib/liberty_reserve_link/sci.rb', line 17 def account @credential.account end |
#check_credential ⇒ Object
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 .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 |
#name ⇒ Object
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, ={}) endpoint = URI.parse ENDPOINT @query = {lr_acc: account, lr_store: name, lr_amnt: amount, lr_currency: currency, lr_merchant_ref: order_id, item_name: item_name, order_id: order_id }.merge(()) 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) "#{account}:#{params[:lr_paidby]}:#{name.gsub(/\\\//, '')}:#{params[:lr_amnt]}:#{params[:lr_transfer]}:#{params[:lr_currency]}:#{secret}" end |
#secret ⇒ Object
25 26 27 |
# File 'lib/liberty_reserve_link/sci.rb', line 25 def secret @credential.secret end |
#valid?(params) ⇒ 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] == account end |