PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_ErrorInfo
oleobject loo_Result
long li_ParsedResult
oleobject loo_UpdateError
li_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.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.AuthToken = "SANDBOX_ACCESS_TOKEN"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Http.SetUrlVar("id","PAYMENT_RESOURCE_ID")
li_Success = loo_Http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",loo_Resp)
if li_Success <> 1 then
Write-Debug "No HTTP response: " + loo_Http.LastErrorText
destroy loo_Http
destroy loo_Resp
return
end if
if (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
loo_ErrorInfo = create oleobject
li_rc = loo_ErrorInfo.ConnectToNewObject("Chilkat.JsonObject")
loo_ErrorInfo.Load(loo_Resp.BodyStr)
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + " " + loo_ErrorInfo.StringOf("name") + " " + loo_ErrorInfo.StringOf("details[0].issue")
Write-Debug "PayPal debug ID: " + loo_ErrorInfo.StringOf("debug_id")
destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
return
end if
loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")
li_ParsedResult = loo_Result.Load(loo_Resp.BodyStr)
if li_ParsedResult <> 1 then
Write-Debug "Expected a JSON response; HTTP " + string(loo_Resp.StatusCode)
destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
destroy loo_Result
return
end if
if (loo_Result.SizeOfArray("line_items") <> 1) OR (loo_Result.StringOfEquals("line_items[0].name","Annual inspection",1) <> 1) OR (loo_Result.StringOfEquals("line_items[0].unit_amount.currency_code","USD",1) <> 1) then
Write-Debug "Select the USD inspection link from your catalog."
destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
destroy loo_Result
return
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 loo_Result.HasMember("id") = 1 then
loo_Result.Delete("id")
end if
if loo_Result.HasMember("create_time") = 1 then
loo_Result.Delete("create_time")
end if
if loo_Result.HasMember("update_time") = 1 then
loo_Result.Delete("update_time")
end if
if loo_Result.HasMember("status") = 1 then
loo_Result.Delete("status")
end if
if loo_Result.HasMember("links") = 1 then
loo_Result.Delete("links")
end if
if loo_Result.HasMember("payment_link") = 1 then
loo_Result.Delete("payment_link")
end if
loo_Result.UpdateString("line_items[0].unit_amount.value","95.00")
li_Success = loo_Http.HttpJson("PUT","https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}",loo_Result,"application/json",loo_Resp)
if li_Success <> 1 then
Write-Debug "No HTTP response: " + loo_Http.LastErrorText
destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
destroy loo_Result
return
end if
if (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
loo_UpdateError = create oleobject
li_rc = loo_UpdateError.ConnectToNewObject("Chilkat.JsonObject")
loo_UpdateError.Load(loo_Resp.BodyStr)
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + " " + loo_UpdateError.StringOf("name") + " " + loo_UpdateError.StringOf("details[0].issue")
Write-Debug "PayPal debug ID: " + loo_UpdateError.StringOf("debug_id")
destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
destroy loo_Result
destroy loo_UpdateError
return
end if
Write-Debug "The inspection price is now USD 95.00."
destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
destroy loo_Result
destroy loo_UpdateError