Skip to content

feat: add Salesforce Nonprofit Cloud GiftTransaction ingest bridge - #315

Merged
shivamlalakiya merged 1 commit into
PhilanthroPy-Project:mainfrom
vridhib:salesforce-nonprofit-cloud-gift-export-reader
Oct 9, 2026
Merged

shivamlalakiya merged 1 commit into
PhilanthroPy-Project:mainfrom
vridhib:salesforce-nonprofit-cloud-gift-export-reader

Conversation

@vridhib

@vridhib vridhib commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #234

Summary

Adds a Salesforce Nonprofit Cloud GiftTransaction export reader alongside the existing CiviCRM, Raiser's Edge, and NPSP bridges, and wires it into the CLI as philanthropy features --source nonprofit_cloud.

  • philanthropy.ingest.read_nonprofit_cloud_gifts(path): reads a GiftTransaction export CSV (or a directory of them) and delegates it to the shared CiviCRM reader.
  • philanthropy.ingest.nonprofit_cloud_gifts_to_features(gifts, *, reference_date=None, include_statuses=DEFAULT_INCLUDED_GIFT_TRANSACTION_STATUSES): rolls the export up into the donor-level feature table, keeping only Paid rows by default before handing the rest to civicrm_contributions_to_features.
  • philanthropy.ingest.DEFAULT_INCLUDED_GIFT_TRANSACTION_STATUSES = ("Paid",).

Why the Paid allowlist exists: NPC's GiftCommitment object represents a pledge or recurring donation agreement and, on save, automatically and immediately generates the GiftTransaction records its schedule implies. Each carries a Status field that starts at Unpaid and only moves to Paid once the money actually arrives. A $1,200 pledge paid monthly becomes twelve GiftTransaction rows the moment the commitment is saved. As a result, until Status is read, the two that have been received look identical to the ten that have not. The same overcount applies to Failed, Canceled, Pending, Fully Refunded, and Written Off rows and to any custom status an org adds. An allowlist is a safer default: only Paid is counted, and an unrecognized status is dropped rather than summed. This mirrors the same commitment versus payment trap the NPSP bridge guards against by excluding Pledged Opportunity stages and the Raiser's Edge bridge guards against by excluding Pledge gift types.

Partial refunds: there is no Partially Refunded status in the NPC status list. For a partial refund, the row remains at the state of Status = 'Paid' and reduces CurrentAmount to the net. The IsPartiallyRefunded boolean is set independently. Since the allowlist keeps Paid rows, and the aggregation uses CurrentAmount (already net of the refund), a partially refunded gift contributes what was actually kept. Only a full refund moves the status to Fully Refunded, which the default drops.

Header aliases accept a Salesforce report export's column labels (Donor ID, Transaction Date, Current Amount, Status), the raw GiftTransaction API field names (DonorId, TransactionDate, CurrentAmount, Status), and Contact ID as a fallback donor key. DonorId is preferred when both are present. It maps to the Account DMO (the person, household, or organization account associated with the gift), whereas ContactId maps to the Individual DMO (the contact associated with the transaction). This mirrors the NPSP bridge's Account-over-Primary-Contact precedence.

NPC vocabulary was verified against Salesforce's own public documentation instead of assumed:

I deliberately did not model the GiftCommitment object. This bridge reads GiftTransaction exports, and I did not want to assert commitment field names I could not verify against a primary source. I also did not populate distinct_financial_types as NPC's designation data lives on the related GiftTransactionDesignation and GiftDesignation objects (not as a direct field on GiftTransaction), and a simple CSV export does not carry those columns. Both are documented in the module docstring as out of scope.

Files Changed

  • philanthropy/ingest/_nonprofit_cloud.py (new)
  • philanthropy/ingest/__init__.py (export the three new names)
    -- philanthropy/ingest/_read_gifts.py (register nonprofit_cloud)
  • philanthropy/cli.py (--source nonprofit_cloud)
  • tests/test_nonprofit_cloud.py (new, same depth as tests/test_npsp.py)
  • tests/test_read_gifts.py (new case for the new source)
  • docs/reference/index.md (Tier 2/Beta row), docs/index.md
  • CHANGELOG.md
  • CONTRIBUTORS.md

Checklist

  • make ci passes locally (lint → collection → tests → coverage ≥ 92%)
  • New/changed public API has docstrings and is exported in the subpackage __init__.py
  • Tests added or updated
  • CHANGELOG.md updated under [Unreleased]
  • Added yourself to CONTRIBUTORS.md (skip if you would rather not be listed)
Required test coverage of 92.0% reached. Total coverage: 98.26%
============= 2425 passed, 30 skipped, 204 warnings in 331.66s (0:05:31) =============
==> All CI checks passed locally.
==> Checking risk-tier coverage floor (93%)...
TOTAL  2812     38    748     31    98%

@shivamlalakiya

Copy link
Copy Markdown
Contributor

Thanks, this is careful work. Reading GiftTransaction rather than GiftCommitment, the DonorId-over-ContactId precedence with its DMO citation, keeping Status separate from GiftType, and the sources in the PR body are what #234 asked for. Changes needed before merge:

Blocking

  1. CI: contributor credit. The Changelog and contributor credit check fails because the PR touches philanthropy/ and @vridhib isn't in CONTRIBUTORS.md. Please add yourself in this PR (see "Getting listed").
  2. Only excluding Unpaid still counts money that never arrived. Your own source lists the terminal statuses Canceled, Failed, Fully Refunded and Written Off. With the default, a failed card charge or a written-off installment is summed into total_gift_amount and gift_count at full amount, which is the exact overcount this bridge exists to prevent. The docstring says those rows were "either received or explicitly unwound", but Failed, Canceled and Written Off were never received. Please either switch to an allowlist on Status (keep Paid, plus any other documented received status), the way the NPSP bridge keeps only closed/won stages, or add those four to the default exclusion set. An allowlist is safer for the org-defined custom statuses the module docstring mentions. Please add a test for each terminal status.
  3. Name aliases used as donor keys. donor_name and contact_name map to contact_id. A name is not an ID: two donors who share a name get merged into one row, and the same donor under two spellings gets split. Please drop those two aliases (and remove them from _DONOR_KEY_ALIASES / _CONTACT_KEY_ALIASES).

Should fix

  1. Register in read_gifts. feat: add a Salesforce Nonprofit Cloud gift export reader (ingest preset) #234 says to register in the read_gifts preset registry if it has landed, and it has: add "nonprofit_cloud" to GIFT_SOURCES and _REGISTRY in philanthropy/ingest/_read_gifts.py, plus a test_read_gifts.py case matching the others. The CLI wiring can stay.
  2. Constant name. DEFAULT_EXCLUDED_STATUSES is very generic for a name re-exported from philanthropy.ingest, next to CiviCRM's own statuses= parameter. Something source-specific like DEFAULT_EXCLUDED_GIFT_TRANSACTION_STATUSES (or DEFAULT_INCLUDED_..._STATUSES if you switch to an allowlist) avoids confusion.
  3. Docstring errors in nonprofit_cloud_gifts_to_features. Returns says the frame is "indexed by donor_id"; it's contact_id. It also says "distinct_financial_types counts distinct GiftTypes here", which contradicts the module Notes (GiftType isn't mapped to financial_type).
  4. Small things. Typo "exluded type default" in the docs/reference/index.md row (and it's a status default, not a type default). Trailing whitespace in the CHANGELOG.md entry, the features help string in cli.py, the ingest/__init__.py docstring, and several comment lines in _nonprofit_cloud.py, plus whitespace-only lines after the return in nonprofit_cloud_gifts_to_features. The ingest/__init__.py blurb says the filter stops "a pledged dollar being counted both as the promise and as the payments"; for NPC it's unpaid installments counted as received, so please reword it to match.
  5. The branch is behind main; please update it when you push.

@vridhib

vridhib commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. On 2, I agree after looking at it again that the exclusion set was wrong. Failed, Canceled, Written Off, and Fully Refunded were never received, and the exclusion approach also counts any custom non-paid status an org adds. I'll switch to an allowlist defaulting to ("Paid",) to match the NPSP bridge's DEFAULT_INCLUDED_STAGES pattern, with the necessary tests. On 3, I'll drop donor_name and contact_name since merging two donors who share a name is worse than failing on a missing ID. I'll fix the rest in this PR.

@shivamlalakiya

shivamlalakiya commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Sounds good, an allowlist defaulting to ("Paid",) is the right call. Two details to settle while you're in there:

  1. Partial refunds. GiftTransaction carries RefundedAmount and CurrentAmount is the net, so if Salesforce's status list includes a partial-refund status (e.g. Partially Refunded), a ("Paid",)-only allowlist would drop that whole gift rather than count its net. Please check the Gift Transactions Overview list and include it in the default if it's documented, with a test.
  2. Blank status. Keep rows with a blank status, the same way the NPSP bridge keeps a blank stage under its allowlist (_npsp.py, (keys == "") | keys.isin(wanted)), so the two Salesforce bridges behave alike. Please say so in the include_statuses docs and pin it in a test.

Thanks for turning this around quickly.

@vridhib
vridhib force-pushed the salesforce-nonprofit-cloud-gift-export-reader branch from b5e6d02 to 53c7245 Compare October 8, 2026 22:44
- Add _nonprofit_cloud.py with header aliases and status allowlist, mirroring the NPSP
  and Raiser's Edge commitment versus payment guards
- Export DEFAULT_INCLUDED_GIFT_TRANSACTION_STATUSES, nonprofit_cloud_gifts_to_features,
  and read_nonprofit_cloud_gifts
- Add tests/test_nonprofit_cloud.py at the depth of test_npsp.py
- Add tests to tests/test_read_gifts.py
- Register the source in cli.py, read_gifts.py, docs/reference/index.md, and docs/index.md
- Add CHANGELOG and CONTRIBUTORS entry
@vridhib
vridhib force-pushed the salesforce-nonprofit-cloud-gift-export-reader branch from 53c7245 to 3ecabd0 Compare October 8, 2026 23:41
@vridhib

vridhib commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

For the partial refunds, I checked the Gift Transactions Overview. The documented status values are Unpaid, Paid, Failed, Fully Refunded, Written Off, Canceled, and Pending. There is no status relating to a partial refund. The object exposes IsPartiallyRefunded as a boolean field (not a status value) and the status stays at Paid after a partial refund. Only a full refund (when CurrentAmount is set to 0) moves the row to Fully Refunded. Thus, the default list of ("Paid",) already includes partial refunds, and since the aggregation uses CurrentAmount (already net of the refund), the row contributes what was kept. I've added a note in the include_statuses docstring about the partial refund logic.

For the blank status, I've implemented it as (keys == "") | keys.isin(wanted) in nonprofit_cloud_gifts_to_features, matching _npsp.py. The docstring notes this case and I have a test that ensures both blank and None statuses are kept.

@shivamlalakiya
shivamlalakiya merged commit eec5681 into PhilanthroPy-Project:main Oct 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add a Salesforce Nonprofit Cloud gift export reader (ingest preset)

2 participants