Skip to content

Commit

Permalink
Merge pull request #80 from CommonGateway/feature/HP-104/redirectUrl
Browse files Browse the repository at this point in the history
Return payment id
  • Loading branch information
smisidjan authored Apr 17, 2023
2 parents db451ea + 17f6f17 commit 7c54599
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Installation/installation.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"version": "0.0.2",
"description": "The Huwelijksplanner Front-end Application. (Domain is used for redirecting after a payment, this might change)",
"domains": [
"utrecht-huwelijksplanner.frameless.io"
"api.huwelijksplanner.online"
]
}
],
Expand Down
64 changes: 40 additions & 24 deletions src/Service/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,16 @@ public function createMolliePayment(array $paymentArray): ?array
*
* @return ObjectEntity Huwelijk object.
*/
private function validateHuwelijkId(array $query): ObjectEntity
private function validateHuwelijkId(array $query): ?ObjectEntity
{
if (isset($query['resource']) === false || Uuid::isValid($query['resource']) === false) {
throw new BadRequestHttpException('No huwelijk id given or false id in the query parameter resource.');
if (isset($query['resource']) === false) {
return null;
}//end if

if (Uuid::isValid($query['resource']) === false) {
throw new BadRequestHttpException('False id in the query parameter resource.');
}

$huwelijkObject = $this->entityManager->find('App:ObjectEntity', $query['resource']);
if ($huwelijkObject instanceof ObjectEntity === false) {
throw new BadRequestHttpException('Cannot find huwelijk with given id: '.$query['resource']);
Expand All @@ -324,34 +328,46 @@ public function createPayment(): ?array
// @TODO add the values amount from huwelijk object etc to array
$paymentSchema = $this->gatewayResourceService->getSchema('https://huwelijksplanner.nl/schemas/hp.mollie.schema.json', 'common-gateway/huwelijksplanner-bundle');

$redirectUrl = null;
$application = $this->entityManager->getRepository('App:Application')->findOneBy(['reference' => 'https://huwelijksplanner.nl/application/hp.frontend.application.json']);
if ($application !== null && $application->getDomains() !== null && count($application->getDomains()) > 0) {
$domain = $application->getDomains()[0];
$redirectUrl = 'https://'.$domain.'/voorgenomen-huwelijk/betalen/betaalstatus-verificatie';
}

$huwelijkObject = $this->validateHuwelijkId($this->data['query']);
if ($huwelijkObject === null) {
return null;
}

// Get all prices from the products
$productPrices = $this->getSDGProductPrices($huwelijkObject->toArray());
// Calculate new price
$kosten = 'EUR '.$this->calculatePrice($productPrices, 'EUR');

$explodedAmount = explode(' ', $kosten);
$paymentObject = new ObjectEntity($paymentSchema);
$paymentArray = [
'amount' => [
'currency' => 'EUR',
'value' => $this->calculatePrice($productPrices, 'EUR'),
// Calculate new price
],
'description' => 'Payment made for huwelijk with id: '.$huwelijkObject->getId()->toString(),
'redirectUrl' => $redirectUrl,
'webhookUrl' => $this->configuration['webhookUrl'],
'method' => $this->configuration['method'],
'status' => 'paid',
// @TODO temporary set the status to paid
];
$paymentObject->hydrate($paymentArray);
$this->entityManager->persist($paymentObject);
$this->entityManager->flush();

// $paymentArray = [
// 'amount' => [
// 'currency' => $explodedAmount[0],
// 'value' => $explodedAmount[1],
// ],
// 'description' => 'Payment made for huwelijk with id: '.$huwelijkObject->getId()->toString(),
// 'redirectUrl' => $this->configuration['redirectUrl'],
// 'webhookUrl' => $this->configuration['webhookUrl'],
// 'method' => $this->configuration['method'],
// ];
// return $this->createMolliePayment($paymentArray);
// todo: temporary, redirect to return [redirectUrl]. Instead of this $paymentArray and return^
$domain = 'utrecht-huwelijksplanner.frameless.io';
$application = $this->entityManager->getRepository('App:Application')->findOneBy(['reference' => 'https://huwelijksplanner.nl/application/hp.frontend.application.json']);
if ($application !== null && $application->getDomains() !== null && count($application->getDomains()) > 0) {
$domain = $application->getDomains()[0];
}

return ['redirectUrl' => 'https://'.$domain.'/voorgenomen-huwelijk/betalen/betaalstatus-verificatie'];
return [
'paymentId' => $paymentObject->getId()->toString(),
'redirectUrl' => $paymentObject->getValue('redirectUrl'),
// @TODO set redirectUrl to the checkout url
];

}//end createPayment()

Expand Down Expand Up @@ -389,7 +405,7 @@ public function createPaymentHandler(?array $data=[], ?array $configuration=[]):
// ];
// }//end if
if ($payment !== null) {
$this->data['response'] = new Response(\Safe\json_encode($payment), 200);
$this->data['response'] = new Response(json_encode($payment), 200);
// $this->data['response'] = new Response(\Safe\json_encode(['checkout' => $payment['_links']['checkout']]), 200);
}

Expand Down

0 comments on commit 7c54599

Please sign in to comment.