diff --git a/api/public/schema/openapi.yaml b/api/public/schema/openapi.yaml index 4fbd5e79..88d2b2be 100644 --- a/api/public/schema/openapi.yaml +++ b/api/public/schema/openapi.yaml @@ -2237,28 +2237,7 @@ paths: description: 'Resource not found' requestBody: content: - application/hal+json: - schema: - $ref: '#/components/schemas/Payment-write' - application/ld+json: - schema: - $ref: '#/components/schemas/Payment:jsonld-write' - application/vnd.api+json: - schema: - $ref: '#/components/schemas/Payment-write' - application/json: - schema: - $ref: '#/components/schemas/Payment-write' - application/xml: - schema: - $ref: '#/components/schemas/Payment-write' - application/x-yaml: - schema: - $ref: '#/components/schemas/Payment-write' - text/csv: - schema: - $ref: '#/components/schemas/Payment-write' - text/html: + application/x-www-form-urlencoded: schema: $ref: '#/components/schemas/Payment-write' description: 'The new Payment resource' diff --git a/api/public/schema/publiccode.yaml b/api/public/schema/publiccode.yaml index 0bd5c2ef..a7a1a2f9 100644 --- a/api/public/schema/publiccode.yaml +++ b/api/public/schema/publiccode.yaml @@ -6,7 +6,7 @@ url: "https://github.com/ConductionNL/Proto-component-commonground" landingURL: "pc.zaakonline.nl" isBasedOn: "https://github.com/ConductionNL/Proto-component-commonground.git" softwareVersion: "V.0.1" -releaseDate: "2020-19-02" +releaseDate: "2020-21-02" logo: pc.zaakonline.nl monochromeLogo: img/logo-mono.svg diff --git a/api/src/Service/MollieService.php b/api/src/Service/MollieService.php index e4fd821e..5f595039 100644 --- a/api/src/Service/MollieService.php +++ b/api/src/Service/MollieService.php @@ -56,7 +56,7 @@ public function createPayment(Invoice $invoice, Request $request):string{ "order_id" => $invoice->getReference(), ], ]); - var_dump($molliePayment); + var_dump($molliePayment->id); return $molliePayment->getCheckoutUrl(); } catch (ApiException $e) @@ -66,21 +66,26 @@ public function createPayment(Invoice $invoice, Request $request):string{ } } - public function updatePayment(string $paymentId, EntityManagerInterface $manager):?Payment + public function updatePayment(string $paymentId, Service $service, EntityManagerInterface $manager):?Payment { $molliePayment = $this->mollie->payments->get($paymentId); $payment = $manager->getRepository('App:Payment')->findOneBy(['paymentId'=> $paymentId]); if($payment instanceof Payment) { $payment->setStatus($molliePayment->status); - //return $payment; + return $payment; } else{ $invoiceReference = $molliePayment->metadata->order_id; + //var_dump($invoiceReference); $invoice = $manager->getRepository('App:Invoice')->findBy(['reference'=>$invoiceReference]); + //var_dump(count($invoice)); + if(is_array($invoice)) + $invoice = end($invoice); if($invoice instanceof Invoice) { $payment = new Payment(); $payment->setPaymentId($molliePayment->id); + $payment->setPaymentProvider($service); $payment->setStatus($molliePayment->status); $payment->setInvoice($invoice); $manager->persist($payment); diff --git a/api/src/Subscriber/InvoiceSubscriber.php b/api/src/Subscriber/InvoiceSubscriber.php index db74f1df..e2456919 100644 --- a/api/src/Subscriber/InvoiceSubscriber.php +++ b/api/src/Subscriber/InvoiceSubscriber.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use PhpParser\Error; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ViewEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Serializer\SerializerInterface; @@ -40,16 +41,16 @@ public function __construct(ParameterBagInterface $params, EntityManagerInterfac public static function getSubscribedEvents() { return [ - KernelEvents::VIEW => ['invoice', EventPriorities::PRE_VALIDATE], + KernelEvents::REQUEST => ['invoice', EventPriorities::PRE_DESERIALIZE], ]; } - public function invoice(ViewEvent $event) + public function invoice(RequestEvent $event) { // $result = $event->getControllerResult(); // $method = $event->getRequest()->getMethod(); $route = $event->getRequest()->attributes->get('_route'); - var_dump($route); + //var_dump($route); $data = json_decode($event->getRequest()->getContent()); if ($route != 'api_invoices_post_order_collection' || $data == null) @@ -62,13 +63,15 @@ public function invoice(ViewEvent $event) $invoice = new Invoice(); // var_dump($order); $invoice->setName($order->name); - $invoice->setDescription($order->description); + if(isset($order->description)) + $invoice->setDescription($order->description); $invoice->setReference($order->reference); $invoice->setPrice($order->price); $invoice->setPriceCurrency($order->priceCurrency); $invoice->setTax($order->tax); $invoice->setCustomer($order->customer); - $invoice->setOrder($order->url); + //@TODO: ORC locatie inregelbaar maken + $invoice->setOrder('https://orc.larping.eu'.$order->_links->self->href); $organization = $this->em->getRepository('App:Organization')->findOrCreateByRsin($order->organization->rsin); if ($organization instanceof Organization) { diff --git a/api/src/Subscriber/PaymentCreationSubscriber.php b/api/src/Subscriber/PaymentCreationSubscriber.php index 8550fbe8..b95eb383 100644 --- a/api/src/Subscriber/PaymentCreationSubscriber.php +++ b/api/src/Subscriber/PaymentCreationSubscriber.php @@ -49,7 +49,7 @@ public function payment(ViewEvent $event) $result = $event->getControllerResult(); $method = $event->getRequest()->getMethod(); $route = $event->getRequest()->attributes->get('_route'); - var_dump($route); + //var_dump($route); if($result instanceof Invoice && $method != 'DELETE') { @@ -83,62 +83,4 @@ public function payment(ViewEvent $event) return; } } -// public function payment(ViewEvent $event) -// { -// $result = $event->getControllerResult(); -// $method = $event->getRequest()->getMethod(); -// $route = $event->getRequest()->attributes->get('_route'); -// -// //var_dump($route); -// if(!$result instanceof Payment || ($route != 'api_payments_post_webhook_collection' && $route != 'api_payments_post_collection')){ -// //var_dump('a'); -// return; -// } -// elseif($route=='api_payment_post_webhook_collection'){ -// $requestData = json_decode($event->getRequest()->getContent(),true); -// $paymentProvider = $this->em->getRepository('App\Entity\Service')->find($requestData['serviceId']); -// if($paymentProvider instanceof Service && $paymentProvider->getType() == 'mollie'){ -// $mollieService = new MollieService($requestData['paymentProvider']); -// $payment = $mollieService->updatePayment($event->getRequest(), $this->em); -// } -// else{ -// return; -// } -// }else{ -// $requestData = json_decode($event->getRequest()->getContent(),true); -// $paymentProvider = $this->em->getRepository('App\Entity\Service')->find($requestData['serviceId']); -// -// if($paymentProvider instanceof Service) { -// switch ($paymentProvider->getType()) { -// case 'mollie': -// $mollieService = new MollieService($paymentProvider); -// $payment = $mollieService->createPayment($event->getRequest()); -// break; -// case 'sumup': -// $sumupService = new SumUpService($paymentProvider); -// $payment = $sumupService->createPayment($event->getRequest()); -// break; -// default: -// return; -// } -// } -// else -// return; -// } -// $this->em->persist($payment); -// $this->em->flush(); -// -// -// $json = $this->serializer->serialize( -// $payment, -// 'jsonhal', ['enable_max_depth'=>true] -// ); -// -// $response = new Response( -// $json, -// Response::HTTP_OK, -// ['content-type' => 'application/json+hal'] -// ); -// $event->setResponse($response); -// } } diff --git a/api/src/Subscriber/PaymentSubscriber.php b/api/src/Subscriber/PaymentSubscriber.php index 3357a60c..1b0f6b9e 100644 --- a/api/src/Subscriber/PaymentSubscriber.php +++ b/api/src/Subscriber/PaymentSubscriber.php @@ -55,7 +55,7 @@ public function payment(RequestEvent $event) if($route=='api_payments_post_webhook_collection'){ //var_dump('a'); $providerId = $event->getRequest()->query->get('provider'); - //var_dump($providerId); + //var_dump($providerId); $provider = $this->em->getRepository('App\Entity\Service')->find($providerId); $paymentId = $event->getRequest()->request->get('id'); @@ -64,7 +64,7 @@ public function payment(RequestEvent $event) if($provider instanceof Service && $provider->getType() == 'mollie'){ $mollieService = new MollieService($provider); - $payment = $mollieService->updatePayment($paymentId, $this->em); + $payment = $mollieService->updatePayment($paymentId, $provider, $this->em); } else{ return;