Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
PayPal: Record a bank transfer against an invoice
See more PayPal Examples
Record USD 45 already received by bank transfer. The invoice may still have a balance. This makes a bookkeeping entry; it does not debit the customer. Save payment_id for reconciliation.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
body: TChilkatJsonObject;
date: TCkDateTime;
errorInfo: TChilkatJsonObject;
result: TChilkatJsonObject;
parsed: Integer;
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);
// Record only a bank transfer you have already received. Reconcile first if a previous
// attempt timed out.
http.SetUrlVar('id','INVOICE_ID');
body := TChilkatJsonObject.Create(Self);
body.UpdateString('method','BANK_TRANSFER');
body.UpdateString('amount.currency_code','USD');
body.UpdateString('amount.value','45.00');
// Use the actual date of the transfer; this example records one made today.
date := TCkDateTime.Create(Self);
date.SetFromCurrentSystemTime();
body.UpdateString('payment_date',date.GetAsIso8601('YYYY-MM-DD',0));
success := http.HttpJson('POST','https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/payments',body.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
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);
parsed := result.Load(resp.BodyStr);
if (parsed <> 1) then
begin
Memo1.Lines.Add('Expected a JSON response; HTTP ' + IntToStr(resp.StatusCode));
Exit;
end;
Memo1.Lines.Add('Record ID: ' + result.StringOf('payment_id'));