示例#1
0
 /**
  * Testing payment error
  *
  */
 public function testPaymentSuccess()
 {
     $this->stripeMethod->expects($this->once())->method('getCreditCartNumber')->will($this->returnValue(self::CART_NUMBER));
     $this->stripeMethod->expects($this->once())->method('getCreditCartExpirationMonth')->will($this->returnValue(self::CART_EXPIRE_MONTH));
     $this->stripeMethod->expects($this->once())->method('getCreditCartExpirationYear')->will($this->returnValue(self::CART_EXPIRE_YEAR));
     $this->paymentBridge->expects($this->once())->method('getOrder')->will($this->returnValue(1));
     $this->stripeMethod->expects($this->any())->method('setTransactionId')->with($this->equalTo('123'))->will($this->returnValue($this->stripeMethod));
     $this->stripeMethod->expects($this->any())->method('setTransactionStatus')->with($this->equalTo('paid'))->will($this->returnValue($this->stripeMethod));
     $this->paymentBridge->expects($this->once())->method('getCurrency')->will($this->returnValue(self::CURRENCY));
     $this->paymentBridge->expects($this->once())->method('getAmount')->will($this->returnValue(self::CART_AMOUNT));
     $cart = array('number' => self::CART_NUMBER, 'exp_month' => self::CART_EXPIRE_MONTH, 'exp_year' => self::CART_EXPIRE_YEAR);
     $chargeParams = array('card' => $cart, 'amount' => self::CART_AMOUNT, 'currency' => strtolower(self::CURRENCY));
     $this->stripeTransactionWrapper->expects($this->once())->method('create')->with($chargeParams)->will($this->returnValue(array('paid' => '1', 'id' => '123')));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderLoad')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderCreated')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->paymentEventDispatcher->expects($this->any())->method('notifyPaymentOrderFail');
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderSuccess')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->stripeMethod));
     $this->stripeManager->processPayment($this->stripeMethod, self::CART_AMOUNT);
 }
示例#2
0
 /**
  * Tries to process a payment through Stripe
  *
  * @param StripeMethod $paymentMethod Payment method
  * @param float        $amount        Amount
  *
  * @throws PaymentAmountsNotMatchException
  * @throws PaymentException
  *
  * @return StripeManager Self object
  */
 public function processPayment(StripeMethod $paymentMethod, $amount)
 {
     /**
      * check and set payment data
      */
     $this->prepareData($paymentMethod, $amount);
     /**
      * make payment
      */
     $transaction = $this->transactionWrapper->create($this->chargeParams);
     /**
      * Payment paid done
      *
      * Paid process has ended ( No matters result )
      */
     $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod);
     /**
      * when a transaction is successful, it is marked as 'closed'
      */
     if ($transaction['paid'] != 1) {
         /**
          * Payment paid failed
          *
          * Paid process has ended failed
          */
         $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod);
         throw new PaymentException();
     }
     $paymentMethod->setTransactionId($transaction['id'])->setTransactionStatus('paid')->setTransactionResponse($transaction);
     /**
      * Payment paid successfully
      *
      * Paid process has ended successfully
      */
     $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod);
     return $this;
 }