diff --git a/README.md b/README.md index 1b1d280..b40e37e 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ repository. )); // Start the purchase - if (!isset($_GET['status'])) { + if (!isset($_GET['trxid'])) { $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $response = $gateway->purchase(array( 'amount' => "1.50", diff --git a/src/Gateway.php b/src/Gateway.php index 02c7bb1..cab8aac 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -4,15 +4,13 @@ namespace Omnipay\Inforbank; use Omnipay\Common\AbstractGateway; -class Gateway extends AbstractGateway { - public function getName() { +class Gateway extends AbstractGateway +{ + public function getName() + { return 'Inforbank'; } - public function getDefaultParameters() { - return array(); - } - /** * Start a purchase request. * @param array $parameters An array of options 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; + } +}