Class: AtPay::Tokenator
- Inherits:
-
Object
- Object
- AtPay::Tokenator
- Defined in:
- lib/atpay/tokenator.rb
Constant Summary collapse
- TARGETS =
{ /url<(.*?)>/ => [:@url, 6], /card<(.*?)>/ => [:@card, 7], /email<(.*?)>/ => [:@email, 8], /member<(.*?)>/ => [:@member, 9] }
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#partner_id ⇒ Object
readonly
Returns the value of attribute partner_id.
-
#site_frame ⇒ Object
readonly
Returns the value of attribute site_frame.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#user_data ⇒ Object
readonly
Returns the value of attribute user_data.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.find_by_checksum(token) ⇒ Object
Check and make sure we haven’t seen this token before.
-
.token_version(token) ⇒ Object
Get the version of the given token.
Instance Method Summary collapse
-
#body(key) ⇒ Object
Here we parse the body of the token.
-
#browser_data(key) ⇒ Object
With a site token you want to call this after header.
-
#header ⇒ Object
We want to pull the header out of the token.
-
#initialize(token, session = nil) ⇒ Tokenator
constructor
A bit clunky but useful for testing token decomposition.
-
#to_h ⇒ Object
Return parts in a hash structure, handy for ActiveRecord.
Constructor Details
#initialize(token, session = nil) ⇒ Tokenator
A bit clunky but useful for testing token decomposition. If you provide a test session then the config values there will be used so that decryption will function without @Pay’s private key.
26 27 28 29 30 31 32 33 |
# File 'lib/atpay/tokenator.rb', line 26 def initialize(token, session = nil) @token = format_token token @session = session @version = Tokenator.token_version(@token) strip_version @checksum = Digest::SHA1.hexdigest(@token) # Before or after removing version? end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def amount @amount end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def expires @expires end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def group @group end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def ip @ip end |
#partner_id ⇒ Object (readonly)
Returns the value of attribute partner_id.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def partner_id @partner_id end |
#site_frame ⇒ Object (readonly)
Returns the value of attribute site_frame.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def site_frame @site_frame end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def source @source end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def token @token end |
#user_data ⇒ Object (readonly)
Returns the value of attribute user_data.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def user_data @user_data end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/atpay/tokenator.rb', line 3 def version @version end |
Class Method Details
.find_by_checksum(token) ⇒ Object
Check and make sure we haven’t seen this token before. NOTE: This is really for internal use by @Pay.
43 44 45 46 47 |
# File 'lib/atpay/tokenator.rb', line 43 def find_by_checksum(token) checksum = Digest::SHA1.hexdigest(token) SecurityKey.find_by_encoded_key(checksum) || ValidationToken.find_by_encoded_key(checksum) end |
.token_version(token) ⇒ Object
Get the version of the given token.
37 38 39 |
# File 'lib/atpay/tokenator.rb', line 37 def token_version(token) token.scan('~').empty? ? 0 : unpack_version(token.split('~')[0]) end |
Instance Method Details
#body(key) ⇒ Object
Here we parse the body of the token. All the useful shit comes out of this.
72 73 74 75 |
# File 'lib/atpay/tokenator.rb', line 72 def body(key) payload(nonce, key, @token) part_out_payload end |
#browser_data(key) ⇒ Object
With a site token you want to call this after header. It will pull the ip address and header sha out of the token.
79 80 81 82 83 84 85 |
# File 'lib/atpay/tokenator.rb', line 79 def browser_data(key) length = @token.slice!(0, 4).unpack("l>")[0] @site_frame = boxer(key).open(nonce, @token.slice!(0, length)) length = @token.slice!(0, 4).unpack("l>")[0] @ip = @token.slice!(0, length) end |
#header ⇒ Object
We want to pull the header out of the token. This means we grab the nonce and the partner id from the token. The version frame should be removed before calling header.
64 65 66 67 68 |
# File 'lib/atpay/tokenator.rb', line 64 def header decode nonce destination end |
#to_h ⇒ Object
Return parts in a hash structure, handy for ActiveRecord.
92 93 94 95 96 97 98 99 |
# File 'lib/atpay/tokenator.rb', line 92 def to_h { sale_price: @amount, expires_at: Time.at(Time.now + @expires), group: @group, encoded_key: @checksum } end |