/** * Creates a new Donation entity. * */ public function newAction(Request $request) { $logger = $this->get('paypal_logger'); $em = $this->getDoctrine()->getManager(); $api = new Api(array('sandbox' => true)); $post = $request->request->all(); foreach ($request->request->all() as $key => $value) { $logger->info($key . ' : ' . $value); } if (Api::NOTIFY_VERIFIED === $api->notifyValidate($_POST)) { if ($post['mc_gross'] >= 3) { $logger->info('valid ipn'); $donation = new Donation(); $sticker = $em->getRepository('AppBundle:Sticker')->findOneById($post['custom']); $donation->setAmount($post['mc_gross']); $donation->setSticker($sticker); $donation->setPaypalTransactionId($post['verify_sign']); $em->persist($donation); $em->flush(); } else { return new JsonResponse(array('status' => 0, 'notification' => 'Valid IPN but invalid amount')); } return new JsonResponse(array('status' => 0, 'notification' => 'Valid IPN')); } else { $logger->info('invalid ipn'); return new JsonResponse(array('status' => 0, 'notification' => 'Not a valid IPN')); } }
/** * @test */ public function shouldReturnInvalidIfResponseContentContainsSomethingNotEqualToVerified() { $clientMock = $this->createClientMock(); $clientMock->expects($this->once())->method('send')->with($this->isInstanceOf('Buzz\\Message\\Form\\FormRequest'), $this->isInstanceOf('Buzz\\Message\\Response'))->will($this->returnCallback(function ($request, $response) { $response->setHeaders(array('HTTP/1.1 200 OK')); $response->setContent('foobarbaz'); })); $api = new Api($clientMock, array('sandbox' => false)); $this->assertEquals(Api::NOTIFY_INVALID, $api->notifyValidate(array())); }
/** * @test */ public function shouldReturnInvalidIfResponseContentContainsSomethingNotEqualToVerified() { $clientMock = $this->createHttpClientMock(); $clientMock->expects($this->once())->method('send')->will($this->returnCallback(function (RequestInterface $request) { return new Response(200, array(), 'foobarbaz'); })); $api = new Api(array('sandbox' => false), $clientMock, $this->createHttpMessageFactory()); $this->assertEquals(Api::NOTIFY_INVALID, $api->notifyValidate(array())); }