示例#1
0
 public function uploadFunds(Payment $payment)
 {
     $con = Propel::getWriteConnection(TransactionTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         if ($payment->getTotalAmount()->isPositive()) {
             $this->transactionService->addUploadFundTransaction($con, $payment);
         }
         if ($payment->getDonationAmount()->isPositive()) {
             $this->transactionService->addDonation($con, $payment);
         }
     } catch (\Exception $e) {
         $con->rollback();
         throw $e;
     }
     $con->commit();
 }
示例#2
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();
 }
示例#3
0
 /**
  * @param Payment $payment
  * @return PaymentDetailsType
  */
 protected function setPaypalCheckoutCart(Payment $payment)
 {
     $paymentDetail = new PaymentDetailsType();
     if ($payment->getCreditAmount()->greaterThan(Money::create(0))) {
         $itemDetail = new PaymentDetailsItemType();
         $itemDetail->Name = 'Lend To Zidisha';
         $itemDetail->Amount = new BasicAmountType('USD', $payment->getCreditAmount()->round(2)->getAmount());
         $itemDetail->Quantity = '1';
         $itemDetail->ItemCategory = 'Digital';
         $paymentDetail->PaymentDetailsItem[] = $itemDetail;
     }
     if ($payment->getDonationAmount()->greaterThan(Money::create(0))) {
         $itemDetail = new PaymentDetailsItemType();
         $itemDetail->Name = 'Donation To Zidisha';
         $itemDetail->Amount = new BasicAmountType('USD', $payment->getDonationAmount()->round(2)->getAmount());
         $itemDetail->Quantity = '1';
         $itemDetail->ItemCategory = 'Digital';
         $paymentDetail->PaymentDetailsItem[] = $itemDetail;
     }
     if ($payment->getTransactionFee()->greaterThan(Money::create(0))) {
         $itemDetail = new PaymentDetailsItemType();
         $itemDetail->Name = ' Zidisha Transaction Fee';
         $itemDetail->Amount = new BasicAmountType('USD', $payment->getTransactionFee()->round(2)->getAmount());
         $itemDetail->Quantity = '1';
         $itemDetail->ItemCategory = 'Digital';
         $paymentDetail->PaymentDetailsItem[] = $itemDetail;
     }
     //Add this item to payment and set the order amount
     $paymentDetail->OrderTotal = new BasicAmountType('USD', $payment->getTotalAmount()->round(2)->getAmount());
     $paymentDetail->NotifyURL = $this->getIpnUrl();
     //Type of Payment (https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECRelatedAPIOps/)
     $paymentDetail->PaymentAction = 'Sale';
     return $paymentDetail;
 }
示例#4
0
 /**
  * Constructs a new UploadFundPayment class, setting the class_key column to PaymentTableMap::CLASSKEY_1.
  */
 public function __construct()
 {
     parent::__construct();
     $this->setClassKey(PaymentTableMap::CLASSKEY_1);
 }
示例#5
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aPayment) {
         $this->aPayment->removeStripeTransaction($this);
     }
     $this->id = null;
     $this->stripe_id = null;
     $this->amount = null;
     $this->donation_amount = null;
     $this->transaction_fee = null;
     $this->total_amount = null;
     $this->status = null;
     $this->payment_id = null;
     $this->created_at = null;
     $this->updated_at = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
示例#6
0
 public function addDonation(ConnectionInterface $con, Payment $payment)
 {
     $donationTransaction = new Transaction();
     $donationTransaction->setUserId($payment->getLenderId())->setAmount($payment->getDonationAmount()->multiply(-1))->setDescription('Donation to Zidisha')->setTransactionDate(new \DateTime())->setType(Transaction::DONATION);
     $donationTransaction->save($con);
     $donationTransaction = new Transaction();
     $donationTransaction->setUserId(Setting::get('site.adminId'))->setAmount($payment->getDonationAmount())->setDescription('Donation from lender')->setTransactionDate(new \DateTime())->setType(Transaction::DONATION);
     $donationTransaction->save($con);
 }
 /**
  * Filter the query by a related \Zidisha\Payment\Payment object
  *
  * @param \Zidisha\Payment\Payment|ObjectCollection $payment The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildStripeTransactionQuery The current query, for fluid interface
  */
 public function filterByPayment($payment, $comparison = null)
 {
     if ($payment instanceof \Zidisha\Payment\Payment) {
         return $this->addUsingAlias(StripeTransactionTableMap::COL_PAYMENT_ID, $payment->getId(), $comparison);
     } elseif ($payment instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(StripeTransactionTableMap::COL_PAYMENT_ID, $payment->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByPayment() only accepts arguments of type \\Zidisha\\Payment\\Payment or Collection');
     }
 }