Swift Requires Chilkat v11.0.0+
Swift
PayPal: Submit proof of fulfillment for a dispute
See more PayPal Examples
Inspect the actions and evidence requested for a selected dispute. When PayPal requests proof of fulfillment from the seller, attach the matching carrier receipt PDF with tracking details in a multipart request. Replace the file and tracking number with those for this case.
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()!
http.setUrlVar(name: "id", value: "DISPUTE_ID")
success = http.httpNoBody(verb: "GET", url: "https://api-m.sandbox.paypal.com/v1/customer/disputes/{$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 parsedResult: Bool = result.load(json: resp.bodyStr)
if parsedResult != true {
print("Expected a JSON response; HTTP \(resp.statusCode.intValue)")
return
}
var canSubmit: Bool = false
var linkIndex: Int = 0
while (linkIndex < result.size(ofArray: "links").intValue) {
result.i = linkIndex
if result.string(ofEquals: "links[i].rel", value: "provide_evidence", caseSensitive: true) == true {
canSubmit = true
}
linkIndex = linkIndex + 1
}
var requested: Bool = false
var i: Int = 0
while (i < result.size(ofArray: "evidences").intValue) {
result.i = i
if (result.string(ofEquals: "evidences[i].evidence_type", value: "PROOF_OF_FULFILLMENT", caseSensitive: true) == true) && (result.string(ofEquals: "evidences[i].source", value: "REQUESTED_FROM_SELLER", caseSensitive: true) == true) {
requested = true
}
i = i + 1
}
if (canSubmit != true) || (requested != true) {
print("PayPal is not requesting seller fulfillment evidence for this case.")
return
}
let body = CkoJsonObject()!
body.updateString(jsonPath: "evidences[0].evidence_type", value: "PROOF_OF_FULFILLMENT")
body.updateString(jsonPath: "evidences[0].evidence_info.tracking_info[0].carrier_name", value: "FEDEX")
body.updateString(jsonPath: "evidences[0].evidence_info.tracking_info[0].tracking_number", value: "123456789012")
body.updateString(jsonPath: "evidences[0].notes", value: "The attached carrier receipt corresponds to this shipment.")
let upload = CkoHttpRequest()!
upload.httpVerb = "POST"
upload.contentType = "multipart/form-data"
success = upload.addString(forUpload2: "input", filename: "", strData: body.emit(), charset: "utf-8", contentType: "application/json")
if success != true {
print("\(upload.lastErrorText!)")
return
}
success = upload.addFile(forUpload2: "file1", path: "carrier-receipt.pdf", contentType: "application/pdf")
if success != true {
print("\(upload.lastErrorText!)")
return
}
success = http.httpReq(url: "https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence", request: upload, response: resp)
if success != true {
print("No HTTP response: \(http.lastErrorText!)")
return
}
if (resp.statusCode.intValue < 200) || (resp.statusCode.intValue >= 300) {
let submitError = CkoJsonObject()!
submitError.load(json: resp.bodyStr)
print("HTTP \(resp.statusCode.intValue) \(submitError.string(of: "name")!) \(submitError.string(of: "details[0].issue")!)")
print("PayPal debug ID: \(submitError.string(of: "debug_id")!)")
return
}
print("PayPal accepted the evidence.")
}