/** * @param array $items * @param $shippingDetails * @param string $intent * @throws Exception * @return null|string */ public function createPayment(array $items, Details $shippingDetails, $intent = PaymentConst::INTENT_SALE) { $apiContext = $this->connectionService->getApiContext(); $dispatcher = $this->connectionService->getDispatcher(); $dispatcher->dispatch(PaymentEvent::NEW_SETUP); $successUrl = ''; $cancelUrl = ''; switch ($intent) { case PaymentConst::INTENT_SALE: $successUrl = $this->router->generate('paypal_payment_sale_success', array(), true); $cancelUrl = $this->router->generate('paypal_payment_sale_cancel', array(), true); break; case PaymentConst::INTENT_AUTHORIZE: $successUrl = $this->router->generate('paypal_payment_authorize_success', array(), true); $cancelUrl = $this->router->generate('paypal_payment_authorize_cancel', array(), true); break; } $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($successUrl)->setCancelUrl($cancelUrl); $payment = PaymentService::create($items, $shippingDetails, $intent, PaymentConst::METHOD_PAYPAL); $payment->setRedirectUrls($redirectUrls); $paymentEvent = new PayPalPaymentEvent($payment); $dispatcher->dispatch(PaymentEvent::NEW_START, $paymentEvent); $result = $payment->create($apiContext); $paymentEvent = new PayPalPaymentEvent($result); $dispatcher->dispatch(PaymentEvent::NEW_END, $paymentEvent); $payment->create($apiContext); $approvalUrl = $payment->getApprovalLink(); return $approvalUrl; }
public function newPayment(CreditCardInterface $cardInterface, array $items, Details $shippingDetails, $paymentIntent = PaymentConst::INTENT_SALE) { $apiContext = $this->connectionService->getApiContext(); $dispatcher = $this->connectionService->getDispatcher(); $dispatcher->dispatch(PaymentEvent::NEW_SETUP); $creditCard = new CreditCard(); $creditCard->setType($cardInterface->getType())->setNumber($cardInterface->getNumber())->setExpireMonth($cardInterface->getExpireMonth())->setExpireYear($cardInterface->getExpireYear())->setCvv2($cardInterface->getCsc())->setFirstName($cardInterface->getFirstName())->setLastName($cardInterface->getLastName()); $fi = new FundingInstrument(); $fi->setCreditCard($creditCard); $payment = PaymentService::create($items, $shippingDetails, $paymentIntent, PaymentConst::METHOD_CREDIT_CARD, $fi); $paymentEvent = new PaymentEvent($payment, PaymentConst::METHOD_CREDIT_CARD); $dispatcher->dispatch(PaymentEvent::NEW_START, $paymentEvent); $result = $payment->create($apiContext); $paymentEvent = new PaymentEvent($result, PaymentConst::METHOD_CREDIT_CARD); $dispatcher->dispatch(PaymentEvent::NEW_END, $paymentEvent); return $result; }