Publish user submitted post after payment

I’m using a plugin called USP Pro which allows users to publish posts on my WordPress Site. Upon pressing the submit button to publish their post, the user is redirected to PayPal(whilst their submitted post is sent to my wordpress posts section to be reviewed and ‘published’). However, if the user doesn’t pay the fee their post will still be submitted, which needs to be prevented. I initially overcame this problem by redirecting the user to the PayPal page for payment before the submit button stage, and then redirecting them back to the form afterwards to press the submit button (which involved echoing the form inputs). However, the form includes file uploads which cannot be sent across multiple pages due to security restrictions, so the PayPal page has to be after the submit button is pressed.

Here is my form:

Read More
<form id="usp-form-990" class="usp-form" method="post" enctype="multipart/form-data" action="" data-validate="parsley" data-persist="garlic" novalidate>

<input name="usp-title" type="text" value="" data-required="true" required="required" maxlength="99" placeholder="Post Title" class="usp-input usp-input-title" />
<input name="usp-title-required" value="1" type="hidden" />

<textarea name="usp-content" rows="5" cols="30" maxlength="999" data-required="true" required="required" placeholder="Post Content" class="usp-input usp-input-content"></textarea>
<input name="usp-content-required" value="1" type="hidden" />

<input name="usp-files[]" type="file" maxlength="255" data-required="true" placeholder="File(s)" class="usp-input usp-input-files select-file multiple" multiple="multiple" id="usp-multiple-files" />
<input name="usp-file-limit" class="usp-file-limit" value="20" type="hidden" />
<input name="usp-file-count" class="usp-file-count" value="1" type="hidden" />
<input name="usp-files-required" value="0" type="hidden" />

<input type="submit" class="usp-submit" value="Publish" />

</form>

Here is the PayPal button that is used:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5F498FHQQGRR2">
<input type="image" src="http://www.aeroex.co.uk/wp-content/themes/vantage/paybutton.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

I don’t know if this will help, but I found this code to prevent this exact issue but for another forms plugin called Formidable Pro. Due to my inexperience with PHP and coding in general, I have found myself unable to customize this code to suit my requirements.

add_action('frm_payment_paypal_ipn', 'publish_paid_post');

function publish_paid_post($args){
if(!$args['pay_vars']['completed'])
return; //don't publish if the payment was not completed

if(!$args['entry']->post_id)
return; //don't publish if not linked to a post

wp_update_post(array('ID' => $args['entry']->post_id, 'post_status' =>    'publish'));

}

My other attempts to solve this:
-saving user file uploads to wordpress directory and then retrieving them at the submit stage (unsuccessful)

Related posts

2 comments

  1. I would suggest the flow to be: Put every thing user submitted with a “Draft” status, and implement an IPN(Instant payment notification) script to read PayPal payment call-backs, then update the WP database to change the post status from “Draft” to “Published”

    The payment return/redirection should not be relied on in this case as when client browser is closed before auto-return, the process breaks. While IPN is the async message POST for a payment status, that’s something you should use for processing the USP posts.

    Not sure if there’s any setup available in the USP Pro plugin but here’s an sample IPN script which you may customize with your WP database update codes.

  2. Formidable Pro has a PayPal extension that will do this. You build your user-submission form, then in form settings you add a PayPal action and fill in the necessary details. You also add a ‘Create Post’ action and use the conditional logic options to only publish if the payment is successful.

Comments are closed.