Class: PayWithAmazon::IpnHandler
- Inherits:
-
Object
- Object
- PayWithAmazon::IpnHandler
- Defined in:
- lib/pay_with_amazon/ipn_handler.rb
Overview
Pay with Amazon Ipn Handler
This class authenticates an sns message sent from Amazon. It will validate the header, subject, and certificate. After validation there are many helper methods in place to extract information received from the ipn notification.
Constant Summary collapse
- SIGNABLE_KEYS =
[ 'Message', 'MessageId', 'Timestamp', 'TopicArn', 'Type', ].freeze
- COMMON_NAME =
'sns.amazonaws.com'
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#proxy_addr ⇒ Object
Returns the value of attribute proxy_addr.
-
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
Instance Method Summary collapse
-
#authentic? ⇒ Boolean
This method will authenticate the ipn message sent from Amazon.
- #environment ⇒ Object
-
#initialize(headers, body, proxy_addr: :ENV, proxy_port: nil, proxy_user: nil, proxy_pass: nil) ⇒ IpnHandler
constructor
A new instance of IpnHandler.
- #message ⇒ Object
- #message_id ⇒ Object
- #message_timestamp ⇒ Object
- #notification_data ⇒ Object
- #notification_type ⇒ Object
- #parse_from(json) ⇒ Object
- #seller_id ⇒ Object
- #signature ⇒ Object
- #signature_version ⇒ Object
- #signing_cert_url ⇒ Object
- #timestamp ⇒ Object
- #topic_arn ⇒ Object
- #type ⇒ Object
- #unsubscribe_url ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(headers, body, proxy_addr: :ENV, proxy_port: nil, proxy_user: nil, proxy_pass: nil) ⇒ IpnHandler
Returns a new instance of IpnHandler.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 40 def initialize( headers, body, proxy_addr: :ENV, proxy_port: nil, proxy_user: nil, proxy_pass: nil) @body = body @raw = parse_from(@body) @headers = headers @proxy_addr = proxy_addr @proxy_port = proxy_port @proxy_user = proxy_user @proxy_pass = proxy_pass end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
31 32 33 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 31 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
31 32 33 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 31 def headers @headers end |
#proxy_addr ⇒ Object
Returns the value of attribute proxy_addr.
32 33 34 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 32 def proxy_addr @proxy_addr end |
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
32 33 34 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 32 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
32 33 34 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 32 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
32 33 34 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 32 def proxy_user @proxy_user end |
Instance Method Details
#authentic? ⇒ Boolean
This method will authenticate the ipn message sent from Amazon. It will return true if everything is verified. It will raise an error message if verification fails.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 60 def authentic? begin decoded_from_base64 = Base64.decode64(signature) validate_header validate_subject(get_certificate.subject) public_key = get_public_key_from(get_certificate) verify_public_key(public_key, decoded_from_base64, canonical_string) return true rescue IpnWasNotAuthenticError => e raise e. end end |
#environment ⇒ Object
118 119 120 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 118 def environment parse_from(@raw['Message'])["ReleaseEnvironment"] end |
#message ⇒ Object
86 87 88 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 86 def @raw['Message'] end |
#message_id ⇒ Object
78 79 80 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 78 def @raw['MessageId'] end |
#message_timestamp ⇒ Object
130 131 132 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 130 def parse_from(@raw['Message'])["Timestamp"] end |
#notification_data ⇒ Object
126 127 128 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 126 def notification_data parse_from(@raw['Message'])["NotificationData"] end |
#notification_type ⇒ Object
110 111 112 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 110 def notification_type parse_from(@raw['Message'])["NotificationType"] end |
#parse_from(json) ⇒ Object
134 135 136 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 134 def parse_from(json) JSON.parse(json) end |
#seller_id ⇒ Object
114 115 116 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 114 def seller_id parse_from(@raw['Message'])["SellerId"] end |
#signature ⇒ Object
94 95 96 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 94 def signature @raw['Signature'] end |
#signature_version ⇒ Object
98 99 100 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 98 def signature_version @raw['SignatureVersion'] end |
#signing_cert_url ⇒ Object
102 103 104 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 102 def signing_cert_url @raw['SigningCertURL'] end |
#timestamp ⇒ Object
90 91 92 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 90 def @raw['Timestamp'] end |
#topic_arn ⇒ Object
82 83 84 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 82 def topic_arn @raw['TopicArn'] end |
#type ⇒ Object
74 75 76 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 74 def type @raw['Type'] end |
#unsubscribe_url ⇒ Object
106 107 108 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 106 def unsubscribe_url @raw['UnsubscribeURL'] end |
#version ⇒ Object
122 123 124 |
# File 'lib/pay_with_amazon/ipn_handler.rb', line 122 def version parse_from(@raw['Message'])["Version"] end |