Want to confirm that a customer really purchased your product before granting access? In this guide, you’ll learn how to build a Gumroad purchase verification endpoint in PHP, step by step. It’s a practical way to connect Gumroad purchases with your website or app.
We’ll look at how your endpoint can receive a purchase code, check it with Gumroad, and return a clear result to your application. By the end, you’ll have a solid starting point for gumroad purchase verification PHP—without making the process more complicated than it needs to be.
Plan the Endpoint and Gather Gumroad Credentials
Before writing PHP, decide what proof your application needs and what it should do with that proof. A little planning now can prevent a valid purchase from being rejected—or access being granted based on an incomplete check.
Start by tracing the information from the buyer to your application, then identify the Gumroad details and hosting setup required to verify it. The choices below will shape the endpoint’s inputs, security, and response.
Understand Gumroad’s Purchase Verification Flow
For license-based verification, your endpoint receives a license key from the customer or your application and sends it to Gumroad’s verification API. The request includes the product’s permalink and license key; Gumroad returns whether the key is valid and information about the associated purchase.
Keep the roles clear: the license key identifies the purchase, while your server makes the verification request. Don’t treat a key supplied by a browser as proof on its own. Check Gumroad’s response server-side, and decide how to handle relevant purchase states—such as a refund—before granting access.
Make a short list of the values you’ll need:
- The product permalink used in the verification request.
- The license key submitted for checking.
- An optional Gumroad API access token if you use an API operation that requires one; the license verification request itself uses the product permalink and key.
Prepare a PHP Environment and Store API Credentials Securely
Once the request flow is clear, confirm that your server can make outbound HTTPS requests and run a supported PHP version. PHP’s cURL extension is a practical choice for calling Gumroad’s API, and a local development environment lets you test input handling before connecting the endpoint to your live site.
Keep any access token out of source code, public files, and browser-side JavaScript. Store secrets in environment variables or a hosting platform’s secret manager, and restrict access to the account and files that can read them. Never log license keys or tokens in plain text; redact sensitive values if you need diagnostic logs.
Decide How Your Application Will Handle Verified Purchases
A successful API response is only one part of the workflow. Decide what your application should return and do next, so the verification endpoint fits neatly into your sign-up, checkout, or account process.
For example, a course site might create an enrollment after a valid purchase, while a download service might issue a short-lived access link. Keep the response predictable—such as a success flag and a clear status—and return an appropriate error for invalid input or an unavailable Gumroad service.
Also plan for repeat requests. A customer may submit the same key twice, so make fulfillment idempotent: repeated successful checks should not create duplicate accounts, orders, or entitlements. With that behavior defined, you’re ready to implement the PHP endpoint and connect it to Gumroad.
Build the gumroad purchase verification PHP Endpoint
Your fulfillment rules are set; now the endpoint can connect them to a real check. The key design choice is to let your server control which Gumroad product is being verified, rather than trusting a browser to choose one.
Start with a small route that accepts JSON, validates the required values, and resolves your own product ID to its Gumroad permalink.
Create a PHP Route to Receive License Keys and Product IDs
For example, a client might send licensekey and productid to a POST /verify-purchase route. Keep an allowlisted product map on the server so a customer cannot substitute another product’s permalink.
This compact PHP fragment shows the input checks and lookup. Return JSON consistently, and reject unsupported methods or malformed requests before making an external call.
$products = ['coursebasic' => 'your-gumroad-permalink'];
$input = jsondecode(filegetcontents('php://input'), true) ?? [];
$key = trim($input['licensekey'] ?? '');
$productId = $input['productid'] ?? '';
$permalink = $products[$productId] ?? null;
if ($key === '' || !$permalink) {
httpresponsecode(422);
echo jsonencode(['verified' => false, 'error' => 'Invalid request']);
exit;
}With trusted product details in hand, the endpoint can make its server-to-server request.
Send a Secure Request to Gumroad’s Verification API
Use HTTPS and PHP’s cURL extension to send a form-encoded POST request to Gumroad’s license verification endpoint. The required values are the product permalink and license key; an API access token is not needed for this license-check operation.
Set a timeout and check for cURL failures. Consider setting incrementuses to false for routine checks, then handle any use-count policy deliberately rather than accidentally changing it on every retry.
curlsetoptarray($ch, [
CURLOPTPOST => true,
CURLOPTPOSTFIELDS => httpbuildquery([
'productpermalink' => $permalink,
'licensekey' => $key,
'incrementuses' => 'false'
]),
CURLOPTRETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10
]);Once Gumroad responds, separate a valid purchase from a successful network exchange.
Parse the Response and Return a Clear Verification Result
Decode the response as JSON and confirm that it contains Gumroad’s success field. A valid key is not automatically permission to fulfill every request: apply your policy to relevant purchase details, such as refund status, before creating an entitlement.
Return only the result your application needs—for example, verified and a short status. Do not pass the full upstream response or sensitive purchase details to the browser.
Finally, make failures predictable so your application can respond safely.
Handle Invalid Purchases, Missing Data, and API Errors
Use a client-error status such as 422 for missing fields or an invalid key, and reserve a server-error response for Gumroad timeouts, cURL failures, or unusable API responses. This distinction helps the client tell a rejected purchase from a temporary service problem.
Keep messages brief, avoid logging license keys, and make successful fulfillment idempotent. That way, retries during an outage—or a customer submitting the same key again—won’t create duplicate access or orders.
Secure, Test, and Integrate the Verification Flow
A successful check is a good start, but what happens if someone repeatedly submits keys—or your app treats a one-time response as permanent permission? A few safeguards and realistic tests can help your endpoint stay reliable as it moves from a working prototype into your product.
First, reduce the endpoint’s exposure before connecting it to customer-facing features. These protections help limit abuse and prevent purchase data or credentials from leaking.
Protect the Endpoint Against Abuse and Credential Exposure
Accept verification requests over HTTPS and allow only the expected HTTP method. Add request-size limits and rate limiting, ideally using both an IP address and an account or session identifier where available. If only your own backend should call the route, require an authentication mechanism; CORS settings alone do not prevent unauthorized requests.
Keep license keys out of URLs, analytics, and routine logs. Return a brief, generic rejection to the client, while recording only sanitized diagnostic details on the server. Also protect any Gumroad credentials in environment variables or a secrets manager, and restrict who can read them. For guidance on the upstream request and response, use Gumroad’s license key documentation.
With those boundaries in place, test the behavior—not just whether the PHP code runs. A small test matrix can reveal mistakes before real buyers encounter them.
Test Valid and Invalid Purchase Scenarios
Use mocked HTTP responses for repeatable tests of success, rejection, malformed JSON, and network timeouts. Then, if your Gumroad setup supports a safe test purchase, run an end-to-end check without exposing a real customer’s license key in development logs or shared test data.
Include cases such as:
- A valid key for an allowed product, including any refund state your policy must reject.
- An invalid or empty key, an unknown product ID, and malformed request JSON.
- A slow or unavailable Gumroad API, confirming your endpoint returns a temporary service error rather than granting access.
- A repeated valid submission, confirming it does not create duplicate orders or entitlements.
Once these outcomes are predictable, connect them to authorization in your application. Verification should inform access—not replace your app’s own access-control rules.
Connect Verification Results to Your App’s Access Controls
After a valid result, create or update an entitlement in your database and associate it with the right user and product. Enforce uniqueness for that relationship, so concurrent retries cannot create duplicate access. The browser should never be able to grant itself access by changing a response or submitting a different product ID.
For later requests, check the stored entitlement on your server, and define how your app handles refunds, revoked access, or account changes. This makes gumroad purchase verification PHP part of a controlled authorization flow, rather than a one-time check that permanently trusts client-side data.
Turn Gumroad Purchase Checks into Reliable Access
A Gumroad purchase verification endpoint doesn’t need to be complicated: accept a carefully validated request, verify the license key with Gumroad from your PHP server, and return a clear result your application can act on. The real strength of the flow comes from pairing that check with secure credential handling, predictable error responses, and fulfillment that safely handles retries.
Before putting your endpoint in front of customers, test valid and invalid purchases, API failures, and repeated submissions. Then use verified results to create server-side entitlements and enforce access through your own application—not through browser-supplied data. With these foundations in place, gumroad purchase verification PHP can help you grant the right customers access while keeping the process secure and dependable.