Skip to content

Commit 355cceb

Browse files
committed
Update: Sofinco Order Status Notification API according to new documentation
1 parent c4dc493 commit 355cceb

File tree

1 file changed

+68
-5
lines changed

1 file changed

+68
-5
lines changed

Gateway/Client/SofincoCACFPaymentGatewayClient.php

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,14 @@ public function getOrderStatusNotificationUrl(): string
513513
return sprintf('https://%s/orderStatusNotification/v1', $this->apiHostName);
514514
}
515515

516-
public function deliverContract(string $id): ?Response
516+
public function deliverContract(string $id, array $options): ?Response
517517
{
518518
$response = null;
519519

520+
$data = $this->resolveDeliverContractOptions($options);
520521
try {
521522
$response = $this->client->request('POST', sprintf('%s/contracts/%s/order/deliver', $this->getOrderStatusNotificationUrl(), $id), [
523+
'query' => $data,
522524
'headers' => [
523525
'Authorization' => sprintf('Bearer %s', $this->getAccessToken()),
524526
'Content-Type' => 'application/json',
@@ -531,18 +533,20 @@ public function deliverContract(string $id): ?Response
531533
}
532534

533535
if (null === $response) {
534-
throw new \UnexpectedValueException('The order status notification deliver order request failed.');
536+
throw new \UnexpectedValueException('The order status notification deliver contract request failed.');
535537
}
536538

537539
return $response;
538540
}
539541

540-
public function cancelContract(string $id): ?Response
542+
public function cancelContract(string $id, array $options): ?Response
541543
{
542544
$response = null;
543545

546+
$data = $this->resolveCancelContractOptions($options);
544547
try {
545548
$response = $this->client->request('POST', sprintf('%s/contracts/%s/order/cancel', $this->getOrderStatusNotificationUrl(), $id), [
549+
'query' => $data,
546550
'headers' => [
547551
'Authorization' => sprintf('Bearer %s', $this->getAccessToken()),
548552
'Content-Type' => 'application/json',
@@ -555,7 +559,7 @@ public function cancelContract(string $id): ?Response
555559
}
556560

557561
if (null === $response) {
558-
throw new \UnexpectedValueException('The order status notification cancel order request failed.');
562+
throw new \UnexpectedValueException('The order status notification cancel contract request failed.');
559563
}
560564

561565
return $response;
@@ -568,7 +572,7 @@ public function validateOrder(string $id, array $options): ?Response
568572
$data = $this->resolveValidateOrderOptions($options);
569573
try {
570574
$response = $this->client->request('POST', sprintf('%s/orders/%s/validate', $this->getOrderStatusNotificationUrl(), $id), [
571-
'json' => $data,
575+
'query' => $data,
572576
'headers' => [
573577
'Authorization' => sprintf('Bearer %s', $this->getAccessToken()),
574578
'Content-Type' => 'application/json',
@@ -587,10 +591,69 @@ public function validateOrder(string $id, array $options): ?Response
587591
return $response;
588592
}
589593

594+
public function cancelOrder(string $id, array $options): ?Response
595+
{
596+
$response = null;
597+
598+
$data = $this->resolveCancelOrderOptions($options);
599+
try {
600+
$response = $this->client->request('POST', sprintf('%s/orders/%s/cancel', $this->getOrderStatusNotificationUrl(), $id), [
601+
'query' => $data,
602+
'headers' => [
603+
'Authorization' => sprintf('Bearer %s', $this->getAccessToken()),
604+
'Content-Type' => 'application/json',
605+
],
606+
]);
607+
} catch (RequestException $e) {
608+
$this->logRequestException($e, $data);
609+
610+
return null;
611+
}
612+
613+
if (null === $response) {
614+
throw new \UnexpectedValueException('The order status notification cancel order request failed.');
615+
}
616+
617+
return $response;
618+
}
619+
620+
private function resolveDeliverContractOptions(array $options): array
621+
{
622+
$resolver = (new OptionsResolver())
623+
->setRequired('businessProviderId')->setAllowedTypes('businessProviderId', ['string'])
624+
->setRequired('equipmentCode')->setAllowedTypes('equipmentCode', ['string'])
625+
->setRequired('orderId')->setAllowedTypes('orderId', ['string'])
626+
;
627+
628+
return $resolver->resolve($options);
629+
}
630+
631+
private function resolveCancelContractOptions(array $options): array
632+
{
633+
$resolver = (new OptionsResolver())
634+
->setRequired('businessProviderId')->setAllowedTypes('businessProviderId', ['string'])
635+
->setRequired('equipmentCode')->setAllowedTypes('equipmentCode', ['string'])
636+
->setRequired('orderId')->setAllowedTypes('orderId', ['string'])
637+
;
638+
639+
return $resolver->resolve($options);
640+
}
641+
590642
private function resolveValidateOrderOptions(array $options): array
591643
{
592644
$resolver = (new OptionsResolver())
593645
->setRequired('businessProviderId')->setAllowedTypes('businessProviderId', ['string'])
646+
->setRequired('equipmentCode')->setAllowedTypes('equipmentCode', ['string'])
647+
;
648+
649+
return $resolver->resolve($options);
650+
}
651+
652+
private function resolveCancelOrderOptions(array $options): array
653+
{
654+
$resolver = (new OptionsResolver())
655+
->setRequired('businessProviderId')->setAllowedTypes('businessProviderId', ['string'])
656+
->setRequired('equipmentCode')->setAllowedTypes('equipmentCode', ['string'])
594657
;
595658

596659
return $resolver->resolve($options);

0 commit comments

Comments
 (0)