Classic ASP Requires Chilkat v11.0.0+
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 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.
set http = Server.CreateObject("Chilkat.Http")
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
set resp = Server.CreateObject("Chilkat.HttpResponse")
success = http.SetUrlVar("id","PAYMENT_RESOURCE_ID")
success = http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",resp)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response: " & http.LastErrorText) & "</pre>"
Response.End
End If
If ((resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
set errorInfo = Server.CreateObject("Chilkat.JsonObject")
success = errorInfo.Load(resp.BodyStr)
Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & " " & errorInfo.StringOf("name") & " " & errorInfo.StringOf("details[0].issue")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "PayPal debug ID: " & errorInfo.StringOf("debug_id")) & "</pre>"
Response.End
End If
set result = Server.CreateObject("Chilkat.JsonObject")
parsedResult = result.Load(resp.BodyStr)
If (parsedResult <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON response; HTTP " & resp.StatusCode) & "</pre>"
Response.End
End If
If ((result.SizeOfArray("line_items") <> 1) Or (result.StringOfEquals("line_items[0].name","Annual inspection",1) <> 1) Or (result.StringOfEquals("line_items[0].unit_amount.currency_code","USD",1) <> 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Select the USD inspection link from your catalog.") & "</pre>"
Response.End
End If
' 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") = 1) Then
success = result.Delete("id")
End If
If (result.HasMember("create_time") = 1) Then
success = result.Delete("create_time")
End If
If (result.HasMember("update_time") = 1) Then
success = result.Delete("update_time")
End If
If (result.HasMember("status") = 1) Then
success = result.Delete("status")
End If
If (result.HasMember("links") = 1) Then
success = result.Delete("links")
End If
If (result.HasMember("payment_link") = 1) Then
success = result.Delete("payment_link")
End If
success = 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 <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response: " & http.LastErrorText) & "</pre>"
Response.End
End If
If ((resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
set updateError = Server.CreateObject("Chilkat.JsonObject")
success = updateError.Load(resp.BodyStr)
Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & " " & updateError.StringOf("name") & " " & updateError.StringOf("details[0].issue")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "PayPal debug ID: " & updateError.StringOf("debug_id")) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "The inspection price is now USD 95.00.") & "</pre>"
%>
</body>
</html>