Skip to content

Commit c8959b6

Browse files
committed
Added support for Connect Application Fees.
1 parent 5517ef9 commit c8959b6

File tree

6 files changed

+188
-0
lines changed

6 files changed

+188
-0
lines changed

src/Gateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,14 @@ public function completePurchase(array $parameters = array())
338338
{
339339
return $this->createRequest('\Omnipay\Stripe\Message\CompletePurchaseRequest', $parameters);
340340
}
341+
342+
/**
343+
* @param array $parameters
344+
*
345+
* @return \Omnipay\Stripe\Message\FetchApplicationFeeRequest
346+
*/
347+
public function fetchApplicationFee(array $parameters = array())
348+
{
349+
return $this->createRequest('\Omnipay\Stripe\Message\FetchApplicationFeeRequest', $parameters);
350+
}
341351
}
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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->getCardReference());
29+
$this->assertNull($response->getMessage());
30+
}
31+
32+
public function testSendError()
33+
{
34+
$this->setMockHttpResponse('FetchApplicationFeeFailure.txt');
35+
$response = $this->request->send();
36+
37+
$this->assertFalse($response->isSuccessful());
38+
$this->assertFalse($response->isRedirect());
39+
$this->assertNull($response->getBalanceTransactionReference());
40+
$this->assertNull($response->getCardReference());
41+
$this->assertSame('No such application fee: fee_1FITlv123YJsynqe3nOIfake', $response->getMessage());
42+
}
43+
}
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)