Givewp: Transactions Status Changes Causes Donation Form Income Amounts + Goals to Not Calculate Correctly

Created on 24 Jul 2015  Â·  24Comments  Â·  Source: impress-org/givewp

See this ticket: https://wordpress.org/support/topic/goal-progress-showing-wrong-total?replies=6#post-7216539

Needs to be confirmed by multiple sources, but it's an important element. Basically, when transactions are deleted, is the Goal updated correctly?

Most helpful comment

Closed with merge above. Yippie!

All 24 comments

Hi @DevinWalker ,

Have you figured this out ? Do you want me to look into this ?

Thanks

@ibndawood if you can that would be great.

@mathetos, Can you please help me to create a step-by-step process to recreate the bug in local environment ?

Yes.

1) Add some transactions to a form that has a Goal. You should try adding both Test Donations and Live Donations (could probably do Offline Donations and mark them as complete so as not to mess with CC info)
2) Then delete some of those transactions.
3) The goal will not be reduced properly.

@DevinWalker and I discussed it a bit and it looks like Goals are stored in metadata rather than actually being a live calculation of currently active donation amounts. I understand why storing in metadata is useful, but then it needs to reliably ALSO update the metadata when transactions are deleted. It looks like all the proper delete functions are there, but for some reason it still doesn't re-calculate after transactions are deleted.

Thanks!

@mathetos @ibndawood and word on this?

@ibndawood I confirmed this problem in another live environment this past weekend. Once transactions that are connected to a goal, the goal postmeta get's wrong. Also the total amount of donations that appear in the backend Forms admin page are wrong. So, something about the deletion functions is resulting in wrong info.

@ibndawood lemme know on this one. I can take a look if you're busy with FFM.

@DevinWalker - I will look into this now and let you know if it is a quick fix or needs more detailed review. If its not a quick fix I'd be glad if you can take that from me.

@ibndawood thanks for getting back to me quickly. LMK

@DevinWalker, I am able to reproduce this error. I will provide a fix.

Great thanks!

Hello @mathetos and @DevinWalker ,

I tested thoroughly with various test cases. I was able to reproduce this in the following scenario:

  • Create a Form with or with Goal.
  • Make a payment ( you can choose any payment here ).
  • Now go back to Transactions and edit the payment you just made.
  • Change the amount (increase or decrease amount) and Save Payment
  • Now if you go back to forms, you will notice that the change is not reflected in Income column.

This is because of this : https://github.com/WordImpress/Give/blob/master/includes/admin/payments/actions.php#L186 here we do not update the form's earnings/sales.

Goal just uses form earnings info which is the same as the info in the Income column.

Hey @mathetos @ibndawood

I've committed some code which now properly increases/decreases the individual donation form income amount which Goals relies on. I've tested it myself and it's working but would appreciate it if you both could confirm by checking out this branch: https://github.com/WordImpress/Give/tree/issue/188 and testing the scerario in the comment above and other scenarios to verify this issue is resolved.

Tested and verified locally. Works exactly as expected now. Great work! That was an important one.

I've had several users report that this is still a problem. I'll reopen and try to duplicate again in detail and report back.

@mathetos - I believe the problem is not with the Goals. Its with calculating the income. Here is what I found from one of my customers.

  1. Make a transaction in Test Mode disabled mode.
  2. Now change the Test Mode to active.
  3. Delete the transaction you just made with test mode disabled.
  4. Check the income.

I believe the issue is mixing up of test transactions and live transactions.

I'm seeing the issue in production with version 1.3.1.1.

See the widget here: http://podcrto.si/podpri/
Compare the widget progress bar with my custom bar on the frontpage http://podcrto.si/ (under the banner on top)

You will se the progress percentage differ by a worth of 210€. The raised amount shown on the widget is 210€ less than the actual amount raised.

The overview on the admin dashboard reports correct values which also coincide with actual funds raised.

The function I'm using to get earnings for the custom progress bar is this:

