Xbase++ Requires Chilkat v11.0.0+
Xbase++
PayPal: Record a bank transfer against an invoice
See more PayPal Examples
Record USD 45 already received by bank transfer. The invoice may still have a balance. This makes a bookkeeping entry; it does not debit the customer. Save payment_id for reconciliation.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oBody
LOCAL oDate
LOCAL oErrorInfo
LOCAL oResult
LOCAL nParsed
nSuccess := 0
// 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.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "SANDBOX_ACCESS_TOKEN"
oResp := CreateObject("Chilkat.HttpResponse")
// Record only a bank transfer you have already received. Reconcile first if a previous
// attempt timed out.
oHttp:SetUrlVar("id", "INVOICE_ID")
oBody := CreateObject("Chilkat.JsonObject")
oBody:UpdateString("method", "BANK_TRANSFER")
oBody:UpdateString("amount.currency_code", "USD")
oBody:UpdateString("amount.value", "45.00")
// Use the actual date of the transfer; this example records one made today.
oDate := CreateObject("Chilkat.CkDateTime")
oDate:SetFromCurrentSystemTime()
oBody:UpdateString("payment_date", oDate:GetAsIso8601("YYYY-MM-DD", 0))
nSuccess := oHttp:HttpJson("POST", "https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/payments", oBody, "application/json", oResp)
IF (nSuccess != 1)
? "No HTTP response: " + oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oDate:destroy()
RETURN
ENDIF
IF ((oResp:StatusCode < 200) .OR. (oResp:StatusCode >= 300))
oErrorInfo := CreateObject("Chilkat.JsonObject")
oErrorInfo:Load(oResp:BodyStr)
? "HTTP " + Str(oResp:StatusCode) + " " + oErrorInfo:StringOf("name") + " " + oErrorInfo:StringOf("details[0].issue")
? "PayPal debug ID: " + oErrorInfo:StringOf("debug_id")
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oDate:destroy()
oErrorInfo:destroy()
RETURN
ENDIF
oResult := CreateObject("Chilkat.JsonObject")
nParsed := oResult:Load(oResp:BodyStr)
IF (nParsed != 1)
? "Expected a JSON response; HTTP " + Str(oResp:StatusCode)
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oDate:destroy()
oErrorInfo:destroy()
oResult:destroy()
RETURN
ENDIF
? "Record ID: " + oResult:StringOf("payment_id")
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oDate:destroy()
oErrorInfo:destroy()
oResult:destroy()