Swift Requires Chilkat v11.0.0+
Swift
PayPal: Remind a customer about an unpaid invoice
See more PayPal Examples
Send a reminder about an outstanding invoice using a short subject and note. PayPal uses the invoice recipient; no new invoice or charge is created.
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 ID of the outstanding invoice. PayPal finds the recipient from that invoice.
http.setUrlVar(name: "id", value: "INVOICE_ID")
let body = CkoJsonObject()!
body.updateString(jsonPath: "subject", value: "Reminder: equipment inspection invoice")
body.updateString(jsonPath: "note", value: "Our records show a balance due. Please use the payment link on your invoice.")
body.updateBool(jsonPath: "send_to_recipient", value: true)
success = http.httpJson(verb: "POST", url: "https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/remind", json: body, contentType: "application/json", 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
}
print("Reminder accepted; HTTP \(resp.statusCode.intValue)")
}