Enabled EC Parameters support

- Updated Api to enabled EC Parameters
- Updated Tests
- Updated Logging Manager
- Added a feature to do validation on accessors.
This commit is contained in:
japatel
2014-10-09 11:30:12 -05:00
parent 459293838e
commit 61a52e4623
99 changed files with 9148 additions and 3609 deletions

View File

@@ -3,52 +3,57 @@ namespace PayPal\Test\Api;
use PayPal\Api\Address;
class AddressTest extends \PHPUnit_Framework_TestCase {
class AddressTest extends \PHPUnit_Framework_TestCase
{
/** @var Address */
private $address;
private $address;
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $type = "Billing";
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $type = "Billing";
public static function createAddress() {
$addr = new Address();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
return $addr;
}
public function setup() {
$this->address = self::createAddress();
}
public static function createAddress()
{
$addr = new Address();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
return $addr;
}
public function testGetterSetter() {
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
}
public function setup()
{
$this->address = self::createAddress();
}
public function testSerializeDeserialize() {
$a1 = $this->address;
$a2 = new Address();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
public function testGetterSetter()
{
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
}
public function testSerializeDeserialize()
{
$a1 = $this->address;
$a2 = new Address();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -5,41 +5,46 @@ namespace PayPal\Test\Api;
use PayPal\Api\Amount;
use PayPal\Test\Constants;
class AmountTest extends \PHPUnit_Framework_TestCase {
class AmountTest extends \PHPUnit_Framework_TestCase
{
private $amounts;
private $amounts;
public static $currency = "USD";
public static $total = "1.12";
public static $currency = "USD";
public static $total = "1.12";
public static function createAmount() {
$amount = new Amount();
$amount->setCurrency(self::$currency);
$amount->setTotal(self::$total);
return $amount;
}
public function setup() {
$this->amounts['partial'] = self::createAmount();
$amount = self::createAmount();
$amount->setDetails(DetailsTest::createAmountDetails());
$this->amounts['full'] = $amount;
}
public static function createAmount()
{
$amount = new Amount();
$amount->setCurrency(self::$currency);
$amount->setTotal(self::$total);
public function testGetterSetter() {
$this->assertEquals(self::$currency, $this->amounts['partial']->getCurrency());
$this->assertEquals(self::$total, $this->amounts['partial']->getTotal());
$this->assertEquals(DetailsTest::$fee, $this->amounts['full']->getDetails()->getFee());
}
public function testSerializeDeserialize() {
$a1 = $this->amounts['partial'];
$a2 = new Amount();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
return $amount;
}
public function setup()
{
$this->amounts['partial'] = self::createAmount();
$amount = self::createAmount();
$amount->setDetails(DetailsTest::createAmountDetails());
$this->amounts['full'] = $amount;
}
public function testGetterSetter()
{
$this->assertEquals(self::$currency, $this->amounts['partial']->getCurrency());
$this->assertEquals(self::$total, $this->amounts['partial']->getTotal());
$this->assertEquals(DetailsTest::$fee, $this->amounts['full']->getDetails()->getFee());
}
public function testSerializeDeserialize()
{
$a1 = $this->amounts['partial'];
$a2 = new Amount();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -4,129 +4,140 @@ namespace PayPal\Test\Api;
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
use PayPal\Api\Links;
use PayPal\Api\PayerInfo;
use PayPal\Test\Constants;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Address;
use PayPal\Api\Payer;
use PayPal\Api\Capture;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Exception\PPConnectionException;
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
private $authorizations = array();
public static $create_time = "2013-02-28T00:00:00Z";
class AuthorizationTest extends \PHPUnit_Framework_TestCase
{
private $authorizations = array();
public static $create_time = "2013-02-28T00:00:00Z";
public static $update_time = "2013-03-28T00:00:00Z";
public static $id = "AUTH-123";
public static $state = "Created";
public static $parent_payment = "PAY-12345";
public static $id = "AUTH-123";
public static $state = "Created";
public static $parent_payment = "PAY-12345";
public static $valid_until = "2013-04-28T00:00:00Z";
public static $currency = "USD";
public static $total = "1.12";
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createAuthorization() {
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setAmount(AmountTest::createAmount());
$authorization->setLinks(array(LinksTest::createLinks()));
return $authorization;
}
public static function authorize()
{
$addr = new Address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostalCode("14305");
$addr->setCountryCode("US");
$addr->setPhone("716-298-1822");
$card = new CreditCard();
$card->setType("visa");
$card->setNumber("4417119669820331");
$card->setExpireMonth("11");
$card->setExpireYear("2019");
$card->setCvv2("012");
$card->setFirstName("Joe");
$card->setLastName("Shopper");
$card->setBillingAddress($addr);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($fi));
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is the payment description.");
$payment = new Payment();
$payment->setIntent("authorize");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$paymnt = $payment->create();
$resArray = $paymnt->toArray();
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
public function setup() {
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setUpdateTime(self::$update_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setParentPayment(self::$parent_payment);
$authorization->setValidUntil(self::$valid_until);
$this->authorizations['partial'] = $authorization;
$this->authorizations['full'] = self::createAuthorization();
}
public static $clearing_time = "2013-04-28T00:00:00Z";
public static $currency = "USD";
public static $total = "1.12";
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public function testGetterSetter() {
$authorization = $this->authorizations['partial'];
$this->assertEquals(self::$create_time, $authorization->getCreateTime());
public static function createAuthorization()
{
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setClearingTime(self::$clearing_time);
$authorization->setAmount(AmountTest::createAmount());
$authorization->setLinks(array(LinksTest::createLinks()));
return $authorization;
}
public static function authorize()
{
$addr = new Address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostalCode("14305");
$addr->setCountryCode("US");
$addr->setPhone("716-298-1822");
$card = new CreditCard();
$card->setType("visa");
$card->setNumber("4417119669820331");
$card->setExpireMonth("11");
$card->setExpireYear("2019");
$card->setCvv2("012");
$card->setFirstName("Joe");
$card->setLastName("Shopper");
$card->setBillingAddress($addr);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($fi));
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is the payment description.");
$payment = new Payment();
$payment->setIntent("authorize");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$paymnt = $payment->create();
$resArray = $paymnt->toArray();
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
public function setup()
{
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setUpdateTime(self::$update_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setParentPayment(self::$parent_payment);
$authorization->setValidUntil(self::$valid_until);
$authorization->setClearingTime(self::$clearing_time);
$this->authorizations['partial'] = $authorization;
$this->authorizations['full'] = self::createAuthorization();
}
public function testGetterSetter()
{
/** @var Authorization $authorization */
$authorization = $this->authorizations['partial'];
$this->assertEquals(self::$create_time, $authorization->getCreateTime());
$this->assertEquals(self::$update_time, $authorization->getUpdateTime());
$this->assertEquals(self::$id, $authorization->getId());
$this->assertEquals(self::$state, $authorization->getState());
$this->assertEquals(self::$parent_payment, $authorization->getParentPayment());
$this->assertEquals(self::$id, $authorization->getId());
$this->assertEquals(self::$state, $authorization->getState());
$this->assertEquals(self::$parent_payment, $authorization->getParentPayment());
$this->assertEquals(self::$valid_until, $authorization->getValidUntil());
$authorization = $this->authorizations['full'];
$this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency());
$this->assertEquals(1, count($authorization->getLinks()));
}
public function testSerializeDeserialize() {
$a1 = $this->authorizations['partial'];
$a2 = new Authorization();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
$this->assertEquals(self::$clearing_time, $authorization->getClearingTime());
$authorization = $this->authorizations['full'];
$this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency());
$this->assertEquals(1, count($authorization->getLinks()));
}
public function testSerializeDeserialize()
{
$a1 = $this->authorizations['partial'];
$a2 = new Authorization();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
/**
* @group integration
*/
public function testOperations() {
public function testOperations()
{
try {
$authId = self::authorize();
$auth = Authorization::get($authId);
@@ -141,7 +152,7 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
$captur->setAmount($amount);
$capt = $auth->capture($captur);
$this->assertNotNull( $capt->getId());
$this->assertNotNull($capt->getId());
$authId = self::authorize();
$auth = Authorization::get($authId);
@@ -159,25 +170,26 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()
);
}
}
}
/**
* @group integration
*/
public function testReauthorize() {
$authorization = Authorization::get('7GH53639GA425732B');
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try {
$authorization->reauthorize();
} catch (PPConnectionException $ex){
public function testReauthorize()
{
$authorization = Authorization::get('7GH53639GA425732B');
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try {
$authorization->reauthorize();
} catch (PPConnectionException $ex) {
//var_dump($ex->getMessage());
$this->assertEquals(strpos($ex->getMessage(),"500"), false);
}
$this->assertEquals(strpos($ex->getMessage(), "500"), false);
}
$authorization->setId(null);
try {
@@ -185,5 +197,5 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
} catch (\InvalidArgumentException $ex) {
$this->assertEquals($ex->getMessage(), "Id cannot be null");
}
}
}
}

View File

@@ -7,60 +7,65 @@ use PayPal\Api\Authorization;
use PayPal\Api\Amount;
use PayPal\Test\Constants;
class CaptureTest extends \PHPUnit_Framework_TestCase {
class CaptureTest extends \PHPUnit_Framework_TestCase
{
private $captures;
private $captures;
public static $authorization_id = "AUTH-123";
public static $create_time = "2013-02-28T00:00:00Z";
public static $id = "C-5678";
public static $parent_payment = "PAY-123";
public static $state = "Created";
public static $authorization_id = "AUTH-123";
public static $create_time = "2013-02-28T00:00:00Z";
public static $id = "C-5678";
public static $parent_payment = "PAY-123";
public static $state = "Created";
public static function createCapture() {
$capture = new Capture();
$capture->setCreateTime(self::$create_time);
$capture->setId(self::$id);
$capture->setParentPayment(self::$parent_payment);
$capture->setState(self::$state);
return $capture;
}
public function setup() {
$this->captures['partial'] = self::createCapture();
$capture = self::createCapture();
$capture->setAmount(AmountTest::createAmount());
$capture->setLinks(array(LinksTest::createLinks()));
$this->captures['full'] = $capture;
}
public static function createCapture()
{
$capture = new Capture();
$capture->setCreateTime(self::$create_time);
$capture->setId(self::$id);
$capture->setParentPayment(self::$parent_payment);
$capture->setState(self::$state);
public function testGetterSetter() {
$this->assertEquals(self::$create_time, $this->captures['partial']->getCreateTime());
$this->assertEquals(self::$id, $this->captures['partial']->getId());
$this->assertEquals(self::$parent_payment, $this->captures['partial']->getParentPayment());
$this->assertEquals(self::$state, $this->captures['partial']->getState());
$this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
$links = $this->captures['full']->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$c1 = $this->captures['partial'];
$c2 = new Capture();
$c2->fromJson($c1->toJson());
$this->assertEquals($c1, $c2);
}
return $capture;
}
public function setup()
{
$this->captures['partial'] = self::createCapture();
$capture = self::createCapture();
$capture->setAmount(AmountTest::createAmount());
$capture->setLinks(array(LinksTest::createLinks()));
$this->captures['full'] = $capture;
}
public function testGetterSetter()
{
$this->assertEquals(self::$create_time, $this->captures['partial']->getCreateTime());
$this->assertEquals(self::$id, $this->captures['partial']->getId());
$this->assertEquals(self::$parent_payment, $this->captures['partial']->getParentPayment());
$this->assertEquals(self::$state, $this->captures['partial']->getState());
$this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
$links = $this->captures['full']->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize()
{
$c1 = $this->captures['partial'];
$c2 = new Capture();
$c2->fromJson($c1->toJson());
$this->assertEquals($c1, $c2);
}
/**
* @group integration
*/
public function testOperations()
{
public function testOperations()
{
try {
$authId = AuthorizationTest::authorize();
$auth = Authorization::get($authId);
@@ -91,6 +96,6 @@ class CaptureTest extends \PHPUnit_Framework_TestCase {
'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()
);
}
}
}
}

View File

@@ -7,66 +7,70 @@ use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Test\Constants;
class CreditCardHistoryTest 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);
$card->setId(self::$id);
$card->setValidUntil(self::$validUntil);
$card->setState(self::$state);
$card->setPayerId(self::$payerId);
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() {
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$this->assertEquals(2, count($cardHistory->getCreditCards()));
}
class CreditCardHistoryTest extends \PHPUnit_Framework_TestCase
{
public function testSerializationDeserialization() {
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$cardHistoryCopy = new CreditCardHistory();
$cardHistoryCopy->fromJson($cardHistory->toJSON());
$this->assertEquals($cardHistory, $cardHistoryCopy);
}
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);
$card->setId(self::$id);
$card->setValidUntil(self::$validUntil);
$card->setState(self::$state);
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()
{
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$this->assertEquals(2, count($cardHistory->getCreditCards()));
}
public function testSerializationDeserialization()
{
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$cardHistoryCopy = new CreditCardHistory();
$cardHistoryCopy->fromJson($cardHistory->toJSON());
$this->assertEquals($cardHistory, $cardHistoryCopy);
}
}

View File

@@ -3,90 +3,99 @@ 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;
class CreditCardTest extends \PHPUnit_Framework_TestCase
{
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";
private $cards;
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);
$card->setPayerId(self::$payerId);
return $card;
}
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 function setup() {
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;
}
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
public function setup()
{
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
public function testGetterSetters() {
$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());
$this->assertEquals(self::$payerId, $c->getPayerId());
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
$link = $c->getLinks();
$this->assertEquals(LinksTest::$href, $link[0]->getHref());
}
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());
public function testSerializeDeserialize() {
$c1 = $this->cards['full'];
$json = $c1->toJson();
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
/** @var Links[] $link */
$link = $c->getLinks();
$this->assertEquals(LinksTest::$href, $link[0]->getHref());
}
$c2 = new CreditCard();
$c2->fromJson($json);
public function testSerializeDeserialize()
{
/** @var CreditCard $c1 */
$c1 = $this->cards['full'];
$json = $c1->toJson();
$this->assertEquals($c1, $c2);
}
$c2 = new CreditCard();
$c2->fromJson($json);
$this->assertEquals($c1, $c2);
}
/**
* @group integration
*/
public function testOperations() {
$c1 = $this->cards['full'];
public function testOperations()
{
/** @var CreditCard $c1 */
$c1 = $this->cards['full'];
// $this->assertNull($c1->getId());
$c1->create();
$this->assertNotNull($c1->getId());
$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());
}
$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());
}
}

View File

@@ -4,35 +4,40 @@ namespace PayPal\Test\Api;
use PayPal\Api\CreditCardToken;
use PayPal\Test\Constants;
class CreditCardTokenTest extends \PHPUnit_Framework_TestCase {
class CreditCardTokenTest extends \PHPUnit_Framework_TestCase
{
private $ccToken;
private $ccToken;
public static $payerId = "PAYER-123";
public static $creditCardId = "CC-123";
public static $payerId = "PAYER-123";
public static $creditCardId = "CC-123";
public static function createCreditCardToken() {
$ccToken = new CreditCardToken();
$ccToken->setPayerId(self::$payerId);
$ccToken->setCreditCardId(self::$creditCardId);
return $ccToken;
}
public function setup() {
$this->ccToken = self::createCreditCardToken();
}
public static function createCreditCardToken()
{
$ccToken = new CreditCardToken();
$ccToken->setPayerId(self::$payerId);
$ccToken->setCreditCardId(self::$creditCardId);
return $ccToken;
}
public function testGetterSetter() {
$this->assertEquals(self::$payerId, $this->ccToken->getPayerId());
$this->assertEquals(self::$creditCardId, $this->ccToken->getCreditCardId());
}
public function testSerializeDeserialize() {
$t1 = $this->ccToken;
$t2 = new CreditCardToken();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
public function setup()
{
$this->ccToken = self::createCreditCardToken();
}
public function testGetterSetter()
{
$this->assertEquals(self::$payerId, $this->ccToken->getPayerId());
$this->assertEquals(self::$creditCardId, $this->ccToken->getCreditCardId());
}
public function testSerializeDeserialize()
{
$t1 = $this->ccToken;
$t2 = new CreditCardToken();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
}

View File

@@ -4,42 +4,47 @@ namespace PayPal\Test\Api;
use PayPal\Api\Details;
use PayPal\Test\Constants;
class DetailsTest extends \PHPUnit_Framework_TestCase {
class DetailsTest extends \PHPUnit_Framework_TestCase
{
private $amountDetails;
private $amountDetails;
public static $subtotal = "2.00";
public static $tax = "1.12";
public static $shipping = "3.15";
public static $fee = "4.99";
public static $subtotal = "2.00";
public static $tax = "1.12";
public static $shipping = "3.15";
public static $fee = "4.99";
public static function createAmountDetails() {
$amountDetails = new Details();
$amountDetails->setSubtotal(self::$subtotal);
$amountDetails->setTax(self::$tax);
$amountDetails->setShipping(self::$shipping);
$amountDetails->setFee(self::$fee);
return $amountDetails;
}
public static function createAmountDetails()
{
$amountDetails = new Details();
$amountDetails->setSubtotal(self::$subtotal);
$amountDetails->setTax(self::$tax);
$amountDetails->setShipping(self::$shipping);
$amountDetails->setFee(self::$fee);
public function setup() {
$this->amountDetails = self::createAmountDetails();
}
public function testGetterSetters() {
$this->assertEquals(self::$subtotal, $this->amountDetails->getSubtotal());
$this->assertEquals(self::$tax, $this->amountDetails->getTax());
$this->assertEquals(self::$shipping, $this->amountDetails->getShipping());
$this->assertEquals(self::$fee, $this->amountDetails->getFee());
}
public function testSerializeDeserialize() {
$a1 = $this->amountDetails;
$a2 = new Details();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
return $amountDetails;
}
public function setup()
{
$this->amountDetails = self::createAmountDetails();
}
public function testGetterSetters()
{
$this->assertEquals(self::$subtotal, $this->amountDetails->getSubtotal());
$this->assertEquals(self::$tax, $this->amountDetails->getTax());
$this->assertEquals(self::$shipping, $this->amountDetails->getShipping());
$this->assertEquals(self::$fee, $this->amountDetails->getFee());
}
public function testSerializeDeserialize()
{
$a1 = $this->amountDetails;
$a2 = new Details();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -5,32 +5,37 @@ namespace PayPal\Test\Api;
use PayPal\Api\FundingInstrument;
use PayPal\Test\Constants;
class FundingInstrumentTest extends \PHPUnit_Framework_TestCase {
class FundingInstrumentTest extends \PHPUnit_Framework_TestCase
{
private $fi;
private $fi;
public static function createFundingInstrument() {
$fi = new FundingInstrument();
$fi->setCreditCard(CreditCardTest::createCreditCard());
$fi->setCreditCardToken(CreditCardTokenTest::createCreditCardToken());
return $fi;
}
public static function createFundingInstrument()
{
$fi = new FundingInstrument();
$fi->setCreditCard(CreditCardTest::createCreditCard());
$fi->setCreditCardToken(CreditCardTokenTest::createCreditCardToken());
return $fi;
}
public function setup() {
$this->fi = self::createFundingInstrument();
}
public function setup()
{
$this->fi = self::createFundingInstrument();
}
public function testGetterSetter() {
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCreditCard()->getNumber());
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->fi->getCreditCardToken()->getCreditCardId());
}
public function testGetterSetter()
{
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCreditCard()->getNumber());
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->fi->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize() {
$fi1 = $this->fi;
public function testSerializeDeserialize()
{
$fi1 = $this->fi;
$fi2 = new FundingInstrument();
$fi2->fromJson($fi1->toJson());
$this->assertEquals($fi1, $fi2);
}
$fi2 = new FundingInstrument();
$fi2->fromJson($fi1->toJson());
$this->assertEquals($fi1, $fi2);
}
}

View File

@@ -5,42 +5,47 @@ use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Test\Constants;
class ItemListTest extends \PHPUnit_Framework_TestCase {
private $items = array();
private static $name = "item name";
private static $price = "1.12";
private static $quantity = "10";
private static $sku = "AXVTY123";
private static $currency = "USD";
public static function createItemList() {
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::createAddress());
return $itemList;
}
public function setup() {
$this->items = self::createItemList();
}
public function testGetterSetters() {
$items = $this->items->getItems();
$this->assertEquals(ItemTest::createItem(), $items[0]);
$this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShippingAddress());
}
public function testSerializeDeserialize() {
$itemList = new ItemList();
$itemList->fromJson($this->items->toJSON());
$this->assertEquals($itemList, $this->items);
}
class ItemListTest extends \PHPUnit_Framework_TestCase
{
private $items = array();
private static $name = "item name";
private static $price = "1.12";
private static $quantity = "10";
private static $sku = "AXVTY123";
private static $currency = "USD";
public static function createItemList()
{
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::createAddress());
return $itemList;
}
public function setup()
{
$this->items = self::createItemList();
}
public function testGetterSetters()
{
$items = $this->items->getItems();
$this->assertEquals(ItemTest::createItem(), $items[0]);
$this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShippingAddress());
}
public function testSerializeDeserialize()
{
$itemList = new ItemList();
$itemList->fromJson($this->items->toJSON());
$this->assertEquals($itemList, $this->items);
}
}

View File

@@ -4,43 +4,49 @@ namespace PayPal\Test\Api;
use PayPal\Api\Item;
use PayPal\Test\Constants;
class ItemTest extends \PHPUnit_Framework_TestCase {
private $item;
public static $name = "item name";
public static $price = "1.12";
public static $quantity = "10";
public static $sku = "AXVTY123";
public static $currency = "USD";
public static function createItem() {
$item = new Item();
$item->setName(self::$name);
$item->setPrice(self::$price);
$item->setQuantity(self::$quantity);
$item->setSku(self::$sku);
$item->setCurrency(self::$currency);
return $item;
}
public function setup() {
$this->item = ItemTest::createItem();
}
public function testGetterSetters() {
$this->assertEquals(self::$name, $this->item->getName());
$this->assertEquals(self::$price, $this->item->getPrice());
$this->assertEquals(self::$sku, $this->item->getSku());
$this->assertEquals(self::$quantity, $this->item->getQuantity());
$this->assertEquals(self::$currency, $this->item->getCurrency());
}
public function testSerializeDeserialize() {
$item = new Item();
$item->fromJson($this->item->toJSON());
$this->assertEquals($item, $this->item);
}
class ItemTest extends \PHPUnit_Framework_TestCase
{
private $item;
public static $name = "item name";
public static $price = "1.12";
public static $quantity = "10";
public static $sku = "AXVTY123";
public static $currency = "USD";
public static function createItem()
{
$item = new Item();
$item->setName(self::$name);
$item->setPrice(self::$price);
$item->setQuantity(self::$quantity);
$item->setSku(self::$sku);
$item->setCurrency(self::$currency);
return $item;
}
public function setup()
{
$this->item = ItemTest::createItem();
}
public function testGetterSetters()
{
$this->assertEquals(self::$name, $this->item->getName());
$this->assertEquals(self::$price, $this->item->getPrice());
$this->assertEquals(self::$sku, $this->item->getSku());
$this->assertEquals(self::$quantity, $this->item->getQuantity());
$this->assertEquals(self::$currency, $this->item->getCurrency());
}
public function testSerializeDeserialize()
{
$item = new Item();
$item->fromJson($this->item->toJSON());
$this->assertEquals($item, $this->item);
}
}

View File

@@ -5,36 +5,41 @@ namespace PayPal\Test\Api;
use PayPal\Api\Links;
use PayPal\Test\Constants;
class LinksTest extends \PHPUnit_Framework_TestCase {
class LinksTest extends \PHPUnit_Framework_TestCase
{
private $links;
private $links;
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createLinks() {
$links = new Links();
$links->setHref(self::$href);
$links->setRel(self::$rel);
$links->setMethod(self::$method);
return $links;
}
public function setup() {
$this->links = self::createLinks();
}
public function testGetterSetters() {
$this->assertEquals(self::$href, $this->links->getHref());
$this->assertEquals(self::$rel, $this->links->getRel());
$this->assertEquals(self::$method, $this->links->getMethod());
}
public function testSerializeDeserialize() {
$link2 = new Links();
$link2->fromJson($this->links->toJSON());
$this->assertEquals($this->links, $link2);
}
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createLinks()
{
$links = new Links();
$links->setHref(self::$href);
$links->setRel(self::$rel);
$links->setMethod(self::$method);
return $links;
}
public function setup()
{
$this->links = self::createLinks();
}
public function testGetterSetters()
{
$this->assertEquals(self::$href, $this->links->getHref());
$this->assertEquals(self::$rel, $this->links->getRel());
$this->assertEquals(self::$method, $this->links->getMethod());
}
public function testSerializeDeserialize()
{
$link2 = new Links();
$link2->fromJson($this->links->toJSON());
$this->assertEquals($this->links, $link2);
}
}

View File

@@ -7,8 +7,10 @@ use PayPal\Api\Details;
use PayPal\Api\Links;
use PayPal\Test\Constants;
class OrderTest extends \PHPUnit_Framework_TestCase {
class OrderTest extends \PHPUnit_Framework_TestCase
{
/** @var Order */
private $order;
public static $id = 'O-0AA8876533760860M';
@@ -18,40 +20,35 @@ class OrderTest extends \PHPUnit_Framework_TestCase {
public static $parentPayment = 'PAY-0AL32935UM2331537KP5Y2VA';
public static $reasonCode = 'order';
public static function createOrder() {
public static function createOrder()
{
$order = new Order();
$links = LinksTest::createLinks();
$order->setId(self::$id);
$order->setCreateTime(self::$createTime);
$order->setUpdateTime(self::$updateTime);
$order->setState(self::$state);
$order->setAmount(AmountTest::createAmount());
$order->setParentPayment(self::$parentPayment);
$order->setLinks(array($links));
$order->setReasonCode(self::$reasonCode);
return $order;
}
public function setup() {
public function setup()
{
$this->order = self::createOrder();
}
public function testGetterSetter() {
public function testGetterSetter()
{
$this->assertEquals(self::$id, $this->order->getId());
$this->assertEquals(self::$createTime, $this->order->getCreateTime());
$this->assertEquals(self::$updateTime, $this->order->getUpdateTime());
$this->assertEquals(self::$state, $this->order->getState());
$this->assertEquals(AmountTest::$currency, $this->order->getAmount()->getCurrency());
$this->assertEquals(self::$parentPayment, $this->order->getParentPayment());
$links = (array)$this->order->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
$this->assertEquals(self::$reasonCode, $this->order->getReasonCode());
}
public function testSerializeDeserialize() {
public function testSerializeDeserialize()
{
$o1 = $this->order;
$o2 = new Order();

View File

@@ -5,40 +5,45 @@ namespace PayPal\Test\Api;
use PayPal\Api\Payee;
use PayPal\Test\Constants;
class PayeeTest extends \PHPUnit_Framework_TestCase {
class PayeeTest extends \PHPUnit_Framework_TestCase
{
private $payee;
private $payee;
public static $email = "test@paypal.com";
public static $merchant_id = "1XY12121";
public static $phone = "+14081234566";
public static $email = "test@paypal.com";
public static $merchant_id = "1XY12121";
public static $phone = "+14081234566";
public static function createPayee() {
$payee = new Payee();
$payee->setEmail(self::$email);
$payee->setMerchantId(self::$merchant_id);
$payee->setPhone(self::$phone);
return $payee;
}
public function setup() {
$this->payee = self::createPayee();
}
public function testGetterSetter() {
$this->assertEquals(self::$email, $this->payee->getEmail());
$this->assertEquals(self::$merchant_id, $this->payee->getMerchantId());
$this->assertEquals(self::$phone, $this->payee->getPhone());
}
public function testSerializeDeserialize() {
$p1 = $this->payee;
$p2 = new Payee();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
public static function createPayee()
{
$payee = new Payee();
$payee->setEmail(self::$email);
$payee->setMerchantId(self::$merchant_id);
$payee->setPhone(self::$phone);
return $payee;
}
public function setup()
{
$this->payee = self::createPayee();
}
public function testGetterSetter()
{
$this->assertEquals(self::$email, $this->payee->getEmail());
$this->assertEquals(self::$merchant_id, $this->payee->getMerchantId());
$this->assertEquals(self::$phone, $this->payee->getPhone());
}
public function testSerializeDeserialize()
{
$p1 = $this->payee;
$p2 = new Payee();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -4,47 +4,52 @@ namespace PayPal\Test\Api;
use PayPal\Api\PayerInfo;
use PayPal\Test\Constants;
class PayerInfoTest extends \PHPUnit_Framework_TestCase {
class PayerInfoTest extends \PHPUnit_Framework_TestCase
{
private $payerInfo;
private $payerInfo;
public static $email = "test@paypal.com";
public static $firstName = "first";
public static $lastName = "last";
public static $phone = "408-1234-5687";
public static $payerId = "PAYER-1234";
public static $email = "test@paypal.com";
public static $firstName = "first";
public static $lastName = "last";
public static $phone = "408-1234-5687";
public static $payerId = "PAYER-1234";
public static function createPayerInfo() {
$payerInfo = new PayerInfo();
$payerInfo->setEmail(self::$email);
$payerInfo->setFirstName(self::$firstName);
$payerInfo->setLastName(self::$lastName);
$payerInfo->setPhone(self::$phone);
$payerInfo->setPayerId(self::$payerId);
$payerInfo->setShippingAddress(ShippingAddressTest::createAddress());
return $payerInfo;
}
public function setup() {
$this->payerInfo = self::createPayerInfo();
}
public static function createPayerInfo()
{
$payerInfo = new PayerInfo();
$payerInfo->setEmail(self::$email);
$payerInfo->setFirstName(self::$firstName);
$payerInfo->setLastName(self::$lastName);
$payerInfo->setPhone(self::$phone);
$payerInfo->setPayerId(self::$payerId);
$payerInfo->setShippingAddress(ShippingAddressTest::createAddress());
public function testGetterSetter() {
$this->assertEquals(self::$email, $this->payerInfo->getEmail());
$this->assertEquals(self::$firstName, $this->payerInfo->getFirstName());
$this->assertEquals(self::$lastName, $this->payerInfo->getLastName());
$this->assertEquals(self::$phone, $this->payerInfo->getPhone());
$this->assertEquals(self::$payerId, $this->payerInfo->getPayerId());
$this->assertEquals(ShippingAddressTest::$line1, $this->payerInfo->getShippingAddress()->getLine1());
}
public function testSerializeDeserialize() {
$p1 = $this->payerInfo;
$p2 = new PayerInfo();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
return $payerInfo;
}
public function setup()
{
$this->payerInfo = self::createPayerInfo();
}
public function testGetterSetter()
{
$this->assertEquals(self::$email, $this->payerInfo->getEmail());
$this->assertEquals(self::$firstName, $this->payerInfo->getFirstName());
$this->assertEquals(self::$lastName, $this->payerInfo->getLastName());
$this->assertEquals(self::$phone, $this->payerInfo->getPhone());
$this->assertEquals(self::$payerId, $this->payerInfo->getPayerId());
$this->assertEquals(ShippingAddressTest::$line1, $this->payerInfo->getShippingAddress()->getLine1());
}
public function testSerializeDeserialize()
{
$p1 = $this->payerInfo;
$p2 = new PayerInfo();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -7,39 +7,44 @@ use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Test\Constants;
class PayerTest extends \PHPUnit_Framework_TestCase {
class PayerTest extends \PHPUnit_Framework_TestCase
{
private $payer;
private $payer;
private static $paymentMethod = "credit_card";
private static $paymentMethod = "credit_card";
public static function createPayer() {
$payer = new Payer();
$payer->setPaymentMethod(self::$paymentMethod);
$payer->setPayerInfo(PayerInfoTest::createPayerInfo());
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
return $payer;
}
public function setup() {
$this->payer = self::createPayer();
}
public static function createPayer()
{
$payer = new Payer();
$payer->setPaymentMethod(self::$paymentMethod);
$payer->setPayerInfo(PayerInfoTest::createPayerInfo());
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
public function testGetterSetter() {
$this->assertEquals(self::$paymentMethod, $this->payer->getPaymentMethod());
$this->assertEquals(PayerInfoTest::$email, $this->payer->getPayerInfo()->getEmail());
$fi = $this->payer->getFundingInstruments();
$this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize() {
$p1 = $this->payer;
$p2 = new Payer();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
return $payer;
}
public function setup()
{
$this->payer = self::createPayer();
}
public function testGetterSetter()
{
$this->assertEquals(self::$paymentMethod, $this->payer->getPaymentMethod());
$this->assertEquals(PayerInfoTest::$email, $this->payer->getPayerInfo()->getEmail());
$fi = $this->payer->getFundingInstruments();
$this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize()
{
$p1 = $this->payer;
$p2 = new Payer();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -5,35 +5,42 @@ namespace PayPal\Test\Api;
use PayPal\Api\PaymentHistory;
use PayPal\Test\Constants;
class PaymentHistoryTest extends \PHPUnit_Framework_TestCase {
private $history;
public static $count = "10";
public static $nextId = "11";
public static function createPaymentHistory() {
$history = new PaymentHistory();
$history->setCount(self::$count);
$history->setNextId(self::$nextId);
$history->setPayments(array(PaymentTest::createPayment()));
return $history;
}
public function setup() {
$this->history = PaymentHistoryTest::createPaymentHistory();
}
public function testGetterSetters() {
$this->assertEquals(self::$count, $this->history->getCount());
$this->assertEquals(self::$nextId, $this->history->getNextId());
}
public function testSerializeDeserialize() {
$history = new PaymentHistory();
$history->fromJson($this->history->toJSON());
$this->assertEquals($history, $this->history);
}
class PaymentHistoryTest extends \PHPUnit_Framework_TestCase
{
/** @var PaymentHistory */
private $history;
public static $count = 10;
public static $nextId = "11";
public static function createPaymentHistory()
{
$history = new PaymentHistory();
$history->setCount(self::$count);
$history->setNextId(self::$nextId);
$history->setPayments(array(PaymentTest::createPayment()));
return $history;
}
public function setup()
{
$this->history = PaymentHistoryTest::createPaymentHistory();
}
public function testGetterSetters()
{
$this->assertEquals(self::$count, $this->history->getCount());
$this->assertEquals(self::$nextId, $this->history->getNextId());
}
public function testSerializeDeserialize()
{
$history = new PaymentHistory();
$history->fromJson($this->history->toJSON());
$this->assertEquals($history, $this->history);
}
}

View File

@@ -1,5 +1,6 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Address;
use PayPal\Api\Amount;
@@ -10,76 +11,170 @@ use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Test\Constants;
class PaymentTest extends \PHPUnit_Framework_TestCase {
class PaymentTest extends \PHPUnit_Framework_TestCase
{
private $payments;
private $payments;
public static function createPayment() {
public static function createPayment()
{
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer(PayerTest::createPayer());
$payment->setTransactions(array(TransactionTest::createTransaction()));
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer(PayerTest::createPayer());
$payment->setTransactions(array(TransactionTest::createTransaction()));
return $payment;
}
return $payment;
}
public static function createNewPayment() {
public static function createNewPayment()
{
$funding = FundingInstrumentTest::createFundingInstrument();
$funding->credit_card_token = null;
$funding = FundingInstrumentTest::createFundingInstrument();
$funding->credit_card_token = null;
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($funding));
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($funding));
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
return $payment;
}
return $payment;
}
public function setup() {
$this->payments['full'] = self::createPayment();
$this->payments['new'] = self::createNewPayment();
}
public function setup()
{
$this->payments['full'] = self::createPayment();
$this->payments['new'] = self::createNewPayment();
}
public function testSerializeDeserialize() {
$p2 = new Payment();
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}
public function testSerializeDeserialize()
{
$p2 = new Payment();
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}
/**
* @group integration
*/
public function testOperations() {
public function testOperations()
{
$p1 = $this->payments['new'];
$p1 = $this->payments['new'];
$p1->create();
$this->assertNotNull($p1->getId());
$p1->create();
$this->assertNotNull($p1->getId());
$p2 = Payment::get($p1->getId());
$this->assertNotNull($p2);
$p2 = Payment::get($p1->getId());
$this->assertNotNull($p2);
$paymentHistory = Payment::all(array('count' => '10'));
$this->assertNotNull($paymentHistory);
}
$paymentHistory = Payment::all(array('count' => '10'));
$this->assertNotNull($paymentHistory);
}
/**
* @group integration
*
* Tests Additional_fields, shipping_discount and insurance information.
* Additional Information: https://developer.paypal.com/docs/integration/direct/explore-payment-capabilities/
*/
public function testECParameters()
{
$json = '{
"intent": "sale",
"redirect_urls": {
"return_url": "http://www.return.com",
"cancel_url": "http://www.cancel.com"
},
"payer": {
"payment_method": "paypal",
"payer_info": {
"tax_id_type": "BR_CPF",
"tax_id": "Fh618775690"
}
},
"transactions": [
{
"amount": {
"total": "34.07",
"currency": "USD",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "1.00",
"handling_fee": "1.00",
"shipping_discount": "1.00",
"insurance": "1.00"
}
},
"description": "This is the payment transaction description.",
"custom": "EBAY_EMS_90048630024435",
"invoice_number": "48787589677",
"payment_options": {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"soft_descriptor": "ECHI5786786",
"item_list": {
"items": [
{
"name": "bowling",
"description": "Bowling Team Shirt",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "USD"
},
{
"name": "mesh",
"description": "80s Mesh Sleeveless Shirt",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "USD"
}
],
"shipping_address": {
"recipient_name": "Betsy Buyer",
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"postal_code": "95070",
"state": "CA"
}
}
}
]
}';
$payment = new Payment();
$payment->fromJson($json);
$payment->create();
$result = Payment::get($payment->getId());
$transactions = $result->getTransactions();
$transaction = $transactions[0];
$this->assertEquals($transaction->getAmount()->getDetails()->getShippingDiscount(), '1.00');
$this->assertEquals($transaction->getAmount()->getDetails()->getInsurance(), '1.00');
$this->assertEquals($transaction->getAmount()->getDetails()->getHandlingFee(), '1.00');
}
}

View File

@@ -3,40 +3,45 @@ namespace PayPal\Test\Api;
use PayPal\Api\RedirectUrls;
class RedirectUrlsTest extends \PHPUnit_Framework_TestCase {
class RedirectUrlsTest extends \PHPUnit_Framework_TestCase
{
public function validRedirectUrlsProvider() {
return array(
array('https://devtools-paypal.com/guide/pay_paypal/php?success=true', 'https://devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
public function validRedirectUrlsProvider()
{
return array(
array('https://devtools-paypal.com/guide/pay_paypal/php?success=true', 'https://devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
public function invalidRedirectUrlsProvider() {
return array(
array('devtools-paypal.com/guide/pay_paypal/php?success=true', 'devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
public function invalidRedirectUrlsProvider()
{
return array(
array('devtools-paypal.com/guide/pay_paypal/php?success=true', 'devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
/**
* @dataProvider validRedirectUrlsProvider
*/
public function testValidRedirectUrls($return_url, $cancel_url) {
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturn_url($return_url);
$redirectUrls->setCancel_url($cancel_url);
/**
* @dataProvider validRedirectUrlsProvider
*/
public function testValidRedirectUrls($return_url, $cancel_url)
{
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
$this->assertEquals($return_url, $redirectUrls->getReturnUrl());
$this->assertEquals($cancel_url, $redirectUrls->getCancelUrl());
}
$this->assertEquals($return_url, $redirectUrls->getReturnUrl());
$this->assertEquals($cancel_url, $redirectUrls->getCancelUrl());
}
/**
* @dataProvider invalidRedirectUrlsProvider
*/
public function testInvalidRedirectUrls($return_url, $cancel_url) {
$redirectUrls = new RedirectUrls();
$this->setExpectedException('\InvalidArgumentException');
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
}
/**
* @dataProvider invalidRedirectUrlsProvider
*/
public function testInvalidRedirectUrls($return_url, $cancel_url)
{
$redirectUrls = new RedirectUrls();
$this->setExpectedException('\InvalidArgumentException');
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
}
}

View File

@@ -4,51 +4,57 @@ namespace PayPal\Test\Api;
use PayPal\Api\Refund;
use PayPal\Test\Constants;
class RefundTest extends \PHPUnit_Framework_TestCase {
class RefundTest extends \PHPUnit_Framework_TestCase
{
private $refund;
private $refund;
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static function createRefund() {
$refund = new Refund();
public static function createRefund()
{
$refund = new Refund();
$refund->setCreateTime(self::$createTime);
$refund->setAmount(AmountTest::createAmount());
$refund->setCaptureId(self::$captureId);
$refund->setId(self::$id);
$refund->setLinks(array(LinksTest::createLinks()));
$refund->setParentPayment(self::$parentPayment);
return $refund;
}
public function setup() {
$this->refund = self::createRefund();
}
$refund->setAmount(AmountTest::createAmount());
$refund->setCaptureId(self::$captureId);
$refund->setId(self::$id);
$refund->setLinks(array(LinksTest::createLinks()));
$refund->setParentPayment(self::$parentPayment);
public function testGetterSetter() {
$this->assertEquals(self::$captureId, $this->refund->getCaptureId());
$this->assertEquals(self::$createTime, $this->refund->getCreateTime());
$this->assertEquals(self::$id, $this->refund->getId());
$this->assertEquals(self::$parentPayment, $this->refund->getParentPayment());
$this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency());
$links = $this->refund->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$r1 = $this->refund;
$r2 = new Refund();
$r2->fromJson($r1->toJson());
$this->assertEquals($r1, $r2);
}
public function testOperations() {
}
return $refund;
}
public function setup()
{
$this->refund = self::createRefund();
}
public function testGetterSetter()
{
$this->assertEquals(self::$captureId, $this->refund->getCaptureId());
$this->assertEquals(self::$createTime, $this->refund->getCreateTime());
$this->assertEquals(self::$id, $this->refund->getId());
$this->assertEquals(self::$parentPayment, $this->refund->getParentPayment());
$this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency());
$links = $this->refund->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize()
{
$r1 = $this->refund;
$r2 = new Refund();
$r2->fromJson($r1->toJson());
$this->assertEquals($r1, $r2);
}
public function testOperations()
{
}
}

View File

@@ -4,34 +4,39 @@ namespace PayPal\Test\Api;
use PayPal\Api\RelatedResources;
use PayPal\Test\Constants;
class RelatedResourcesTest extends \PHPUnit_Framework_TestCase {
class RelatedResourcesTest extends \PHPUnit_Framework_TestCase
{
private $RelatedResources;
private $RelatedResources;
public static function createRelatedResources() {
$relatedResources = new RelatedResources();
$relatedResources->setAuthorization(AuthorizationTest::createAuthorization());
$relatedResources->setCapture(CaptureTest::createCapture());
public static function createRelatedResources()
{
$relatedResources = new RelatedResources();
$relatedResources->setAuthorization(AuthorizationTest::createAuthorization());
$relatedResources->setCapture(CaptureTest::createCapture());
$relatedResources->setOrder(OrderTest::createOrder());
return $relatedResources;
}
public function setup() {
$this->relatedResources = self::createRelatedResources();
}
return $relatedResources;
}
public function testGetterSetter() {
$this->assertEquals(AuthorizationTest::$create_time, $this->relatedResources->getAuthorization()->getCreateTime());
$this->assertEquals(CaptureTest::$create_time, $this->relatedResources->getCapture()->getCreateTime());
public function setup()
{
$this->relatedResources = self::createRelatedResources();
}
public function testGetterSetter()
{
$this->assertEquals(AuthorizationTest::$create_time, $this->relatedResources->getAuthorization()->getCreateTime());
$this->assertEquals(CaptureTest::$create_time, $this->relatedResources->getCapture()->getCreateTime());
$this->assertEquals(OrderTest::$id, $this->relatedResources->getOrder()->getId());
}
public function testSerializeDeserialize() {
$s1 = $this->relatedResources;
$s2 = new RelatedResources();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
}
public function testSerializeDeserialize()
{
$s1 = $this->relatedResources;
$s2 = new RelatedResources();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
}

View File

@@ -9,54 +9,58 @@ use PayPal\Test\Api\PaymentTest;
use PayPal\Test\Api\LinksTest;
use PayPal\Exception\PPConnectionException;
class SaleTest extends \PHPUnit_Framework_TestCase {
class SaleTest extends \PHPUnit_Framework_TestCase
{
private $sale;
/** @var Sale */
private $sale;
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $state = "Created";
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $state = "Created";
public static function createSale() {
$sale = new Sale();
$sale->setAmount(AmountTest::createAmount());
$sale->setCreateTime(self::$createTime);
$sale->setId(self::$id);
$sale->setLinks(array(LinksTest::createLinks()));
$sale->setParentPayment(self::$parentPayment);
$sale->setState(self::$state);
return $sale;
}
public function setup() {
$this->sale = self::createSale();
}
public static function createSale()
{
$sale = new Sale();
$sale->setAmount(AmountTest::createAmount());
$sale->setCreateTime(self::$createTime);
$sale->setId(self::$id);
$sale->setParentPayment(self::$parentPayment);
$sale->setState(self::$state);
return $sale;
}
public function testGetterSetter() {
$this->assertEquals(self::$createTime, $this->sale->getCreateTime());
$this->assertEquals(self::$id, $this->sale->getId());
$this->assertEquals(self::$parentPayment, $this->sale->getParentPayment());
$this->assertEquals(self::$state, $this->sale->getState());
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
$links = $this->sale->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$s1 = $this->sale;
$s2 = new Sale();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
public function setup()
{
$this->sale = self::createSale();
}
public function testGetterSetter()
{
$this->assertEquals(self::$createTime, $this->sale->getCreateTime());
$this->assertEquals(self::$id, $this->sale->getId());
$this->assertEquals(self::$parentPayment, $this->sale->getParentPayment());
$this->assertEquals(self::$state, $this->sale->getState());
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
}
public function testSerializeDeserialize()
{
$s1 = $this->sale;
$s2 = new Sale();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
/**
* @group integration
*/
public function testOperations() {
public function testOperations()
{
try {
$payment = PaymentTest::createNewPayment();
$payment->create();
@@ -79,5 +83,5 @@ class SaleTest extends \PHPUnit_Framework_TestCase {
'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()
);
}
}
}
}

View File

@@ -4,53 +4,58 @@ namespace PayPal\Test\Api;
use PayPal\Api\ShippingAddress;
use PayPal\Test\Constants;
class ShippingAddressTest extends \PHPUnit_Framework_TestCase {
class ShippingAddressTest extends \PHPUnit_Framework_TestCase
{
private $address;
private $address;
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $recipientName = "TestUser";
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $recipientName = "TestUser";
public static function createAddress() {
$addr = new ShippingAddress();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
$addr->setRecipientName(self::$recipientName);
return $addr;
}
public function setup() {
$this->address = self::createAddress();
}
public static function createAddress()
{
$addr = new ShippingAddress();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
$addr->setRecipientName(self::$recipientName);
return $addr;
}
public function testGetterSetter() {
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
$this->assertEquals(self::$recipientName, $this->address->getRecipientName());
}
public function testSerializeDeserialize() {
$a1 = $this->address;
$a2 = new ShippingAddress();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
public function setup()
{
$this->address = self::createAddress();
}
public function testGetterSetter()
{
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
$this->assertEquals(self::$recipientName, $this->address->getRecipientName());
}
public function testSerializeDeserialize()
{
$a1 = $this->address;
$a2 = new ShippingAddress();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -7,52 +7,57 @@ use PayPal\Api\SubTransaction;
use PayPal\Api\Transaction;
use PayPal\Test\Constants;
class TransactionTest extends \PHPUnit_Framework_TestCase {
class TransactionTest extends \PHPUnit_Framework_TestCase
{
private $transaction;
private $transaction;
public static $description = "desc . . . ";
public static $invoiceNumber = "#123";
public static $custom = "custom";
public static $softDescriptor = "descriptor";
public static $total = "1.12";
public static $description = "desc . . . ";
public static $invoiceNumber = "#123";
public static $custom = "custom";
public static $softDescriptor = "descriptor";
public static $total = "1.12";
public static function createTransaction() {
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setInvoiceNumber(self::$invoiceNumber);
$transaction->setCustom(self::$custom);
$transaction->setSoftDescriptor(self::$softDescriptor);
$transaction->setItemList(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelatedResources( array(RelatedResourcesTest::createRelatedResources()) );
return $transaction;
}
public function setup() {
$this->transaction = self::createTransaction();
}
public static function createTransaction()
{
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setInvoiceNumber(self::$invoiceNumber);
$transaction->setCustom(self::$custom);
$transaction->setSoftDescriptor(self::$softDescriptor);
$transaction->setItemList(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelatedResources(array(RelatedResourcesTest::createRelatedResources()));
return $transaction;
}
public function testGetterSetter() {
$this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency());
$this->assertEquals(self::$description, $this->transaction->getDescription());
$this->assertEquals(self::$invoiceNumber, $this->transaction->getInvoiceNumber());
$this->assertEquals(self::$custom, $this->transaction->getCustom());
$this->assertEquals(self::$softDescriptor, $this->transaction->getSoftDescriptor());
$items = $this->transaction->getItemList()->getItems();
$this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity());
$this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail());
$resources = $this->transaction->getRelatedResources();
$this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreateTime());
}
public function testSerializeDeserialize() {
$t1 = $this->transaction;
$t2 = new Transaction();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
public function setup()
{
$this->transaction = self::createTransaction();
}
public function testGetterSetter()
{
$this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency());
$this->assertEquals(self::$description, $this->transaction->getDescription());
$this->assertEquals(self::$invoiceNumber, $this->transaction->getInvoiceNumber());
$this->assertEquals(self::$custom, $this->transaction->getCustom());
$this->assertEquals(self::$softDescriptor, $this->transaction->getSoftDescriptor());
$items = $this->transaction->getItemList()->getItems();
$this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity());
$this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail());
$resources = $this->transaction->getRelatedResources();
$this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreateTime());
}
public function testSerializeDeserialize()
{
$t1 = $this->transaction;
$t2 = new Transaction();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
}