gui-gui/omnipay-payu-brazil

View on GitHub
src/Message/Response.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Omnipay\PayUBrazil\Message;

use Omnipay\Common\Message\AbstractResponse;

class Response extends AbstractResponse
{

    /**
     * Is the transaction successful?
     *
     * @return bool
     */
    public function isSuccessful()
    {
        if (!isset($this->data['error'])) {
            return $this->data['code'] === 'SUCCESS' && $this->data['transactionResponse']['state'] === 'APPROVED';
        }
        return false;
    }

    /**
     * Is the response successful?
     *
     * @return boolean
     */
    public function isPending()
    {
        if (!isset($this->data['error']) && $this->data['transactionResponse']['state'] === 'PENDING') {
            return true;
        }
        return false;
    }
     /**
     * Get the transaction reference generated by the gateway.
     *
     * @return string|null
     */
    public function getTransactionReference()
    {
        if (!isset($this->data['error'])) {
            return $this->data['transactionResponse']['transactionId'];
        }

        return null;
    }

     /**
     * Get the order reference generated by the gateway.
     *
     * @return string|null
     */
    public function getOrderReference()
    {
        if (!isset($this->data['error']) ) {
            return $this->data['transactionResponse']['orderId'];
        }

        return null;
    }
    /**
     * Response Message
     *
     * @return null|string A response message from the payment gateway
     */
    public function getMessage()
    {
        if (!isset($this->data['error']) ) {
            return $this->data['transactionResponse']['responseMessage'];
        }

        return $this->data['error'];

    }

    /**
     * Response code
     *
     * @return null|string A response code from the payment gateway
     */
    public function getCode()
    {
        if (!isset($this->data['error']) ) {
            return $this->data['transactionResponse']['responseCode'];
        }

        return $this->data['code'];
    }
}