Esempio n. 1
0
 public function makePayment(Payment $payment, $data = [])
 {
     if (empty($data['stripeToken'])) {
         throw new \Exception('Missing Stripe Token.');
     }
     $stripeTransaction = new StripeTransaction();
     $stripeTransaction->setAmount($payment->getCreditAmount())->setDonationAmount($payment->getDonationAmount())->setTransactionFee($payment->getTransactionFee())->setTotalAmount($payment->getTotalAmount())->setStatus('START')->setPaymentId($payment->getId());
     $stripeTransaction->save();
     \Stripe::setApiKey(Setting::get('stripe.secretKey'));
     $paymentError = $charge = null;
     try {
         $charge = \Stripe_Charge::create(array("amount" => $payment->getTotalAmount()->getAmountInCents(), "currency" => "usd", "card" => $data['stripeToken']));
     } catch (Stripe_CardError $e) {
         $paymentError = new PaymentError('Your Card Information is not correct.');
     } catch (Stripe_InvalidRequestError $e) {
         $paymentError = new PaymentError('Invalid parameters give to stripe.');
     } catch (Stripe_AuthenticationError $e) {
         $paymentError = new PaymentError('Stripe Authentication failed.');
     } catch (Stripe_ApiConnectionError $e) {
         $paymentError = new PaymentError('We could not communicate with stripe please try again.');
     } catch (Stripe_Error $e) {
         //Todo: send mail to admin
         $paymentError = new PaymentError('Sorry we can not process your card at this moment.');
     } catch (\Exception $e) {
         //Todo: send mail to admin
         $paymentError = new PaymentError('Oops something is wrong.');
     }
     if ($paymentError) {
         return $this->paymentBus->getFailedHandler($payment, $paymentError)->setPayment($payment)->redirect();
     }
     $stripeTransaction->setStatus('Completed')->setStripeId($charge->id);
     $stripeTransaction->save();
     $serializedData = serialize($charge);
     //Stripe log
     $stripeLog = new StripeLog();
     $stripeLog->setLog($serializedData);
     $stripeLog->save();
     return $this->paymentBus->getCompletedHandler($payment)->process()->redirect();
 }
Esempio n. 2
0
 /**
  * Exclude object from result
  *
  * @param   ChildStripeTransaction $stripeTransaction Object to remove from the list of results
  *
  * @return $this|ChildStripeTransactionQuery The current query, for fluid interface
  */
 public function prune($stripeTransaction = null)
 {
     if ($stripeTransaction) {
         $this->addUsingAlias(StripeTransactionTableMap::COL_ID, $stripeTransaction->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }