Top Level Namespace

Defined Under Namespace

Modules: Jekyll

Instance Method Summary collapse

Instance Method Details

#getBool(val) ⇒ Object



156
157
158
# File 'lib/jekyllEWP.rb', line 156

def getBool(val)
    val.to_s.downcase == 'true'
end

#getButtonCmd(purpose) ⇒ Object

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# 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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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
    [email protected]
    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 = "") ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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