Overview
  • Namespace
  • Class

Namespaces

  • Omnipay
    • Pagarme
      • Message

Classes

  • Omnipay\Pagarme\CreditCard
  • Omnipay\Pagarme\Gateway
  • Omnipay\Pagarme\Message\AbstractRequest
  • Omnipay\Pagarme\Message\AuthorizeRequest
  • Omnipay\Pagarme\Message\CaptureRequest
  • Omnipay\Pagarme\Message\CreateCardRequest
  • Omnipay\Pagarme\Message\CreateCustomerRequest
  • Omnipay\Pagarme\Message\InstallmentsRequest
  • Omnipay\Pagarme\Message\PurchaseRequest
  • Omnipay\Pagarme\Message\RefundRequest
  • Omnipay\Pagarme\Message\Response
  • Omnipay\Pagarme\Message\VoidRequest
  1 <?php
  2 
  3 namespace Omnipay\Pagarme\Message;
  4 
  5 use Omnipay\Common\Message\AbstractResponse;
  6 
  7 /**
  8  * Pagarme Response
  9  *
 10  * This is the response class for all Pagarme requests.
 11  *
 12  * @see \Omnipay\Pagarme\Gateway
 13  */
 14 class Response extends AbstractResponse
 15 {
 16     /**
 17      * Is the transaction successful?
 18      *
 19      * @return bool
 20      */
 21     public function isSuccessful()
 22     {
 23         if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
 24             return !($this->data['status'] == 'refused');
 25         }
 26         return !isset($this->data['errors']);
 27     }
 28     
 29     /**
 30      * Get the transaction reference.
 31      *
 32      * @return string|null
 33      */
 34     public function getTransactionReference()
 35     {
 36         if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
 37             return $this->data['id'];
 38         }
 39 
 40         return null;
 41     }
 42     
 43     /**
 44      * Get a card reference, for createCard or createCustomer requests.
 45      *
 46      * @return string|null
 47      */
 48     public function getCardReference()
 49     {
 50         if (isset($this->data['object']) && 'card' === $this->data['object']) {
 51             if (! empty($this->data['id'])) {
 52                 return $this->data['id'];
 53             }
 54         } elseif (isset($this->data['object']) && 'transaction' === $this->data['object']) {
 55             return $this->data['card']['id'];
 56         }
 57 
 58         return null;
 59     }
 60     
 61     /**
 62      * Get a customer reference, for createCustomer requests.
 63      *
 64      * @return string|null
 65      */
 66     public function getCustomerReference()
 67     {
 68         if (isset($this->data['object']) && 'customer' === $this->data['object']) {
 69             return $this->data['id'];
 70         }
 71         if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
 72             if (! empty($this->data['customer'])) {
 73                 return $this->data['customer']['id'];
 74             }
 75         }
 76         if (isset($this->data['object']) && 'card' === $this->data['object']) {
 77             if (! empty($this->data['customer'])) {
 78                 return $this->data['customer']['id'];
 79             }
 80         }
 81 
 82         return null;
 83     }
 84     
 85     /**
 86      * Get the error message from the response.
 87      *
 88      * Returns null if the request was successful.
 89      *
 90      * @return string|null
 91      */
 92     public function getMessage()
 93     {
 94         if (!$this->isSuccessful()) {
 95             if (isset($this->data['errors'])) {
 96                 return $this->data['errors'][0]['message'];
 97             } else {
 98                 return $this->data['refuse_reason'];
 99             }
100         }
101 
102         return null;
103     }
104     
105     /**
106      * Get the boleto_url, boleto_barcode and boleto_expiration_date in the
107      * transaction object.
108      * 
109      * @return array|null the boleto_url, boleto_barcode and boleto_expiration_date
110      */
111     public function getBoleto()
112     {
113         if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
114             if ( $this->data['boleto_url'] ) {
115                 $data = array(
116                     'boleto_url' => $this->data['boleto_url'], 
117                     'boleto_barcode' => $this->data['boleto_barcode'],
118                     'boleto_expiration_date' => $this->data['boleto_expiration_date'],
119                 );
120                 return $data;
121             } else {
122                 return null;
123             }
124         }
125         
126         return null;
127     }
128     
129     /**
130      * Get the Calculted Installments provided by Pagar.me API.
131      * 
132      * @return array|null the calculated installments
133      */
134     public function getCalculatedInstallments()
135     {
136         if (isset($this->data['installments'])) {
137             $data = $this->data['installments'];
138             return $data;
139         } else {
140             return null;
141         }
142     }
143 }
API documentation generated by ApiGen