Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mjwshared
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wmortada
mjwshared
Commits
35ebb009
Commit
35ebb009
authored
4 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Update Mjwpayment.get_payment API to support multiple parameters and options
parent
40cb2ce4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/v3/Mjwpayment.php
+22
-45
22 additions, 45 deletions
api/v3/Mjwpayment.php
with
22 additions
and
45 deletions
api/v3/Mjwpayment.php
+
22
−
45
View file @
35ebb009
...
...
@@ -160,17 +160,12 @@ function _civicrm_api3_mjwpayment_get_payment_spec(&$params) {
'type'
=>
CRM_Utils_Type
::
T_INT
,
'api.aliases'
=>
[
'payment_id'
,
'id'
],
],
'is_payment'
=>
[
'title'
=>
ts
(
'Is Payment'
),
'description'
=>
ts
(
'Is this entry a payment (is_payment=1) or a reversal of a payment (is_payment=0)?'
),
'type'
=>
CRM_Utils_Type
::
T_BOOLEAN
,
'api.default'
=>
TRUE
,
],
];
}
/**
* Retrieve a set of financial transactions which are payments.
* @todo This matches Payment.Get following https://github.com/civicrm/civicrm-core/pull/17071 which will be in CiviCRM 5.26
*
* @param array $params
* Input parameters.
...
...
@@ -180,56 +175,38 @@ function _civicrm_api3_mjwpayment_get_payment_spec(&$params) {
* @throws \CiviCRM_API3_Exception
*/
function
civicrm_api3_mjwpayment_get_payment
(
$params
)
{
$ftParams
=
[];
$params
[
'is_payment'
]
=
TRUE
;
$contributionID
=
$params
[
'entity_id'
]
??
NULL
;
// To get by contribution ID we need to "join" civicrm_financial_trxn.id on civicrm_entity_financial_trxn.financial_trxn_id
// But this is a pseudo API so we can't do that directly (FinancialTrxn can).
if
(
isset
(
$params
[
'entity_id'
])
&&
(
$params
[
'entity_table'
]
===
'civicrm_contribution'
))
{
// In order to support contribution id we need to do an extra lookup.
if
(
$contributionID
)
{
$eftParams
=
[
'entity_id'
=>
$
params
[
'entity_id'
]
,
'entity_table'
=>
$params
[
'entity_table'
]
,
'entity_id'
=>
$
contributionID
,
'entity_table'
=>
'civicrm_contribution'
,
'options'
=>
[
'limit'
=>
0
],
'financial_trxn_id.is_payment'
=>
1
,
];
$eft
=
civicrm_api3
(
'EntityFinancialTrxn'
,
'get'
,
$eftParams
)[
'values'
];
$eftIds
=
[];
foreach
(
$eft
as
$efts
)
{
if
(
empty
(
$efts
[
'financial_trxn_id'
]))
{
continue
;
}
$eftIds
[]
=
$efts
[
'financial_trxn_id'
];
$map
[
$efts
[
'financial_trxn_id'
]]
=
$efts
[
'entity_id'
];
if
(
empty
(
$eft
))
{
return
civicrm_api3_create_success
([],
$params
,
'Payment'
,
'get'
);
}
if
(
!
empty
(
$eftIds
))
{
$ftParams
=
[
'id'
=>
[
'IN'
=>
$eftIds
],
'is_payment'
=>
$params
[
'is_payment'
],
];
foreach
(
$eft
as
$entityFinancialTrxn
)
{
$params
[
'financial_trxn_id'
][
'IN'
][]
=
$entityFinancialTrxn
[
'financial_trxn_id'
];
}
}
// If we have IDs from EntityFinancialTrxn merge them here.
$ftParams
=
array_merge
(
$params
,
$ftParams
);
$ftParams
[
'return'
]
=
array_values
(
CRM_Utils_Array
::
collect
(
'name'
,
civicrm_api3
(
'FinancialTrxn'
,
'getfields'
)[
'values'
]));
$ftParams
[
'return'
][]
=
'id.entity_id'
;
$ftParams
[
'sequential'
]
=
0
;
$financialTrxn
=
civicrm_api3
(
'FinancialTrxn'
,
'get'
,
$ftParams
)[
'values'
];
if
(
empty
(
$eftIds
)
&&
!
empty
(
$financialTrxn
))
{
$eftParams
=
[
'financial_trxn_id'
=>
[
'IN'
=>
array_keys
(
$financialTrxn
)],
'entity_table'
=>
'civicrm_contribution'
,
];
$eft
=
civicrm_api3
(
'EntityFinancialTrxn'
,
'get'
,
$eftParams
)[
'values'
];
foreach
(
$eft
as
$efts
)
{
if
(
empty
(
$efts
[
'financial_trxn_id'
]))
{
continue
;
}
$map
[
$efts
[
'financial_trxn_id'
]]
=
$efts
[
'entity_id'
];
$financialTrxn
=
civicrm_api3
(
'FinancialTrxn'
,
'get'
,
array_merge
(
$params
,
[
'sequential'
=>
FALSE
]))[
'values'
];
if
(
$contributionID
)
{
foreach
(
$financialTrxn
as
&
$values
)
{
$values
[
'contribution_id'
]
=
$contributionID
;
}
}
// Map contribution_id from id.entity_id
foreach
(
$financialTrxn
as
&
$values
)
{
$values
[
'contribution_id'
]
=
$map
[
$values
[
'id'
]]
??
NULL
;
elseif
(
!
empty
(
$financialTrxn
))
{
$entityFinancialTrxns
=
civicrm_api3
(
'EntityFinancialTrxn'
,
'get'
,
[
'financial_trxn_id'
=>
[
'IN'
=>
array_keys
(
$financialTrxn
)],
'entity_table'
=>
'civicrm_contribution'
,
'options'
=>
[
'limit'
=>
0
]])[
'values'
];
foreach
(
$entityFinancialTrxns
as
$entityFinancialTrxn
)
{
$financialTrxn
[
$entityFinancialTrxn
[
'financial_trxn_id'
]][
'contribution_id'
]
=
$entityFinancialTrxn
[
'entity_id'
];
}
}
return
civicrm_api3_create_success
(
$financialTrxn
??
[]
,
$params
,
'Mjwpayment'
,
'get_payment'
);
return
civicrm_api3_create_success
(
$financialTrxn
,
$params
,
'Mjwpayment'
,
'get_payment'
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment