Skip to main content

Security issue with PayPal

Hi friend as you know PayPal is one of the biggest player for online payment.
Since you implement the paypal integration in your web site as developer or as webmaster etc. How you tackle the security issue when especially you handle the paypal button. Here some idea with sample code can help you.

You can encrypt the paypal button by open ssl certificate with paypal certificate.
1. Step 1: create private key with open ssl from your linux/unix command prompt [make sure your server have open ssl installed]

openssl genrsa -out my-prvkey.pem 1024

2. Step 2: Create public certificate [key + signature]

openssl req -new -key my-prvkey.pem -x509 -days 365 -out my-pubcert.pem

3. Step 3: create paypal certificate to use encrypt the paypal button code

To upload your public certificates to PayPal:

1. Log in to your Business or Premier account.
2. Click the Profile subtab.
3. In the Seller Preferences column, click Encrypted Payment Settings.
4. Click Add.
5. Click Browse, and select your public certificate file.
6. When your public certificate is successfully uploaded, it appears on the next screen under Your Public Certificates.

You use PayPal's public certificate to encrypt your button code. To download PayPal's public certificate:

1. Log in to your Business or Premier account.
2. Click the Profile subtab.
3. In the Seller Preferences column, click Encrypted Payment Settings.
4. Click Download in the PayPal Public Certificate area.

To prevent someone from creating a spoof version of your payment buttons, you can block non-encrypted website payments to your account. Follow the instruction in Blocking Non-encrypted Website Payments.

PHP code for buton encryption



# private key file to use
$MY_KEY_FILE = "secu/my-prvkey.pem";

# public certificate file to use
$MY_CERT_FILE = "secu/my-pubcert.pem";

# Paypal's public certificate
$PAYPAL_CERT_FILE = "secu/paypal_cert.pem";

# path to the openssl binary
$OPENSSL = "/usr/bin/openssl";

// QUUNRT25HWJLY ray user
$form = array('cmd' => '_xclick',
'business' => 'sddhiradsdj_11932536710_biz@master.com',
'cert_id' => 'U7PRFGN9MNWNE64QL',
'lc' => 'IE',
'custom' => 'test',
'invoice' => '',
'currency_code' => 'EUR',
'no_shipping' => '0',
'item_name' => 'Lunch',
'item_number' => session_id(),
'rm' => 2,
// 'notify_url' => 'paypalipn.php',
'amount' => $tot
);


$encrypted = paypal_encrypt($form);


function paypal_encrypt($hash)
{
global $MY_KEY_FILE;
global $MY_CERT_FILE;
global $PAYPAL_CERT_FILE;
global $OPENSSL;


if (!file_exists($MY_KEY_FILE)) {
echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n";
}
if (!file_exists($MY_CERT_FILE)) {
echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
}
if (!file_exists($PAYPAL_CERT_FILE)) {
echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
}
if (!file_exists($OPENSSL)) {
echo "ERROR: OPENSSL $OPENSSL not found\n";
}


//Assign Build Notation for PayPal Support
$hash['bn']= 'StellarWebSolutions.PHP_EWP';

$openssl_cmd = "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
"-outform der -nodetach -binary | $OPENSSL smime -encrypt " .
"-des3 -binary -outform pem $PAYPAL_CERT_FILE";

$descriptors = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
);

$process = proc_open($openssl_cmd, $descriptors, $pipes);

if (is_resource($process)) {
foreach ($hash as $key => $value) {
if ($value != "") {
//echo "Adding to blob: $key=$value\n";
fwrite($pipes[0], "$key=$value\n");
}
}
fflush($pipes[0]);
fclose($pipes[0]);

$output = "";
while (!feof($pipes[1])) {
$output .= fgets($pipes[1]);
}
//echo $output;
fclose($pipes[1]);
$return_value = proc_close($process);
return $output;
}
return "ERROR";
};

References : paypal dot com and stellerweb dot com

Comments

Popular posts from this blog

Financial Engineering

Financial Engineering: Key Concepts Financial engineering is a multidisciplinary field that combines financial theory, mathematics, and computer science to design and develop innovative financial products and solutions. Here's an in-depth look at the key concepts you mentioned: 1. Statistical Analysis Statistical analysis is a crucial component of financial engineering. It involves using statistical techniques to analyze and interpret financial data, such as: Hypothesis testing : to validate assumptions about financial data Regression analysis : to model relationships between variables Time series analysis : to forecast future values based on historical data Probability distributions : to model and analyze risk Statistical analysis helps financial engineers to identify trends, patterns, and correlations in financial data, which informs decision-making and risk management. 2. Machine Learning Machine learning is a subset of artificial intelligence that involves training algorithms t...

Wholesale Customer Solution with Magento Commerce

The client want to have a shop where regular customers to be able to see products with their retail price, while Wholesale partners to see the prices with ? discount. The extra condition: retail and wholesale prices hasn’t mathematical dependency. So, a product could be $100 for retail and $50 for whole sale and another one could be $60 retail and $50 wholesale. And of course retail users should not be able to see wholesale prices at all. Basically, I will explain what I did step-by-step, but in order to understand what I mean, you should be familiar with the basics of Magento. 1. Creating two magento websites, stores and views (Magento meaning of website of course) It’s done from from System->Manage Stores. The result is: Website | Store | View ———————————————— Retail->Retail->Default Wholesale->Wholesale->Default Both sites using the same category/product tree 2. Setting the price scope in System->Configuration->Catalog->Catalog->Price set drop-down to...

How to Prepare for AI Driven Career

  Introduction We are all living in our "ChatGPT moment" now. It happened when I asked ChatGPT to plan a 10-day holiday in rural India. Within seconds, I had a detailed list of activities and places to explore. The speed and usefulness of the response left me stunned, and I realized instantly that life would never be the same again. ChatGPT felt like a bombshell—years of hype about Artificial Intelligence had finally materialized into something tangible and accessible. Suddenly, AI wasn’t just theoretical; it was writing limericks, crafting decent marketing content, and even generating code. The world is still adjusting to this rapid shift. We’re in the middle of a technological revolution—one so fast and transformative that it’s hard to fully comprehend. This revolution brings both exciting opportunities and inevitable challenges. On the one hand, AI is enabling remarkable breakthroughs. It can detect anomalies in MRI scans that even seasoned doctors might miss. It can trans...