id)) { fwrite($myfile, $date . " : Error. Invalid Bitpay payment notification message received - did not receive invoice ID.\n"); fclose($myfile); throw new \Exception('Invalid Bitpay payment notification message received - did not receive invoice ID.'); } // Now fetch the invoice from BitPay // This is needed, since the IPN does not contain any authentication $storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword'); $privateKey = $storageEngine->load('/tmp/bitpay.pri'); $publicKey = $storageEngine->load('/tmp/bitpay.pub'); $client = new \Bitpay\Client\Client(); $adapter = new \Bitpay\Client\Adapter\CurlAdapter(); $client->setPrivateKey($privateKey); $client->setPublicKey($publicKey); $client->setUri('https://btcpay.server/'); $client->setAdapter($adapter); $token = new \Bitpay\Token(); $token->setToken('UpdateThisValue'); // UPDATE THIS VALUE $client->setToken($token); $token->setFacade('merchant'); /** * This is where we will fetch the invoice object */ $invoice = $client->getInvoice($ipn->id); $invoiceId = $invoice->getId(); $invoiceStatus = $invoice->getStatus(); $invoiceExceptionStatus = $invoice->getExceptionStatus(); $invoicePrice = $invoice->getPrice(); fwrite($myfile, $date . " : IPN received for BitPay invoice ".$invoiceId." . Status = " .$invoiceStatus." / exceptionStatus = " . $invoiceExceptionStatus." Price = ". $invoicePrice." Tax Included = ". $taxIncluded."\n"); fwrite($myfile, "Raw IPN: ". $raw_post_data."\n"); //Respond with HTTP 200, so BitPay knows the IPN has been received correctly //If BitPay receives <> HTTP 200, then BitPay will try to send the IPN again with increasing intervals for two more hours. header("HTTP/1.1 200 OK");