-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from pixelandtonic/master
Updates including refunds
- Loading branch information
Showing
10 changed files
with
157 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
} | ||
], | ||
"require": { | ||
"php": "^7.2", | ||
"php": "^7.0", | ||
"omnipay/common": "^3.0" | ||
}, | ||
"require-dev": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Omnipay\Paystack\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidRequestException; | ||
|
||
class RefundRequest extends AbstractRequest | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getApiEndpoint() | ||
{ | ||
return '/refund'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getData() | ||
{ | ||
$data = []; | ||
$data['transaction'] = $this->getTransactionReference(); | ||
$data['currency'] = $this->getCurrency(); | ||
|
||
if ($this->getAmountInteger()) { | ||
$data['amount'] = $this->getAmountInteger(); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function sendData($data) | ||
{ | ||
try { | ||
$response = $this->sendRequest('POST', $this->getApiEndpoint(), $data); | ||
} catch (\Exception $e) { | ||
throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
|
||
return $this->response = new RefundResponse($this, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Omnipay\Paystack\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
|
||
class RefundResponse extends AbstractResponse | ||
{ | ||
|
||
public function isSuccessful() | ||
{ | ||
|
||
if (isset($this->data['data']) && $transaction = $this->data['data']['transaction']) { | ||
if (isset($transaction['status']) && $transaction['status'] == 'reversed') { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function isRedirect() | ||
{ | ||
return false; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
if (isset($this->data['message']) && $message = $this->data['message']) { | ||
return $message; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
public function getCode() | ||
{ | ||
if (isset($this->data['data']) && $data = $this->data['data']) { | ||
return $data['access_code']; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
public function getTransactionReference() | ||
{ | ||
if (isset($this->data['data']) && $data = $this->data['data']) { | ||
if (isset($data['transaction']) && $transaction = $data['transaction']) { | ||
return $transaction['reference']; | ||
} | ||
} | ||
|
||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,34 +13,49 @@ class GatewayTest extends GatewayTestCase | |
/** @var Gateway */ | ||
protected $gateway; | ||
|
||
/** @var array */ | ||
protected $options; | ||
|
||
/** | ||
* | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); | ||
|
||
$this->options = [ | ||
'amount' => '100', | ||
'amount' => '2500', | ||
'reference' => static::PURCHASE_REFERENCE | ||
]; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testPurchase() | ||
{ | ||
$this->setMockHttpResponse('PurchaseSuccess.txt'); | ||
|
||
$options = array_merge($this->options, [ | ||
'email' => '[email protected]', | ||
'reference' => static::PURCHASE_REFERENCE | ||
'email' => '[email protected]' | ||
]); | ||
|
||
$response = $this->gateway->purchase($options)->send(); | ||
|
||
$this->assertTrue($response->isRedirect(), 'Purchase response is a redirect'); | ||
$this->assertEquals(static::PURCHASE_REFERENCE, $response->getTransactionReference(), 'Reference is as we gave it.'); | ||
$this->assertEquals( | ||
static::PURCHASE_REFERENCE, | ||
$response->getTransactionReference(), | ||
'Reference is as we gave it.' | ||
); | ||
$this->assertEquals('Authorization URL created', $response->getMessage()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testRefund() | ||
{ | ||
$this->setMockHttpResponse('RefundSuccess.txt'); | ||
|