Beispiel #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();
 }
Beispiel #2
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;
 }
Beispiel #3
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);
 }