Swift Requires Chilkat v11.0.0+
Swift
PayPal: Look up a checkout order
See more PayPal Examples
Read intent, order status and the amount requested for each purchase unit. A completed checkout order can contain payment resources with their own statuses; use their IDs to inspect individual captures or authorizations.
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()!
// Look up the order itself; its ID does not identify an individual capture.
http.setUrlVar(name: "id", value: "ORDER_ID")
success = http.httpNoBody(verb: "GET", url: "https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}", 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
}
print("ID: \(result.string(of: "id")!)")
print("Status: \(result.string(of: "status")!)")
print("Intent: \(result.string(of: "intent")!)")
var i: Int = 0
while (i < result.size(ofArray: "purchase_units").intValue) {
result.i = i
print("\(result.string(of: "purchase_units[i].reference_id")!): \(result.string(of: "purchase_units[i].amount.value")!) \(result.string(of: "purchase_units[i].amount.currency_code")!)")
i = i + 1
}
}