File tree Expand file tree Collapse file tree 5 files changed +156
-0
lines changed Expand file tree Collapse file tree 5 files changed +156
-0
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,14 @@ public function cancelSubscription($subscriptionId)
250
250
return $ this ->createRequest ('\Omnipay\Braintree\Message\CancelSubscriptionRequest ' , array ('id ' => $ subscriptionId ));
251
251
}
252
252
253
+ /**
254
+ * @return \Omnipay\Common\Message\PlansRequest
255
+ */
256
+ public function plans ()
257
+ {
258
+ return $ this ->createRequest ('\Omnipay\Braintree\Message\PlanRequest ' , array ());
259
+ }
260
+
253
261
/**
254
262
* @param array $parameters
255
263
*
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * PlanRequest Class
4
+ */
5
+
6
+ namespace Omnipay \Braintree \Message ;
7
+
8
+ class PlanRequest extends AbstractRequest
9
+ {
10
+ /**
11
+ * @return null
12
+ */
13
+ public function getData ()
14
+ {
15
+ return null ;
16
+ }
17
+
18
+ /**
19
+ * @param null $data
20
+ * @return PlanResponse
21
+ */
22
+ public function sendData ($ data = null )
23
+ {
24
+ $ response = $ this ->braintree ->plan ()->all ();
25
+ return $ this ->response = new PlanResponse ($ this , $ response );
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * PlanResponse class
4
+ */
5
+ namespace Omnipay \Braintree \Message ;
6
+
7
+
8
+ class PlanResponse extends Response
9
+ {
10
+ /**
11
+ * Returns array of Braintree_Plans objects with available plans
12
+ * If there aren't any plans created it will return empty array
13
+ * @return array
14
+ */
15
+ public function getPlansData ()
16
+ {
17
+ if (isset ($ this ->data )) {
18
+ return $ this ->data ;
19
+ }
20
+ return array ();
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: xobb
5
+ * Date: 1/22/16
6
+ * Time: 5:53 PM
7
+ */
8
+
9
+ namespace Omnipay \Braintree \Message ;
10
+
11
+ use Omnipay \Tests \TestCase ;
12
+
13
+ class PlanRequestTest extends TestCase
14
+ {
15
+ /** @var PlanRequest */
16
+ private $ request ;
17
+
18
+ public function setUp ()
19
+ {
20
+ parent ::setUp ();
21
+
22
+ $ gateway = $ this ->buildMockGateway ();
23
+ $ this ->request = new PlanRequest ($ this ->getHttpClient (), $ this ->getHttpRequest (), $ gateway );
24
+ $ this ->request ->initialize (array ());
25
+ }
26
+
27
+ public function testGetData ()
28
+ {
29
+ $ data = $ this ->request ->getData ();
30
+ $ this ->assertNull ($ data );
31
+ }
32
+
33
+ public function testSendData ()
34
+ {
35
+ $ data = array ();
36
+ $ response = $ this ->request ->sendData ($ data );
37
+
38
+ $ this ->assertInstanceOf ('Omnipay\BrainTree\Message\PlanResponse ' , $ response );
39
+ }
40
+
41
+ protected function buildMockGateway ()
42
+ {
43
+ $ gateway = $ this ->getMockBuilder ('\Braintree_Gateway ' )
44
+ ->disableOriginalConstructor ()
45
+ ->setMethods (array (
46
+ 'plan '
47
+ ))
48
+ ->getMock ();
49
+
50
+ $ plan = $ this ->getMockBuilder ('\Braintree_PlanGateway ' )
51
+ ->disableOriginalConstructor ()
52
+ ->getMock ();
53
+
54
+ $ gateway ->expects ($ this ->any ())
55
+ ->method ('plan ' )
56
+ ->will ($ this ->returnValue ($ plan ));
57
+
58
+ return $ gateway ;
59
+ }
60
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: xobb
5
+ * Date: 1/22/16
6
+ * Time: 5:53 PM
7
+ */
8
+
9
+ namespace Omnipay \Braintree \Message ;
10
+ use Omnipay \Tests \TestCase ;
11
+
12
+ class PlanResponseTest extends TestCase
13
+ {
14
+ /** @var PlanRequest */
15
+ private $ request ;
16
+
17
+ public function setUp ()
18
+ {
19
+ parent ::setUp ();
20
+
21
+ $ this ->request = new PlanRequest (
22
+ $ this ->getHttpClient (), $ this ->getHttpRequest (), \Braintree_Configuration::gateway ()
23
+ );
24
+ }
25
+
26
+ public function testGetPlansData ()
27
+ {
28
+ $ data = null ;
29
+
30
+ $ response = new PlanResponse ($ this ->request , $ data );
31
+ $ this ->assertTrue (is_array ($ response ->getPlansData ()));
32
+ $ this ->assertTrue (count ($ response ->getPlansData ()) === 0 );
33
+
34
+ $ data = "planData " ;
35
+
36
+ $ response = new PlanResponse ($ this ->request , $ data );
37
+ $ this ->assertEquals ('planData ' , $ response ->getPlansData ());
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments