artfulrobot / uk.artfulrobot.civicrm.gocardless

A CiviCRM extension providing GoCardless integration to handle UK Direct Debits.
GNU Affero General Public License v3.0
5 stars 18 forks source link

contribution_recur_id in API3 expects integer not string #64

Closed TomCrawshaw closed 4 years ago

TomCrawshaw commented 4 years ago

In line 365 of GoCardlessUtils.php (an api3 call), contribution_status_id is set to "In Progress", rather than the numeric value "5", as seems to be expected by the api. This causes a "not a valid integer" error. Setting contribution_status = "In Progress" works.

Is this an error in the code, or am I misunderstanding the api3?

artfulrobot commented 4 years ago

@TomCrawshaw

Link to referenced line in 1.9beta

I don't see this error, and testing with the APIv3 explorer leads to setting contribution_recur_id by the name and works for both create and update(i.e. create while also supplying an ID).

What version of CiviCRM are you running?

TomCrawshaw commented 4 years ago

I’m on Civi 5.20.0, and GoCardless extension 1.8

I’m testing this for membership signup - does that make a difference? The error message starts:

completeRedirectFlowCiviCore: EXCEPTION after successfully setting up subscription at GoCardless: contribution_status_id is not a valid integer #0 /var/www/vhosts/weyarun.org.uk/httpdocs/drupal_demo/sites/default/files/civicrm/ext/uk.artfulrobot.civicrm.gocardless/CRM/GoCardlessUtils.php(344): civicrm_api3('ContributionRec...', 'create', Array) #1 /var/www/vhosts/weyarun.org.uk/httpdocs/drupal_demo/sites/default/files/civicrm/ext/uk.artfulrobot.civicrm.gocardless/gocardless.php(175): CRM_GoCardlessUtils::completeRedirectFlowCiviCore(Array) #2 /var/www/vhosts/weyarun.org.uk/httpdocs/drupal_demo/sites/all/modules/civicrm/CRM/Utils/Hook.php(305): gocardless_civicrm_buildForm('CRMContribute...', Object(CRM_Contribute_Form_Contribution_ThankYou)) #3 /var/www/vhosts/weyarun.org.uk/httpdocs/drupal_demo/sites/all/modules/civicrm/CRM/Utils/Hook/DrupalBase.php(90): CRM_Utils_Hook->runHooks(Array, 'civicrm_buildFo...', 2, 'CRMContribute...', Object(CRM_Contribute_Form_Contribution_ThankYou), NULL, NULL, NULL, NULL) #4

The DD is set up on GoCardless, but the recurring contribution status is “Pending (Incomplete Transaction)” not “In Progress”, although the contribution_status_id in the civicrm_contribution_recur table IS set to “5”. Odd

On 24 Dec 2019, at 08:28, Rich Lott notifications@github.com wrote:

@TomCrawshaw https://github.com/TomCrawshaw Link to referenced line in 1.9beta https://github.com/artfulrobot/uk.artfulrobot.civicrm.gocardless/blob/1.9beta2/CRM/GoCardlessUtils.php#L365 I don't see this error. What version of CiviCRM are you running?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/artfulrobot/uk.artfulrobot.civicrm.gocardless/issues/64?email_source=notifications&email_token=ADRMUTKJO6HUSSYTUSUH26DQ2HB4DA5CNFSM4J6XV5G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHSY5UY#issuecomment-568692435, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRMUTJUZFPRIUQ24P6F5RLQ2HB4DANCNFSM4J6XV5GQ.

artfulrobot commented 4 years ago

Very odd. You haven't deleted 'In Progress' somehow, have you? You're not using civirules with something triggering on/affecting recur records are you?

TomCrawshaw commented 4 years ago

No, “In Progress” is present & correct as an option, and no rules used.

All I can think is that when searching for and displaying contribution records, Civi doesn’t show the status of the _contribution_recur record, only the _contribution record (which in this case the contribution_status_id field is set to “2” - “Pending”). In other words, the _contribution_recur table payment status “‘In Progress” never gets displayed. To test this I’ve edited the database directly to change the status of the matching line in the _contribution table to “In Progress” (5), and now when searching for the Recurring Transaction ID, the result does show “In Progress”, indicating that this is displaying the _contribution record, NOT the _contribution_recur record.

I don’t know if this means the code should be changed, or if this is in fact “expected behaviour”.

