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(); }
/** * @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; }
public function addUploadFundTransaction(ConnectionInterface $con, Payment $payment) { $this->assertAmount($payment->getTotalAmount()); $transactionUpload = new Transaction(); $transactionUpload->setUserId($payment->getLenderId())->setAmount($payment->getTotalAmount())->setDescription('Funds upload to lender account')->setTransactionDate(new \DateTime())->setType(Transaction::FUND_UPLOAD)->setSubType(Transaction::FUND_UPLOAD); $transactionUpload->save($con); if ($payment->getTransactionFee()->isPositive()) { if ($payment->getPaymentMethod() == 'stripe') { $transactionType = Transaction::STRIPE_FEE; $description = 'Stripe transaction fee'; } elseif ($payment->getPaymentMethod() == 'paypal') { $transactionType = Transaction::PAYPAL_FEE; $description = 'Paypal transaction fee'; } else { throw \Exception('No matching payment method found.'); } $transactionStripeFee = new Transaction(); $transactionStripeFee->setUserId($payment->getLenderId())->setAmount($payment->getTransactionFee()->multiply(-1))->setDescription($description)->setTransactionDate(new \DateTime())->setType($transactionType); $transactionStripeFee->save($con); $transactionStripeAdmin = new Transaction(); $transactionStripeAdmin->setUserId(Setting::get('site.adminId'))->setAmount($payment->getTransactionFee())->setDescription('Lender transaction fee')->setTransactionDate(new \DateTime())->setType($transactionType); $transactionStripeAdmin->save($con); } }