/** * @param \Symfony\Component\HttpFoundation\Request $request The request * @param \JMS\Payment\CoreBundle\Entity\PaymentInstruction $instruction The payment instruction * * @return \Symfony\Component\HttpFoundation\Response */ public function urlcAction(Request $request, PaymentInstruction $instruction) { $this->get('event_dispatcher')->dispatch(DotpayEvents::PAYMENT_DOTPAY_CONFIRMATION_RECEIVED, new DotpayConfirmationReceivedEvent($instruction, $request->request)); $client = $this->get('payment.dotpay.client.token'); $logger = $this->get('logger'); // Check the PIN $control = md5(sprintf("%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s", $client->getPin(), $client->getId(), $request->request->get('control'), $request->request->get('t_id'), $request->request->get('amount'), $request->request->get('email'), $request->request->get('service'), $request->request->get('code'), $request->request->get('username'), $request->request->get('password'), $request->request->get('t_status'))); if ($control !== $request->request->get('md5')) { $logger->err('[Dotpay - URLC] pin verification failed'); return new Response('FAIL', 500); } if (null === ($transaction = $instruction->getPendingTransaction())) { $logger->err('[Dotpay - URLC] no pending transaction found for the payment instruction'); return new Response('FAIL', 500); } $amountParts = explode(' ', $request->get('orginal_amount')); // Yes, the right parameter is 'orginal_amount' $amount = (double) $amountParts[0]; // there is a typo error in the DotPay API $transaction->getExtendedData()->set('t_status', $request->get('t_status')); $transaction->getExtendedData()->set('t_id', $request->get('t_id')); $transaction->getExtendedData()->set('amount', $amount); try { $this->get('payment.plugin_controller')->approveAndDeposit($transaction->getPayment()->getId(), $amount); } catch (\Exception $e) { $logger->err(sprintf('[Dotpay - URLC] %s', $e->getMessage())); return new Response('FAIL', 500); } $this->getDoctrine()->getManager()->flush(); $logger->info(sprintf('[Dotpay - URLC] Payment instruction %s successfully updated', $instruction->getId())); return new Response('OK'); }
public function testConstructor() { $data = new ExtendedData(); $instruction = new PaymentInstruction(123.45, 'USD', 'foo', $data); $this->assertEquals(123.45, $instruction->getAmount()); $this->assertEquals('USD', $instruction->getCurrency()); $this->assertEquals('foo', $instruction->getPaymentSystemName()); $this->assertSame($data, $instruction->getExtendedData()); $this->assertSame(FinancialTransaction::STATE_NEW, $instruction->getState()); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $instruction->getCredits()); $this->assertEquals(0, count($instruction->getCredits())); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $instruction->getPayments()); $this->assertEquals(0, count($instruction->getPayments())); $this->assertEquals(0.0, $instruction->getApprovingAmount()); $this->assertEquals(0.0, $instruction->getApprovedAmount()); $this->assertEquals(0.0, $instruction->getDepositingAmount()); $this->assertEquals(0.0, $instruction->getDepositedAmount()); $this->assertEquals(0.0, $instruction->getCreditingAmount()); $this->assertEquals(0.0, $instruction->getCreditedAmount()); $this->assertEquals(0.0, $instruction->getReversingApprovedAmount()); $this->assertEquals(0.0, $instruction->getReversingCreditedAmount()); $this->assertEquals(0.0, $instruction->getReversingDepositedAmount()); $this->assertNull($instruction->getId()); $this->assertTrue(time() - $instruction->getCreatedAt()->getTimestamp() < 10); $this->assertNull($instruction->getUpdatedAt()); }
/** * Przekierowanie do systemu płatności * @param PaymentInstruction $instruction * @return Response */ public function redirectAction(PaymentInstruction $instruction) { $sci = $this->get('payment.perfectmoney.client'); if (null === ($transaction = $instruction->getPendingTransaction())) { throw new \RuntimeException('No pending transaction found for the payment instruction'); } $extendedData = $transaction->getExtendedData(); if (!$extendedData->has('payment_url')) { throw new \RuntimeException('You must configure a payment_url.'); } if (!$extendedData->has('nopayment_url')) { throw new \RuntimeException('You must configure a nopayment_url.'); } $html = $this->container->get('twig')->render('vSymfoPaymentPerfectMoneyBundle:Default:redirect.html.twig', array("PAYEE_ACCOUNT" => $sci->getPayeeAccount(), "PAYMENT_AMOUNT" => $transaction->getRequestedAmount(), "PAYMENT_UNITS" => $instruction->getCurrency(), "PAYMENT_URL" => $extendedData->get('payment_url'), "NOPAYMENT_URL" => $extendedData->get('nopayment_url'), "PAYEE_NAME" => $this->container->getParameter('vsymfo_payment_perfectmoney.payee_name'), "STATUS_URL" => $this->generateUrl('vsymfo_payment_perfectmoney_callback', array("id" => $instruction->getId()), true))); return new Response(ViewUtility::redirectView($html)); }