예제 #1
0
 /**
  * Tries to process a payment through Paymill
  *
  * @param PaymillMethod $paymentMethod Payment method
  * @param integer       $amount        Amount
  *
  * @return PaymillManager Self object
  *
  * @throws PaymentAmountsNotMatchException
  * @throws PaymentOrderNotFoundException
  * @throws PaymentException
  */
 public function processPayment(PaymillMethod $paymentMethod, $amount)
 {
     /// first check that amounts are the same
     $paymentBridgeAmount = intval($this->paymentBridge->getAmount());
     /**
      * If both amounts are different, execute Exception
      */
     if ($amount != $paymentBridgeAmount) {
         throw new PaymentAmountsNotMatchException(sprintf('Amounts differ. Requested: [%s] but in PaymentBridge: [%s].', $amount, $paymentBridgeAmount));
     }
     /**
      * At this point, order must be created given a card, and placed in PaymentBridge
      *
      * So, $this->paymentBridge->getOrder() must return an object
      */
     $this->paymentEventDispatcher->notifyPaymentOrderLoad($this->paymentBridge, $paymentMethod);
     /**
      * Order Not found Exception must be thrown just here
      */
     if (!$this->paymentBridge->getOrder()) {
         throw new PaymentOrderNotFoundException();
     }
     /**
      * Order exists right here
      */
     $this->paymentEventDispatcher->notifyPaymentOrderCreated($this->paymentBridge, $paymentMethod);
     /**
      * Validate the order in the module
      * params for paymill interaction
      */
     $extraData = $this->paymentBridge->getExtraData();
     $params = array('amount' => $paymentBridgeAmount, 'currency' => $this->paymentBridge->getCurrency(), 'token' => $paymentMethod->getApiToken(), 'description' => $extraData['order_description']);
     try {
         $transaction = $this->paymillTransactionWrapper->create($params['amount'], $params['currency'], $params['token'], $params['description']);
     } catch (PaymillException $e) {
         /**
          * create 'failed' transaction
          */
         $transaction = new Transaction();
         $transaction->setStatus('failed');
         $transaction->setDescription($e->getCode() . ' ' . $e->getMessage());
     }
     $this->processTransaction($transaction, $paymentMethod);
     return $this;
 }
예제 #2
0
 /**
  * Testing payment Success
  */
 public function testPaymentSuccess()
 {
     $this->paymillMethod->expects($this->once())->method('getApiToken')->will($this->returnValue(self::API_TOKEN));
     $this->paymentBridge->expects($this->once())->method('getOrder')->will($this->returnValue(1));
     $this->paymillMethod->expects($this->any())->method('setTransactionId')->with($this->equalTo('123'))->will($this->returnValue($this->paymillMethod));
     $this->paymillMethod->expects($this->any())->method('setTransactionStatus')->with($this->equalTo('closed'))->will($this->returnValue($this->paymillMethod));
     $this->paymentBridge->expects($this->once())->method('getCurrency')->will($this->returnValue(self::CURRENCY));
     $this->paymentBridge->expects($this->once())->method('getAmount')->will($this->returnValue(self::ORDER_AMOUNT));
     $this->paymentBridge->expects($this->once())->method('getExtraData')->will($this->returnValue(array('order_description' => self::ORDER_DESCRIPTION)));
     $this->paymillResponseTransaction->expects($this->once())->method('getStatus')->will($this->returnValue('closed'));
     $this->paymillResponseTransaction->expects($this->once())->method('getId')->will($this->returnValue(123));
     $this->paymillTransactionWrapper->expects($this->once())->method('create')->with($this->equalTo(self::ORDER_AMOUNT), $this->equalTo(self::CURRENCY), $this->equalTo(self::API_TOKEN), $this->equalTo(self::ORDER_DESCRIPTION))->will($this->returnValue($this->paymillResponseTransaction));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderLoad')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderCreated')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymentEventDispatcher->expects($this->any())->method('notifyPaymentOrderFail');
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderSuccess')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymillManager->processPayment($this->paymillMethod, self::ORDER_AMOUNT);
 }