Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loBody
LOCAL loDate
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsed
lnSuccess = 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.
loHttp = CreateObject('Chilkat.Http')
loHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
loResp = CreateObject('Chilkat.HttpResponse')
* Record only a bank transfer you have already received. Reconcile first if a previous
* attempt timed out.
loHttp.SetUrlVar("id","INVOICE_ID")
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("method","BANK_TRANSFER")
loBody.UpdateString("amount.currency_code","USD")
loBody.UpdateString("amount.value","45.00")
* Use the actual date of the transfer; this example records one made today.
loDate = CreateObject('Chilkat.CkDateTime')
loDate.SetFromCurrentSystemTime()
loBody.UpdateString("payment_date",loDate.GetAsIso8601("YYYY-MM-DD",0))
lnSuccess = loHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/payments",loBody,"application/json",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDate
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loErrorInfo = CreateObject('Chilkat.JsonObject')
loErrorInfo.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loErrorInfo.StringOf("name") + " " + loErrorInfo.StringOf("details[0].issue")
? "PayPal debug ID: " + loErrorInfo.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDate
RELEASE loErrorInfo
CANCEL
ENDIF
loResult = CreateObject('Chilkat.JsonObject')
lnParsed = loResult.Load(loResp.BodyStr)
IF (lnParsed <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDate
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
? "Record ID: " + loResult.StringOf("payment_id")
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDate
RELEASE loErrorInfo
RELEASE loResult