diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index b0d8da6..fbc9bec 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -2,12 +2,11 @@ namespace Omnipay\Paystack\Message; -use Omnipay\Common\Exception\BadMethodCallException; use Omnipay\Common\Exception\InvalidRequestException; abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { - protected $baseApiEndpoint = 'https://api.paystack.co/'; + protected $baseApiEndpoint = 'https://api.paystack.co'; /** * @return string The URL endpoint for the request diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index 637f5e4..538acd9 100644 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -11,7 +11,7 @@ class CompletePurchaseRequest extends AbstractRequest */ public function getApiEndpoint() { - return $this->baseApiEndpoint . 'transaction/verify/' . rawurlencode($this->getTransactionReference()); + return '/transaction/verify/' . rawurlencode($this->getTransactionReference()); } /** @@ -28,12 +28,11 @@ public function getData() public function sendData($data) { try { - $response = $this->sendRequest('GET', $this->getApiEndpoint(), json_encode($data)); + $response = $this->sendRequest('GET', $this->getApiEndpoint(), $data); } catch (\Exception $e) { - throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e); } - return $this->response = new CompletePurchaseResponse($this, $responseData); + return $this->response = new CompletePurchaseResponse($this, $response); } } \ No newline at end of file diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 27f8407..70d9712 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -11,7 +11,7 @@ class PurchaseRequest extends AbstractRequest */ public function getApiEndpoint() { - return $this->baseApiEndpoint . '/transaction/initialize/'; + return '/transaction/initialize'; } /** @@ -26,7 +26,9 @@ public function getData() return [ 'amount' => $amount, + 'currency' => $this->getCurrency(), 'email' => $email, + 'reference' => $this->getTransactionReference(), 'callback_url' => $this->getReturnUrl(), 'metadata' => $this->getParameter('metadata') ]; diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index 5f15eca..82c458e 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -11,7 +11,7 @@ class RefundRequest extends AbstractRequest */ public function getApiEndpoint() { - return $this->baseApiEndpoint . '/refund'; + return '/refund'; } /** @@ -19,13 +19,12 @@ public function getApiEndpoint() */ public function getData() { - $amount = $this->getAmountInteger(); - $reference = $this->getTransactionReference(); + $data = []; + $data['transaction'] = $this->getTransactionReference(); + $data['currency'] = $this->getCurrency(); - $data = ['transaction' => $reference]; - - if ($amount) { - $data['amount'] = $amount; + if ($this->getAmountInteger()) { + $data['amount'] = $this->getAmountInteger(); } return $data;