Skip to content

Commit fa2ad61

Browse files
committed
Merge pull request #11 from cfreear/master
Stripe Connect transaction_fee
2 parents b3ed102 + 132b20e commit fa2ad61

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The following gateways are provided by this package:
3636
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
3737
repository.
3838

39+
### Stripe.js
40+
3941
The Stripe integration is fairly straight forward. Essentially you just pass
4042
a `token` field through to Stripe instead of the regular credit card data.
4143

@@ -50,6 +52,20 @@ $token = $_POST['stripeToken'];
5052
$response = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'token' => $token])->send();
5153
```
5254

55+
### Stripe Connect
56+
57+
Stripe connect applications can charge an additional fee on top of Stripe's fees for charges they make on behalf of
58+
their users. To do this you need to specify an additional `transactionFee` parameter as part of an authorize or purchase
59+
request.
60+
61+
When a charge is refunded the transaction fee is refunded with an amount proportional to the amount of the charge
62+
refunded and by default this will come from your connected user's Stripe account effectively leaving them out of pocket.
63+
To refund from your (the applications) Stripe account instead you can pass a ``refundApplicationFee`` parameter with a
64+
boolean value of true as part of a refund request.
65+
66+
Note: making requests with Stripe Connect specific parameters can only be made using the OAuth access token you received
67+
as part of the authorization process. Read more on Stripe Connect [here](https://stripe.com/docs/connect).
68+
5369
## Test Mode
5470

5571
Stripe accounts have test-mode API keys as well as live-mode API keys. These keys can be active

src/Message/AuthorizeRequest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@
6262
*/
6363
class AuthorizeRequest extends AbstractRequest
6464
{
65+
public function getApplicationFee()
66+
{
67+
return $this->getParameter('applicationFee');
68+
}
69+
70+
public function getApplicationFeeInteger()
71+
{
72+
return (int) round($this->getApplicationFee() * pow(10, $this->getCurrencyDecimalPlaces()));
73+
}
74+
75+
public function setApplicationFee($value)
76+
{
77+
return $this->setParameter('applicationFee', $value);
78+
}
79+
6580
public function getData()
6681
{
6782
$this->validate('amount', 'currency');
@@ -73,6 +88,10 @@ public function getData()
7388
$data['metadata'] = $this->getMetadata();
7489
$data['capture'] = 'false';
7590

91+
if ($this->getApplicationFee()) {
92+
$data['application_fee'] = $this->getApplicationFeeInteger();
93+
}
94+
7695
if ($this->getCardReference()) {
7796
$data['customer'] = $this->getCardReference();
7897
} elseif ($this->getToken()) {

src/Message/RefundRequest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,44 @@
5050
*/
5151
class RefundRequest extends AbstractRequest
5252
{
53+
/**
54+
* @return bool Whether the application fee should be refunded
55+
*/
56+
public function getRefundApplicationFee()
57+
{
58+
return $this->getParameter('refundApplicationFee');
59+
}
60+
61+
/**
62+
* Whether to refund the application fee associated with a charge.
63+
*
64+
* From the {@link https://stripe.com/docs/api#create_refund Stripe docs}:
65+
* Boolean indicating whether the application fee should be refunded
66+
* when refunding this charge. If a full charge refund is given, the
67+
* full application fee will be refunded. Else, the application fee
68+
* will be refunded with an amount proportional to the amount of the
69+
* charge refunded. An application fee can only be refunded by the
70+
* application that created the charge.
71+
*
72+
* @param bool $value Whether the application fee should be refunded
73+
* @return AbstractRequest
74+
*/
75+
public function setRefundApplicationFee($value)
76+
{
77+
return $this->setParameter('refundApplicationFee', $value);
78+
}
79+
5380
public function getData()
5481
{
5582
$this->validate('transactionReference', 'amount');
5683

5784
$data = array();
5885
$data['amount'] = $this->getAmountInteger();
5986

87+
if ($this->getRefundApplicationFee()) {
88+
$data['refund_application_fee'] = true;
89+
}
90+
6091
return $data;
6192
}
6293

tests/Message/AuthorizeRequestTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function setUp()
1818
'metadata' => array(
1919
'foo' => 'bar',
2020
),
21+
'applicationFee' => '1.00'
2122
)
2223
);
2324
}
@@ -31,6 +32,7 @@ public function testGetData()
3132
$this->assertSame('Order #42', $data['description']);
3233
$this->assertSame('false', $data['capture']);
3334
$this->assertSame(array('foo' => 'bar'), $data['metadata']);
35+
$this->assertSame(100, $data['application_fee']);
3436
}
3537

3638
/**

tests/Message/RefundRequestTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function setUp()
1010
{
1111
$this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest());
1212
$this->request->setTransactionReference('ch_12RgN9L7XhO9mI')
13-
->setAmount('10.00');
13+
->setAmount('10.00')->setRefundApplicationFee(true);
1414
}
1515

1616
public function testEndpoint()
@@ -24,6 +24,12 @@ public function testAmount()
2424
$this->assertSame(1000, $data['amount']);
2525
}
2626

27+
public function testRefundApplicationFee()
28+
{
29+
$data = $this->request->getData();
30+
$this->assertTrue($data['refund_application_fee']);
31+
}
32+
2733
public function testSendSuccess()
2834
{
2935
$this->setMockHttpResponse('RefundSuccess.txt');

0 commit comments

Comments
 (0)