PHP code example of michaelhairetis / mpp

1. Go to this page and download the library: Download michaelhairetis/mpp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaelhairetis / mpp example snippets


use Mpp\ChallengeBinding;
use Mpp\Method\Tempo\TempoCharge;
use Mpp\Server\PaymentGate;

$gate = new PaymentGate(
    binding: new ChallengeBinding($_ENV['MPP_SECRET']),
    method: new TempoCharge(),
    verifier: $yourVerifier,
    realm: 'api.example.com',
);

$challenge = $gate->challenge([
    'amount' => '500000',                                        // base units
    'currency' => '0x20c0...',                                   // TIP-20 token
    'recipient' => '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',
]);

// 402 + WWW-Authenticate: $challenge->toHeader()
// then, on the retry:
$receipt = $gate->verify($request->getHeaderLine($gate->credentialHeaderName()));

$middleware = new PaymentMiddleware($gate, $responseFactory, function ($request) {
    return str_starts_with($request->getUri()->getPath(), '/paid/')
        ? ['amount' => '500000', 'currency' => $token, 'recipient' => $wallet]
        : null;
});

$http = new PaymentClient($yourPsr18Client, $yourPayer);
$response = $http->sendRequest($request);
$receipt = $http->receiptFrom($response);

$binding = new ChallengeBinding($secret);
$challenge = $binding->issue($realm, 'tempo', 'charge', $requestB64);
$binding->verify($challenge);