Class: Rpostf
- Inherits:
-
Object
- Object
- Rpostf
- Defined in:
- lib/rpostf.rb
Overview
Rpostf – Ruby POST Finance a ruby library for the “Post Finance (SWISS POST)” payment gateway
usage:
pf = Rpostf.new(:login => 'asdf', :secret => 'xxxx', :local_host => 'http://bogus.net')
url = pf.url_for_get(:orderID => bogus_id,
:amount => suspicious_amount)
# in rails something like
form_tag url
# or as a link
link_to 'Checkout', url, :method => :post
as of EPay Docs url
should be used in a form with POST and iso-8859-1
Defined Under Namespace
Classes: MissingParameter
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :base_url => 'https://e-payment.postfinance.ch/ncol/test/orderdirect.asp', #:base_url => 'https://e-payment.postfinance.ch/ncol/test/orderstandard.asp', :locale => 'de_DE', :currency => 'CHF', :local_port => 80, :local_protocol => 'https', :local_route => '/postfinance_payments' }
Instance Method Summary collapse
-
#form_for_post(options = {}) ⇒ Object
returns a string containing html markup.
-
#initialize(options = {}) ⇒ Rpostf
constructor
mandatory keys for
options
are:login
:secret
:local_host
. -
#params_for_post(options = {}) ⇒ Object
returns a hash containing the params for a POST.
-
#url_for_get(options = {}) ⇒ Object
returns a string containing a url for a GET.
-
#verify_signature(params) ⇒ Object
verifies a signature.
Constructor Details
#initialize(options = {}) ⇒ Rpostf
mandatory keys for options
are
+:login+
+:secret+
+:local_host+
optional keys for options
are
+:base_url+ default is ''
+:language+ default is 'de_DE'
+:currency+ default is 'CHF'
+:local_port+ default is 80
+:local_protocol+ default is 'https'
+:locale_route+ default is '/postfinance_payments'
61 62 63 64 |
# File 'lib/rpostf.rb', line 61 def initialize(={}) check_keys , :login, :secret, :local_host @options = .reverse_merge!(DEFAULT_OPTIONS) end |
Instance Method Details
#form_for_post(options = {}) ⇒ Object
returns a string containing html markup
hands options over to params_for_post
+:submit_value+ is the caption of the submit button
112 113 114 115 116 117 118 |
# File 'lib/rpostf.rb', line 112 def form_for_post(={}) submit_value = .delete(:submit_value) || 'Checkout with Post Finance' = params_for_post() (["<form action=\"#{@options[:base_url]}\" method=\"post\">"] + .map { |n, v| hidden_field(n, v) } + ["<input type=\"submit\" value=\"#{submit_value}\" />", '</form>']) * "\n" end |
#params_for_post(options = {}) ⇒ Object
returns a hash containing the params for a POST
mandatory keys for options
are
+:orderID+
+:amount+
optionsl keys for options
are
+:PSPID+
+:currency+
+:language+
+:accepturl+
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rpostf.rb', line 90 def params_for_post(={}) check_keys , :orderID, :amount .reverse_merge!({ :PSPID => @options[:login], :currency => @options[:currency], :language => @options[:locale], :accepturl => [ @options[:local_protocol], '://', @options[:local_host], ':', @options[:local_port], @options[:local_route] ]*'' }) [:SHASign] = generate_signature() end |
#url_for_get(options = {}) ⇒ Object
returns a string containing a url for a GET
hands options over to params_for_post
69 70 71 72 73 74 75 76 |
# File 'lib/rpostf.rb', line 69 def url_for_get(={}) = params_for_post() parameters = [] .each { |p| parameters << p*'=' } [@options[:base_url], parameters*'&'].join('?') end |
#verify_signature(params) ⇒ Object
verifies a signature
121 122 123 124 125 126 |
# File 'lib/rpostf.rb', line 121 def verify_signature(params) keys = [:orderID, :currency, :amount, :PM, :ACCEPTANCE, :STATUS, :CARDNO, :ALIAS, :PAYID, :NCERROR, :BRAND] hash = (keys.map { |key| params[key] } << @options[:secret]).join('') params[:SHASIGN] == hash.sha1 end |