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

B4X
Dim success As Boolean = 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.
Dim http As ChilkatHttp
http.Initialize("http")
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
Dim resp As ChilkatHttpResponse
resp.Initialize

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 Then
    Log("No HTTP response: " & http.LastErrorText)
    Return
End If

If (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
    Dim errorInfo As ChilkatJsonObject
    errorInfo.Initialize
    errorInfo.Load(resp.BodyStr)
    Log("HTTP " & resp.StatusCode & " " & errorInfo.StringOf("name") & " " & errorInfo.StringOf("details[0].issue"))
    Log("PayPal debug ID: " & errorInfo.StringOf("debug_id"))
    Return
End If


Dim result As ChilkatJsonObject
result.Initialize
Dim parsedResult As Boolean = result.Load(resp.BodyStr)
If parsedResult <> True Then
    Log("Expected a JSON response; HTTP " & resp.StatusCode)
    Return
End If

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) Then
    Log("Select the USD inspection link from your catalog.")
    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 result.HasMember("id") = True Then
    result.Delete("id")
End If

If result.HasMember("create_time") = True Then
    result.Delete("create_time")
End If

If result.HasMember("update_time") = True Then
    result.Delete("update_time")
End If

If result.HasMember("status") = True Then
    result.Delete("status")
End If

If result.HasMember("links") = True Then
    result.Delete("links")
End If

If result.HasMember("payment_link") = True Then
    result.Delete("payment_link")
End If

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 Then
    Log("No HTTP response: " & http.LastErrorText)
    Return
End If

If (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
    Dim updateError As ChilkatJsonObject
    updateError.Initialize
    updateError.Load(resp.BodyStr)
    Log("HTTP " & resp.StatusCode & " " & updateError.StringOf("name") & " " & updateError.StringOf("details[0].issue"))
    Log("PayPal debug ID: " & updateError.StringOf("debug_id"))
    Return
End If

Log("The inspection price is now USD 95.00.")