Python Requires Chilkat v11.0.0+
Python
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.
Chilkat Python Downloads
import sys
import chilkat2
success = 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.
http = chilkat2.Http()
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
resp = chilkat2.HttpResponse()
http.SetUrlVar("id","PAYMENT_RESOURCE_ID")
success = http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",resp)
if (success != True):
print("No HTTP response: " + http.LastErrorText)
sys.exit()
if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)):
errorInfo = chilkat2.JsonObject()
errorInfo.Load(resp.BodyStr)
print("HTTP " + str(resp.StatusCode) + " " + errorInfo.StringOf("name") + " " + errorInfo.StringOf("details[0].issue"))
print("PayPal debug ID: " + errorInfo.StringOf("debug_id"))
sys.exit()
result = chilkat2.JsonObject()
parsedResult = result.Load(resp.BodyStr)
if (parsedResult != True):
print("Expected a JSON response; HTTP " + str(resp.StatusCode))
sys.exit()
if ((result.SizeOfArray("line_items") != 1) or (result.StringOfEquals("line_items[0].name","Annual inspection",True) != True) or (result.StringOfEquals("line_items[0].unit_amount.currency_code","USD",True) != True)):
print("Select the USD inspection link from your catalog.")
sys.exit()
# Preserve line items, taxes, shipping and checkout settings from the retrieved link.
# Remove the resource metadata PayPal added to the GET response.
if (result.HasMember("id") == True):
result.Delete("id")
if (result.HasMember("create_time") == True):
result.Delete("create_time")
if (result.HasMember("update_time") == True):
result.Delete("update_time")
if (result.HasMember("status") == True):
result.Delete("status")
if (result.HasMember("links") == True):
result.Delete("links")
if (result.HasMember("payment_link") == True):
result.Delete("payment_link")
result.UpdateString("line_items[0].unit_amount.value","95.00")
success = http.HttpJson("PUT","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",result,"application/json",resp)
if (success != True):
print("No HTTP response: " + http.LastErrorText)
sys.exit()
if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)):
updateError = chilkat2.JsonObject()
updateError.Load(resp.BodyStr)
print("HTTP " + str(resp.StatusCode) + " " + updateError.StringOf("name") + " " + updateError.StringOf("details[0].issue"))
print("PayPal debug ID: " + updateError.StringOf("debug_id"))
sys.exit()
print("The inspection price is now USD 95.00.")