a1162fde4fd490960e4e43ebf52c30bf88630e58
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 namespace PayPal\Test\Api;
3
4 use PayPal\Api\Capture;
5 use PayPal\Api\Refund;
6 use PayPal\Api\Authorization;
7 use PayPal\Api\Amount;
8 use PayPal\Test\Constants;
9
10 class CaptureTest extends \PHPUnit_Framework_TestCase {
11
12         private $captures;
13
14         public static $authorization_id = "AUTH-123";
15         public static $create_time = "2013-02-28T00:00:00Z";
16         public static $id = "C-5678";
17         public static $parent_payment = "PAY-123";
18         public static $state = "Created";
19
20         public static function createCapture() {
21                 $capture = new Capture();
22                 $capture->setCreateTime(self::$create_time);
23                 $capture->setId(self::$id);
24                 $capture->setParentPayment(self::$parent_payment);
25                 $capture->setState(self::$state);               
26                 
27                 return $capture;
28         }
29         
30         public function setup() {
31                 $this->captures['partial'] = self::createCapture();
32                 
33                 $capture = self::createCapture();
34                 $capture->setAmount(AmountTest::createAmount());
35                 $capture->setLinks(array(LinksTest::createLinks()));
36                 $this->captures['full'] = $capture;
37         }
38
39         public function testGetterSetter() {
40                 $this->assertEquals(self::$create_time, $this->captures['partial']->getCreateTime());
41                 $this->assertEquals(self::$id, $this->captures['partial']->getId());
42                 $this->assertEquals(self::$parent_payment, $this->captures['partial']->getParentPayment());
43                 $this->assertEquals(self::$state, $this->captures['partial']->getState());
44                 
45                 $this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
46                 $links = $this->captures['full']->getLinks();
47                 $this->assertEquals(LinksTest::$href, $links[0]->getHref());
48         }
49         
50         public function testSerializeDeserialize() {
51                 $c1 = $this->captures['partial'];
52                 
53                 $c2 = new Capture();
54                 $c2->fromJson($c1->toJson());
55                 
56                 $this->assertEquals($c1, $c2);
57         }
58         
59         public function testOperations()
60         {
61                 $authId = AuthorizationTest::authorize();
62                 $auth = Authorization::get($authId);
63                 
64                 $amount = new Amount();
65                 $amount->setCurrency("USD");
66                 $amount->setTotal("1.00");
67                 
68                 $captr = new Capture();
69                 $captr->setId($authId);
70                 $captr->setAmount($amount);
71                 
72                 $capt = $auth->capture($captr);
73                 $captureId = $capt->getId();
74                 $this->assertNotNull($captureId);
75                 
76                 $refund = new Refund();
77                 $refund->setId($captureId);
78                 $refund->setAmount($amount);
79                 
80                 $capture = Capture::get($captureId);
81                 $this->assertNotNull($capture->getId());
82                 
83                 $retund = $capture->refund($refund);
84                 $this->assertNotNull($retund->getId());
85                 
86         }
87 }