forked from thephpleague/omnipay-stripe
-
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.
Added support for Connect Application Fees.
- Loading branch information
Showing
6 changed files
with
188 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,69 @@ | ||
<?php | ||
|
||
/** | ||
* Stripe Fetch Application Fee Request. | ||
*/ | ||
|
||
namespace Omnipay\Stripe\Message; | ||
|
||
/** | ||
* Stripe Fetch Application Fee Request. | ||
* | ||
* Example -- note this example assumes that an application fee has been successful. | ||
* | ||
* <code> | ||
* // Fetch the transaction so that details can be found for refund, etc. | ||
* $transaction = $gateway->fetchApplicationFee(); | ||
* $transaction->setApplicationFeeReference($application_fee_id); | ||
* $response = $transaction->send(); | ||
* $data = $response->getData(); | ||
* echo "Gateway fetchApplicationFee response data == " . print_r($data, true) . "\n"; | ||
* </code> | ||
* | ||
* @see \Omnipay\Stripe\Gateway | ||
* | ||
* @link https://stripe.com/docs/api#retrieve_application_fee | ||
*/ | ||
class FetchApplicationFeeRequest extends AbstractRequest | ||
{ | ||
/** | ||
* Get the application fee reference | ||
* | ||
* @return string | ||
*/ | ||
public function getApplicationFeeReference() | ||
{ | ||
return $this->getParameter('applicationFeeReference'); | ||
} | ||
|
||
/** | ||
* Set the application fee reference | ||
* | ||
* @param string $value | ||
* | ||
* @return AbstractRequest provides a fluent interface. | ||
*/ | ||
public function setApplicationFeeReference($value) | ||
{ | ||
return $this->setParameter('applicationFeeReference', $value); | ||
} | ||
|
||
public function getData() | ||
{ | ||
$this->validate('applicationFeeReference'); | ||
|
||
$data = array(); | ||
|
||
return $data; | ||
} | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->endpoint . '/application_fees/' . $this->getApplicationFeeReference(); | ||
} | ||
|
||
public function getHttpMethod() | ||
{ | ||
return 'GET'; | ||
} | ||
} |
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 FetchApplicationFeeTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->request = new FetchApplicationFeeRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->setApplicationFeeReference('fee_1FITlv123YJsynqe3nOIfake'); | ||
} | ||
|
||
public function testEndpoint() | ||
{ | ||
$this->assertSame('https://api.stripe.com/v1/application_fees/fee_1FITlv123YJsynqe3nOIfake', $this->request->getEndpoint()); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('FetchApplicationFeeSuccess.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertSame('fee_1FITlv123YJsynqe3nOIfake', $response->getApplicationFeeReference()); | ||
$this->assertNull($response->getCardReference()); | ||
$this->assertNull($response->getMessage()); | ||
} | ||
|
||
public function testSendError() | ||
{ | ||
$this->setMockHttpResponse('FetchApplicationFeeFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertNull($response->getBalanceTransactionReference()); | ||
$this->assertNull($response->getCardReference()); | ||
$this->assertSame('No such application fee: fee_1FITlv123YJsynqe3nOIfake', $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,17 @@ | ||
HTTP/1.1 404 Not Found | ||
Server: nginx | ||
Date: Wed, 24 Jul 2013 13:40:31 GMT | ||
Content-Type: application/json;charset=utf-8 | ||
Content-Length: 132 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
|
||
{ | ||
"error": { | ||
"type": "invalid_request_error", | ||
"message": "No such application fee: fee_1FITlv123YJsynqe3nOIfake", | ||
"param": "id" | ||
} | ||
} |
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,32 @@ | ||
HTTP/1.1 200 OK | ||
Server: nginx | ||
Date: Wed, 24 Jul 2013 07:14:02 GMT | ||
Content-Type: application/json;charset=utf-8 | ||
Content-Length: 1092 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
|
||
{ | ||
"id": "fee_1FITlv123YJsynqe3nOIfake", | ||
"object": "application_fee", | ||
"account": "acct_14901h0a0fh01293", | ||
"amount": 100, | ||
"amount_refunded": 0, | ||
"application": "ca_Fo5xaLt123SEtSKHui0SZOgAiuVwfake", | ||
"balance_transaction": "txn_1FH8W123vYJsynqeQKMWfake", | ||
"charge": "ch_1FIT123rvYJsynqeQpJOFfake", | ||
"created": 1568438771, | ||
"currency": "usd", | ||
"livemode": false, | ||
"originating_transaction": null, | ||
"refunded": false, | ||
"refunds": { | ||
"object": "list", | ||
"data": [], | ||
"has_more": false, | ||
"total_count": 0, | ||
"url": "/v1/application_fees/fee_1FITlvArvYJsynqe3nOIfake/refunds" | ||
} | ||
} |