1
votes

I am using a Wordpress template to serve as a system to collect verbal bids, really post comments, that will cost visiters to the site $1 to make. I've changed the standard "Post Comment" text at the end of posts to "Submit Bid".

I've also installed a PayPal donation plugin that displays a "Donate" button on the page.

I want to combine the functionality of both of these buttons into one button, the "Submit Bid" button. To be clear, the Submit Bid button posts the user's comment to the post page; I need a button that does this while simultaneously directing the user to PayPal to donate the $1.

Ideally, I'd have a check in place to verify that the user actually paid the $1 in order for the bid to be submitted, but since this is more complicated, and because this is for charitable purposes, I am putting faith in my users to actually pay. After the donation, PayPal will redirect them to the page to which they submit their verbal bid ("comment").

The php for the "Submit Bid" button looks like (it's from the standard "comments.php of the typical wordpress blog):

<input type="submit" value="Submit Bid" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />

The PayPal "Donate" button is a plugin actually placed on the page as a function:

<?php echo Paypal_payment_accept(); ?>

The function code is quite long, but the code placing the actual "Donate" button on the page is:

$output .= "<input type=\"image\" src=\"$payment_button\" name=\"submit\" alt=\"Make payments with payPal - it's fast, free and secure!\" />";

Would greatly appreciate thoughts on how to solve this seemingly trivial problem!

2

2 Answers

1
votes

Actually, there might be a simpler way, rather than using the Paypal submission using a form.

Keep the redirect code, but edit the $location variable to be the URL that takes the user to paypal, with all the variables you want to send to them, eg: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=email%40paypalhacks%2Ecom&amount=1%2E00&currency_code=USD&item_name=donation&item_number=1001&quantity=1&shipping=3%2E00&no_shipping=0

So it will process the comment normally, and then send the user to the paypal page to make the payment. You can go to that URL in your browser to check it works. Probably add a 'return' variable as well to send the user back to the original $location value, so the user will get to the comment page upon successful payment to paypal.

0
votes

You basically want one button, to perform 2 actions. So rather than having two forms (paypal plugin will add its own form tag), why don't you add the paypal redirecting functionality either before or after the comment processing code?

So when the user presses the submit button on a comment, let the page process the submission normally, but in that file, after it processes the comment, redirect the user to paypal.

You can change the code in wp-comments-post.php file, which is in your root Wordpress folder.

You need not use a plugin for this, its a pretty simple paypal code:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<!-- paypal user email which receives payments -->">
<input type="hidden" name="lc" value="CA">
<input type="hidden" name="item_name" value="<!-- donation -->">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="<!-- donation amount -->">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="return" value="<!-- the URL to redirect the user after payment -->">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"><br />
            </form>

Also, you could moderate all comments, so they are not published on the website until approved by a moderator. You can manage these settings in Dashboard > Settings > Discussion. This way, you can choose to approve comments only for users who have successfully made a payment through paypal (by comparing their email IDs).