PayPal API Guide for Merchant Backoffice Applications
Use Chilkat to collect a payment, ship an order, refund a customer, or reconcile the day’s activity from the merchant’s own backoffice application.
The example links below open in your selected language. The invoice walkthrough on this page is always in C#.
Choose the payment flow that fits the sale. A reusable Payment Link works for a service sold at a catalog price. An invoice bills a named customer for specific work. An order connects a buyer’s checkout to the authorization and capture that your staff can look up later.
C# walkthrough: read an invoice
Suppose a customer asks how much they still owe. After obtaining a sandbox token, look up the PayPal invoice ID on their local billing record. The following C# code uses Chilkat.Http to retrieve the invoice and Chilkat.JsonObject to read its outstanding balance. The linked examples use Chilkat 11.0.0 or later.
// accessToken comes from merchant credentials; invoiceId comes from the billing record.
var http = new Chilkat.Http();
http.AuthToken = accessToken;
http.SetUrlVar("id", invoiceId);
var response = new Chilkat.HttpResponse();
if (!http.HttpNoBody("GET", "https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}", response)) {
Console.WriteLine(http.LastErrorText);
return;
}
var invoice = new Chilkat.JsonObject();
if (response.StatusCode != 200) {
invoice.Load(response.BodyStr);
Console.WriteLine("HTTP " + response.StatusCode + " PayPal debug ID: " + invoice.StringOf("debug_id"));
return;
}
if (!invoice.Load(response.BodyStr)) {
Console.WriteLine("Expected invoice JSON.");
return;
}
Console.WriteLine(invoice.StringOf("detail.invoice_number") + " " + invoice.StringOf("status"));
Console.WriteLine("Balance due: " + invoice.StringOf("due_amount.value") + " " +
invoice.StringOf("due_amount.currency_code"));
HttpNoBody reports whether an HTTP response arrived. Check the HTTP status before using the JSON. For an operation that writes data and supports PayPal-Request-Id, such as a capture or refund, save a unique request ID with the operation before sending it. If the outcome is uncertain, retry the same request with the saved ID within PayPal’s retention period. PayPal’s retry guidance.
Authentication
Create a sandbox REST app for the merchant and exchange its client ID and secret for an OAuth access token. Load those credentials from the credential store on the merchant-controlled workstation. The token example saves the issue time and lifetime separately, so the application can renew the token before it expires. Use sandbox credentials with api-m.sandbox.paypal.com. Keep the merchant secret and bearer token out of logs and applications distributed to customers. PayPal authentication.
Payment Links
A service desk sells annual inspections at a fixed price. Enable Payment Links and Buttons for the merchant app, create a reusable link for the service, and save the payment resource ID with the catalog item. Give customers the URL from the response link whose rel is payment_link. When the inspection price changes, retrieve the resource by its ID and send its complete updated definition so the other settings survive the edit. PayPal Payment Links.
Wallet checkout and saved payment methods
For an individual purchase, create an order from the merchant’s cart, store its ID, and open the payer-action link in the buyer’s browser. Configure the merchant return and cancel URLs. When the buyer returns, match the order to the local sale, capture the approved order, and check the capture status, amount, and currency before releasing the goods. A buyer using a saved card may still need to complete an authentication challenge. PayPal Orders API.
Authorizations and captures
If an order will ship later, create it with intent=AUTHORIZE. After approval, authorize the order and save the returned authorization ID. At shipment, use that ID to capture the authorized amount. A merchant eligible for multiple captures can capture each shipment separately and mark the last capture as final. Save each capture ID with its shipment. If the sale falls through before capture, void the unused authorization to release the hold. PayPal Payments API.
Shipping and fulfillment
When a shipping label is ready, retrieve both PayPal IDs from the shipment record. Send the order ID in the tracking endpoint URL and the capture ID for that shipment in the JSON body, alongside the carrier and tracking number. Choose whether PayPal emails the buyer based on who sends shipping notices for your business. PayPal order and tracking workflow.
Refunds and transaction reporting
For a return, select the capture that paid for the item. Request the refund against that capture, save the new refund ID, and use it to follow a pending refund. For month-end reconciliation, use Transaction Search with reporting access. Page through a bounded UTC date range, preserve signed amounts and fees, and compare balances within each currency. Reporting can lag by up to three hours. For a customer waiting on today’s checkout, look up the order or capture directly. PayPal Transaction Search.
Creating and sending invoices
For work billed to a particular customer, create an itemized draft. Save the PayPal invoice ID alongside the invoice number the customer sees. Review the draft, then send it. If your office sends its own email, make a current-dated invoice payable with send_to_recipient=false and retrieve detail.metadata.recipient_view_url. The same payable invoice can supply a QR code for a printed bill. PayPal Invoicing reference.
Managing invoices
For a collections call, find the invoice by recipient or due date and read the balance still due. A partial payment can leave the original total unchanged. Record a bank transfer only after it arrives. If it was posted to the wrong invoice, remove the external payment record using its ID and record it against the correct invoice. Recording an external refund documents money already returned. To send money back through PayPal, use the capture refund workflow above. PayPal Invoices API.
- List merchant invoices across pages
- Find invoices for a recipient
- Read an invoice and its outstanding balance
- Revise a draft invoice from its full billing record
- Delete an unsent draft invoice
- Cancel a sent, unpaid invoice
- Record a bank transfer against an invoice
- Record an external refund against an invoice
- Build a worklist of overdue invoices
- Remove an external payment recorded on the wrong invoice
Subscription management
Start with the subscription ID stored on the customer’s account. To answer a billing inquiry, read the subscription status and next billing time, then list recent transactions to see which payments completed. If the customer requests a pause, suspend the active subscription. Resume it on a later request after checking that its status is suspended. PayPal Subscriptions API.
Disputes
Build a queue of cases waiting for the seller, with the response deadline when PayPal supplies one. Before uploading evidence, retrieve the selected case again and check its available actions and the evidence requested from the seller. For proof of fulfillment, the example submits the carrier receipt PDF and tracking details together in a multipart request. PayPal disputes workflow.