Module: Recurly::JS
- Defined in:
- lib/recurly/js.rb
Overview
A collection of helper methods to use to verify Recurly.js callbacks.
Defined Under Namespace
Classes: RequestForgery, RequestTooOld
Class Attribute Summary collapse
-
.private_key ⇒ String
A private key for Recurly.js.
Class Method Summary collapse
-
.fetch(token) ⇒ BillingInfo, ...
Fetches a record using a token provided by Recurly.js.
- .inspect ⇒ String
-
.sign(*records) ⇒ Object
Create a signature for a given hash for Recurly.js.
Class Attribute Details
.private_key ⇒ String
Returns A private key for Recurly.js.
19 20 21 22 23 |
# File 'lib/recurly/js.rb', line 19 def private_key defined? @private_key and @private_key or raise( ConfigurationError, "private_key not configured" ) end |
Class Method Details
.fetch(token) ⇒ BillingInfo, ...
Fetches a record using a token provided by Recurly.js.
56 57 58 |
# File 'lib/recurly/js.rb', line 56 def fetch token Resource.from_response API.get "recurly_js/result/#{token}" end |
.inspect ⇒ String
61 62 63 |
# File 'lib/recurly/js.rb', line 61 def inspect 'Recurly.js' end |
.sign(*records) ⇒ Object
Create a signature for a given hash for Recurly.js
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/recurly/js.rb', line 28 def sign *records data = records.last.is_a?(Hash) ? records.pop.dup : {} records.each do |record| data[record.class.member_name] = record.signable_attributes end Helper.stringify_keys! data data['timestamp'] ||= Time.now.to_i data['nonce'] ||= Base64.encode64( OpenSSL::Random.random_bytes(32) ).gsub(/\W/, '') unsigned = to_query data signed = OpenSSL::HMAC.hexdigest 'sha1', private_key, unsigned signature = [signed, unsigned].join '|' signature = signature.html_safe if signature.respond_to? :html_safe signature end |