Skip to content

The following code sample is a possible implementation of the solution in PHP. In the sample, use the form to enter your Trustap API key and redirect URI configured during setup.

The sample creates a simple button. When a buyer presses the button you can redirect them to pay seller sarah.garcia@gmail.com for an item.

BuyerMarketplaceTrustapClick "Buy Now" buttonSend seller & transaction details (API call)Return actions_urlRedirect to Trustap payment screenComplete paymentSend webhook (payment confirmed)Send webhook (optional - transaction cancelled)BuyerMarketplaceTrustap

Step 1

Add your API credentials configured during your Trustap setup.

Your Trustap API key

In this example, the credentials are hard coded. For production, this is a security risk. We recommend using environmental variables or using a secret manager.

Step 2

Add your redirect_uri. This was configured during your Trustap setup.

Your redirect_uri

Step 3

Configure your seller details including details about the product or service for sale. These are required fields.

Step 4

Add the appropriate API endpoint.

  • For testing, use https://dev.stage.trustap.com/api/v1/p2p/listings/create_with_seller.
  • For production, use https://dev.trustap.com/api/v1/p2p/listings/create_with_seller.

Step 5

Send the request to the Trustap API.

Step 6

Enable buyer to purchase item with button. The button click makes the API call to Trustap.

Step 7

Redirect your user to the Trustap payment screen to pay for the transaction.

<?php


// Set your Trustap API key
$apiKey = '{{your-trustap-key}}';



// Set your redirect URI (change to whatever you need)
$redirect_uri = '{{your-redirect-uri}}';





$responseData = null;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Simulate seller details
    $seller = [
        'seller_email' => 'sarah.garcia@gmail.com',
        'seller_phone_number' => '088456564565',
        'seller_country_code' => 'ie',
        'currency' => 'eur',
        'description' => '2022 BMW 3 Series - 201 D 1234',
        'value' => 10000,
        'ad_id' => '1987',
        'image_url' => 'https://www.topgear.com/sites/default/files/news-listicle/image/e28.jpg'
    ];



    // API endpoint
    $url = 'https://dev.stage.trustap.com/api/v1/p2p/listings/create_with_seller';



    // Send via cURL
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Content-Type: application/json",
        "Authorization: Basic " . base64_encode($apiKey . ":")
    ]);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($seller));
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        $responseData = ['error' => curl_error($ch)];
    } else {
        $responseData = json_decode($response, true);

        // Append redirect_uri if actions_url exists
        if (!empty($responseData['actions_url'])) {
            // Check if actions_url already has a query string
            $separator = (parse_url($responseData['actions_url'], PHP_URL_QUERY) ? '&' : '?');
            $responseData['actions_url'] .= $separator . 'redirect_uri=' . urlencode($redirect_uri);
        }
    }
    curl_close($ch);

}
?>


<!DOCTYPE html>
<html>
<head>
    <title>Trustap Test</title>
    <style>
        .button {
            display: inline-block;
            background-color: #007BFF;
            color: white;
            padding: 10px 16px;
            text-decoration: none;
            border-radius: 6px;
            font-weight: bold;
            transition: background-color 0.2s ease;
            border: none;
            cursor: pointer;
        }
        .button:hover {
            background-color: #0056b3;
        }
        pre {
            background-color: #f4f4f4;
            padding: 10px;
            border-radius: 4px;
            overflow-x: auto;
        }
    </style>
</head>
<body>

    <form method="POST">
        <button type="submit" class="button">Buy item</button>
    </form>

    <?php if ($responseData): ?>
        <?php if (!empty($responseData['actions_url'])): ?>
            <p>Item selected</p>
            <a href="<?= htmlspecialchars($responseData['actions_url']) ?>" class="button" target="_blank">Send buyer to payment</a>
        <?php endif; ?>
        <h3>Full API Response:</h3>
        <pre><?php print_r($responseData); ?></pre>
    <?php endif; ?>

</body>
</html>