Skip to content

Commit d9580b1

Browse files
authored
Merge pull request #153 from fotomerchant/feature/connect-application-fee
Added support for Connect Application Fees endpoint
2 parents 5517ef9 + f4b689c commit d9580b1

File tree

6 files changed

+191
-0
lines changed

6 files changed

+191
-0
lines changed

src/AbstractGateway.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ public function fetchBalanceTransaction(array $parameters = array())
263263
return $this->createRequest('\Omnipay\Stripe\Message\FetchBalanceTransactionRequest', $parameters);
264264
}
265265

266+
//
267+
// Application Fees
268+
// @link https://stripe.com/docs/api#application_fees
269+
//
270+
271+
/**
272+
* @param array $parameters
273+
*
274+
* @return \Omnipay\Stripe\Message\FetchApplicationFeeRequest
275+
*/
276+
public function fetchApplicationFee(array $parameters = array())
277+
{
278+
return $this->createRequest('\Omnipay\Stripe\Message\FetchApplicationFeeRequest', $parameters);
279+
}
280+
266281
//
267282
// Transfers
268283
// @link https://stripe.com/docs/api#transfers
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* Stripe Fetch Application Fee Request.
5+
*/
6+
7+
namespace Omnipay\Stripe\Message;
8+
9+
/**
10+
* Stripe Fetch Application Fee Request.
11+
*
12+
* Example -- note this example assumes that an application fee has been successful.
13+
*
14+
* <code>
15+
* // Fetch the transaction so that details can be found for refund, etc.
16+
* $transaction = $gateway->fetchApplicationFee();
17+
* $transaction->setApplicationFeeReference($application_fee_id);
18+
* $response = $transaction->send();
19+
* $data = $response->getData();
20+
* echo "Gateway fetchApplicationFee response data == " . print_r($data, true) . "\n";
21+
* </code>
22+
*
23+
* @see \Omnipay\Stripe\Gateway
24+
*
25+
* @link https://stripe.com/docs/api#retrieve_application_fee
26+
*/
27+
class FetchApplicationFeeRequest extends AbstractRequest
28+
{
29+
/**
30+
* Get the application fee reference
31+
*
32+
* @return string
33+
*/
34+
public function getApplicationFeeReference()
35+
{
36+
return $this->getParameter('applicationFeeReference');
37+
}
38+
39+
/**
40+
* Set the application fee reference
41+
*
42+
* @param string $value
43+
*
44+
* @return AbstractRequest provides a fluent interface.
45+
*/
46+
public function setApplicationFeeReference($value)
47+
{
48+
return $this->setParameter('applicationFeeReference', $value);
49+
}
50+
51+
public function getData()
52+
{
53+
$this->validate('applicationFeeReference');
54+
55+
$data = array();
56+
57+
return $data;
58+
}
59+
60+
public function getEndpoint()
61+
{
62+
return $this->endpoint . '/application_fees/' . $this->getApplicationFeeReference();
63+
}
64+
65+
public function getHttpMethod()
66+
{
67+
return 'GET';
68+
}
69+
}

src/Message/Response.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,23 @@ public function getTransactionReference()
100100
return null;
101101
}
102102

103+
/**
104+
* Get the balance transaction reference.
105+
*
106+
* @return string|null
107+
*/
108+
public function getApplicationFeeReference()
109+
{
110+
if (isset($this->data['object']) && 'application_fee' === $this->data['object']) {
111+
return $this->data['id'];
112+
}
113+
if (isset($this->data['error']) && isset($this->data['error']['application_fee'])) {
114+
return $this->data['error']['application_fee'];
115+
}
116+
117+
return null;
118+
}
119+
103120
/**
104121
* Get the balance transaction reference.
105122
*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Omnipay\Stripe\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class FetchApplicationFeeTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new FetchApplicationFeeRequest($this->getHttpClient(), $this->getHttpRequest());
12+
$this->request->setApplicationFeeReference('fee_1FITlv123YJsynqe3nOIfake');
13+
}
14+
15+
public function testEndpoint()
16+
{
17+
$this->assertSame('https://api.stripe.com/v1/application_fees/fee_1FITlv123YJsynqe3nOIfake', $this->request->getEndpoint());
18+
}
19+
20+
public function testSendSuccess()
21+
{
22+
$this->setMockHttpResponse('FetchApplicationFeeSuccess.txt');
23+
$response = $this->request->send();
24+
25+
$this->assertTrue($response->isSuccessful());
26+
$this->assertFalse($response->isRedirect());
27+
$this->assertSame('fee_1FITlv123YJsynqe3nOIfake', $response->getApplicationFeeReference());
28+
$this->assertNull($response->getMessage());
29+
}
30+
31+
public function testSendError()
32+
{
33+
$this->setMockHttpResponse('FetchApplicationFeeFailure.txt');
34+
$response = $this->request->send();
35+
36+
$this->assertFalse($response->isSuccessful());
37+
$this->assertFalse($response->isRedirect());
38+
$this->assertNull($response->getApplicationFeeReference());
39+
$this->assertSame('No such application fee: fee_1FITlv123YJsynqe3nOIfake', $response->getMessage());
40+
}
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
HTTP/1.1 404 Not Found
2+
Server: nginx
3+
Date: Wed, 24 Jul 2013 13:40:31 GMT
4+
Content-Type: application/json;charset=utf-8
5+
Content-Length: 132
6+
Connection: keep-alive
7+
Access-Control-Allow-Credentials: true
8+
Access-Control-Max-Age: 300
9+
Cache-Control: no-cache, no-store
10+
11+
{
12+
"error": {
13+
"type": "invalid_request_error",
14+
"message": "No such application fee: fee_1FITlv123YJsynqe3nOIfake",
15+
"param": "id"
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
HTTP/1.1 200 OK
2+
Server: nginx
3+
Date: Wed, 24 Jul 2013 07:14:02 GMT
4+
Content-Type: application/json;charset=utf-8
5+
Content-Length: 1092
6+
Connection: keep-alive
7+
Access-Control-Allow-Credentials: true
8+
Access-Control-Max-Age: 300
9+
Cache-Control: no-cache, no-store
10+
11+
{
12+
"id": "fee_1FITlv123YJsynqe3nOIfake",
13+
"object": "application_fee",
14+
"account": "acct_14901h0a0fh01293",
15+
"amount": 100,
16+
"amount_refunded": 0,
17+
"application": "ca_Fo5xaLt123SEtSKHui0SZOgAiuVwfake",
18+
"balance_transaction": "txn_1FH8W123vYJsynqeQKMWfake",
19+
"charge": "ch_1FIT123rvYJsynqeQpJOFfake",
20+
"created": 1568438771,
21+
"currency": "usd",
22+
"livemode": false,
23+
"originating_transaction": null,
24+
"refunded": false,
25+
"refunds": {
26+
"object": "list",
27+
"data": [],
28+
"has_more": false,
29+
"total_count": 0,
30+
"url": "/v1/application_fees/fee_1FITlvArvYJsynqe3nOIfake/refunds"
31+
}
32+
}

0 commit comments

Comments
 (0)