Dynamic Paypal Button Encryption

Dynamic Paypal button encryption

maybe you could try putting those variables in a temporary table with a unique id. then use that id for the buttons. querying the variables from the table whenever the customer clicks the paypal buttons. I just hope i understood your statement right xD

Dynamic encrypted paypal button?

A long time ago I tried to do something similar to this.

To my knowledge, there is no way to do it. You won't be able to simply change the values of the encrypted button and if it isn't encrypted, the user can change it and basically pay anything.

If you want to be able to safely and dynamically change values, I would suggest looking into their API/Express Checkout. That's what I did, and I am really glad that I did.

You can check everything before it is forwarded to PayPal, and I have never had an issue with that aspect of it (I pass the item ID and query my database to get the cost/etc and apply other checks to stop various issues.). And you can go through and apply any calculations that you need to for the price without an issue.

Otherwise, the only way I could think of is having multiple encrypted buttons for different prices. But that isn't very fun nor an optimal solution.

Edit: Now that I am not on mobile, here is a link to the Express Checkout Getting Started Guide.

Also, I do not believe that you need to worry about your Merchant ID being seen. It is used to process payments and I believe it can be seen in the transaction details.

Dynamic PayPal button generation - isn't it very insecure?

You should use the PayPal Button API such as below:

$sendPayData = array(
"METHOD" => "BMCreateButton",
"VERSION" => "65.2",
"USER" => "username",
"PWD" => "password",
"SIGNATURE" => "abcdefg",
"BUTTONCODE" => "ENCRYPTED",
"BUTTONTYPE" => "BUYNOW",
"BUTTONSUBTYPE" => "SERVICES",
"BUTTONCOUNTRY" => "GB",
"BUTTONIMAGE" => "reg",
"BUYNOWTEXT" => "BUYNOW",
"L_BUTTONVAR1" => "item_number=$invoiceNumber",
"L_BUTTONVAR2" => "item_name=$invoiceType",
"L_BUTTONVAR3" => "amount=$invoiceTotal",
"L_BUTTONVAR4" => "currency_code=GBP",
"L_BUTTONVAR5" => "no_shipping=1",
"L_BUTTONVAR6" => "no_note=1",
"L_BUTTONVAR7" => "notify_url=http://www.abc.co.uk/paypal/ipn.php",
"L_BUTTONVAR8" => "cancel_return=http://www.abc.co.uk/paypal/thanks",
"L_BUTTONVAR9" => "return=http://www.abc.co.uk/paypal/return.php"
);

You can then send that with cURL to their API

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, 'https://api-3t.paypal.com/nvp?'.http_build_query($sendPayData));
$nvpPayReturn = curl_exec($curl);
curl_close($curl);

