This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/tests/PayPal/Test/Api/CreditCardTest.php
japatel 61a52e4623 Enabled EC Parameters support
- Updated Api to enabled EC Parameters
- Updated Tests
- Updated Logging Manager
- Added a feature to do validation on accessors.
2014-10-10 10:50:49 -05:00

101 lines
3.0 KiB
PHP

<?php
namespace PayPal\Test\Api;
use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Api\Links;
use PayPal\Test\Constants;
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()
{
$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);
}
/**
* @group integration
*/
public function testOperations()
{
/** @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());
}
}