Sample code for 30+ languages & platforms
AutoIt 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 AutoIt Downloads

AutoIt
Local $bSuccess = 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.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("Chilkat.HttpResponse")

$oHttp.SetUrlVar("id","PAYMENT_RESOURCE_ID")

$bSuccess = $oHttp.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",$oResp)
If ($bSuccess <> True) Then
    ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
    Exit
EndIf

If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
    $oErrorInfo = ObjCreate("Chilkat.JsonObject")
    $oErrorInfo.Load($oResp.BodyStr)
    ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
    ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
    Exit
EndIf

$oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsedResult = $oResult.Load($oResp.BodyStr)
If ($bParsedResult <> True) Then
    ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
    Exit
EndIf

If (($oResult.SizeOfArray("line_items") <> 1) Or ($oResult.StringOfEquals("line_items[0].name","Annual inspection",True) <> True) Or ($oResult.StringOfEquals("line_items[0].unit_amount.currency_code","USD",True) <> True)) Then
    ConsoleWrite("Select the USD inspection link from your catalog." & @CRLF)
    Exit
EndIf

;  Preserve line items, taxes, shipping and checkout settings from the retrieved link.
;  Remove the resource metadata PayPal added to the GET response.
If ($oResult.HasMember("id") = True) Then
    $oResult.Delete("id")
EndIf

If ($oResult.HasMember("create_time") = True) Then
    $oResult.Delete("create_time")
EndIf

If ($oResult.HasMember("update_time") = True) Then
    $oResult.Delete("update_time")
EndIf

If ($oResult.HasMember("status") = True) Then
    $oResult.Delete("status")
EndIf

If ($oResult.HasMember("links") = True) Then
    $oResult.Delete("links")
EndIf

If ($oResult.HasMember("payment_link") = True) Then
    $oResult.Delete("payment_link")
EndIf

$oResult.UpdateString("line_items[0].unit_amount.value","95.00")
$bSuccess = $oHttp.HttpJson("PUT","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",$oResult,"application/json",$oResp)
If ($bSuccess <> True) Then
    ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
    Exit
EndIf

If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
    $oUpdateError = ObjCreate("Chilkat.JsonObject")
    $oUpdateError.Load($oResp.BodyStr)
    ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oUpdateError.StringOf("name") & " " & $oUpdateError.StringOf("details[0].issue") & @CRLF)
    ConsoleWrite("PayPal debug ID: " & $oUpdateError.StringOf("debug_id") & @CRLF)
    Exit
EndIf

ConsoleWrite("The inspection price is now USD 95.00." & @CRLF)