class ActiveMerchant::Billing::PaystationGateway
Constants
- SUCCESSFUL_FUTURE_PAYMENT
an “error code” of “34” means “Future Payment Stored OK”
- SUCCESSFUL_RESPONSE_CODE
an “error code” of “0” means “No error - transaction successful”
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/paystation.rb, line 25 def initialize(options = {}) requires!(options, :paystation_id, :gateway_id) super end
Public Instance Methods
capture(money, authorization_token, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 41 def capture(money, authorization_token, options = {}) post = new_request add_invoice(post, options) add_amount(post, money, options) add_authorization_token(post, authorization_token, options[:credit_card_verification]) commit(post) end
purchase(money, payment_source, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 51 def purchase(money, payment_source, options = {}) post = new_request add_invoice(post, options) add_amount(post, money, options) if payment_source.is_a?(String) add_token(post, payment_source) else add_credit_card(post, payment_source) end add_customer_data(post, options) if options.has_key?(:customer) commit(post) end
refund(money, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 78 def refund(money, authorization, options={}) post = new_request add_amount(post, money, options) add_invoice(post, options) add_refund_specific_fields(post, authorization) commit(post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 95 def scrub(transcript) transcript. gsub(%r((pstn_cn=)\d*), '\1[FILTERED]'). gsub(%r((pstn_cc=)\d*), '\1[FILTERED]') end
store(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 68 def store(credit_card, options = {}) post = new_request add_invoice(post, options) add_credit_card(post, credit_card) store_credit_card(post, options) commit(post) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 91 def supports_scrubbing? true end
verify(credit_card, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 87 def verify(credit_card, options={}) authorize(0, credit_card, options) end
Private Instance Methods
add_amount(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 156 def add_amount(post, money, options) post[:am] = amount(money) post[:cu] = options[:currency] || currency(money) end
add_credit_card(post, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 123 def add_credit_card(post, credit_card) post[:cn] = credit_card.number post[:ct] = credit_card.brand post[:ex] = format_date(credit_card.month, credit_card.year) post[:cc] = credit_card.verification_value if credit_card.verification_value? end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 113 def add_customer_data(post, options) post[:mc] = options[:customer] end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 117 def add_invoice(post, options) post[:ms] = generate_unique_id post[:mo] = options[:description] post[:mr] = options[:order_id] end
add_refund_specific_fields(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 145 def add_refund_specific_fields(post, authorization) post[:rc] = 't' post[:rt] = authorization end
add_token(post, token)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 130 def add_token(post, token) post[:fp] = 't' # turn on "future payments" - what paystation calls Token Billing post[:ft] = token end
commit(post)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 173 def commit(post) post[:tm] = 'T' if test? pstn_prefix_params = post.collect { |key, value| "pstn_#{key}=#{CGI.escape(value.to_s)}" }.join('&') data = ssl_post(self.live_url, "#{pstn_prefix_params}&paystation=_empty") response = parse(data) message = message_from(response) PaystationResponse.new(success?(response), message, response, :test => (response[:tm]&.casecmp('t')&.zero?), :authorization => response[:paystation_transaction_id] ) end
format_date(month, year)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 195 def format_date(month, year) "#{format(year, :two_digits)}#{format(month, :two_digits)}" end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 191 def message_from(response) response[:em] end
new_request()
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 103 def new_request { :pi => @options[:paystation_id], # paystation account id :gi => @options[:gateway_id], # paystation gateway id '2p' => 't', # two-party transaction type :nr => 't', # -- redirect?? :df => 'yymm' # date format: optional sometimes, required others } end
parse(xml_response)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 161 def parse(xml_response) response = {} xml = REXML::Document.new(xml_response) xml.elements.each("#{xml.root.name}/*") do |element| response[element.name.underscore.to_sym] = element.text end response end
store_credit_card(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 135 def store_credit_card(post, options) post[:fp] = 't' # turn on "future payments" - what paystation calls Token Billing post[:fs] = 't' # tells paystation to store right now, not bill post[:ft] = options[:token] if options[:token] # specify a token to use that, or let Paystation generate one end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/paystation.rb, line 187 def success?(response) (response[:ec] == SUCCESSFUL_RESPONSE_CODE) || (response[:ec] == SUCCESSFUL_FUTURE_PAYMENT) end