Test My PayPal Buy Now Buttons on My WordPress Site for PayPal PDT

Screen Shot 2013-10-27 at 3.44.40 PM My client has several digital products for sale. She has several buy now buttons hosted at PayPal. Hosted buttons have their own unique ID’s. To test these buttons, I need to set up the same buttons in my PayPal sandbox merchant account. When I do, they give me different button ID’s. Ugghh. Sure makes testing more difficult.

Now I must change the PayPal url and the button id on each product page for testing, then when I get it working correctly, I’ll have to change them back to the production PayPal url and the production button code. Changing and saving each product page in WordPress can be rather time consuming, so to save some time, I decided to add some code to make the switch easier.

I added a line to my wp-config.php file.

$testing = true;  // set to false for production

Now, in all my product pages I can put the following at the top of my page:

global $testing;
if ($testing) {
    $button = 'XX396F3UKJKBG'; 
    $url = 'https://sandbox.paypal.com/cgi-bin/webscr';
} else {
    $button = 'YD482IQUYJKX4'; 
    $url = 'https://paypal.com/cgi-bin/webscr';

I add the following code where I want the button to appear:

<form action="<?php echo $url ?>" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick" /> 
    <input type="hidden" name="hosted_button_id" value="<?php echo $button ?>" /> 
    <input type="image" alt="PayPal - The safer, easier way to pay online!" height="99" name="submit" src="../wp-content/uploads/2013/10/BuyNowButton.jpg" width="148" />

I’m sure there are other ways that will work just as well, but this is working for me. When I’m done testing and ready to push everything live I can just change the $testing variable to 'false'.

$testing = 'false';

1 thought on “Test My PayPal Buy Now Buttons on My WordPress Site for PayPal PDT”

  1. Pingback: PayPal Payment Data Transfer (PDT) - Getting PayPal Information Returned to Your Site - Cullen Web Services | Cullen Web Services

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top