Swift Requires Chilkat v11.0.0+
Swift
PayPal: Reconcile a transaction ID in a reporting window
See more PayPal Examples
Supply the reporting transaction ID and a window containing the activity. Return all matches: transaction IDs are not necessarily unique in the report. Include non-balance-affecting records when reconciling an event.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// See Unlock Chilkat before making requests.
// For the merchant's internal backoffice application. Load the sandbox token
// from the merchant's credential store. Keep it out of publicly distributed apps.
// See Get a PayPal access token.
let http = CkoHttp()!
http.authToken = "SANDBOX_ACCESS_TOKEN"
let resp = CkoHttpResponse()!
// Use the UTC window containing the transaction (at most 31 days per request).
let dt = CkoDateTime()!
dt.setFromCurrentSystemTime()
let query = CkoJsonObject()!
query.updateString(jsonPath: "end_date", value: dt.get(asTimestamp: false))
dt.addDays(numDays: -1)
query.updateString(jsonPath: "start_date", value: dt.get(asTimestamp: false))
query.updateString(jsonPath: "fields", value: "transaction_info")
query.updateInt(jsonPath: "page_size", value: 100)
query.updateString(jsonPath: "transaction_id", value: "REPORT_TRANSACTION_ID")
query.updateString(jsonPath: "balance_affecting_records_only", value: "N")
var page: Int = 1
var lastPage: Int = 1
while (page <= lastPage) {
query.updateInt(jsonPath: "page", value: page)
success = http.httpParams(verb: "GET", url: "https://api-m.sandbox.paypal.com/v1/reporting/transactions", json: query, response: resp)
if success != true {
print("No HTTP response: \(http.lastErrorText!)")
return
}
if (resp.statusCode.intValue < 200) || (resp.statusCode.intValue >= 300) {
let errorInfo = CkoJsonObject()!
errorInfo.load(json: resp.bodyStr)
print("HTTP \(resp.statusCode.intValue) \(errorInfo.string(of: "name")!) \(errorInfo.string(of: "details[0].issue")!)")
print("PayPal debug ID: \(errorInfo.string(of: "debug_id")!)")
return
}
let result = CkoJsonObject()!
var parsed: Bool = result.load(json: resp.bodyStr)
if parsed != true {
print("Expected a JSON response; HTTP \(resp.statusCode.intValue)")
return
}
var i: Int = 0
var count: Int = result.size(ofArray: "transaction_details").intValue
while (i < count) {
result.i = i
print("\(result.string(of: "transaction_details[i].transaction_info.transaction_id")!) \(result.string(of: "transaction_details[i].transaction_info.transaction_event_code")!) \(result.string(of: "transaction_details[i].transaction_info.transaction_status")!)")
print(" \(result.string(of: "transaction_details[i].transaction_info.transaction_amount.value")!) \(result.string(of: "transaction_details[i].transaction_info.transaction_amount.currency_code")!)")
i = i + 1
}
lastPage = result.int(of: "total_pages").intValue
page = page + 1
}
}