Class: SagePay::Server::Notification
- Inherits:
-
Object
- Object
- SagePay::Server::Notification
- Defined in:
- lib/sage_pay/server/notification.rb
Instance Attribute Summary collapse
-
#address_result ⇒ Object
readonly
Returns the value of attribute address_result.
-
#address_status ⇒ Object
readonly
Returns the value of attribute address_status.
-
#avs_cv2 ⇒ Object
readonly
Returns the value of attribute avs_cv2.
-
#card_type ⇒ Object
readonly
Returns the value of attribute card_type.
-
#cavv ⇒ Object
readonly
Returns the value of attribute cavv.
-
#cv2_result ⇒ Object
readonly
Returns the value of attribute cv2_result.
-
#gift_aid ⇒ Object
readonly
Returns the value of attribute gift_aid.
-
#last_4_digits ⇒ Object
readonly
Returns the value of attribute last_4_digits.
-
#payer_status ⇒ Object
readonly
Returns the value of attribute payer_status.
-
#post_code_result ⇒ Object
readonly
Returns the value of attribute post_code_result.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_detail ⇒ Object
readonly
Returns the value of attribute status_detail.
-
#threed_secure_status ⇒ Object
readonly
Returns the value of attribute threed_secure_status.
-
#tx_auth_no ⇒ Object
readonly
Returns the value of attribute tx_auth_no.
-
#tx_type ⇒ Object
readonly
Returns the value of attribute tx_type.
-
#vendor_tx_code ⇒ Object
readonly
Returns the value of attribute vendor_tx_code.
-
#vps_protocol ⇒ Object
readonly
Returns the value of attribute vps_protocol.
-
#vps_signature ⇒ Object
readonly
Returns the value of attribute vps_signature.
-
#vps_tx_id ⇒ Object
readonly
Returns the value of attribute vps_tx_id.
Class Method Summary collapse
Instance Method Summary collapse
- #address_matched? ⇒ Boolean
- #avs_cv2_matched? ⇒ Boolean
- #cv2_matched? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Notification
constructor
A new instance of Notification.
- #ok? ⇒ Boolean
- #post_code_matched? ⇒ Boolean
- #response(redirect_url) ⇒ Object
- #threed_secure_status_ok? ⇒ Boolean
- #valid_signature? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Notification
Returns a new instance of Notification.
145 146 147 148 149 150 151 |
# File 'lib/sage_pay/server/notification.rb', line 145 def initialize(attributes = {}) attributes.each do |k, v| # We're only providing readers, not writers, so we have to directly # set the instance variable. instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#address_result ⇒ Object (readonly)
Returns the value of attribute address_result.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def address_result @address_result end |
#address_status ⇒ Object (readonly)
Returns the value of attribute address_status.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def address_status @address_status end |
#avs_cv2 ⇒ Object (readonly)
Returns the value of attribute avs_cv2.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def avs_cv2 @avs_cv2 end |
#card_type ⇒ Object (readonly)
Returns the value of attribute card_type.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def card_type @card_type end |
#cavv ⇒ Object (readonly)
Returns the value of attribute cavv.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def cavv @cavv end |
#cv2_result ⇒ Object (readonly)
Returns the value of attribute cv2_result.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def cv2_result @cv2_result end |
#gift_aid ⇒ Object (readonly)
Returns the value of attribute gift_aid.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def gift_aid @gift_aid end |
#last_4_digits ⇒ Object (readonly)
Returns the value of attribute last_4_digits.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def last_4_digits @last_4_digits end |
#payer_status ⇒ Object (readonly)
Returns the value of attribute payer_status.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def payer_status @payer_status end |
#post_code_result ⇒ Object (readonly)
Returns the value of attribute post_code_result.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def post_code_result @post_code_result end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def status @status end |
#status_detail ⇒ Object (readonly)
Returns the value of attribute status_detail.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def status_detail @status_detail end |
#threed_secure_status ⇒ Object (readonly)
Returns the value of attribute threed_secure_status.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def threed_secure_status @threed_secure_status end |
#tx_auth_no ⇒ Object (readonly)
Returns the value of attribute tx_auth_no.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def tx_auth_no @tx_auth_no end |
#tx_type ⇒ Object (readonly)
Returns the value of attribute tx_type.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def tx_type @tx_type end |
#vendor_tx_code ⇒ Object (readonly)
Returns the value of attribute vendor_tx_code.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def vendor_tx_code @vendor_tx_code end |
#vps_protocol ⇒ Object (readonly)
Returns the value of attribute vps_protocol.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def vps_protocol @vps_protocol end |
#vps_signature ⇒ Object (readonly)
Returns the value of attribute vps_signature.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def vps_signature @vps_signature end |
#vps_tx_id ⇒ Object (readonly)
Returns the value of attribute vps_tx_id.
4 5 6 |
# File 'lib/sage_pay/server/notification.rb', line 4 def vps_tx_id @vps_tx_id end |
Class Method Details
.from_params(params, signature_verification_details = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/sage_pay/server/notification.rb', line 10 def self.from_params(params, signature_verification_details = nil) key_converter = { "VPSProtocol" => :vps_protocol, "TxType" => :tx_type, "VendorTxCode" => :vendor_tx_code, "VPSTxId" => :vps_tx_id, "Status" => :status, "StatusDetail" => :status_detail, "TxAuthNo" => :tx_auth_no, "AVSCV2" => :avs_cv2, "AddressResult" => :address_result, "PostCodeResult" => :post_code_result, "CV2Result" => :cv2_result, "GiftAid" => :gift_aid, "3DSecureStatus" => :threed_secure_status, "CAVV" => :cavv, "AddressStatus" => :address_status, "PayerStatus" => :payer_status, "CardType" => :card_type, "Last4Digits" => :last_4_digits, "VPSSignature" => :vps_signature } match_converter = { "NOTPROVIDED" => :not_provided, "NOTCHECKED" => :not_checked, "MATCHED" => :matched, "NOTMATCHED" => :not_matched } true_false_converter = { "0" => false, "1" => true } value_converter = { :tx_type => { "PAYMENT" => :payment, "DEFERRED" => :deferred, "AUTHENTICATE" => :authenticate }, :status => { "OK" => :ok, "NOTAUTHED" => :not_authed, "ABORT" => :abort, "REJECTED" => :rejected, "AUTHENTICATED" => :authenticated, "REGISTERED" => :registered, "ERROR" => :error }, :avs_cv2 => { "ALL MATCH" => :all_match, "SECURITY CODE MATCH ONLY" => :security_code_match_only, "ADDRESS MATCH ONLY" => :address_match_only, "NO DATA MATCHES" => :no_data_matches, "DATA NOT CHECKED" => :data_not_checked }, :address_result => match_converter, :post_code_result => match_converter, :cv2_result => match_converter, :gift_aid => true_false_converter, :threed_secure_status => { "OK" => :ok, "NOTCHECKED" => :not_checked, "NOTAVAILABLE" => :not_available, "NOTAUTHED" => :not_authed, "INCOMPLETE" => :incomplete, "ERROR" => :error }, :address_status => { "NONE" => :none, "CONFIRMED" => :confirmed, "UNCONFIRMED" => :unconfirmed }, :payer_status => { "VERIFIED" => :verified, "UNVERIFIED" => :unverified }, :card_type => { "VISA" => :visa, "MC" => :mastercard, "DELTA" => :visa_delta, "SOLO" => :solo, "MAESTRO" => :maestro, "UKE" => :visa_electron, "AMEX" => :american_express, "DC" => :diners, "JCB" => :jcb, "LASER" => :laser, "PAYPAL" => :paypal } } attributes = {} params.each do |key, value| unless value.nil? converted_key = key_converter[key] converted_value = value_converter[converted_key].nil? ? value : value_converter[converted_key][value] attributes[converted_key] = converted_value end end if signature_verification_details.nil? && block_given? signature_verification_details = yield(attributes) end unless signature_verification_details.nil? # We need to calculate the VPS signature from the values passed in as # additional params from the original registration and notification. fields_used_in_signature = [ params["VPSTxId"], params["VendorTxCode"], params["Status"], params["TxAuthNo"], signature_verification_details.vendor, params["AVSCV2"], signature_verification_details.security_key, params["AddressResult"], params["PostCodeResult"], params["CV2Result"], params["GiftAid"], params["3DSecureStatus"], params["CAVV"], params["AddressStatus"], params["PayerStatus"], params["CardType"], params["Last4Digits"] ] attributes[:calculated_hash] = Digest::MD5.hexdigest(fields_used_in_signature.join).upcase end new(attributes) end |
Instance Method Details
#address_matched? ⇒ Boolean
161 162 163 |
# File 'lib/sage_pay/server/notification.rb', line 161 def address_matched? address_result == :matched end |
#avs_cv2_matched? ⇒ Boolean
157 158 159 |
# File 'lib/sage_pay/server/notification.rb', line 157 def avs_cv2_matched? avs_cv2 == :all_match end |
#cv2_matched? ⇒ Boolean
169 170 171 |
# File 'lib/sage_pay/server/notification.rb', line 169 def cv2_matched? cv2_result == :matched end |
#ok? ⇒ Boolean
153 154 155 |
# File 'lib/sage_pay/server/notification.rb', line 153 def ok? status == :ok end |
#post_code_matched? ⇒ Boolean
165 166 167 |
# File 'lib/sage_pay/server/notification.rb', line 165 def post_code_matched? post_code_result == :matched end |
#response(redirect_url) ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/sage_pay/server/notification.rb', line 181 def response(redirect_url) if valid_signature? SagePay::Server::NotificationResponse.new(:status => :ok, :redirect_url => redirect_url) else SagePay::Server::NotificationResponse.new(:status => :invalid, :redirect_url => redirect_url, :status_detail => "Signature did not match our expectations") end.response end |
#threed_secure_status_ok? ⇒ Boolean
173 174 175 |
# File 'lib/sage_pay/server/notification.rb', line 173 def threed_secure_status_ok? threed_secure_status == :ok end |
#valid_signature? ⇒ Boolean
177 178 179 |
# File 'lib/sage_pay/server/notification.rb', line 177 def valid_signature? @calculated_hash == vps_signature end |