function it_returns_requests_marked_as_unknown(Transaction $model, BitPayResponse $response, GetStatusInterface $request) { $model->getResponse()->willReturn($response); $response->getStatus()->willReturn('unknown_status'); $request->getModel()->willReturn($model); $request->markUnknown()->shouldBeCalled(); $this->execute($request); }
function it_handles_non_supported_requests(BitpayClient $bitPayClient, Capture $request) { $model = new Transaction(); $model->createRequest(null, null); $bitPayClient->createInvoice($model->getRequest()->jsonSerialize())->willThrow('\\Exception'); $request->getModel()->willReturn($model); $this->shouldThrow('\\Payum\\Core\\Exception\\RequestNotSupportedException')->duringExecute($request); }
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' => '20140101T19:01:01.123Z', 'expirationTime' => '20140101T19:01:01.123Z', 'currentTime' => '20140101T19: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 Transaction $model * * @return void */ protected function doUpdateModel($model) { echo "Invoice {$model->getResponse()->getId()} has been stored\n"; }
<?php /** * @author Peter Fox <*****@*****.**> * @copyright Peter Fox 2014 * * @package payum-bitpay */ require_once __DIR__ . '/config.php'; use Payum\Core\Request\Capture; use Payum\Core\Request\GetHumanStatus; use PayumBitPay\Model\Transaction; // Create the Transaction and configure the invoice request $model = new Transaction(); $model->createRequest(0.0001, 'BTC')->setItemCode('TEST-ITEM-001')->setItemDesc('This is a test item using Payum BitPay')->setOrderID('TEST-ORDER-001'); // Request the invoice and check the current status $payment = $registry->getPayment('bitpay'); $payment->execute(new Capture($model)); $payment->execute($status = new GetHumanStatus($model)); // If the status is new then it was created, BitPay will only make a request as complete // when the invoice is paid and the blockchain has confirmed the payment which // you would typically handle with HTTPS notifications if ($status->isNew()) { echo "You can access your invoice at {$model->getResponse()->getUrl()}\n"; } else { if ($status->isFailed()) { echo "An error occured\n"; } else { echo "Something went wrong but we don`t know the exact status\n"; } }