Class: SageParty::Transaction
- Inherits:
-
Object
- Object
- SageParty::Transaction
- Includes:
- PartyResource
- Defined in:
- lib/sage_party.rb
Constant Summary collapse
- URLS =
{:simulator => 'https://test.sagepay.com/simulator/VSPServerGateway.asp?Service=VendorRegisterTx', :test => 'https://test.sagepay.com/gateway/service/vspserver-register.vsp', :live => 'https://live.sagepay.com/gateway/service/vspserver-register.vsp'}
Class Method Summary collapse
-
.find(vendor_id, sage_id) ⇒ Transaction
Find a stored transaction.
-
.register_tx(data) ⇒ Transaction
Register a new transaction with SagePay.
-
.sage_pay_server(server) ⇒ Object
Define which Sage server to use.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Test transaction equality.
-
#exists? ⇒ Boolean
Detrmine if this transaction exists.
-
#merge!(data) ⇒ Transaction
Merge in transaction stage two data.
-
#response ⇒ String
Return HTTP response to return to SagePay server.
-
#signature_ok? ⇒ Boolean
Check if transaction data matches its signature.
Class Method Details
.find(vendor_id, sage_id) ⇒ Transaction
Find a stored transaction
47 48 49 50 51 |
# File 'lib/sage_party.rb', line 47 def find(vendor_id, sage_id) transaction = get(vendor_id) return missing_transaction if transaction.nil? || transaction.vps_tx_id != sage_id transaction end |
.register_tx(data) ⇒ Transaction
Register a new transaction with SagePay
35 36 37 38 39 40 41 42 43 |
# File 'lib/sage_party.rb', line 35 def register_tx(data) response = raw_register(data) hash = {} response.split("\r\n").each do |line| line = line.split("=", 2) hash[line.first] = line.last end self.new(hash.merge({:id => data[:VendorTxCode], :vendor_name => data[:Vendor]})) end |
.sage_pay_server(server) ⇒ Object
Define which Sage server to use
29 30 31 |
# File 'lib/sage_party.rb', line 29 def sage_pay_server(server) PartyResource::Connector.add(:sage_party, {:base_uri => URLS[server.to_sym]}) end |
Instance Method Details
#==(other) ⇒ Boolean
Test transaction equality
77 78 79 |
# File 'lib/sage_party.rb', line 77 def ==(other) properties_equal?(other) && self.exists? == other.exists? end |
#exists? ⇒ Boolean
Detrmine if this transaction exists
82 83 84 |
# File 'lib/sage_party.rb', line 82 def exists? !@not_found end |
#merge!(data) ⇒ Transaction
Merge in transaction stage two data
88 89 90 91 92 93 |
# File 'lib/sage_party.rb', line 88 def merge!(data) data = data.with_indifferent_access data.delete(:SecurityKey) populate_properties(data) self end |
#response ⇒ String
Return HTTP response to return to SagePay server
66 67 68 69 70 71 72 73 |
# File 'lib/sage_party.rb', line 66 def response return format_response(:invalid, 'Transaction not found') unless exists? return format_response(:invalid, 'Security check failed') unless signature_ok? return format_response(:error, 'Sage Pay reported an error') if status == 'ERROR' return format_response(:invalid, 'Unexpected status') if %w{AUTHENTICATED REGISTERED}.include?(status) return format_response(:invalid, "Invalid status: #{status}") unless %w{OK NOTAUTHED ABORT REJECTED}.include?(status) format_response(:ok) end |
#signature_ok? ⇒ Boolean
Check if transaction data matches its signature
96 97 98 |
# File 'lib/sage_party.rb', line 96 def signature_ok? generate_md5 == vps_signature end |