File tree Expand file tree Collapse file tree 5 files changed +75
-1
lines changed Expand file tree Collapse file tree 5 files changed +75
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ The following gateways are provided by this package:
36
36
For general usage instructions, please see the main [ Omnipay] ( https://github.com/thephpleague/omnipay )
37
37
repository.
38
38
39
+ ### Stripe.js
40
+
39
41
The Stripe integration is fairly straight forward. Essentially you just pass
40
42
a ` token ` field through to Stripe instead of the regular credit card data.
41
43
@@ -50,6 +52,20 @@ $token = $_POST['stripeToken'];
50
52
$response = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'token' => $token])->send();
51
53
```
52
54
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
+
53
69
## Test Mode
54
70
55
71
Stripe accounts have test-mode API keys as well as live-mode API keys. These keys can be active
Original file line number Diff line number Diff line change 62
62
*/
63
63
class AuthorizeRequest extends AbstractRequest
64
64
{
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
+
65
80
public function getData ()
66
81
{
67
82
$ this ->validate ('amount ' , 'currency ' );
@@ -73,6 +88,10 @@ public function getData()
73
88
$ data ['metadata ' ] = $ this ->getMetadata ();
74
89
$ data ['capture ' ] = 'false ' ;
75
90
91
+ if ($ this ->getApplicationFee ()) {
92
+ $ data ['application_fee ' ] = $ this ->getApplicationFeeInteger ();
93
+ }
94
+
76
95
if ($ this ->getCardReference ()) {
77
96
$ data ['customer ' ] = $ this ->getCardReference ();
78
97
} elseif ($ this ->getToken ()) {
Original file line number Diff line number Diff line change 50
50
*/
51
51
class RefundRequest extends AbstractRequest
52
52
{
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
+
53
80
public function getData ()
54
81
{
55
82
$ this ->validate ('transactionReference ' , 'amount ' );
56
83
57
84
$ data = array ();
58
85
$ data ['amount ' ] = $ this ->getAmountInteger ();
59
86
87
+ if ($ this ->getRefundApplicationFee ()) {
88
+ $ data ['refund_application_fee ' ] = true ;
89
+ }
90
+
60
91
return $ data ;
61
92
}
62
93
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public function setUp()
18
18
'metadata ' => array (
19
19
'foo ' => 'bar ' ,
20
20
),
21
+ 'applicationFee ' => '1.00 '
21
22
)
22
23
);
23
24
}
@@ -31,6 +32,7 @@ public function testGetData()
31
32
$ this ->assertSame ('Order #42 ' , $ data ['description ' ]);
32
33
$ this ->assertSame ('false ' , $ data ['capture ' ]);
33
34
$ this ->assertSame (array ('foo ' => 'bar ' ), $ data ['metadata ' ]);
35
+ $ this ->assertSame (100 , $ data ['application_fee ' ]);
34
36
}
35
37
36
38
/**
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ public function setUp()
10
10
{
11
11
$ this ->request = new RefundRequest ($ this ->getHttpClient (), $ this ->getHttpRequest ());
12
12
$ this ->request ->setTransactionReference ('ch_12RgN9L7XhO9mI ' )
13
- ->setAmount ('10.00 ' );
13
+ ->setAmount ('10.00 ' )-> setRefundApplicationFee ( true ) ;
14
14
}
15
15
16
16
public function testEndpoint ()
@@ -24,6 +24,12 @@ public function testAmount()
24
24
$ this ->assertSame (1000 , $ data ['amount ' ]);
25
25
}
26
26
27
+ public function testRefundApplicationFee ()
28
+ {
29
+ $ data = $ this ->request ->getData ();
30
+ $ this ->assertTrue ($ data ['refund_application_fee ' ]);
31
+ }
32
+
27
33
public function testSendSuccess ()
28
34
{
29
35
$ this ->setMockHttpResponse ('RefundSuccess.txt ' );
You can’t perform that action at this time.
0 commit comments