Class Index [+]

Quicksearch

ActiveMerchant::Billing::PaystationGateway

Constants

URL
SUCCESSFUL_RESPONSE_CODE

an “error code” of “0” means “No error - transaction successful“

SUCCESSFUL_FUTURE_PAYMENT

an “error code” of “34” means “Future Payment Stored OK“

Public Class Methods

new(options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 25
25:       def initialize(options = {})
26:         # You need to pass your Paystation ID and Gateway ID
27:         requires!(options, :paystation_id, :gateway_id)
28:         @options = options
29:         super
30:       end

Public Instance Methods

authorize(money, credit_card, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 32
32:       def authorize(money, credit_card, options = {})
33:         post = new_request
34:         
35:         add_invoice(post, options)
36:         add_amount(post, money, options)
37:         
38:         add_credit_card(post, credit_card)
39:         
40:         add_authorize_flag(post, options)
41:         
42:         commit(post)
43:       end
capture(money, authorization_token, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 45
45:       def capture(money, authorization_token, options = {})
46:         post = new_request
47:         
48:         add_invoice(post, options)
49:         add_amount(post, money, options)
50:         
51:         add_authorization_token(post, authorization_token, options[:credit_card_verification])
52:         
53:         commit(post)
54:       end
purchase(money, payment_source, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 56
56:       def purchase(money, payment_source, options = {})
57:         post = new_request
58:         
59:         add_invoice(post, options)
60:         add_amount(post, money, options)
61:         
62:         if payment_source.is_a?(String)
63:           add_token(post, payment_source)        
64:         else
65:           add_credit_card(post, payment_source)
66:         end
67:         
68:         add_customer_data(post, options) if options.has_key?(:customer)
69:         
70:         commit(post)
71:       end
store(credit_card, options = {}) click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 73
73:       def store(credit_card, options = {})
74:         post = new_request
75:         
76:         add_invoice(post, options)
77:         add_credit_card(post, credit_card)
78:         store_credit_card(post, options)
79:         
80:         commit(post)
81:       end

Private Instance Methods

add_amount(post, money, options) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 140
140:         def add_amount(post, money, options)
141:           
142:           post[:am] = amount(money)
143:           post[:cu] = options[:currency] || currency(money)
144:           
145:         end
add_authorization_token(post, auth_token, verification_value = nil) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 134
134:         def add_authorization_token(post, auth_token, verification_value = nil)
135:           post[:cp] = "t" # Capture Payment flag – tells Paystation this transaction should be treated as a capture payment
136:           post[:cx] = auth_token
137:           post[:cc] = verification_value
138:         end
add_authorize_flag(post, options) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 130
130:         def add_authorize_flag(post, options)
131:           post[:pa] = "t" # tells Paystation that this is a pre-auth authorisation payment (account must be in pre-auth mode)
132:         end
add_credit_card(post, credit_card) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 107
107:         def add_credit_card(post, credit_card)     
108:           
109:           post[:cn] = credit_card.number
110:           post[:ct] = credit_card.type
111:           post[:ex] = format_date(credit_card.month, credit_card.year)
112:           post[:cc] = credit_card.verification_value if credit_card.verification_value?
113:           
114:         end
add_customer_data(post, options) click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 95
95:         def add_customer_data(post, options)
96:           post[:mc] = options[:customer]
97:         end
add_invoice(post, options) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 99
 99:         def add_invoice(post, options)
100:           requires!(options, :order_id)
101: 
102:           post[:ms] = options[:order_id]     # "Merchant Session", must be unique per request
103:           post[:mo] = options[:invoice]      # "Order Details", displayed in Paystation Admin
104:           post[:mr] = options[:description]  # "Merchant Reference Code", seen from Paystation Admin
105:         end
add_token(post, token) click to toggle source

bill a token (stored via “store”) rather than a Credit Card

     # File lib/active_merchant/billing/gateways/paystation.rb, line 117
117:         def add_token(post, token)
118:           post[:fp] = "t"    # turn on "future payments" - what paystation calls Token Billing
119:           post[:ft] = token
120:         end
commit(post) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 161
161:         def commit(post)
162:           
163:           post[:tm] = "T" if test? # test mode
164:         
165:           pstn_prefix_params = post.collect { |key, value| "pstn_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
166:           
167:           # need include paystation param as "initiator flag for payment engine"
168:           data     = ssl_post(URL, "#{pstn_prefix_params}&paystation=_empty")
169:           response = parse(data)
170:           message  = message_from(response)
171:           
172:           PaystationResponse.new(success?(response), message, response, 
173:               :test          => (response[:tm] && response[:tm].downcase == "t"),
174:               :authorization => response[:paystation_transaction_id]
175:           )
176:         end
format_date(month, year) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 186
186:         def format_date(month, year)
187:           "#{format(year, :two_digits)}#{format(month, :two_digits)}"
188:         end
message_from(response) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 182
182:         def message_from(response)
183:           response[:em]
184:         end
new_request() click to toggle source
    # File lib/active_merchant/billing/gateways/paystation.rb, line 85
85:         def new_request
86:           { 
87:             :pi    => @options[:paystation_id], # paystation account id
88:             :gi    => @options[:gateway_id],    # paystation gateway id
89:             "2p"   => "t",                      # two-party transaction type
90:             :nr    => "t",                      # -- redirect??
91:             :df    => "yymm"                    # date format: optional sometimes, required others
92:           } 
93:         end
parse(xml_response) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 147
147:         def parse(xml_response)
148:           response = {}
149:           
150:           xml = REXML::Document.new(xml_response)
151:           
152:           # for normal payments, the root node is <Response>
153:           # for "future payments", it's <PaystationFuturePaymentResponse>
154:           xml.elements.each("#{xml.root.name}/*") do |element|
155:             response[element.name.underscore.to_sym] = element.text
156:           end
157:                   
158:           response
159:         end
store_credit_card(post, options) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 122
122:         def store_credit_card(post, options)
123:           
124:           post[:fp] = "t"                                # turn on "future payments" - what paystation calls Token Billing
125:           post[:fs] = "t"                                # tells paystation to store right now, not bill
126:           post[:ft] = options[:token] if options[:token] # specify a token to use that, or let Paystation generate one
127:         
128:         end
success?(response) click to toggle source
     # File lib/active_merchant/billing/gateways/paystation.rb, line 178
178:         def success?(response)
179:           (response[:ec] == SUCCESSFUL_RESPONSE_CODE) || (response[:ec] == SUCCESSFUL_FUTURE_PAYMENT)
180:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.