/** * @param \Ilis\Bundle\PaymentBundle\Provider\Paypal\PaymentsStandard\Button\BuyNow $button * @return string * @throws \Ilis\Bundle\PaymentBundle\Exception\Exception */ public function initPaypalBuyNowTransaction(BuyNow $button) { if (!$this->methodIsAvailable(Method::CODE_PAYPAL_PAYMENTS_STANDARDS)) { throw new Exception('Paypal Payments Standards is not available'); } $filtered = $this->methods->filter(function ($method) { return $method->getCode() === Method::CODE_PAYPAL_PAYMENTS_STANDARDS; }); if ($filtered->count() !== 1) { throw new Exception(sprintf('Unable to load Method "%s"', Method::CODE_PAYPAL_PAYMENTS_STANDARDS)); } $method = $filtered->current(); $transaction = new PaypalTransaction(); $transaction->setType(PaypalTransaction::TYPE_BUYNOW); $transaction->setAmount($button->getAmount()); $transaction->setCmd($button->getCmd()); $transaction->setBn($button->getBn()); $transaction->setCurrencyCode($button->getCurrencyCode()); $transaction->setQuantity($button->getQuantity()); $transaction->setItemName($button->getItemName()); $transaction->setItemNumber($button->getItemNumber()); $transaction->setMethod($method); $this->em->persist($transaction); $this->em->flush(); /** @var $processor \Ilis\Bundle\PaymentBundle\Processor\Paypal\PaymentStandard */ $processor = $this->getProcessor($method); $url = $processor->buildUrl($transaction); return $url; }