Class: PrismPay::Webpay
- Inherits:
-
Object
- Object
- PrismPay::Webpay
- Defined in:
- lib/prismpay/webpay.rb
Overview
CreditSalePB
Constant Summary collapse
- CGI_ACTIONS =
an incomplete action map.. these are going to be what we are initially using to map some symbols to their corresponding webpay cgi actions
{ :profile_add => 'profile_add', :cc_sale => 'ns_quicksale_cc'}
- POST_URL =
"https://trans.merchantpartners.com/cgi-bin/WebPay.cgi"
Instance Attribute Summary collapse
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #build_customdata(options = {}) ⇒ Object
- #build_encrypted_form_id(formid, amount = "") ⇒ Object
- #cc_sale_form_id(amount) ⇒ Object
- #cc_sale_postback ⇒ Object
- #decrypt_string(hexstr) ⇒ Object
- #encrypt_string(str) ⇒ Object
- #get_formid(hexstr) ⇒ Object
- #hexstr_to_str(str) ⇒ Object
-
#initialize(config_file = "") ⇒ Webpay
constructor
A new instance of Webpay.
-
#profile_add_form_id ⇒ Object
TODO: mega repitition..
- #profile_add_postback ⇒ Object
- #str_to_hexstr(hexstr) ⇒ Object
- #url_encrypt_string(str) ⇒ Object
Constructor Details
#initialize(config_file = "") ⇒ Webpay
Returns a new instance of Webpay.
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 |
# File 'lib/prismpay/webpay.rb', line 47 def initialize(config_file = "") # make sure the file exists... if not wreck # instance variables: form/postback_list, session_id, acct_id, # password, subid, encryption_key myopts = YAML.load_file(config_file) @login = myopts["login"] @session_id = myopts["session_id"] @key = hexstr_to_str(myopts["key"]) @password = myopts["password"] # assigns nil if not in config @subid = myopts["subid"] # assigns nil if not in config # example of form_ids hash # this could use some rethinking Went this route because it was # the cleanest looking yaml config file # form_ids = { action => {form_id1 => postback_url}, # action => {form_id2 => postback_url}} @form_ids = [] # list of Form objs myopts["form_ids"].each {|action, hash| # ugly way to do this... No time to worry about that now though @form_ids << Form.new({action => hash} ) } end |
Instance Attribute Details
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
45 46 47 |
# File 'lib/prismpay/webpay.rb', line 45 def session_id @session_id end |
Instance Method Details
#build_customdata(options = {}) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/prismpay/webpay.rb', line 161 def build_customdata( = {}) # build encrypted string for customdata field # the values of this need to be url_encrypted str = "" unless .empty? # build the string .each{|key, val| str << "&" unless str.empty? str << "#{ERB::Util::url_encode(key)}=" str << "#{ERB::Util::url_encode(val)}" } str = url_encrypt_string(str) end return str end |
#build_encrypted_form_id(formid, amount = "") ⇒ Object
154 155 156 157 158 159 |
# File 'lib/prismpay/webpay.rb', line 154 def build_encrypted_form_id(formid, amount="") # build the encrypted formid hexstr # acctid:subid:formid:amount: str = "#{@login}:#{@subid}:#{formid}:#{amount}:" encrypt_string(str) end |
#cc_sale_form_id(amount) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/prismpay/webpay.rb', line 104 def cc_sale_form_id(amount) form = nil @form_ids.each{|x| form = x if x.action == 'cc_sale' } build_encrypted_form_id form.id, amount end |
#cc_sale_postback ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/prismpay/webpay.rb', line 96 def cc_sale_postback form = nil @form_ids.each{|x| form = x if x.action == 'cc_sale' } encrypt_string(form.postback) end |
#decrypt_string(hexstr) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/prismpay/webpay.rb', line 142 def decrypt_string(hexstr) # maybe pass the need to convert from the hexstr str = hexstr_to_str(hexstr) retstr = "" cipher = OpenSSL::Cipher.new('des-ede3') cipher.decrypt cipher.key = @key retstr << cipher.update(str) retstr << cipher.final return retstr end |
#encrypt_string(str) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/prismpay/webpay.rb', line 182 def encrypt_string(str) # returns the hexstr for the url # TODO: need to uri escape the string before encrypting retstr = "" cipher = OpenSSL::Cipher.new("des-ede3") cipher.encrypt cipher.key = @key retstr << cipher.update(str) retstr << cipher.final retstr = str_to_hexstr(retstr) return retstr end |
#get_formid(hexstr) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/prismpay/webpay.rb', line 117 def get_formid(hexstr) # returns the formid string to be used when composing our formid # strings. Receives a hexstring generated from their web based # form creation cms str = decrypt_string(hexstr) str.split(":")[2] end |
#hexstr_to_str(str) ⇒ Object
201 202 203 |
# File 'lib/prismpay/webpay.rb', line 201 def hexstr_to_str(str) [str].pack 'H*' end |
#profile_add_form_id ⇒ Object
TODO: mega repitition.. good place to apply DRY in refactoring and do some things ruby is awesome at using the action map
80 81 82 83 84 85 86 |
# File 'lib/prismpay/webpay.rb', line 80 def profile_add_form_id form = nil @form_ids.each{|x| form = x if x.action == 'profile_add' } build_encrypted_form_id form.id end |
#profile_add_postback ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/prismpay/webpay.rb', line 88 def profile_add_postback form = nil @form_ids.each{|x| form = x if x.action == 'profile_add' } encrypt_string(form.postback) end |
#str_to_hexstr(hexstr) ⇒ Object
196 197 198 |
# File 'lib/prismpay/webpay.rb', line 196 def str_to_hexstr(hexstr) hexstr.unpack('H*').first end |
#url_encrypt_string(str) ⇒ Object
177 178 179 180 |
# File 'lib/prismpay/webpay.rb', line 177 def url_encrypt_string(str) str = ERB::Util::url_encode(str) encrypt_string(str) end |