Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  *
  * @param $request Authorize
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var $payment Payment */
     $payment = $request->getModel();
     $this->gateway->execute($status = new GetHumanStatus($payment));
     if ($status->isNew()) {
         $this->gateway->execute(new ObtainMissingDetailsRequest($payment, $request->getToken()));
         try {
             $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken()));
             $payment->setDetails($convert->getResult());
         } catch (RequestNotSupportedException $e) {
             $payumPayment = new PayumPayment();
             $payumPayment->setNumber($payment->getNumber());
             $payumPayment->setTotalAmount($payment->getTotalAmount());
             $payumPayment->setCurrencyCode($payment->getCurrencyCode());
             $payumPayment->setClientEmail($payment->getPayer()->getEmail());
             $payumPayment->setClientId($payment->getPayer()->getId() ?: $payment->getPayer()->getEmail());
             $payumPayment->setDescription($payment->getDescription() ?: sprintf('Payment %s', $payment->getNumber()));
             $payumPayment->setCreditCard($payment->getCreditCard());
             $payumPayment->setDetails($payment->getDetails());
             $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken()));
             $payment->setDetails($convert->getResult());
         }
     }
     $details = ArrayObject::ensureArrayObject($payment->getDetails());
     try {
         $request->setModel($details);
         $this->gateway->execute($request);
     } finally {
         $payment->setDetails((array) $details);
     }
 }
Exemplo n.º 2
0
    /**
     * {@inheritDoc}
     *
     * @param Capture $request
     */
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var $order OrderInterface */
        $order = $request->getModel();

        $this->payment->execute($status = new GetHumanStatus($order));
        if ($status->isNew()) {
            $this->payment->execute(new FillOrderDetails($order, $request->getToken()));
        }

        $details = ArrayObject::ensureArrayObject($order->getDetails());

        $request->setModel($details);
        try {
            $this->payment->execute($request);

            $order->setDetails($details);
        } catch (\Exception $e) {
            $order->setDetails($details);

            throw $e;
        }
    }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function shouldMarkNewIfModelHasNotCardSet()
 {
     $action = new StatusAction();
     $model = array();
     $action->execute($status = new GetHumanStatus($model));
     $this->assertTrue($status->isNew());
 }
Exemplo n.º 4
0
 /**
  * @test
  */
 public function shouldMarkNewIfDetailsEmpty()
 {
     $action = new StatusAction();
     $model = [];
     $action->execute($status = new GetHumanStatus($model));
     $this->assertTrue($status->isNew());
 }
Exemplo n.º 5
0
 /**
  * @test
  */
 public function shouldNotMarkRefundedIfStatusNotSetAndRefundedTrue()
 {
     $action = new StatusAction();
     $model = array('refunded' => true);
     $action->execute($status = new GetHumanStatus($model));
     $this->assertFalse($status->isRefunded());
     $this->assertTrue($status->isNew());
 }
Exemplo n.º 6
0
 /**
  * {@inheritDoc}
  *
  * @param Payout $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var $payout PayoutInterface */
     $payout = $request->getModel();
     $this->gateway->execute($status = new GetHumanStatus($payout));
     if ($status->isNew()) {
         $this->gateway->execute($convert = new Convert($payout, 'array', $request->getToken()));
         $payout->setDetails($convert->getResult());
     }
     $details = ArrayObject::ensureArrayObject($payout->getDetails());
     $request->setModel($details);
     try {
         $this->gateway->execute($request);
     } finally {
         $payout->setDetails($details);
     }
 }
Exemplo n.º 7
0
 /**
  * @test
  */
 public function shouldNotMatchOthersThenSuspendedStatus()
 {
     $statusRequest = new GetHumanStatus(new \stdClass());
     $statusRequest->markSuspended();
     $this->assertTrue($statusRequest->isSuspended());
     $this->assertFalse($statusRequest->isCaptured());
     $this->assertFalse($statusRequest->isExpired());
     $this->assertFalse($statusRequest->isCanceled());
     $this->assertFalse($statusRequest->isPending());
     $this->assertFalse($statusRequest->isFailed());
     $this->assertFalse($statusRequest->isNew());
     $this->assertFalse($statusRequest->isUnknown());
 }
Exemplo n.º 8
0
 /**
  * @test
  */
 public function shouldMarkNewIfExecCodeNotSet()
 {
     $action = new StatusAction();
     $action->execute($status = new GetHumanStatus(array()));
     $this->assertTrue($status->isNew());
 }
Exemplo n.º 9
0
 /**
  * @test
  */
 public function shouldMarkAsNew()
 {
     $action = new StatusAction();
     $action->execute($getStatus = new GetHumanStatus(array()));
     $this->assertTrue($getStatus->isNew());
 }
Exemplo n.º 10
0
 /**
  * @test
  */
 public function shouldMarkNewIfAuthResultIsNull()
 {
     $action = new StatusAction();
     $action->execute($status = new GetHumanStatus(['authResult' => null]));
     $this->assertTrue($status->isNew());
 }
Exemplo n.º 11
0
<?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";
    }
}
Exemplo n.º 12
0
 /**
  * @test
  */
 public function shouldNotMatchOthersThenPayedoutStatus()
 {
     $getStatus = new GetHumanStatus(new \stdClass());
     $getStatus->markPayedout();
     $this->assertTrue($getStatus->isPayedout());
     $this->assertFalse($getStatus->isCaptured());
     $this->assertFalse($getStatus->isAuthorized());
     $this->assertFalse($getStatus->isExpired());
     $this->assertFalse($getStatus->isCanceled());
     $this->assertFalse($getStatus->isPending());
     $this->assertFalse($getStatus->isFailed());
     $this->assertFalse($getStatus->isNew());
     $this->assertFalse($getStatus->isUnknown());
 }