if(class_exists('Give_Payment_Stats') && !function_exists('podcrto_give_progress')) {
  function podcrto_give_progress($form_id = 0, $total_ammount, $start_date, $end_date = 'now') {

    // Exit early if invalid input
    if(!is_numeric($total_ammount) || !strtotime($start_date) || ($end_date && !strtotime($end_date)))
      return;

    $stats = new Give_Payment_Stats;
    $earnings = $stats->get_earnings($form_id, $start_date, $end_date);

    return round($earnings * 100 / (int) $total_ammount, 1);
  }
}

This returns a valid amount.

Now the 210€ that don't show come from 2 different transactions.

Under Donations > All Forms reported transactions count is 24.

Under Donations > Transactions I have 26 succesfully completed transactions.

There is only 1 donation form set up. It's been in production mode the entire time.

I'll dig into the code later when I have the time.

EDIT: I see it's getting the value from postmeta instead of looking up confirmed transactions. So there's a problem with updating postmeta. One of the transactions I'm not seeing had been deleted 'pending' transaction.

@mathetos @anaerobic this may be related to #409 which I fixed yesterday. Can you try pulling down the latest master branch and testing to confirm?

OK, I pulled the latest master, which #409 is merged into. Here's what I find:

SCENARIO:

  • I have a form with $13780 raised toward a goal of $50,000
  • That form had 31 donations connected to it
  • I deleted a transaction connected to that form that was $500

Here's what happened:

  • The Goal was not reduced at all
  • On the "All Forms" page the "Donations" column still shows 31 donations (which is wrong). If you click that link to see all Transactions you see 30 transactions total (which is correct).
  • On the "All Forms" page the "Income" column says $13780 (which is wrong). If you click on that link it takes you to the Reports page and it shows a total income of $13280 (which is correct).

So this issue still is present, though it's not as bothersome as it was previously. Here's what needs to be fixed:

  • The front-end Goal needs to be updated to reflect the reduced amount correctly after a transaction is deleted
  • The number of "Donations" on the All Forms admin page needs to be updated after a transaction is deleted
  • The "Income" on the All Forms admin page needs to be updated after a transaction is deleted

Hi @mathetos, I have been reading through this thread because this issue has happened to me. I deleted a bunch of transactions (that were from myself when clicking on the donate button to see if it would take me to paypal - I never actually went through with any of the transactions), and now even though my donors have donated $2000, my progress bar only shows $1650. I am wondering what to do in this situation. I would like to get my progress bar back up to $2000, but cannot figure out how to do it based on the thread above - do I need to access the database? I have never done that before as I am new to all this. Thank-you Sir.

@allankember What you need to do is manually update a meta field (custom field) on the donation post type. For that you will need access to the database through a tool like PhpMyAdmin or shell as Give hides custom fields functionality from the WordPress interface.

To do that first look for the post ID of the donation form (edit your donation form in WP and look at the number in the URL e.g. https://mysite/wp-admin/post.php?post=7422&action=edit

Then run this on the database (change post id and table prefix if necessary):

SELECT `meta_id`, `meta_value` FROM `wp_postmeta` WHERE `post_id` = 7422 AND `meta_key` = '_give_form_earnings';

This should give you the field that you want to update and its meta_id. If yes, then update with:

UPDATE `wp_postmeta` SET `meta_value` = 12345 WHERE `wp_postmeta`.`meta_id` = 678;

Needless to say 12345 is the donated amount and 678 is the meta_id you got from the SELECT.

Ticket # 1362 is having issues with the goal not calculating right. Customer did mention that he did delete out his test transactions.

Closed with merge above. Yippie!

WOOT!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mathetos picture mathetos  Â·  3Comments

mathetos picture mathetos  Â·  4Comments

emgk picture emgk  Â·  3Comments

ravinderk picture ravinderk  Â·  4Comments

Benunc picture Benunc  Â·  3Comments