public function makePayment(Payment $payment, $data = []) { $payPalCustom = md5($payment->getId() . '-' . time()); $payPalTransaction = new PaypalTransaction(); $payPalTransaction->setAmount($payment->getCreditAmount())->setDonationAmount($payment->getDonationAmount())->setPaypalTransactionFee($payment->getTransactionFee())->setTotalAmount($payment->getTotalAmount())->setStatus('START')->setCustom($payPalCustom)->setPaymentId($payment->getId()); $payPalTransaction->save(); $paymentDetail = $this->setPaypalCheckoutCart($payment); $expressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType(); $expressCheckoutRequestDetails->Custom = $payPalCustom; $expressCheckoutRequestDetails->PaymentDetails = $paymentDetail; $expressCheckoutRequestDetails->CancelURL = action('PayPalController@getCancel'); $expressCheckoutRequestDetails->ReturnURL = action('PayPalController@getReturn'); // Display options $expressCheckoutRequestDetails->cpplogoimage = 'https://www.zidisha.org/static/images/logo/zidisha-logo-small.png'; $expressCheckoutRequestDetails->BrandName = 'Zidisha'; //Shipping options if required. $expressCheckoutRequestDetails->NoShipping = 1; $expressCheckoutRequestDetails->ReqConfirmShipping = 0; //Set and configure express checkout $setExpressCheckoutRequestType = new SetExpressCheckoutRequestType(); $setExpressCheckoutRequestType->SetExpressCheckoutRequestDetails = $expressCheckoutRequestDetails; $setExpressCheckoutRequest = new SetExpressCheckoutReq(); $setExpressCheckoutRequest->SetExpressCheckoutRequest = $setExpressCheckoutRequestType; try { //Try Express Checkout. $setExpressCheckoutResponse = $this->payPalApi->SetExpressCheckout($setExpressCheckoutRequest); } catch (PPConnectionException $e) { $paymentError = new PaymentError('Error Connecting to PayPal.', $e); return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect(); } //Check if we get a Successful acknowledgment from the server. if ($setExpressCheckoutResponse->Ack != 'Success') { $this->logPayPalErrors($payment, $setExpressCheckoutResponse); $paymentError = new PaymentError('Error Connecting to PayPal.'); return $this->paymentBus->getFailedHandler($payment, $paymentError)->redirect(); } $payPalTransaction->setToken($setExpressCheckoutResponse->Token); $payPalTransaction->save(); $paypalUrl = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . $setExpressCheckoutResponse->Token; return \Redirect::away($paypalUrl); }
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(); }
/** * Declares an association between this object and a ChildPayment object. * * @param ChildPayment $v * @return $this|\Zidisha\Payment\Stripe\StripeTransaction The current object (for fluent API support) * @throws PropelException */ public function setPayment(ChildPayment $v = null) { if ($v === null) { $this->setPaymentId(NULL); } else { $this->setPaymentId($v->getId()); } $this->aPayment = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildPayment object, it will not be re-added. if ($v !== null) { $v->addStripeTransaction($this); } return $this; }
/** * 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'); } }