From 2885b70b670739cbe0e1780851f97db1f907be0a Mon Sep 17 00:00:00 2001 From: Vojta Svoboda Date: Fri, 4 Feb 2022 12:57:47 +0100 Subject: [PATCH] Add special Response for Checkout Session --- src/Message/Checkout/PurchaseRequest.php | 13 ++++++++++ src/Message/Checkout/Response.php | 33 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/Message/Checkout/Response.php diff --git a/src/Message/Checkout/PurchaseRequest.php b/src/Message/Checkout/PurchaseRequest.php index d3d2386d..0887ae27 100644 --- a/src/Message/Checkout/PurchaseRequest.php +++ b/src/Message/Checkout/PurchaseRequest.php @@ -14,6 +14,19 @@ */ class PurchaseRequest extends AbstractRequest { + /** + * Create response + * + * @param string $data + * @param array $headers + * + * @return Response + */ + protected function createResponse($data, $headers = []) + { + return $this->response = new Response($this, $data, $headers); + } + /** * Set the success url * diff --git a/src/Message/Checkout/Response.php b/src/Message/Checkout/Response.php new file mode 100644 index 00000000..ed135920 --- /dev/null +++ b/src/Message/Checkout/Response.php @@ -0,0 +1,33 @@ +getRedirectUrl() !== null; + } + + /** + * @return mixed + */ + public function getRedirectUrl() + { + if (isset($this->data['object']) && 'checkout.session' !== $this->data['object']) { + return null; + } + + return !empty($this->data['url']) ? $this->data['url'] : null; + } +}