Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Add documentation about how to migrate off transact api #705

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/financial/OrderAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,37 @@ Notes:

Here is how to create an order for a membership, an event registration, and two separate contribution line items. [ Rich to provide]


## Transitioning from Contribution.transact api to Order api

Contribution.transact api was a v2 api that we left in place in v3. It has never had unit tests & has never been supported. Unfortunately by not being more aggressive about deprecating it some sites have adopted it.

The Contribution.transact api will create a 'simple' contribution and process a payment. It will not create the line items correctly for anything other than a straight forward donation and does not follow our practice of creating a pending contribution and then adding a payment. It's likely there are other unknown gaps in how it works.

The simplest first step to migrate off it is to replace the order api call with a call that follows the recommended flow but still does not address the line item creation gaps & it is recommended you look at the patterns above to do that. This first step looks like

```
# start with the same parameters as Contribution.transact.
$params = $transactParams;
# it would be better just to include the relevant params but....
$paymentParams = $transactParams;
$params['contribution_status_id'] = 'Pending';
if (!isset($params['invoice_id')) {
// Set an invoice_id here if you have not already done so.
// Potentially Order api should do this https://lab.civicrm.org/dev/financial/issues/78
}
if (!isset($params['invoiceID']) {
// This would be required prior to https://lab.civicrm.org/dev/financial/issues/77
$params['invoiceID'] = $params['invoice_id'];
}
$order = civicrm_api3('Order', 'create' $params);
try {
civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
}
catch {
// it failed
}
```

The above is a few more lines but it is an important step towards transitioning to a supported method and away from a flawed api.