SQL Server Requires Chilkat v11.0.0+
SQL Server
PayPal: Revise a draft invoice from its full billing record
See more PayPal Examples
PUT replaces the invoice. This example revises the quantity on the simple two-inspection draft to three. Rebuild the complete editable document from your billing record; omitted items, terms or recipients can be lost. Do not use this body for an unrelated invoice.
Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @iTmp1 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
-- Use only the ID of the matching draft from the create example, while it is still a
-- draft. Preserve all of your real draft fields, including any custom invoice number.
EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'id', 'INVOICE_ID'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Prefer', 'return=representation'
DECLARE @body int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @body OUT
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'detail.currency_code', 'USD'
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'detail.payment_term.term_type', 'NET_30'
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'primary_recipients[0].billing_info.email_address', 'buyer@example.com'
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'items[0].name', 'Equipment inspection'
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'items[0].quantity', '3'
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'items[0].unit_amount.currency_code', 'USD'
EXEC sp_OAMethod @body, 'UpdateString', @success OUT, 'items[0].unit_amount.value', '45.00'
EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'PUT', 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}', @body, '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 @body
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 @body
EXEC @hr = sp_OADestroy @errorInfo
RETURN
END
DECLARE @result int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @result OUT
DECLARE @parsed int
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
EXEC sp_OAMethod @result, 'Load', @parsed OUT, @sTmp0
IF @parsed <> 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 @body
EXEC @hr = sp_OADestroy @errorInfo
EXEC @hr = sp_OADestroy @result
RETURN
END
EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'id'
PRINT 'ID: ' + @sTmp0
EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'status'
PRINT 'Status: ' + @sTmp0
EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'amount.value'
PRINT 'New total: ' + @sTmp0
EXEC sp_OAMethod @result, 'StringOf', @sTmp0 OUT, 'amount.currency_code'
PRINT 'Currency: ' + @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @body
EXEC @hr = sp_OADestroy @errorInfo
EXEC @hr = sp_OADestroy @result
END
GO