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

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @iTmp1 int
    DECLARE @iTmp2 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @sTmp1 nvarchar(4000)
    DECLARE @success int
    SELECT @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.
    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @http, 'AuthToken', 'SANDBOX_ACCESS_TOKEN'
    DECLARE @resp int
    EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT

    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'id', 'PAYMENT_RESOURCE_ID'

    EXEC sp_OAMethod @http, 'HttpNoBody', @success OUT, 'GET', 'https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}', @resp
    IF @success <> 1
      BEGIN

        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT 'No HTTP response: ' + @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp1 OUT
    IF (@iTmp0 < 200) or (@iTmp1 >= 300)
      BEGIN
        DECLARE @errorInfo int
        EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @errorInfo OUT

        EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
        EXEC sp_OAMethod @errorInfo, 'Load', @success OUT, @sTmp0

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT

        EXEC sp_OAMethod @errorInfo, 'StringOf', @sTmp0 OUT, 'name'

        EXEC sp_OAMethod @errorInfo, 'StringOf', @sTmp1 OUT, 'details[0].issue'
        PRINT 'HTTP ' + @iTmp0 + ' ' + @sTmp0 + ' ' + @sTmp1

        EXEC sp_OAMethod @errorInfo, 'StringOf', @sTmp0 OUT, 'debug_id'
        PRINT 'PayPal debug ID: ' + @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @errorInfo
        RETURN
      END

    DECLARE @result int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @result OUT

    DECLARE @parsedResult int
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    EXEC sp_OAMethod @result, 'Load', @parsedResult OUT, @sTmp0
    IF @parsedResult <> 1
      BEGIN

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
        PRINT 'Expected a JSON response; HTTP ' + @iTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @errorInfo
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    EXEC sp_OAMethod @result, 'SizeOfArray', @iTmp0 OUT, 'line_items'
    EXEC sp_OAMethod @result, 'StringOfEquals', @iTmp1 OUT, 'line_items[0].name', 'Annual inspection', 1
    EXEC sp_OAMethod @result, 'StringOfEquals', @iTmp2 OUT, 'line_items[0].unit_amount.currency_code', 'USD', 1
    IF (@iTmp0 <> 1) or (@iTmp1 <> 1) or (@iTmp2 <> 1)
      BEGIN

        PRINT 'Select the USD inspection link from your catalog.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @errorInfo
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    --  Preserve line items, taxes, shipping and checkout settings from the retrieved link.
    --  Remove the resource metadata PayPal added to the GET response.
    EXEC sp_OAMethod @result, 'HasMember', @iTmp0 OUT, 'id'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @result, 'Delete', @success OUT, 'id'
      END
    EXEC sp_OAMethod @result, 'HasMember', @iTmp0 OUT, 'create_time'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @result, 'Delete', @success OUT, 'create_time'
      END
    EXEC sp_OAMethod @result, 'HasMember', @iTmp0 OUT, 'update_time'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @result, 'Delete', @success OUT, 'update_time'
      END
    EXEC sp_OAMethod @result, 'HasMember', @iTmp0 OUT, 'status'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @result, 'Delete', @success OUT, 'status'
      END
    EXEC sp_OAMethod @result, 'HasMember', @iTmp0 OUT, 'links'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @result, 'Delete', @success OUT, 'links'
      END
    EXEC sp_OAMethod @result, 'HasMember', @iTmp0 OUT, 'payment_link'
    IF @iTmp0 = 1
      BEGIN
        EXEC sp_OAMethod @result, 'Delete', @success OUT, 'payment_link'
      END
    EXEC sp_OAMethod @result, 'UpdateString', @success OUT, 'line_items[0].unit_amount.value', '95.00'
    EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'PUT', 'https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}', @result, 'application/json', @resp
    IF @success <> 1
      BEGIN

        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT 'No HTTP response: ' + @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @errorInfo
        EXEC @hr = sp_OADestroy @result
        RETURN
      END
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp1 OUT
    IF (@iTmp0 < 200) or (@iTmp1 >= 300)
      BEGIN
        DECLARE @updateError int
        EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @updateError OUT

        EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
        EXEC sp_OAMethod @updateError, 'Load', @success OUT, @sTmp0

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT

        EXEC sp_OAMethod @updateError, 'StringOf', @sTmp0 OUT, 'name'

        EXEC sp_OAMethod @updateError, 'StringOf', @sTmp1 OUT, 'details[0].issue'
        PRINT 'HTTP ' + @iTmp0 + ' ' + @sTmp0 + ' ' + @sTmp1

        EXEC sp_OAMethod @updateError, 'StringOf', @sTmp0 OUT, 'debug_id'
        PRINT 'PayPal debug ID: ' + @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @errorInfo
        EXEC @hr = sp_OADestroy @result
        EXEC @hr = sp_OADestroy @updateError
        RETURN
      END

    PRINT 'The inspection price is now USD 95.00.'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @resp
    EXEC @hr = sp_OADestroy @errorInfo
    EXEC @hr = sp_OADestroy @result
    EXEC @hr = sp_OADestroy @updateError


END
GO