Hi univate,

I've been working on getting the eWAY module working with uc_recurring 2.x and I needed to make this change. I hope you can incorporate it.

Basically, when uc_recurring_[fee_handler]_renew is called, the recurring fee may still be 'Pending' in eWAY. There's no guarantee eWAY will have processed the payment yet. So I've added another hook that is called at the top of uc_recurring_renew().

function uc_recurring_renew($fee, $check_handler = TRUE) {
  // give the fee handler module a chance to say the payment is still pending
  $pending_test_func = 'uc_recurring_'. $fee['fee_handler'] .'_renew_pending';
  if (function_exists($pending_test_func)) {
    $pending_result = $pending_test_func($fee);
    if ($pending_result) {
      uc_order_comment_save($fee['order_id'], 0, t('Info: Recurring fee <a href="!url">!fee</a> for product @model is currently pending. Will retry.', array('!url' => url('admin/store/orders/recurring/view/fee/'. $fee['rfid']), '!fee' => $fee['rfid'], '@model' => $fee['data']['model'])));
      watchdog('uc_recurring', 'Recurring fee of !amount for product @model on order !order_id is still pending. Will retry.', array('!amount' => $fee['fee_amount'], '@model' => $fee['data']['model'], '!order_id' => $fee['order_id']), WATCHDOG_INFO, l(t('order !order_id', array('!order_id' => $fee['order_id'])), 'admin/store/orders/'. $fee['order_id']));
      return FALSE;
    }
  }
  // payment is no longer pending, continue to create order for fee and check the transaction status...

This way, if cron is run before eWAY actually does the transaction, we just skip it and try again next time.

Obviously this change won't impact any existing gateways implementing recurring fees.

Let me know what you think.

Cheers

PS. Patch also includes a fix for uc_recurring_fee_delete():

module_invoke_all('recurring_api', 'delete', $feature['fid']);

should be

module_invoke_all('recurring_api', 'delete', $feature['pfid']);

Comments

ac’s picture

subscribing

thtas’s picture

@benkant

I'm trying to do exactly what you're doing right now: get uc_recurring and eway to play

It looks like you're a lot further down the line than i am. i'm still trying to figure out how to even get uc_recurring call the correct functions in uc_eway... suspect i messed something up with all these patches and different versions floating around. considering starting from scratch now..

Where are you up to in the whole thing? what version of the code did you start with and which patches to ubercart and uc_recurring did you use to get it working?

Hope you can help out.

-Tim

ac’s picture

univate - can you please review and commit this please

benkant’s picture

Tim,

You can get uc_eway working with uc_recurring using the above patch, and the patch I've submitted over here: #459052: eWay recurring payment support.

Let me know how it goes.

thtas’s picture

going well..

accidently replied here... moved to here: #459052: eWay recurring payment support

univate’s picture

I think instead of calling this "payment_pending" we should just have a generic preprocess or prepare callback?

I would also prefer to move this code outside the renew function and instead just have a call from the cron function to a separate "prepare" function that executes this code, if that function succeeds (ie: doesn't return FALSE) then call to the renew function.

Just make the api more generic as that callback might be useful for other things then just checking if the payment is pending.

benkant’s picture

StatusFileSize
new1.75 KB

Good idea. Here's a patch that does that.

Also included in the patch is the bugfix for uc_recurring_fee_delete().

ac’s picture

any chance of getting this into head too? :D

ac’s picture

Project: UC Recurring Payments and Subscriptions » Ubercart eWay Payment Gateway
Status: Needs review » Needs work

After speaking to Univate this is now a gateway issue so I am moving this to Eway module and will reroll.

From IRC

"the "magic" functions uc_recurring_[fee_handler]_* actually no longer exist, each module now needs to define a hook_recurring_info() function to define each of the callbacks.

the change is not major as they should just need to add the info function to point to each of the existing callback, and possible make sure the arguments are correct of each function
so eway just needs to add the function uc_eway_recurring_info() which returns the array of callbacks for renew, process etc..."

ac’s picture

Title: New hook uc_recurring_[fee_handler]_renew_pending » Add function uc_eway_recurring_info()
univate’s picture

Actually these are two separate issues, I have left a comment about adding the info function in the other issue.

At the moment there is still no 'prepare' callback in uc_recurring to handle this special requirement of this gateway.

I would like to try and avoid the case of adding things into uc_recurring just because one gateway needs something (otherwise we will end up with all these gateway specific bits of code needing to be supported).

We now have the concept of gateways setting a flag to indicate to uc_recurring that they will handle the renewals themselves, eway seems to be a special case where the gateway handles the renewals, but you need to query the gateway to check if renewals have occured.

One option could be that uc_eway just have its own cron function - it would be almost identical to uc_recurring_cron, but just adding the extra check for calling the pending function before triggering the renewal.

There is another feature that I want to add into uc_recurring and that is the "extensions api", which will allow modules to effect what happens when a payment fails - that may be another place that eway could handle its renewals, ie: if a payment fails, eway could check if it was even attempted and then request it to be renewed again after a certain time.

benkant’s picture

Title: Add function uc_eway_recurring_info() » Update for uc_recurring 2.x
Category: feature » task

Given the changes to uc_recurring involving the new hook_recurring_info() we need to update uc_eway.

With regard to not having a prepare callback, we'll need to do something similar to univate's cron suggestion in #11. In this case, as univate said, uc_recurring will not handle the actual eWay renewal.

I should have a patch early next week.

benkant’s picture

StatusFileSize
new5.31 KB

Here's a patch that updates uc_eway (DRUPAL-6--2) to work with uc_recurring 2.x (DRUPAL-6--2).

Included in the zip is uc_eway_recurrring_2.patch which patches the current uc_eway.module to include admin settings for uc_recurring, and includes uc_eway.recurring.inc (also in the zip) in the event eWAY recurring billing is enabled.

Please note this code is ALPHA. I am posting this with the hope people will test and provide feedback. If it works for others I will clean it up ready for commit.

Cheers

ac’s picture

Status: Needs work » Needs review
agileware’s picture

Status: Needs review » Closed (duplicate)

Marking this as a duplicate of #459052: eWay recurring payment support since this issue has been moved into this modules issue queue and we already had the issue for it.