Tuesday, 24 October 2017 12:54

Simple Drupal Webform (v4) PayPal Integration using custom PHP confirmation message

Written by 
Simple Drupal Webform (v4) PayPal Integration 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 e-mail 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>

 

Read 148 times Last modified on Tuesday, 24 October 2017 13:08

Leave a comment

Make sure you enter the (*) required information where indicated.
Basic HTML code is allowed.

Copyright © 2005-2016 Covington Creations, LLC | Hosting by InMotion | Legal