Example #1
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;
 }