2 namespace PayPal\Test\Api;
4 use PayPal\Api\Capture;
6 use PayPal\Api\Authorization;
8 use PayPal\Test\Constants;
10 class CaptureTest extends \PHPUnit_Framework_TestCase {
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";
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);
30 public function setup() {
31 $this->captures['partial'] = self::createCapture();
33 $capture = self::createCapture();
34 $capture->setAmount(AmountTest::createAmount());
35 $capture->setLinks(array(LinksTest::createLinks()));
36 $this->captures['full'] = $capture;
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());
45 $this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
46 $links = $this->captures['full']->getLinks();
47 $this->assertEquals(LinksTest::$href, $links[0]->getHref());
50 public function testSerializeDeserialize() {
51 $c1 = $this->captures['partial'];
54 $c2->fromJson($c1->toJson());
56 $this->assertEquals($c1, $c2);
59 public function testOperations()
61 $authId = AuthorizationTest::authorize();
62 $auth = Authorization::get($authId);
64 $amount = new Amount();
65 $amount->setCurrency("USD");
66 $amount->setTotal("1.00");
68 $captr = new Capture();
69 $captr->setId($authId);
70 $captr->setAmount($amount);
72 $capt = $auth->capture($captr);
73 $captureId = $capt->getId();
74 $this->assertNotNull($captureId);
76 $refund = new Refund();
77 $refund->setId($captureId);
78 $refund->setAmount($amount);
80 $capture = Capture::get($captureId);
81 $this->assertNotNull($capture->getId());
83 $retund = $capture->refund($refund);
84 $this->assertNotNull($retund->getId());