Thought this might be helpful to someone else out there. I had a project where the client had organic groups... each OG can enable their own donation button. The donations all go to a central paypal account, but we wanted to track donations with a meter on each OG landing page. There's nothing particularly OG-y about this code... it would work just as well as one-donate-button-per-node. I thought I'd post this more as a case study for other people who want to tweak lm_paypal to do just what they want.
On the OG group content type, I added fields for donation target, and donations received. I added a block for the meter, with this code:
$node = menu_get_object();
if ($node->field_event_donate['und']['0']['value'] == '1') {
$total=$node->field_event_donate_received['und']['0']['value']; //total received so far
$goal=$node->field_event_donate_target['und']['0']['value'];; // total fundraising goal
$width=170; //width of the thermometer in pixels
$o="<table cellpadding=0 cellspacing=0 border=2px><tr>";
$o.='<td width='.round($total/$goal*$width,0).'px bgcolor=#00FF00 align="right">';
if ($total/$goal >= 0.5) $o.=round($total/$goal*100,1)."% ";
$o.='</td><td width='.round((1-$total/$goal)*$width,0).'px bgcolor=#DDDDDD> ';
if ($total/$goal < 0.5) $o.=round($total/$goal*100,1)."%";
$o.="</td></tr></table><br>";
print $o;
print '<strong> $'. round($total,2) . ' </strong> raised towards our goal of $'.$goal.'';
}
Then I added the donation block:
if (function_exists('lm_paypal_donate')) {
$node = menu_get_object();
if ($node->field_event_donate['und']['0']['value'] == '1') {
$name = $node->title;
$eid = $node->nid;
print lm_paypal_donate(array(50), array(
'item_name' => 'Organic Group donation for ' . "$name" . ', ID ' . "$eid",
'currency_code' => 'USD',
'text' => 'Donate through this event',
'button' => array('text' => 'Donate with Paypal')
)
) . '<br>';
}
}
(note: field_event_donate is the field the OG admin can use to enable/disable this donation button. I also use it for block visibility for both the meter and donation button block)
(also note: the item_name includes the NID as the last word in the string. This is important in the custom module.)
Finally, I wrote a little custom module to fire when paypal sends an IPN response that confirms successful payment. It pulls the NID out of the item_name, and adds the donated amount to the node's "donations received" field. Module attached.
I hope someone else finds this helpful! Thanks to the lm_paypal maintainers for making this module hookable.
| Comment | File | Size | Author |
|---|---|---|---|
| lm_paypal_og.zip | 1.1 KB | ohthehugemanatee |