Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
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 Delphi ActiveX Downloads
var
success: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
errorInfo: TChilkatJsonObject;
result: TChilkatJsonObject;
parsedResult: Integer;
updateError: TChilkatJsonObject;
begin
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.
http := TChilkatHttp.Create(Self);
http.AuthToken := 'SANDBOX_ACCESS_TOKEN';
resp := TChilkatHttpResponse.Create(Self);
http.SetUrlVar('id','PAYMENT_RESOURCE_ID');
success := http.HttpNoBody('GET','https://api-m.sandbox.paypal.com/v1/checkout/payment-resources/{$id}',resp.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add('No HTTP response: ' + http.LastErrorText);
Exit;
end;
if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
begin
errorInfo := TChilkatJsonObject.Create(Self);
errorInfo.Load(resp.BodyStr);
Memo1.Lines.Add('HTTP ' + IntToStr(resp.StatusCode) + ' ' + errorInfo.StringOf('name') + ' ' + errorInfo.StringOf('details[0].issue'));
Memo1.Lines.Add('PayPal debug ID: ' + errorInfo.StringOf('debug_id'));
Exit;
end;
result := TChilkatJsonObject.Create(Self);
parsedResult := result.Load(resp.BodyStr);
if (parsedResult <> 1) then
begin
Memo1.Lines.Add('Expected a JSON response; HTTP ' + IntToStr(resp.StatusCode));
Exit;
end;
if ((result.SizeOfArray('line_items') <> 1) or (result.StringOfEquals('line_items[0].name','Annual inspection',1) <> 1) or (result.StringOfEquals('line_items[0].unit_amount.currency_code','USD',1) <> 1)) then
begin
Memo1.Lines.Add('Select the USD inspection link from your catalog.');
Exit;
end;
// 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') = 1) then
begin
result.Delete('id');
end;
if (result.HasMember('create_time') = 1) then
begin
result.Delete('create_time');
end;
if (result.HasMember('update_time') = 1) then
begin
result.Delete('update_time');
end;
if (result.HasMember('status') = 1) then
begin
result.Delete('status');
end;
if (result.HasMember('links') = 1) then
begin
result.Delete('links');
end;
if (result.HasMember('payment_link') = 1) then
begin
result.Delete('payment_link');
end;
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.ControlInterface,'application/json',resp.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add('No HTTP response: ' + http.LastErrorText);
Exit;
end;
if ((resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
begin
updateError := TChilkatJsonObject.Create(Self);
updateError.Load(resp.BodyStr);
Memo1.Lines.Add('HTTP ' + IntToStr(resp.StatusCode) + ' ' + updateError.StringOf('name') + ' ' + updateError.StringOf('details[0].issue'));
Memo1.Lines.Add('PayPal debug ID: ' + updateError.StringOf('debug_id'));
Exit;
end;
Memo1.Lines.Add('The inspection price is now USD 95.00.');