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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vResp
    Handle hoResp
    Handle hoErrorInfo
    Variant vResult
    Handle hoResult
    Boolean iParsedResult
    Handle hoUpdateError
    String sTemp1
    String sTemp2
    Integer iTemp1
    Integer iTemp2
    Boolean bTemp1
    Boolean bTemp2

    Move False To iSuccess

    //  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.
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComAuthToken Of hoHttp To "SANDBOX_ACCESS_TOKEN"
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End

    Get ComSetUrlVar Of hoHttp "id" "PAYMENT_RESOURCE_ID" To iSuccess

    Get pvComObject of hoResp to vResp
    Get ComHttpNoBody Of hoHttp "GET" "https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}" vResp To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln "No HTTP response: " sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Get ComStatusCode Of hoResp To iTemp2
    If ((iTemp1 < 200) Or (iTemp2 >= 300)) Begin
        Get Create (RefClass(cComChilkatJsonObject)) To hoErrorInfo
        If (Not(IsComObjectCreated(hoErrorInfo))) Begin
            Send CreateComObject of hoErrorInfo
        End
        Get ComBodyStr Of hoResp To sTemp1
        Get ComLoad Of hoErrorInfo sTemp1 To iSuccess
        Get ComStatusCode Of hoResp To iTemp1
        Get ComStringOf Of hoErrorInfo "name" To sTemp1
        Get ComStringOf Of hoErrorInfo "details[0].issue" To sTemp2
        Showln "HTTP " iTemp1 " " sTemp1 " " sTemp2
        Get ComStringOf Of hoErrorInfo "debug_id" To sTemp1
        Showln "PayPal debug ID: " sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoResult
    If (Not(IsComObjectCreated(hoResult))) Begin
        Send CreateComObject of hoResult
    End
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoad Of hoResult sTemp1 To iParsedResult
    If (iParsedResult <> True) Begin
        Get ComStatusCode Of hoResp To iTemp1
        Showln "Expected a JSON response; HTTP " iTemp1
        Procedure_Return
    End

    Get ComSizeOfArray Of hoResult "line_items" To iTemp1
    Get ComStringOfEquals Of hoResult "line_items[0].name" "Annual inspection" True To bTemp1
    Get ComStringOfEquals Of hoResult "line_items[0].unit_amount.currency_code" "USD" True To bTemp2
    If ((iTemp1 <> 1) Or (bTemp1 <> True) Or (bTemp2 <> True)) Begin
        Showln "Select the USD inspection link from your catalog."
        Procedure_Return
    End

    //  Preserve line items, taxes, shipping and checkout settings from the retrieved link.
    //  Remove the resource metadata PayPal added to the GET response.
    Get ComHasMember Of hoResult "id" To bTemp1
    If (bTemp1 = True) Begin
        Get ComDelete Of hoResult "id" To iSuccess
    End

    Get ComHasMember Of hoResult "create_time" To bTemp1
    If (bTemp1 = True) Begin
        Get ComDelete Of hoResult "create_time" To iSuccess
    End

    Get ComHasMember Of hoResult "update_time" To bTemp1
    If (bTemp1 = True) Begin
        Get ComDelete Of hoResult "update_time" To iSuccess
    End

    Get ComHasMember Of hoResult "status" To bTemp1
    If (bTemp1 = True) Begin
        Get ComDelete Of hoResult "status" To iSuccess
    End

    Get ComHasMember Of hoResult "links" To bTemp1
    If (bTemp1 = True) Begin
        Get ComDelete Of hoResult "links" To iSuccess
    End

    Get ComHasMember Of hoResult "payment_link" To bTemp1
    If (bTemp1 = True) Begin
        Get ComDelete Of hoResult "payment_link" To iSuccess
    End

    Get ComUpdateString Of hoResult "line_items[0].unit_amount.value" "95.00" To iSuccess
    Get pvComObject of hoResult to vResult
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "PUT" "https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}" vResult "application/json" vResp To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln "No HTTP response: " sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Get ComStatusCode Of hoResp To iTemp2
    If ((iTemp1 < 200) Or (iTemp2 >= 300)) Begin
        Get Create (RefClass(cComChilkatJsonObject)) To hoUpdateError
        If (Not(IsComObjectCreated(hoUpdateError))) Begin
            Send CreateComObject of hoUpdateError
        End
        Get ComBodyStr Of hoResp To sTemp1
        Get ComLoad Of hoUpdateError sTemp1 To iSuccess
        Get ComStatusCode Of hoResp To iTemp1
        Get ComStringOf Of hoUpdateError "name" To sTemp1
        Get ComStringOf Of hoUpdateError "details[0].issue" To sTemp2
        Showln "HTTP " iTemp1 " " sTemp1 " " sTemp2
        Get ComStringOf Of hoUpdateError "debug_id" To sTemp1
        Showln "PayPal debug ID: " sTemp1
        Procedure_Return
    End

    Showln "The inspection price is now USD 95.00."


End_Procedure