class Object
Public Instance Methods
getBool(val)
click to toggle source
# File lib/jekyllEWP.rb, line 156 def getBool(val) val.to_s.downcase == 'true' end
getButtonCmd(purpose)
click to toggle source
determines the button command from the string input. possible commands listed at developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/formbasics/#specifying-button-type–cmd
# File lib/jekyllEWP.rb, line 135 def getButtonCmd(purpose) case purpose when "addtocart" return "_cart\nadd=1" #this is a dirty hack to insert the correct parameter for the cart buttons. better solutions welcome when "viewcart" return "_cart\ndisplay=1" #this is a dirty hack to insert the correct parameter for the cart buttons. better solutions welcome when "buynow" return "_xclick" when "donate" return "_donations" when "autobilling" return "_xclick-auto-billing" when "paymentplan" return "_xclick-payment-plan" else return "_xclick" end end
getButtonEncryptionValue(data, privateKeyData, certData, payPalCertData, keyPass = nil)
click to toggle source
# File lib/jekyllEWP.rb, line 38 def getButtonEncryptionValue(data, privateKeyData, certData, payPalCertData, keyPass = nil) #puts data #get keys and certs #https://stackoverflow.com/a/11136771 paypal_pub_cert = OpenSSL::X509::Certificate.new(payPalCertData.gsub('\n', "\n")) my_pub_cert = OpenSSL::X509::Certificate.new(certData.gsub('\n', "\n")) my_private_key = '' if keyPass #https://stackoverflow.com/a/862090S #https://docs.ruby-lang.org/en/2.1.0/OpenSSL/PKey/RSA.html#method-c-new my_private_key = OpenSSL::PKey::RSA.new(privateKeyData.gsub('\n', "\n"), keyPass) else my_private_key = OpenSSL::PKey::RSA.new(privateKeyData.gsub('\n', "\n")) end #modified from http://railscasts.com/episodes/143-paypal-security #https://docs.ruby-lang.org/en/2.1.0/OpenSSL/PKCS7.html#method-c-sign signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(my_pub_cert), my_private_key, data, [], OpenSSL::PKCS7::BINARY) OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(paypal_pub_cert)], signed.to_der, OpenSSL::Cipher.new("des-ede3-cbc"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "") # puts signed.class return signed.to_pem() end
getButtonOptionsString(certID, cmd, paypal_business_email, item_name, item_price, item_number = "0000", currency_code = "USD", tax = nil, shipping = nil )
click to toggle source
# File lib/jekyllEWP.rb, line 70 def getButtonOptionsString(certID, cmd, paypal_business_email, item_name, item_price, item_number = "0000", currency_code = "USD", tax = nil, shipping = nil ) options = "" options.concat("cert_id=" + certID + "\n") options.concat("cmd=" + cmd + "\n") # if cmd == "_cart" # case cart_options # when "add" # when "display" # options.concat(cart_options + "=1\n") # when "upload" # puts "unsupported value 'upload' used in paypal EWP plugin. the form probably isnt going to work" # end # end options.concat("business=" + paypal_business_email + "\n") options.concat("item_name=" + item_name + "\n") #options.concat("item_number=" + item_number + "\n") options.concat("amount=" + item_price + "\n") options.concat("currency_code=" + currency_code + "\n") unless tax.nil? || tax == "0" options.concat("tax=" + tax + "\n") end unless shipping.nil? || shipping == "0" options.concat("shipping=" + shipping + "\n") end =begin Below is the full list of supported key/vaue pairs from the paypal docs (https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/encryptedwebpayments/#id08A3I0PD04Y) the ones beginning with a hash (#) are not implemented here. some of these are also passthrough variables that arent used by paypal: https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/formbasics/#variations-on-basic-variables cert_id=Z24MFU6DSHBXQ cmd=_xclick business=sales@company.com item_name=Handheld Computer #item_number=1234 #custom=sc-id-789 amount=500.00 currency_code=USD tax=41.25 shipping=20.00 #address_override=1 #address1=123 Main St #city=Austin #state=TX #zip=94085 #country=USA #cancel_return=https://example.com/cancel =end return options end
wrapInForm(encryptedValue, use_sandbox=false, separate_submit=false, button_image = "", identifier="")
click to toggle source
# File lib/jekyllEWP.rb, line 5 def wrapInForm(encryptedValue, use_sandbox=false, separate_submit=false, button_image = "", identifier="") if identifier.nil? identifier = "" end if button_image.nil? button_image = "" end if getBool(use_sandbox) == true stage = "sandbox." else stage="" end unless getBool(separate_submit) == true submit = '<input type="image" src="' + button_image + '" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">' id='' else submit = "" id=' id="' + identifier + '"' end return_str = '<form' + id +' action="https://www.' + stage + 'paypal.com/cgi-bin/webscr" method="post">' + '<input type="hidden" name="cmd" value="_s-xclick">' + submit + '<input type="hidden" name="encrypted" value="' + encryptedValue + '"></form>'; return return_str end