Simple Invoices logo
    • CommentAuthorspeedpixel
    • CommentTimeOct 10th 2007 edited
     permalink
    Hi,

    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.
    • CommentAuthorspeedpixel
    • CommentTimeOct 10th 2007 edited
     permalink
    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.
    • CommentAuthorjustin
    • CommentTimeOct 10th 2007 edited
     permalink
    Hey SpeedPixel,

    re variable

    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&currency_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&currency_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.

    &currency_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

    Cheers

    Justin
    • CommentAuthorspeedpixel
    • CommentTimeOct 10th 2007 edited
     permalink
    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:

    [code]
    <tr>
    <td class="tbl1-left tbl1-right" colspan=6>
    <a href="http://www.domain.com/paypal.php?invoice={$invoice.id}">http://www.domain.com/paypal.php?invoice={$invoice.id}</a>
    </td>
    </tr>
    [/code]

    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)

    // https://www.paypal.com/IntegrationCenter/ic_std-variable-reference.html#HTMLVariablesforShoppingCarts
    $invoice_items .= "
    <input type='hidden' name='item_name_$i' value='$name'>
    <input type='hidden' name='amount_$i' value='$amt'>
    ";

    $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)

    ?>
    <html>
    <head>
    <title>Processing Payment ...</title>
    </head>
    <body>
    <h4><b>Invoice: <?=$invoice?><br />
    <b>Total: $ <?=$total?></h4>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypal_payment">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="business" value="<?=$paypalID?>">
    <input type="hidden" name="cpp_header_image" value="<?=$paypalIMG?>">
    <input type="hidden" name="invoice" value="<?=$invoice?>">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="lc" value="US">
    <?=$invoice_items?>

    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    <?=(TRUE===$redirect?'<i>Please wait while redirecting...</i>':'')?>
    </body>
    <script type="text/javascript">
    $(document).ready(function(){
    <?=(TRUE===$redirect?' document.getElementById("paypal_payment").submit();':'')?>
    });
    </script>
    </html>[/code]

    --steve
    • CommentAuthorjustin
    • CommentTimeOct 11th 2007 edited
     permalink
    awesome work steve

    good to see the remote framework getting used

    i'll take a look at it - might included it in future versions it works ok

    cheers

    justin
    • CommentAuthorspeedpixel
    • CommentTimeOct 11th 2007 edited
     permalink
    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]

    With this:

    [code]</body>
    <script type="text/javascript">
    <?=(TRUE===$redirect?' document.getElementById("paypal_payment").submit();':'')?>
    </script>
    </html>[/code]