Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

PayPal: Update the price on a reusable payment link

See more PayPal Examples

Retrieve the simple USD inspection link from the create example. Check its item and currency, retain its configuration, and replace the price with USD 95. PUT sends the complete editable definition.

PayPal documentation

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsedResult
LOCAL loUpdateError

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","PAYMENT_RESOURCE_ID")

lnSuccess = loHttp.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$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

IF ((loResult.SizeOfArray("line_items") <> 1) OR (loResult.StringOfEquals("line_items[0].name","Annual inspection",1) <> 1) OR (loResult.StringOfEquals("line_items[0].unit_amount.currency_code","USD",1) <> 1)) THEN
    ? "Select the USD inspection link from your catalog."
    RELEASE loHttp
    RELEASE loResp
    RELEASE loErrorInfo
    RELEASE loResult
    CANCEL
ENDIF

*  Preserve line items, taxes, shipping and checkout settings from the retrieved link.
*  Remove the resource metadata PayPal added to the GET response.
IF (loResult.HasMember("id") = 1) THEN
    loResult.Delete("id")
ENDIF

IF (loResult.HasMember("create_time") = 1) THEN
    loResult.Delete("create_time")
ENDIF

IF (loResult.HasMember("update_time") = 1) THEN
    loResult.Delete("update_time")
ENDIF

IF (loResult.HasMember("status") = 1) THEN
    loResult.Delete("status")
ENDIF

IF (loResult.HasMember("links") = 1) THEN
    loResult.Delete("links")
ENDIF

IF (loResult.HasMember("payment_link") = 1) THEN
    loResult.Delete("payment_link")
ENDIF

loResult.UpdateString("line_items[0].unit_amount.value","95.00")
lnSuccess = loHttp.HttpJson("PUT","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",loResult,"application/json",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
    loUpdateError = CreateObject('Chilkat.JsonObject')
    loUpdateError.Load(loResp.BodyStr)
    ? "HTTP " + STR(loResp.StatusCode) + " " + loUpdateError.StringOf("name") + " " + loUpdateError.StringOf("details[0].issue")
    ? "PayPal debug ID: " + loUpdateError.StringOf("debug_id")
    RELEASE loHttp
    RELEASE loResp
    RELEASE loErrorInfo
    RELEASE loResult
    RELEASE loUpdateError
    CANCEL
ENDIF

? "The inspection price is now USD 95.00."

RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
RELEASE loUpdateError