PHP code example of krzysiekpiasecki / dotphpay

1. Go to this page and download the library: Download krzysiekpiasecki/dotphpay 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/ */

    

krzysiekpiasecki / dotphpay example snippets


composer 

class BusinessPaymentHandler implements \Dotpay\Server\Handler\PaymentHandlerInterface
{
    public function handle(Payment $payment)
    {
        // TODO: Implement handle() method.
    }
}

$psrRequest = Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_GET,
    $_POST
);

$paymentMiddleware = new \Dotpay\Server\Payment();

$httpResponse = $paymentMiddleware->process(
    $psrRequest,
    new \Dotpay\Server\Handler\PaymentHandler(
        '747789',
        'Np3n4QmXxp6MOTrLCVs905fdrGf3QIGm',
        new BusinessPaymentHandler()
    )
);

$emitter = new \Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($httpResponse);

class BusinessURLCHandler implements \Dotpay\Server\Handler\URLCHandlerInterface
{
    public function handle(\Dotpay\Response\URLC $URLC)
    {
        // TODO: Implement handle() method.
    }
}

$psrRequest = \Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_POST
);

$urlcMiddleware = new \Dotpay\Server\Payment();

$httpResponse = $urlcMiddleware->process(
    $psrRequest, 
    new \Dotpay\Server\Handler\URLCHandler(
        'Np3n4QmXxp6MOTrLCVs905fdrGf3QIGm',
        new BusinessURLCHandler()
    )
);

$emitter = new \Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($httpResponse);

class BusinessErrorCodeHandler implements \Dotpay\Server\Handler\ErrorCodeHandlerInterface  {
    public function handle(string $errorCode)
    {
        // TODO: Implement handle() method with custom logic
    }
}

$psrRequest = Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_GET
);

$errorCodeMiddleware = new \Dotpay\Server\ErrorCode();

$httpResponse = $errorCodeMiddleware->process(
     $psrRequest,
     new \Dotpay\Server\Handler\ErrorCodeHandler(
         new BusinessErrorCodeHandler()
     )
);

use Symfony\Component\Validator\Validation;

$validator = Validation::createValidator();
$violations = $validator->validate('-1',
    new \Dotpay\Request\Validator\Constraint\IdConstraint()
);

if (0 !== count($violations)) {
    // there are errors, now you can show them
    foreach ($violations as $violation) {
        echo $violation->getMessage().'<br>';
        // Output: The value "-1" is not a valid 'id' parameter
    }
}