Skip to content

Commit

Permalink
Added support for Connect Application Fees.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabsfm committed Sep 14, 2019
1 parent 5517ef9 commit c8959b6
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,14 @@ public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\CompletePurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\Stripe\Message\FetchApplicationFeeRequest
*/
public function fetchApplicationFee(array $parameters = array())
{
return $this->createRequest('\Omnipay\Stripe\Message\FetchApplicationFeeRequest', $parameters);
}
}
69 changes: 69 additions & 0 deletions src/Message/FetchApplicationFeeRequest.php
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';
}
}
17 changes: 17 additions & 0 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ public function getTransactionReference()
return null;
}

/**
* Get the balance transaction reference.
*
* @return string|null
*/
public function getApplicationFeeReference()
{
if (isset($this->data['object']) && 'application_fee' === $this->data['object']) {
return $this->data['id'];
}
if (isset($this->data['error']) && isset($this->data['error']['application_fee'])) {
return $this->data['error']['application_fee'];
}

return null;
}

/**
* Get the balance transaction reference.
*
Expand Down
43 changes: 43 additions & 0 deletions tests/Message/FetchApplicationFeeTest.php
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());
}
}
17 changes: 17 additions & 0 deletions tests/Mock/FetchApplicationFeeFailure.txt
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"
}
}
32 changes: 32 additions & 0 deletions tests/Mock/FetchApplicationFeeSuccess.txt
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"
}
}

0 comments on commit c8959b6

Please sign in to comment.