Posted by JmsCrk on April 23, 2008 at 2:02am
Hi, I'm trying to run a custom function when a payment is made - to allow the user to publish certain node types - but I'm having trouble working out the correct hook for the ecommerce module. I'm using ec 3.4 and drupal 5.7
I want to hook in and run the function only when a payment is completed successfully (ie payment received, workflow complete) - I'm trying to use ec_transaction_api, is that right? Here's my code so far, any help woul dbe appreciated:
function mymodule_ec_transactionapi(&$txn, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'insert':
// check if the transaction is successful
if ($txn->allocation == 2) {
//run the custom function
}
break;
}
}
Comments
I am/was looking to do the
I am/was looking to do the same thing but couldn't find help anywhere, and I don't know much about how the hook system works. If you figure it out please post the solution :o)
Here's one of several threads I started on drupal.org looking for assistance. http://drupal.org/node/248422
Thanks Justin, I hadn't
Thanks Justin, I hadn't actually thought of using the return/thankyou page to do it, but I could. Although I still don't know how to tell if the transaction was completed successfully or not... I'll muddle around with it a bit more.
Would still be great if someone who knew the ec system properly could give a better answer though :P
Accidental duplicate entry
Accidental duplicate entry
It's okay, I figured it out
I was using the wrong hook:
function mymodule_ecommerceapi(&$txn, $op) { switch ($op) { case 'on payment completion': //here goes the function } }This is only for v3.x, this
This is only for v3.x, this has been completely changed for v4. For v4 see http://drupalecommerce.org/api/function/hook_ec_txn_workflow/54 to see how to do it.
Gordon Heydon
Lead Drupal Developer - Lonely Planet
--
Gordon Heydon
How does this work for v3.x
How does this work for v3.x when a payment is made via PayPal? Right now I have it set up so that a user has to click on the "Return to site.com" before they can be signed up for an event. Problem with this is if the user makes the payment and doesn't return to the site, then they will have been charged but not enrolled in the event. Do you set PayPal up so that it automatically redirects the user back home or does the hook above still work via IPN?
Any help gordon?
Any help gordon?