PHP code example of darneus / payu

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

    

darneus / payu example snippets


    /**
     * @var \Darneus\PayU\PayUGateway
     */
    private $payUGateway;

    private $order;
    
    public function __construct(PayUGateway $payUGateway) {
        $this->payUGateway = $payUGateway;
    }

    public function hanlePay() : ?string {
        $payUOrder = new Order('1234', 'Order 1234', 'PLN', 10000);
        $payUOrder->setContinueUrl($this->link('//return!'));
        $payUOrder->setBuyer(new Buyer('[email protected]', 123456789, 'John', 'Doe'));

        $payUOrder->addProduct(new Product('product', 10000, 1);
		
        $response = $this->payUGateway->createPayment($payUOrder);

        $order->setPaymentId($response->getOrderId());

        $this->redirectUrl($response->getRedirectUri());
    }

    public function handleReturn() : void {
        $result = $this->getPaymentData($order->getPaymentId());

        $status = reset($result->getResponse()->orders)->status;
        if ($status === 'COMPLETED') {
            $order->setPaid();
        }
    }