-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authorize and capture separately (#7)
* wip * add PHP 8.1 to test suite * use setTransactionReference instead of setPaymentReference for CaptureRequest * update license * update readme and add comments * add badges * update readme * improve tests
- Loading branch information
Showing
7 changed files
with
198 additions
and
12 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ jobs: | |
- "7.3" | ||
- "7.4" | ||
- "8.0" | ||
- "8.1" | ||
operating-system: | ||
- "ubuntu-latest" | ||
|
||
|
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,50 @@ | ||
<?php | ||
|
||
namespace Omnipay\EveryPay\Messages; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
|
||
class CaptureRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate( | ||
'amount', | ||
'transactionReference' | ||
); | ||
|
||
$baseData = $this->getBaseData(); | ||
|
||
return array_merge($baseData, [ | ||
'amount' => $this->getAmount(), | ||
'payment_reference' => $this->getTransactionReference(), | ||
]); | ||
} | ||
|
||
public function sendData($data): PurchaseResponse | ||
{ | ||
try { | ||
$payment = $this->httpRequest( | ||
'POST', | ||
$this->getEndpoint() . '/payments/capture', | ||
$this->getHeaders(), | ||
$data | ||
); | ||
|
||
return $this->response = new PurchaseResponse( | ||
$this, | ||
$payment | ||
); | ||
} catch (InvalidResponseException $e) { | ||
return $this->response = new PurchaseResponse( | ||
$this, | ||
[ | ||
'error' => [ | ||
'message' => $e->getMessage(), | ||
'code' => $e->getCode(), | ||
], | ||
] | ||
); | ||
} | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
use Omnipay\Tests\TestCase; | ||
use Omnipay\EveryPay\Gateway; | ||
use Omnipay\EveryPay\Enums\PaymentType; | ||
use Omnipay\EveryPay\Messages\CaptureRequest; | ||
use Omnipay\EveryPay\Messages\CitPaymentRequest; | ||
use Omnipay\EveryPay\Messages\MitPaymentRequest; | ||
use Omnipay\EveryPay\Messages\OneOffPaymentRequest; | ||
use Omnipay\EveryPay\Messages\CompletePurchaseRequest; | ||
|
||
class RequestsTest extends TestCase | ||
{ | ||
public function testPurchaseRequest() | ||
{ | ||
$gateway = new Gateway(); | ||
|
||
$this->assertInstanceOf(OneOffPaymentRequest::class, $gateway->purchase()); | ||
|
||
$this->assertInstanceOf(OneOffPaymentRequest::class, $gateway->purchase([ | ||
'paymentType' => PaymentType::ONE_OFF, | ||
])); | ||
|
||
$this->assertInstanceOf(CitPaymentRequest::class, $gateway->purchase([ | ||
'paymentType' => PaymentType::CIT, | ||
])); | ||
|
||
$this->assertInstanceOf(MitPaymentRequest::class, $gateway->purchase([ | ||
'paymentType' => PaymentType::MIT, | ||
])); | ||
} | ||
|
||
public function testCompletePurchaseRequest() | ||
{ | ||
$gateway = new Gateway(); | ||
|
||
$this->assertInstanceOf(CompletePurchaseRequest::class, $gateway->completePurchase()); | ||
$this->assertInstanceOf(CompletePurchaseRequest::class, $gateway->completeAuthorize()); | ||
} | ||
|
||
public function testCaptureRequest() | ||
{ | ||
$gateway = new Gateway(); | ||
|
||
$this->assertInstanceOf(CaptureRequest::class, $gateway->capture()); | ||
} | ||
} |