On 29 Dec 2019, at 08:15, Rich Lott notifications@github.com wrote:

Very odd. You haven't deleted 'In Progress' somehow, have you? You're not using civirules with something triggering on/affecting recur records are you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/artfulrobot/uk.artfulrobot.civicrm.gocardless/issues/64?email_source=notifications&email_token=ADRMUTOYOEBNNMKKJBW44J3Q3BMAVA5CNFSM4J6XV5G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHY2KWQ#issuecomment-569484634, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRMUTPYWSUKIQ6X3C56DADQ3BMAVANCNFSM4J6XV5GQ.

artfulrobot commented 4 years ago

@TomCrawshaw you should not change the contribution status directly - suggest you change it back asap. The reason for this is that there is a world of financial transaction data below the contribution record that will become corrupt if you change the status directly without going through the API. Also individual contribs should not have an In Progress status. N.b. you can mess around with the contribution recur status with fewer side effects at the mo, but the contribution status is sensitive.

The code you linked to is setting the contribution recur status, not a contribution status - the two sets of statuses are actually separate (though historically they have been equivalent),

Yes, (from memory) the contribution results show the contrib status not the contrib recur status.

Do you have access to the API explorer (v3)? or the command line cv tool? If so, identify a test contrib recur record and try setting its status to "In Progress"

cv api ContributionRecur.create id=<NUMERIC_ID_GOES_HERE> contribution_status_id="In Progress" 

see if you get the same error. (if successful you can use a similar command to change it back again to whatever it was)

You could also double check that this returns a the option:

cv api OptionValue.getsingle sequential=1 option_group_id="contribution_recur_status" name="In Progress" is_active=1 
TomCrawshaw commented 4 years ago

Thanks for the advice - this was on a demo/test site, which gets wiped often anyway.

I do have access to the API and cv. Using cv api ContributionRecur.create id=77 contribution_status_id="In Progress" I get this response:

{ "error_field": "contribution_status_id", "type": "integer", "error_code": 2001, "entity": "ContributionRecur", "action": "create", "is_error": 1, "error_message": "contribution_status_id is not a valid integer" }

On 31 Dec 2019, at 08:48, Rich Lott notifications@github.com wrote:

@TomCrawshaw https://github.com/TomCrawshaw you should not change the contribution status directly - suggest you change it back asap. The reason for this is that there is a world of financial transaction data below the contribution record that will become corrupt if you change the status directly without going through the API. Also individual contribs should not have an In Progress status. N.b. you can mess around with the contribution recur status with fewer side effects at the mo, but the contribution status is sensitive.

The code you linked to is setting the contribution recur status, not a contribution status - the two sets of statuses are actually separate (though historically they have been equivalent),

Yes, (from memory) the contribution results show the contrib status not the contrib recur status.

Do you have access to the API explorer (v3)? or the command line cv tool? If so, identify a test contrib recur record and try setting its status to "In Progress"

cv api ContributionRecur.create id= contribution_status_id="In Progress" see if you get the same error. (if successful you can use a similar command to change it back again to whatever it was)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/artfulrobot/uk.artfulrobot.civicrm.gocardless/issues/64?email_source=notifications&email_token=ADRMUTOKAKZE2E6J4RR6QI3Q3MBOBA5CNFSM4J6XV5G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH35NTA#issuecomment-569890508, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRMUTL75VGBAMPD5NDS263Q3MBOBANCNFSM4J6XV5GQ.

artfulrobot commented 4 years ago

...and what does running the other cv command give? (sorry I think I edited that in and I notice you're replying by email, so you may have missed it)

TomCrawshaw commented 4 years ago

Yes, I did miss it.. Here is the response:

{ "id": "1377", "option_group_id": "127", "label": "In Progress", "value": "5", "name": "In Progress", "weight": "5", "is_optgroup": "0", "is_reserved": "1", "is_active": "1" }

artfulrobot commented 4 years ago

That's so weird. I think it's a bit off topic - it's not to do with the GoCardless extension, as far as I can see, unless there's something very odd going on. But I've asked on mattermost

artfulrobot commented 4 years ago

I'm going to close this as I don't think it's specific to this extension. The fact that this happens suggests it's something odd about your install - as as far as I'm aware, that API call is unrelated to any particular payment processor. Good luck! And feel free to re-open if it does turn out to be something to do with this!