Bitpay\Client\Client::getInvoice PHP Method

getInvoice() public method

public getInvoice ( $invoiceId )
    public function getInvoice($invoiceId)
    {
        $this->request = $this->createNewRequest();
        $this->request->setMethod(Request::METHOD_GET);
        if ($this->token->getFacade() === 'merchant') {
            $this->request->setPath(sprintf('invoices/%s?token=%s', $invoiceId, $this->token->getToken()));
            $this->addIdentityHeader($this->request);
            $this->addSignatureHeader($this->request);
        } else {
            $this->request->setPath(sprintf('invoices/%s', $invoiceId));
        }
        $this->response = $this->sendRequest($this->request);
        $body = json_decode($this->response->getBody(), true);
        if (isset($body['error'])) {
            throw new \Exception($body['error']);
        }
        $data = $body['data'];
        $invoice = new \Bitpay\Invoice();
        $invoiceToken = new \Bitpay\Token();
        $invoice->setToken($invoiceToken->setToken($data['token']))->setUrl($data['url'])->setPosData($data['posData'])->setStatus($data['status'])->setBtcPrice($data['btcPrice'])->setPrice($data['price'])->setCurrency(new \Bitpay\Currency($data['currency']))->setOrderId($data['orderId'])->setInvoiceTime($data['invoiceTime'])->setExpirationTime($data['expirationTime'])->setCurrentTime($data['currentTime'])->setId($data['id'])->setBtcPaid($data['btcPaid'])->setRate($data['rate'])->setExceptionStatus($data['exceptionStatus']);
        return $invoice;
    }

Usage Example

 public function confirmBitPayInvoice($bitPayInvoice)
 {
     $storageEngine = new Bitpay\Storage\FilesystemStorage();
     if (_BIT_PAY_PRODUCTION_) {
         $privateKey = $storageEngine->load('/tmp/bitpay.pri');
         $publicKey = $storageEngine->load('/tmp/bitpay.pub');
     } else {
         $privateKey = $storageEngine->load('/tmp/bitpaydev.pri');
         $publicKey = $storageEngine->load('/tmp/bitpaydev.pub');
     }
     $client = new Bitpay\Client\Client();
     if (_BIT_PAY_PRODUCTION_) {
         $network = new Bitpay\Network\Livenet();
     } else {
         $network = new Bitpay\Network\Testnet();
     }
     $adapter = new Bitpay\Client\Adapter\CurlAdapter();
     $client->setPrivateKey($privateKey);
     $client->setPublicKey($publicKey);
     $client->setNetwork($network);
     $client->setAdapter($adapter);
     $token = new Bitpay\Token();
     if (_BIT_PAY_PRODUCTION_) {
         $token->setToken(_BIT_PAY_TOKEN_LIVE_NET_);
     } else {
         $token->setToken(_BIT_PAY_TOKEN_TEST_NET_);
     }
     $client->setToken($token);
     $invoice = $client->getInvoice($bitPayInvoice);
     return $invoice->getStatus();
 }