-
Notifications
You must be signed in to change notification settings - Fork 168
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 #17 from andrewtweber/master
Void transactions
- Loading branch information
Showing
6 changed files
with
115 additions
and
0 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
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 | ||
/** | ||
* Stripe Void Request | ||
*/ | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
/** | ||
* Stripe Void Request | ||
* | ||
* Stripe does not support voiding, per se, but | ||
* we treat it as a full refund. | ||
* | ||
* See RefundRequest for additional information | ||
* | ||
* Example -- note this example assumes that the purchase has been successful | ||
* and that the transaction ID returned from the purchase is held in $sale_id. | ||
* See PurchaseRequest for the first part of this example transaction: | ||
* | ||
* <code> | ||
* // Do a void transaction on the gateway | ||
* $transaction = $gateway->void(array( | ||
* 'transactionReference' => $sale_id, | ||
* )); | ||
* $response = $transaction->send(); | ||
* if ($response->isSuccessful()) { | ||
* echo "Void transaction was successful!\n"; | ||
* $void_id = $response->getTransactionReference(); | ||
* echo "Transaction reference = " . $void_id . "\n"; | ||
* } | ||
* </code> | ||
* | ||
* @see RefundRequest | ||
* @see Omnipay\Stripe\Gateway | ||
* @link https://stripe.com/docs/api#create_refund | ||
*/ | ||
class VoidRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('transactionReference'); | ||
|
||
return null; | ||
} | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->endpoint.'/charges/'.$this->getTransactionReference().'/refund'; | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
use Omnipay\Tests\TestCase; | ||
|
||
class VoidRequestTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->setTransactionReference('ch_12RgN9L7XhO9mI'); | ||
} | ||
|
||
public function testEndpoint() | ||
{ | ||
$this->assertSame('https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund', $this->request->getEndpoint()); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('VoidSuccess.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertSame('ch_12RgN9L7XhO9mI', $response->getTransactionReference()); | ||
$this->assertNull($response->getCardReference()); | ||
$this->assertNull($response->getMessage()); | ||
} | ||
|
||
public function testSendError() | ||
{ | ||
$this->setMockHttpResponse('VoidFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertNull($response->getTransactionReference()); | ||
$this->assertNull($response->getCardReference()); | ||
$this->assertSame('Charge ch_12RgN9L7XhO9mI has already been refunded.', $response->getMessage()); | ||
} | ||
} |
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,3 @@ | ||
HTTP/1.1 200 OK | ||
|
||
{"error":{"message":"Charge ch_12RgN9L7XhO9mI has already been refunded."}} |
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,3 @@ | ||
HTTP/1.1 200 OK | ||
|
||
{"id":"ch_12RgN9L7XhO9mI","object": "charge"} |