I'm planning on writing a quick payment method for customers to pay me via Paypal. My goal is to give customers a short link in the PDF that they can click on that will lead to a custom PHP page (i.e. domain.com/payment.php?invoice=12345 ) ... that PHP page will look up the invoice, generate the Paypal form ( https://www.paypal.com/IntegrationCenter/ic_standard_home.html#individual ) , and redirect the user to Paypal's website with the invoice items pre-filled and streamlined for the paying customer.
My hang-up is two-fold ... 1) how do I get URL's to be clickable in the PDF? 2) how can I implant that Invoice ID into said URL?
For the PHP "payment.php" page, I was considering using Tebas's Remote Framework ( http://simpleinvoices.org/forum/topic.php?id=247 ) for the invoice lookups, since it sounded like it was well-received by the dev team and would likely make it into future upgrades.
I answered one of my questions: 1) to make a clickable URL, one must use HTML code (<a href="...">link</a> I found using the "Invoice detail line" box the best option ... that does not have the 50 character limit as the other boxes do, which allows me to add in as much HTML code as I would like. 2) still searching for the magical way to include the variable in the HTML code of this field. I have a feeling it cannot be done, except by editing the template file.
you can try something like <a href="paypal.php?inv=<?php echo $invoice.id ; ?>"
-read through the template file to know which variables to use for the invoice id etc..
heres some other info that might be usefull - from another user that aded a paypal button to the PDFs [quote]My current PayPal link at the bottom of invoices is added by putting this into the invoice footer section for the biller:
Credit card via PayPal: <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=admin% 40mydomain%2ecom&item_name=0Hosting% 20Payment&no_shipping=0&no_note=1¤cy_code=AUD&lc=AU&bn=PP% 2dBuyNowBF&charset=UTF%2d8"target="_blank">Pay via PayPal</a>
The link used is: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=admin% 40mydomain%2ecom&item_name=Hosting% 20Payment&no_shipping=0&no_note=1¤cy_code=AUD&lc=AU&bn=PP% 2dBuyNowBF&charset=UTF
Breakdown:
%20 is a space &business=admin%40mydomain%2ecom (This is the Email address, with %40 for the @ symbol and %2e for the "dot")
&item_name=Hosting%20Payment (What the payment is for)
&no_shipping=0 No shipping address is required
&no_note=1 A note isn't included, I think. Not an essential item.
¤cy_code=AUD We prefer to be paid in Australian dollars
&bn=PP%2dBuyNowBF Not sure. Think it's for a single buy it now item.
&charset=UTF self explanatory. [/quote]
If you get it working please post details so others can use it as well
meh, the PHP code <?php echo "test"; ?> didn't get parsed. Probably b/c it's within Smarty and being inserted as a string rather than something to be parsed/executed.
I ended up just editing the template file ./templates/invoices/default/template.tpl ... I added a table row:
Just in case anyone's interested in my code, here is what is in paypal.php (minus my HTML code to make it look pretty):
[code]<?php $redirect = TRUE; // automatically submit form to send user straight to Paypal // Change this to FALSE if you want them to click "Pay Now"
$paypalID = 'sales@domain.com'; // Your PayPal email to receive the payment to $paypalIMG = 'http://www.domain.com/logo.gif'; // Your logo
// Check for an invoice ID $invoice = $_GET['invoice']; if (!preg_match('/^\d+$/', $invoice)) die('ERROR: Invalid Invoice: '.htmlspecialchars($invoice));
// Load the Remote Framework file require_once('simpleinvoices/SI_RF.php'); $xml = simplexml_load_string(getInvoices($invoice));
// Loop through each line item of the invoice and generate the HTML & tally the total $invoice_items = ''; // HTML output container $total = 0; // for tracking total price $i = 0; // for incrementing each product foreach ($xml->record as $product) { if (isset($product->description[1])) // Description can be listed twice in XML (if using consultation invoice) $desc = $product->description[1] .' :: '. $product->description[0]; else $desc = $product->description; $name = substr($desc, 0, 127); // REQUIRED :: 127 characters $amt = $product->total; // REQUIRED $qty = $product->quantity; // Optional :: Positive interger $i++; // Paypal starts with 1, and so must we (so increment before outputing HTML)
$total += preg_replace('/[^0-9]/', '.', $amt); // Wierd ... the period from the XML was not a true period } $total = sprintf("%01.2f", $total); // Format pretty-like (force two decimal places)
One edit to the previously posted "paypal.php" code ... I had originally used jquery to do the form submit automatically, but when doing some revisions I found it to be overkill for one silly line of javascript. I guess I missed one part when I took the jquery code out, and unfortunately I cannot find a way to edit my original post. Thus, if anyone does use this, please replace this code: [code]</body> <script type="text/javascript"> $(document).ready(function(){ <?=(TRUE===$redirect?' document.getElementById("paypal_payment").submit();':'')?> }); </script> </html>[/code]