Script to retrieve transactions pending authorization

Any issue about Cyclos 4 scripting and Webservices

Moderators: alexandre, hugo, rmvanarkel

Post Reply
mcash
Posts: 14
Joined: Thu Jul 28, 2022 10:26 am

Script to retrieve transactions pending authorization

Post by mcash »

Hello,

I'd like to retrieve transactions pending authorization so as to permit bulk authorization.

I do not seen to see anything in the class reference to permit retrieval of transactions pending authorization. Any one able to share any pointers?

For context I am able to list transactions that have already succeeded with the script below

import org.cyclos.model.banking.transactions.TransactionQuery
import org.cyclos.entities.banking.Transfer

def q = new TransactionQuery()
q.setUnlimited()
def transfers=transactionService.search(q)
for (transfer in transfers) {
println transfer.dump()
}
rajesh
Posts: 22
Joined: Thu Jan 20, 2022 8:35 am

Re: Script to retrieve transactions pending authorization

Post by rajesh »

All you need is to include the query. Find the below sample.

Code: Select all

import org.cyclos.model.banking.transactions.TransactionAuthorizationStatus
import org.cyclos.model.banking.transactions.TransactionQuery

def q = new TransactionQuery()
q.authorizationStatuses = [TransactionAuthorizationStatus.PENDING_AUTHORIZATION]
q.setUnlimited()
def transfers = transactionService.search(q)
for (transfer in transfers) {
    println transfer.dump()
}
mcash
Posts: 14
Joined: Thu Jul 28, 2022 10:26 am

Re: Script to retrieve transactions pending authorization

Post by mcash »

Thanks for your response Rajesh.

However this does not return anything (and I'm sure the user I'm running it as has has two transactions awaiting authorization). Transfers has zero items:

Code: Select all

<org.cyclos.utils.PageImpl@72709060 pageItems=[] currentPage=0 pageSize=1000 totalCount=0 hasNextPage=false>
In the meantime I'm also looking at the service TransactionAuthorizationService that claims to:
Service interface for transaction authorizations.
It allow authorize, deny etc a transaction and search for transactions to authorize and already authorized.

Although its implementation does not seem to include any search function as per this link: https://documentation.cyclos.org/4.15.6/scripting-api-docs/org/cyclos/impl/banking/TransactionAuthorizationServiceImpl.html

Will keep on trying various things till I crack it.
rajesh
Posts: 22
Joined: Thu Jan 20, 2022 8:35 am

Re: Script to retrieve transactions pending authorization

Post by rajesh »

I have given the script after verification, am not sure why is not returning any rows to you.
Please note that transfers will be created only after (all) transaction authorizations. So, you will have to use TransacactionService, may be you shall try with TransactionOverviewQuery at your end.
luis
Posts: 265
Joined: Fri Feb 17, 2006 11:01 am

Re: Script to retrieve transactions pending authorization

Post by luis »

Hi mcash.
The javadoc of the service is outdated, since 4.14, when we merged the transaction authorization search with the transaction search itself.

rajesh's answer uses a search with the point-of-view of an account owner, ie, transactions with positive / negative amounts are returned.

You could try, instead, this script for searching a transaction overview, in which each result has a from and to (and always positive amount), instead of a related account. Also, I've modified it a bit in order to iterate, so, if you have too many, it won't load thousands of entries in memory. Finally, I've included an example on how to authorize them all at once.

Code: Select all

import org.cyclos.model.banking.authorizations.TransactionAuthorizationDTO
import org.cyclos.model.banking.transactions.TransactionAuthorizationStatus
import org.cyclos.model.banking.transactions.TransactionOverviewQuery
import org.cyclos.model.banking.transactions.TransactionVO

def affected = 0
def q = new TransactionOverviewQuery()
q.authorizationStatuses = [TransactionAuthorizationStatus.PENDING_AUTHORIZATION]
def transactions = transactionSearchHandler.iterateEntities(q)
scriptHelper.processBatch(transactions) { transaction ->
    transactionAuthorizationService.authorize(new TransactionAuthorizationDTO(
        transaction: new TransactionVO(transaction.id)
    ))
    affected++
}
return "Authorized $affected pending transactions"
Luis Fernando Planella Gonzalez
Cyclos development team
mcash
Posts: 14
Joined: Thu Jul 28, 2022 10:26 am

Re: Script to retrieve transactions pending authorization

Post by mcash »

Thanks a lot Luis.

This works perfectly
Post Reply