Enabled Billing Plans and Agreements APIs

- Added API Classes, Samples, and Tests
- Updated Functional Tests
- Updated Documentation with new SDK Name
- Updated Few Samples to use newer nicer result page
This commit is contained in:
japatel
2014-10-31 10:16:13 -05:00
parent f55fd3d984
commit 4d481ad104
192 changed files with 13310 additions and 1045 deletions

View File

@@ -1,101 +1,277 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Address;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PPRestCall;
use PayPal\Api\CreditCard;
use PayPal\Api\Links;
use PayPal\Test\Constants;
/**
* Class CreditCard
*
* @package PayPal\Test\Api
*/
class CreditCardTest extends \PHPUnit_Framework_TestCase
{
private $cards;
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public static function createCreditCard()
/**
* Gets Json String of Object CreditCard
* @return string
*/
public static function getJson()
{
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpireMonth(self::$expireMonth);
$card->setExpireYear(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirstName(self::$firstName);
$card->setLastName(self::$lastName);
return $card;
}
public function setup()
{
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
public function testGetterSetters()
{
/** @var CreditCard $c */
$c = $this->cards['partial'];
$this->assertEquals(self::$cardType, $c->getType());
$this->assertEquals(self::$cardNumber, $c->getNumber());
$this->assertEquals(self::$expireMonth, $c->getExpireMonth());
$this->assertEquals(self::$expireYear, $c->getExpireYear());
$this->assertEquals(self::$cvv, $c->getCvv2());
$this->assertEquals(self::$firstName, $c->getFirstName());
$this->assertEquals(self::$lastName, $c->getLastName());
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
/** @var Links[] $link */
$link = $c->getLinks();
$this->assertEquals(LinksTest::$href, $link[0]->getHref());
}
public function testSerializeDeserialize()
{
/** @var CreditCard $c1 */
$c1 = $this->cards['full'];
$json = $c1->toJson();
$c2 = new CreditCard();
$c2->fromJson($json);
$this->assertEquals($c1, $c2);
return '{"id":"TestSample","number":"TestSample","type":"TestSample","expire_month":123,"expire_year":123,"cvv2":123,"first_name":"TestSample","last_name":"TestSample","billing_address":' .AddressTest::getJson() . ',"external_customer_id":"TestSample","state":"TestSample","valid_until":"TestSample","create_time":"TestSample","update_time":"TestSample"}';
}
/**
* @group integration
* Gets Object Instance with Json data filled in
* @return CreditCard
*/
public function testOperations()
public static function getObject()
{
/** @var CreditCard $c1 */
$c1 = $this->cards['full'];
$c1->create();
$this->assertNotNull($c1->getId());
$c2 = CreditCard::get($c1->getId());
$this->assertEquals($c1->getBillingAddress(), $c2->getBillingAddress());
$this->assertGreaterThan(0, count($c2->getLinks()));
$this->assertEquals(self::$cardType, $c2->getType());
$this->assertNotNull($c2->getState());
$this->assertEquals(true, $c2->delete());
return new CreditCard(self::getJson());
}
}
/**
* Tests for Serialization and Deserialization Issues
* @return CreditCard
*/
public function testSerializationDeserialization()
{
$obj = new CreditCard(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getId());
$this->assertNotNull($obj->getNumber());
$this->assertNotNull($obj->getType());
$this->assertNotNull($obj->getExpireMonth());
$this->assertNotNull($obj->getExpireYear());
$this->assertNotNull($obj->getCvv2());
$this->assertNotNull($obj->getFirstName());
$this->assertNotNull($obj->getLastName());
$this->assertNotNull($obj->getBillingAddress());
$this->assertNotNull($obj->getExternalCustomerId());
$this->assertNotNull($obj->getState());
$this->assertNotNull($obj->getValidUntil());
$this->assertNotNull($obj->getCreateTime());
$this->assertNotNull($obj->getUpdateTime());
$this->assertNotNull($obj->getLinks());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param CreditCard $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getId(), "TestSample");
$this->assertEquals($obj->getNumber(), "TestSample");
$this->assertEquals($obj->getType(), "TestSample");
$this->assertEquals($obj->getExpireMonth(), 123);
$this->assertEquals($obj->getExpireYear(), 123);
$this->assertEquals($obj->getCvv2(), 123);
$this->assertEquals($obj->getFirstName(), "TestSample");
$this->assertEquals($obj->getLastName(), "TestSample");
$this->assertEquals($obj->getBillingAddress(), AddressTest::getObject());
$this->assertEquals($obj->getExternalCustomerId(), "TestSample");
$this->assertEquals($obj->getState(), "TestSample");
$this->assertEquals($obj->getValidUntil(), "TestSample");
$this->assertEquals($obj->getCreateTime(), "TestSample");
$this->assertEquals($obj->getUpdateTime(), "TestSample");
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param CreditCard $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getExpire_month(), 123);
$this->assertEquals($obj->getExpire_year(), 123);
$this->assertEquals($obj->getFirst_name(), "TestSample");
$this->assertEquals($obj->getLast_name(), "TestSample");
$this->assertEquals($obj->getBilling_address(), AddressTest::getObject());
$this->assertEquals($obj->getExternal_customer_id(), "TestSample");
$this->assertEquals($obj->getValid_until(), "TestSample");
$this->assertEquals($obj->getCreate_time(), "TestSample");
$this->assertEquals($obj->getUpdate_time(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param CreditCard $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Expire_month
$obj->setExpireMonth(null);
$this->assertNull($obj->getExpire_month());
$this->assertNull($obj->getExpireMonth());
$this->assertSame($obj->getExpireMonth(), $obj->getExpire_month());
$obj->setExpire_month(123);
$this->assertEquals($obj->getExpire_month(), 123);
// Check for Expire_year
$obj->setExpireYear(null);
$this->assertNull($obj->getExpire_year());
$this->assertNull($obj->getExpireYear());
$this->assertSame($obj->getExpireYear(), $obj->getExpire_year());
$obj->setExpire_year(123);
$this->assertEquals($obj->getExpire_year(), 123);
// Check for First_name
$obj->setFirstName(null);
$this->assertNull($obj->getFirst_name());
$this->assertNull($obj->getFirstName());
$this->assertSame($obj->getFirstName(), $obj->getFirst_name());
$obj->setFirst_name("TestSample");
$this->assertEquals($obj->getFirst_name(), "TestSample");
// Check for Last_name
$obj->setLastName(null);
$this->assertNull($obj->getLast_name());
$this->assertNull($obj->getLastName());
$this->assertSame($obj->getLastName(), $obj->getLast_name());
$obj->setLast_name("TestSample");
$this->assertEquals($obj->getLast_name(), "TestSample");
// Check for Billing_address
$obj->setBillingAddress(null);
$this->assertNull($obj->getBilling_address());
$this->assertNull($obj->getBillingAddress());
$this->assertSame($obj->getBillingAddress(), $obj->getBilling_address());
$obj->setBilling_address(AddressTest::getObject());
$this->assertEquals($obj->getBilling_address(), AddressTest::getObject());
// Check for External_customer_id
$obj->setExternalCustomerId(null);
$this->assertNull($obj->getExternal_customer_id());
$this->assertNull($obj->getExternalCustomerId());
$this->assertSame($obj->getExternalCustomerId(), $obj->getExternal_customer_id());
$obj->setExternal_customer_id("TestSample");
$this->assertEquals($obj->getExternal_customer_id(), "TestSample");
// Check for Valid_until
$obj->setValidUntil(null);
$this->assertNull($obj->getValid_until());
$this->assertNull($obj->getValidUntil());
$this->assertSame($obj->getValidUntil(), $obj->getValid_until());
$obj->setValid_until("TestSample");
$this->assertEquals($obj->getValid_until(), "TestSample");
// Check for Create_time
$obj->setCreateTime(null);
$this->assertNull($obj->getCreate_time());
$this->assertNull($obj->getCreateTime());
$this->assertSame($obj->getCreateTime(), $obj->getCreate_time());
$obj->setCreate_time("TestSample");
$this->assertEquals($obj->getCreate_time(), "TestSample");
// Check for Update_time
$obj->setUpdateTime(null);
$this->assertNull($obj->getUpdate_time());
$this->assertNull($obj->getUpdateTime());
$this->assertSame($obj->getUpdateTime(), $obj->getUpdate_time());
$obj->setUpdate_time("TestSample");
$this->assertEquals($obj->getUpdate_time(), "TestSample");
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
/**
* @dataProvider mockProvider
* @param CreditCard $obj
*/
public function testCreate($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$result = $obj->create($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param CreditCard $obj
*/
public function testGet($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
CreditCardTest::getJson()
));
$result = $obj->get("creditCardId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param CreditCard $obj
*/
public function testDelete($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
true
));
$result = $obj->delete($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param CreditCard $obj
*/
public function testUpdate($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
self::getJson()
));
$result = $obj->update($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
public function mockProvider()
{
$obj = self::getObject();
$mockApiContext = $this->getMockBuilder('ApiContext')
->disableOriginalConstructor()
->getMock();
return array(
array($obj, $mockApiContext),
array($obj, null)
);
}
}