Skip to content
payrocdevelopers

Retrieve transactions

Retrieve a single transaction or list multiple transactions with the Tap to Pay on iPhone SDK using the reporting listener.

Prerequisites: Authentication · Run a sale

You can use the SDK to view your transactions, which include sales and refunds.

The steps that you follow depend on whether you want to retrieve a single transaction or list your transactions.

We return all results to the CoreAPIReportingListener.

Retrieve a single transaction

Before you retrieve a single transaction, you need to have the uniqueRef of the transaction. If you don't have the uniqueRef, go to List your transactions.

To retrieve a transaction, register the reporting listener, and then call getTransaction: with the uniqueRef.

Step 1. Register the reporting listener

  • Register CoreAPIReportingListener when your view appears, and unregister it when the view disappears.

Swift

swift
// viewWillAppear:
terminal.register(self as CoreAPIReportingListener)

// viewWillDisappear:
terminal.unRegister(self as CoreAPIReportingListener)

Objective-C

objectivec
// viewWillAppear:
[[WTPSTerminal singleton] registerCoreAPIReportingListener:self];

// viewWillDisappear:
[[WTPSTerminal singleton] unRegisterCoreAPIReportingListener:self];

Step 2. Retrieve the transaction

  • Call getTransaction: with a uniqueRef to get the full details of a transaction.

Swift

swift
terminal.getTransaction(uniqueRef)

Objective-C

objectivec
[[WTPSTerminal singleton] getTransaction:uniqueRef];

The SDK returns the transaction details to onTransactionRetrieved: as a CoreResponse.

List your transactions

If you want to view a list of your transactions, you can use the SDK to return multiple transactions. To handle large numbers of results, the SDK uses pagination to split the request into multiple pages. You can then navigate the pages to view all the transactions that the SDK returned.

To list your transactions, register your reporting listener, and then call getTransactions: with optional filters. You can then navigate through the results.

Step 1. Register the reporting listener

  • Register CoreAPIReportingListener when your view appears, and unregister it when the view disappears.

Swift

swift
// viewWillAppear:
terminal.register(self as CoreAPIReportingListener)

// viewWillDisappear:
terminal.unRegister(self as CoreAPIReportingListener)

Objective-C

objectivec
// viewWillAppear:
[[WTPSTerminal singleton] registerCoreAPIReportingListener:self];

// viewWillDisappear:
[[WTPSTerminal singleton] unRegisterCoreAPIReportingListener:self];

Step 2. List transactions

  1. Create a CoreTransactionFilter.
  2. (Optional) To filter your results by date, send a value for startDate and for endDate.
  3. (Optional) To filter your results by transaction state, send a value for state.
  4. (Optional) To adjust the number of results returned in each page, send a value for resultsPerPage.
  5. Call getTransactions:.

The following example lists transactions with filters for transaction state and dates. The example also specifies that the SDK returns 25 results in each page:

Swift

swift
let filter = CoreTransactionFilter()
filter.state = OPEN // OPEN, CLOSED, or ALL

let calendar = NSCalendar(calendarIdentifier: .gregorian)!

var from = calendar.components([.day, .month, .year], from: fromDatePicker.date)
from.hour = 0; from.minute = 0; from.second = 0
filter.startDate = calendar.date(from: from)

var to = calendar.components([.day, .month, .year], from: toDatePicker.date)
to.hour = 23; to.minute = 59; to.second = 59
filter.endDate = calendar.date(from: to)

filter.resultsPerPage = 25

terminal.getTransactions(filter)

Objective-C

objectivec
CoreTransactionFilter *filter = [[CoreTransactionFilter alloc] init];
filter.state = OPEN; // OPEN, CLOSED, or ALL

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

NSDateComponents *from = [calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear)
                                     fromDate:self.fromDate.date];
from.hour = 0; from.minute = 0; from.second = 0;
filter.startDate = [calendar dateFromComponents:from];

NSDateComponents *to = [calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear)
                                   fromDate:self.toDate.date];
to.hour = 23; to.minute = 59; to.second = 59;
filter.endDate = [calendar dateFromComponents:to];

filter.resultsPerPage = @25;

[[WTPSTerminal singleton] getTransactions:filter];

The SDK returns the results to onTransactionListResponse: in a CoreTransactions object. The CoreTransactions object has a transactionSummary array of CoreTransactionSummary items, each containing information about a transaction.

Note: CoreTransactionSummary doesn't include receipt information. If you want to view merchantReceipt or cardholderReceipt, retrieve the single transaction instead.

The following code prints each result to the console:

Swift

swift
func onTransactionListResponse(_ transactions: CoreTransactions!) {
    guard let summaries = transactions.transactionSummary, summaries.count > 0 else {
        return // No more results
    }
    for case let summary as CoreTransactionSummary in summaries {
        print("\(summary.uniqueRef ?? "") - \(summary.transactionType ?? "") \(summary.amount ?? 0)")
    }
}

Objective-C

objectivec
- (void)onTransactionListResponse:(CoreTransactions *)transactions {
    if (transactions.transactionSummary.count == 0) {
        return; // No more results
    }
    for (CoreTransactionSummary *summary in transactions.transactionSummary) {
        NSLog(@"%@ - %@ %@", summary.uniqueRef, summary.transactionType, summary.amount);
    }
}

Step 3. Navigate through the results

When the SDK returns the CoreTransactions object, it includes a next field.

To get the next page, set filter.next to the value that you received in the next field, and then call getTransactions: again. If there are no more results, the SDK doesn't return a next value.

The following code navigates to the next page of results:

Swift

swift
// In onTransactionListResponse: store the next cursor
nextPage = transactions.next

// When the last visible row is displayed:
if let nextPageRef = nextPage, !nextPageRef.isEmpty {
    filter.next = nextPageRef
    terminal.getTransactions(filter)
}

Objective-C

objectivec
// In onTransactionListResponse: store the next cursor
self.nextPage = transactions.next;

// When the last visible row is displayed:
if (self.nextPage.length > 0) {
    filter.next = self.nextPage;
    [[WTPSTerminal singleton] getTransactions:filter];
}

Browse guides

Search documentation

API reference169
Guides118
Knowledge38
legal1
Solutions32
Workflows74
↑↓highlight↵openView all search results

Menu

Theme

Sign out

Your saved plans remain in your organization. This browser’s private draft and account view will be cleared.

Talk to an engineer