To then generate a encrypted HTML button that cannot be edited

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIIUwYJKoZIhvcNAQcEoIIIRDCCCEACAQExggE6MIIBNgIBADCBnjCBmDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMRUwEwYDVQQKEwxQYXlQYWwsIEluYy4xFjAUBgNVBAsUDXNhbmRib3hfY2VydHMxFDASBgNVBAMUC3NhbmRib3hfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tAgEAMA0GCSqGSIb3DQEBAQUABIGAfqXycFvfW2NCSYDg0Gw80R85HLRk8CuBqaYasckuMJucw5I5osTTcUYJ7JWTBxaZfgz+SVAwj5QzNBdeBSHf9N+RMrjWLF8X9lDX9QXrns0RRUCBL46GfoXW8QMEo+lEnjMxtkycLTtBwJzzQrkR9cVk3hrbvZCputr0EXs5zhExCzAJBgUrDgMCGgUAMIIBnQYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAhVGECT5w1q5YCCAXg4kqM0T3pJ9jfI1UjbvQGgfDHZpgYeWpCZcIv1t0PB5AryGz9ZfQhaoF5Y+pljStxEMt67HLJwbWcoIhoAoKTlO7aR7JOLxBT/jd4nkI0p3fDCU7trzy0uQLoFO7AGH2JFmMTUZlnaMKmmfCLcyOsLry0f2n8yhnXjeX2SznSgtvz9fIesEFTJpokKU70K4GqikqPz0aBVyalXnml4YAeqOgxwEON4KhDbfp/nb1SPg7AJ3wR7TJyitY+8J3KTg7XVBeHk7ch3fcJ4kBuHuBGvfcNNTQ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UzETMBEGA1UECBMKQ2FsaWZvcm5pYTERMA8GA1UEBxMIU2FuIEpvc2UxFTATBgNVBAoTDFBheVBhbCwgSW5jLjEWMBQGA1UECxQNc2FuZGJveF9jZXJ0czEUMBIGA1UEAxQLc2FuZGJveF9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQBXNvPA2Bl/hl9vlj/3cHV8H4nH/q5RvtFfRgTyWWCmSUNOvVv2UZFLlhUPjqXdsoT6Z3hns5sN2lNttghq3SoTqwSUUXKaDtxYxx5l1pKoG0Kg1nRu0vv5fJ9UHwz6fo6VCzq3JxhFGONSJo2SU8pWyUNW+TwQYxoj9D6SuPHHRTGCAaQwggGgAgEBMIGeMIGYMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTERMA8GA1UEBxMIU2FuIEpvc2UxFTATBgNVBAoTDFBheVBhbCwgSW5jLjEWMBQGA1UECxQNc2FuZGJveF9jZXJ0czEUMBIGA1UEAxQLc2FuZGJveF9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTExMDYxMjE0MDE0OFowIwYJKoZIhvcNAQkEMRYEFNu5UjQG2vaycSRYaiKfzYlhQv4cMA0GCSqGSIb3DQEBAQUABIGARpzYolvSZ2+oPziwSIeC+BjbdLrA9w6PhA2FPGcLYJFtkpGtlGazCviJbbnEBVpzGt1rmdPpzvhnOA6FKZ1nC668jADjqgF+LugFc1hIc0X9um6PQ7CXkSBAweLUGHp2xlKkIVUoRXWs2ppTLeVBz7JDjM4vpMr6mB5V494EEpM=-----END PKCS7-----
">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="Sample Image" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">

These links should help you with the button options:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_BMCreateButton

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ButtonMgrAPIIntro

problem with encrypting dynamic add to cart paypal button with php

I'd change the cmd to _s-xclick. All PayPal encrypted payments use this command.

When I tried it I got
"The email address for the business is not present in the encrypted blob. Please contact your merchant." error. Have you tried the "Secure Merchant ID" instead of the email? It's in the account's profile.

Personally I'd recommend using the button manager APIs instead of the encrypted buttons.
https://merchant.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ButtonMgrAPIIntro
its major advantage is you can call the API to retrieve the contents of the button. The encrypted blob can't really be decrypted to see if the email is actually there.

I hope this helps.
Lorefold

How to encrypt PayPal's button

Check this, it may help you: Dynamic Paypal button encryption; also verify you're using the current certificate and be advised that if you're doing tests in the sandbox, the sandbox uses a different certificate of the one you get in the main site (and also you must have an account in the sandbox which is different of your main account).

Automatic OpenSSL encryption for custom PayPal Buttons? PHP

Due to time restrictions i just skimmed the PayPal document.

First, using any sort of encryption without knowing what you're doing is bad and might easily lead to security issues.

But let's look at what you're trying to achieve and what I've "read".

You'll have to upload your public (NOT your private key) and download their public key (certificate).

The term "Encrypt the payment button code" sounds wrong as you'll likely only have to encrypt some parameters (but that gets into too much detail for the short time I have).

Anyway, this "button code" has to be (asymetric) encrypted by using their public key / certificate which means that only PayPal can decrypt it.

In the next step, this "encrypted button code" has to be signed with your private key. PayPal can then check the authenticity of the message because they are in possesion of your public key (and only you're able to sign it - so keep your private key safe!).

string openssl_encrypt ( string $data , string $method , string $password [, int $options = 0 [, string $iv = "" ]] )

or maybe

int openssl_seal ( string $data , string &$sealed_data , array &$env_keys , array $pub_key_ids [, string $method = "RC4" ] )

are the methods that can be used.

Alternatively the openssl binary could be called directly to do the job.

Anyway, you should be careful:

  • Validate all input carefully as you might sign malicious data

  • If you directly call the binary be sure that you won't implement any sort of os command injection vulnerability.



Related Topics



Leave a reply



Submit