From 4f4b7a9d40b58e4a8c457a48392ec260c6e4a6bd Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Sun, 19 Feb 2017 11:19:42 +0100 Subject: [PATCH] Added base plugin, in preperation for the API --- src/Message/AbstractRequest.php | 20 ++++++++++++ src/Message/AbstractResponse.php | 19 +++++++++++ src/Message/CompletePurchaseRequest.php | 38 ++++++++++++++++++++++ src/Message/CompletePurchaseResponse.php | 21 +++++++++++++ src/Message/PurchaseRequest.php | 40 ++++++++++++++++++++++++ src/Message/PurchaseResponse.php | 38 ++++++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 src/Message/AbstractRequest.php create mode 100644 src/Message/AbstractResponse.php create mode 100644 src/Message/CompletePurchaseRequest.php create mode 100644 src/Message/CompletePurchaseResponse.php create mode 100644 src/Message/PurchaseRequest.php create mode 100644 src/Message/PurchaseResponse.php diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php new file mode 100644 index 0000000..ebb0b65 --- /dev/null +++ b/src/Message/AbstractRequest.php @@ -0,0 +1,20 @@ +getParameter('clientId'); + } + + public function getClientSecret() + { + return $this->getParameter('clientSecret'); + } +} diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php new file mode 100644 index 0000000..307f88e --- /dev/null +++ b/src/Message/AbstractResponse.php @@ -0,0 +1,19 @@ +data->success) { + $this->error = (string) $this->data->error; + } + } +} diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php new file mode 100644 index 0000000..a36c223 --- /dev/null +++ b/src/Message/CompletePurchaseRequest.php @@ -0,0 +1,38 @@ +getTransactionReference() . $this->getClientId() . $this->getClientSecret() + ); + } + + public function getTransactionReference() + { + return $this->httpRequest->query->get('trxid'); + } + + public function getData() + { + $this->validate('merchantId', 'merchantKey'); + + $data = array( + "clientId" => $this->getClientId(), + "clientSecret" => $this->getClientSecret(), + "transactionId" => $this->getTransactionReference(), + "sha1" => $this->generateSignature() + ); + } + + public function sendData($data) + { + $httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send(); + return $this->response = new CompletePurchaseResponse($this, $httpResponse->json()); + } +} diff --git a/src/Message/CompletePurchaseResponse.php b/src/Message/CompletePurchaseResponse.php new file mode 100644 index 0000000..309f2f9 --- /dev/null +++ b/src/Message/CompletePurchaseResponse.php @@ -0,0 +1,21 @@ +data->transaction->status === "Success"); + } + + public function isRedirect() + { + return false; + } + + public function getStatus() + { + return $this->data->transaction->status; + } +} diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php new file mode 100644 index 0000000..7c07228 --- /dev/null +++ b/src/Message/PurchaseRequest.php @@ -0,0 +1,40 @@ +getTransactionId() . $this->getAmountInteger() . $this->getClientId() . $this->getClientSecret() + ); + } + + public function getData() + { + $this->validate( + 'amount', + 'transactionId', + 'returnUrl' + ); + + $data = array( + "clientId" => $this->getClientId(), + "clientSecret" => $this->getClientSecret(), + "transactionId" => $this->getTransactionId(), + "amount" => $this->getAmountInteger(), + "description" => $this->getDescription(), + "returnUrl" => $this->getReturnUrl(), + "sha1" => $this->generateSignature() + ); + } + + public function sendData($data) + { + $httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send(); + return $this->response = new PurchaseResponse($this, $httpResponse->json()); + } +} diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php new file mode 100644 index 0000000..b2e72e0 --- /dev/null +++ b/src/Message/PurchaseResponse.php @@ -0,0 +1,38 @@ +error); + } + + public function isPending() + { + return true; + } + + public function getRedirectUrl() + { + return $this->data->redirect; + } + + public function getRedirectMethod() + { + return 'GET'; + } + + public function getRedirectData() + { + return null; + } +}