function it_should_store_invoices(StorageInterface $storageInterface, SecuredNotify $request, Transaction $transaction)
 {
     $notification = ['id' => '1', 'url' => 'http://bitpay.com/invoice', 'status' => BitPayNotification::STATUS_CONFIRMED, 'btcPrice' => 0.001, 'price' => 0.001, 'currency' => 'BTC', 'invoiceTime' => '2014­01­01T19:01:01.123Z', 'expirationTime' => '2014­01­01T19:01:01.123Z', 'currentTime' => '2014­01­01T19:01:01.123Z'];
     $invoice = BitPayNotification::fromArray($notification);
     $request->getNotification()->willReturn($notification);
     $transaction->setResponse($invoice)->shouldBeCalled();
     $storageInterface->findModelById('1')->willReturn($transaction);
     $storageInterface->updateModel($transaction)->shouldBeCalled();
     $this->execute($request);
 }
 /**
  * @param Notify $request
  *
  * @throws RequestNotSupportedException if the action dose not support the request.
  */
 public function execute($request)
 {
     /** @var Array $notification */
     $notification = $request->getNotification();
     $response = BitPayNotification::fromArray($notification);
     /** @var Transaction $model */
     $model = $this->storageInterface->findModelById($response->getId());
     $model->setResponse($response);
     $this->storageInterface->updateModel($model);
 }
Exemplo n.º 3
0
 /**
  * Call from your notification handler to convert raw post data to an array containing invoice data
  *
  * @param string $jsonString The raw POST data from file_get_contents("php://input");
  *
  * @return Invoice
  *
  * @throws Exception\CallbackPosDataMissingException
  * @throws Exception\CallbackJsonMissingException
  * @throws Exception\CallbackInvalidJsonException
  * @throws Exception\CallbackBadHashException
  */
 public function verifyNotification($jsonString)
 {
     if (!$jsonString) {
         throw new CallbackJsonMissingException();
     }
     $json = json_decode($jsonString, true);
     if (!is_array($json)) {
         throw new CallbackInvalidJsonException();
     }
     if (!array_key_exists('posData', $json)) {
         throw new CallbackPosDataMissingException();
     }
     $posData = json_decode($json['posData'], true);
     if ($posData['hash'] != $this->generateHash(serialize($posData['posData']))) {
         throw new CallbackBadHashException();
     }
     $json['posData'] = $posData['posData'];
     return Invoice::fromArray($json);
 }
Exemplo n.º 4
0
 public function testInvoiceUrlWithInvalidLanguage()
 {
     $invoice = Invoice::fromCommand($this->getMockOperationCommand());
     $this->assertEquals('https://bitpay.com/invoice?id=XXXXXXXXXXXXXXXXXXXXXX', $invoice->getUrl('foo'));
 }