Downloads

Google Ad

Paypal IPN Plugin v3.5 -- Email and Multi Items

Date: Thu, Nov 5th 2009, 03:27 Author: nick Views: 9768 Comments share

CakePHP Paypal IPN Plugin

Info:
Watch:
Get it:
  • Download Now
  • git clone git://github.com/webtechnick/CakePHP-Paypal-IPN-Plugin
I've improved upon the Paypal IPN plugin to include easy email notifications and multiple item third party cart uploads to paypal via the helper.

Migration Guide

Migrating to 3.5 from v3.0 just requires another table to handle multiple cart items. I've written a schema file to migrate for you.

Migration v3.0 to v3.5:
  1. cake schema run create -path plugins/paypal_ipn/config/sql -name items

Fresh Install v3.5:
  1. cake schema run create -path plugins/paypal_ipn/config/sql -name ipn

If you don't have access to a terminal, you'll need to read the paypal_ipn/paypal_ipn.sql into your database via phpmyadmin or some other tool.

Adding Multiple Items for PayPal...

I've added a new type to the paypal options parser called 'cart'. With this, you'll be able to pass in an array of items to pass in to paypal.

Example:
  1. $paypal->button('Checkout', array(
  2.   'type' => 'cart',
  3.   'items' => array(
  4.     array('item_name' => 'Item 1', 'amount' => '120', 'quantity' => 2, 'item_number' => '1234'),
  5.     array('item_name' => 'Item 2', 'amount' => '50'),
  6.     array('item_name' => 'Item 3', 'amount' => '80', 'quantity' => 3),
  7.   )
  8. ));

This will generate a "Checkout" Button that will upload the cart information and calculate the total cost via paypal. You can pass in any option you would normally pass into a single item as an key=>value pair in 'items'. This is useful for say shipping on one item but not another.

Pretty slick!

Basic Emails via Transactions...

Paypal IPN Plugin comes with a utility email method that is useful for shotting off quick emails tailored to a specific transaction. The email function works off an specific Paypal IPN transaction, pulling the to and from field from its payer_email and business columns. This is useful for sending quick thank you messages or declines.

The usage of this method is pretty basic. Here are some examples of its use:
  1. $IPN = ClassRegistry::init('PaypalIpn.InstantPaymentNotification');
  2.  
  3. //You can pass in just text and it will send the message
  4. //make sure to set the id first before you attempt the send
  5. //or it won't know where you want to send it.
  6. $IPN->id = '4aeca923-4f4c-49ec-a3af-73d3405bef47';
  7. $IPN->email('Thank you for your transaction!');
  8.  
  9. //You can pass in multiple options in as an associative array
  10. $IPN->email(array(
  11.   'id' => '4aeca923-4f4c-49ec-a3af-73d3405bef47',
  12.   'subject' => 'Donation Complete!',
  13.   'message' => 'Thank you for your donation!',
  14.   'sendAs' => 'text'
  15. ));

The full list of options is the same options available to the native Email component plus a few extras. Here is the full list of options available to the InstantPaypalNotification::email()

Email Options

  • id: id of instant payment notification to base email off of
  • subject: subject of email (default: Thank you for your paypal transaction)
  • sendAs: html | text (default: html)
  • to: email address to send email to (default: ipn payer_email)
  • from: from email address (default: ipn business)
  • cc: array of email addresses to carbon copy to (default: array())
  • bcc: array of email addresses to blind carbon copy to (default: array())
  • layout: layout of email to send (default: default)
  • template: template of email to send (default: null)
  • log: boolean true | false if you'd like to log the email being sent. (default: true)
  • message: actual body of message to be sent (default: null)

I also suggest you take a look at the API for more: http://projects.webtechnick.com/docs/paypal_ipn

I hope you find this plugin useful. Please, if you like the plugin, find a bug, or have a feature request, post a comment. =)