Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
PayPal: Remove an external payment recorded on the wrong invoice
See more PayPal Examples
Use the saved external payment record ID. Verify that it belongs to the selected invoice, then remove the bookkeeping entry. The bank transfer itself is unaffected. Record it on the correct invoice as a separate step.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsedResult
LOCAL lcPaymentId
LOCAL lnMatched
LOCAL i
LOCAL loRemoveError
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')
loHttp.SetUrlVar("id","INVOICE_ID")
lnSuccess = loHttp.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
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 loErrorInfo
CANCEL
ENDIF
loResult = CreateObject('Chilkat.JsonObject')
lnParsedResult = loResult.Load(loResp.BodyStr)
IF (lnParsedResult <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
lcPaymentId = "EXTERNAL_PAYMENT_ID"
lnMatched = 0
i = 0
DO WHILE (i < loResult.SizeOfArray("payments.transactions"))
loResult.I = i
IF ((loResult.StringOfEquals("payments.transactions[i].payment_id",lcPaymentId,1) = 1) AND (loResult.StringOfEquals("payments.transactions[i].type","EXTERNAL",1) = 1)) THEN
lnMatched = 1
ENDIF
i = i + 1
ENDDO
IF (lnMatched <> 1) THEN
? "This invoice has no matching external payment record."
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
loHttp.SetUrlVar("paymentId",lcPaymentId)
lnSuccess = loHttp.HttpNoBody("DELETE","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/payments/{$paymentId}",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loRemoveError = CreateObject('Chilkat.JsonObject')
loRemoveError.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loRemoveError.StringOf("name") + " " + loRemoveError.StringOf("details[0].issue")
? "PayPal debug ID: " + loRemoveError.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
RELEASE loRemoveError
CANCEL
ENDIF
? "External payment entry removed."
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
RELEASE loRemoveError