Skip to content

Commit

Permalink
Update for adherence to order component and bugfixing webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Feb 21, 2020
1 parent df8c341 commit 5e82ff8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 92 deletions.
23 changes: 1 addition & 22 deletions api/public/schema/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion api/public/schema/publiccode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions api/src/Service/MollieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions api/src/Subscriber/InvoiceSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down
60 changes: 1 addition & 59 deletions api/src/Subscriber/PaymentCreationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
{
Expand Down Expand Up @@ -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);
// }
}
4 changes: 2 additions & 2 deletions api/src/Subscriber/PaymentSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down

0 comments on commit 5e82ff8

Please sign in to comment.