Tuesday, 24 October 2017 17:54

Simple Drupal Webform (v4) PayPal Integration

Written by

...using custom PHP confirmation message:

I needed something that would allow a client to provide name, email, invoice number, and amount.  All of the solutions I could find were either for the older version of Webform, or they were too cumbersome... too many modules required... not enough simplicity and control.  Many of the solutions would only allow for "donations" of fixed amounts. 

My solution was to adapt the solution found here (which was written for a specific scenario, also using the older version of Webform), adapt it for my needs, and recode for Webform v4.  

Note that this solution requires that you enable the "PHP Filter" module, which is a potential security issue if configured incorrectly.  

My code is as follows - also available as an attachment below:

<?php
include_once(drupal_get_path('module', 'webform') .'/includes/webform.submissions.inc');
$nid = arg(1); // need to hard-code nid if this is a custom page
$sid = $_GET['sid']; $submission = webform_get_submission($nid, $sid);
$invoice_numbers = $submission->data[3][0];  // 3 is the ID number of the field for invoice numbers under form components
$amount = $submission->data[4][0]; // 4 is the ID number of the amount field under form components
?>

<h2>Confirmation</h2>

<ul>
<li>Click "Buy Now" to finalize your registration.</li>
<li> Important: Print out your PayPal payment as a receipt.</li> </ul>

<h4> Amount: $<?php print $amount; ?></h4>

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_xclick" />
<input name="business" type="hidden" value=“This email address is being protected from spambots. You need JavaScript enabled to view it.“ />
<input name="item_name" type="hidden" value="Payment on Invoice <?php print $invoice_numbers; ?>" />
<input name="item_number" type="hidden" value="SKU0123" />
<input name="amount" type="hidden" value="<?php print $amount; ?>" />
<input name="bn" type="hidden" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" />
<input style = "width: 120px; height: auto;" alt="PayPal - The safer, easier way to pay online!" border="0" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" />
<img alt="" border="0" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" /></form>

 

Last modified on Friday, 17 December 2021 21:23
Comments (2)
This comment was minimized by the moderator on the site

Thanks for this code!
The paypal form doesn't allow guest payment (with credit card) but only via paypal account. I can't figure out why.
Maybe because the button is not wncrypted?

giucas
This comment was minimized by the moderator on the site
@giucas - No, this is a "PayPal" thing. Most likely there IS a way for a user to pay with a guest account, but PayPal hides the button and constantly rearranges the layout. I've also seen Internet Explorer behave totally different than Firefox...
@giucas - No, this is a "PayPal" thing. Most likely there IS a way for a user to pay with a guest account, but PayPal hides the button and constantly rearranges the layout. I've also seen Internet Explorer behave totally different than Firefox or Chrome. So actual mileage may vary...
More
Nate Covington
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Suggested Locations

Latest Comments

Got a similar email that seemed suspicious. Ignored it and they even followed up today.
My organization received one of these emails from "Linda," but uses https://www.bestprosintown.com/p...
Hi Nate, I got the same email template from the same email address today and found you through a ...
Just received one today (16 Aug 2022) from "Mailchimp". Thanks for sharing!
Thanks for posting this. I just got one today. I was 99% sure it was a scam, and your post confirmed...


Design & Development

Wordpress, Drupal, Joomla
New custom websites
Bespoke themes and extensions
Redesigns, upgrades, migrations

Web Design & Development


Optimization & SEO

Let us optimize and manage your overall online presence. We offer full service monthly SEO as well as one-time projects.  

Optimization Plans & Pricing


Maintenance, Patching

White glove monthly backups, security updates, maintenance and testing for your Wordpress, Drupal, or Joomla site.

Maintenance Plans & Pricing


Email Newsletter

Bring your web & marketing performance to the next level: monthly blog post roundup via email.  

Stay in Touch!