Skip to content

Commit

Permalink
Added support for API v2.01
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-drzewiecki committed Jul 30, 2015
1 parent 490af3e commit c4a6a2c
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 13 deletions.
45 changes: 45 additions & 0 deletions MangoPay/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace MangoPay;

/**
* Class represents an address.
*/
class Address extends Libraries\Dto {

/**
* Address line 1.
* @var String
*/
public $AddressLine1;

/**
* Address line 2.
* @var String
*/
public $AddressLine2;

/**
* City.
* @var String
*/
public $City;

/**
* Region.
* @var String
*/
public $Region;

/**
* Postal code.
* @var String
*/
public $PostalCode;

/**
* Country.
* @var String
*/
public $Country;
}
14 changes: 13 additions & 1 deletion MangoPay/BankAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BankAccount extends Libraries\EntityBase {

/**
* Owner address
* @var string
* @var Address
*/
public $OwnerAddress;

Expand All @@ -36,6 +36,18 @@ class BankAccount extends Libraries\EntityBase {
*/
public $Details;

/**
* Get array with mapping which property is object and what type of object
* @return array
*/
public function GetSubObjects() {
$subObjects = parent::GetSubObjects();

$subObjects['OwnerAddress'] = '\MangoPay\Address';

return $subObjects;
}

/**
* Get array with mapping which property depends on other property
* @return array
Expand Down
4 changes: 2 additions & 2 deletions MangoPay/Libraries/UrlTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private function GetHost(){
public function GetRestUrl($urlKey, $addClientId = true, $pagination = null, $additionalUrlParams = null) {

if (!$addClientId) {
$url = '/v2' . $urlKey;
$url = '/v2.01' . $urlKey;
} else {
$url = '/v2/' . $this->_root->Config->ClientId . $urlKey;
$url = '/v2.01/' . $this->_root->Config->ClientId . $urlKey;
}

$paramsAdded = false;
Expand Down
17 changes: 15 additions & 2 deletions MangoPay/UserLegal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UserLegal extends User {

/**
*
* @var String
* @var Address
*/
public $HeadquartersAddress;

Expand All @@ -38,7 +38,7 @@ class UserLegal extends User {

/**
*
* @var String
* @var Address
*/
public $LegalRepresentativeAddress;

Expand Down Expand Up @@ -98,6 +98,19 @@ function __construct($id = null) {
$this->SetPersonType(PersonType::Legal);
}

/**
* Get array with mapping which property is object and what type of object
* @return array
*/
public function GetSubObjects() {
$subObjects = parent::GetSubObjects();

$subObjects['HeadquartersAddress'] = '\MangoPay\Address';
$subObjects['LegalRepresentativeAddress'] = '\MangoPay\Address';

return $subObjects;
}

/**
* Get array with read-only properties
* @return array
Expand Down
14 changes: 13 additions & 1 deletion MangoPay/UserNatural.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UserNatural extends User {

/**
* Address for user
* @var String
* @var Address
*/
public $Address;

Expand Down Expand Up @@ -74,6 +74,18 @@ function __construct($id = null) {
$this->SetPersonType(PersonType::Natural);
}

/**
* Get array with mapping which property is object and what type of object
* @return array
*/
public function GetSubObjects() {
$subObjects = parent::GetSubObjects();

$subObjects['Address'] = '\MangoPay\Address';

return $subObjects;
}

/**
* Get array with read-only properties
* @return array
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ MangopaySDK is a PHP client library to work with
[Mangopay REST API](http://docs.mangopay.com/api-references/).


Compatibility Note
-------------------------------------------------
Since v2.1 of this SDK, you must be using at least v2.01 of the API ([more information about the changes required](https://docs.mangopay.com/api-v2-01-overview/))


Installation
-------------------------------------------------
SDK has been written in PHP 5.5 and has no dependencies on external packages.
Expand Down
62 changes: 56 additions & 6 deletions tests/cases/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ protected function buildNewMangoPayApi() {

return $api;
}

/**
* Creates new address
* @return \MangoPay\Address
*/
protected function getNewAddress() {
$result = new \MangoPay\Address();

$result->AddressLine1 = 'Address line 1';
$result->AddressLine2 = 'Address line 2';
$result->City = 'City';
$result->Country = 'FR';
$result->PostalCode = '11222';
$result->Region = 'Region';

return $result;
}

/**
* Creates self::$John (test natural user) if not created yet
Expand All @@ -106,7 +123,7 @@ protected function getJohn() {
$user->FirstName = "John";
$user->LastName = "Doe";
$user->Email = "[email protected]";
$user->Address = "Some Address";
$user->Address = $this->getNewAddress();
$user->Birthday = mktime(0, 0, 0, 12, 21, 1975);
$user->Nationality = "FR";
$user->CountryOfResidence = "FR";
Expand All @@ -126,7 +143,7 @@ protected function getNewJohn() {
$user->FirstName = "John";
$user->LastName = "Doe";
$user->Email = "[email protected]";
$user->Address = "Some Address";
$user->Address = $this->getNewAddress();
$user->Birthday = mktime(0, 0, 0, 12, 21, 1975);
$user->Nationality = "FR";
$user->CountryOfResidence = "FR";
Expand All @@ -146,7 +163,7 @@ protected function getMatrix() {
$user->Name = "MartixSampleOrg";
$user->Email = "[email protected]";
$user->LegalPersonType = "BUSINESS";
$user->HeadquartersAddress = "Some Address";
$user->HeadquartersAddress = $this->getNewAddress();
$user->LegalRepresentativeFirstName = $john->FirstName;
$user->LegalRepresentativeLastName = $john->LastName;
$user->LegalRepresentativeAddress = $john->Address;
Expand Down Expand Up @@ -607,7 +624,14 @@ protected function assertIdenticalInputProps($entity1, $entity2) {
$this->assertIdentical($entity1->FirstName, $entity2->FirstName);
$this->assertIdentical($entity1->LastName, $entity2->LastName);
$this->assertIdentical($entity1->Email, $entity2->Email);
$this->assertIdentical($entity1->Address, $entity2->Address);
$this->assertNotNull($entity1->Address);
$this->assertNotNull($entity2->Address);
$this->assertEqual($entity1->Address->AddressLine1, $entity1->Address->AddressLine1);
$this->assertEqual($entity1->Address->AddressLine2, $entity1->Address->AddressLine2);
$this->assertEqual($entity1->Address->City, $entity1->Address->City);
$this->assertEqual($entity1->Address->Country, $entity1->Address->Country);
$this->assertEqual($entity1->Address->PostalCode, $entity1->Address->PostalCode);
$this->assertEqual($entity1->Address->Region, $entity1->Address->Region);
$this->assertIdentical($entity1->Birthday, $entity2->Birthday);
$this->assertIdentical($entity1->Nationality, $entity2->Nationality);
$this->assertIdentical($entity1->CountryOfResidence, $entity2->CountryOfResidence);
Expand All @@ -617,10 +641,29 @@ protected function assertIdenticalInputProps($entity1, $entity2) {
$this->assertIdentical($entity1->Tag, $entity2->Tag);
$this->assertIdentical($entity1->PersonType, $entity2->PersonType);
$this->assertIdentical($entity1->Name, $entity2->Name);
$this->assertIdentical($entity1->HeadquartersAddress, $entity2->HeadquartersAddress);
$this->assertNotNull($entity1->HeadquartersAddress);
$this->assertNotNull($entity2->HeadquartersAddress);
$this->assertEqual($entity1->HeadquartersAddress->AddressLine1, $entity1->HeadquartersAddress->AddressLine1);
$this->assertEqual($entity1->HeadquartersAddress->AddressLine2, $entity1->HeadquartersAddress->AddressLine2);
$this->assertEqual($entity1->HeadquartersAddress->City, $entity1->HeadquartersAddress->City);
$this->assertEqual($entity1->HeadquartersAddress->Country, $entity1->HeadquartersAddress->Country);
$this->assertEqual($entity1->HeadquartersAddress->PostalCode, $entity1->HeadquartersAddress->PostalCode);
$this->assertEqual($entity1->HeadquartersAddress->Region, $entity1->HeadquartersAddress->Region);
$this->assertIdentical($entity1->LegalRepresentativeFirstName, $entity2->LegalRepresentativeFirstName);
$this->assertIdentical($entity1->LegalRepresentativeLastName, $entity2->LegalRepresentativeLastName);


//$this->assertIdentical($entity1->LegalRepresentativeAddress, $entity2->LegalRepresentativeAddress, "***** TEMPORARY API ISSUE: RETURNED OBJECT MISSES THIS PROP AFTER CREATION *****");
$this->assertNotNull($entity1->LegalRepresentativeAddress);
$this->assertNotNull($entity2->LegalRepresentativeAddress);
$this->assertEqual($entity1->LegalRepresentativeAddress->AddressLine1, $entity1->LegalRepresentativeAddress->AddressLine1);
$this->assertEqual($entity1->LegalRepresentativeAddress->AddressLine2, $entity1->LegalRepresentativeAddress->AddressLine2);
$this->assertEqual($entity1->LegalRepresentativeAddress->City, $entity1->LegalRepresentativeAddress->City);
$this->assertEqual($entity1->LegalRepresentativeAddress->Country, $entity1->LegalRepresentativeAddress->Country);
$this->assertEqual($entity1->LegalRepresentativeAddress->PostalCode, $entity1->LegalRepresentativeAddress->PostalCode);
$this->assertEqual($entity1->LegalRepresentativeAddress->Region, $entity1->LegalRepresentativeAddress->Region);


$this->assertIdentical($entity1->LegalRepresentativeEmail, $entity2->LegalRepresentativeEmail);
$this->assertIdentical($entity1->LegalRepresentativeBirthday, $entity2->LegalRepresentativeBirthday, "***** TEMPORARY API ISSUE: RETURNED OBJECT HAS THIS PROP CHANGED FROM TIMESTAMP INTO ISO STRING AFTER CREATION *****");
$this->assertIdentical($entity1->LegalRepresentativeNationality, $entity2->LegalRepresentativeNationality);
Expand All @@ -630,7 +673,14 @@ protected function assertIdenticalInputProps($entity1, $entity2) {
$this->assertIdentical($entity1->UserId, $entity2->UserId);
$this->assertIdentical($entity1->Type, $entity2->Type);
$this->assertIdentical($entity1->OwnerName, $entity2->OwnerName);
$this->assertIdentical($entity1->OwnerAddress, $entity2->OwnerAddress);
$this->assertNotNull($entity1->OwnerAddress);
$this->assertNotNull($entity2->OwnerAddress);
$this->assertEqual($entity1->OwnerAddress->AddressLine1, $entity1->OwnerAddress->AddressLine1);
$this->assertEqual($entity1->OwnerAddress->AddressLine2, $entity1->OwnerAddress->AddressLine2);
$this->assertEqual($entity1->OwnerAddress->City, $entity1->OwnerAddress->City);
$this->assertEqual($entity1->OwnerAddress->Country, $entity1->OwnerAddress->Country);
$this->assertEqual($entity1->OwnerAddress->PostalCode, $entity1->OwnerAddress->PostalCode);
$this->assertEqual($entity1->OwnerAddress->Region, $entity1->OwnerAddress->Region);
if ($entity1->Type == 'IBAN') {
$this->assertIdentical($entity1->Details->IBAN, $entity2->Details->IBAN);
$this->assertIdentical($entity1->Details->BIC, $entity2->Details->BIC);
Expand Down
15 changes: 14 additions & 1 deletion tests/cases/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,25 @@ function test_Users_CreateLegal_FailsIfRequiredPropsNotProvided() {

function test_Users_CreateLegal_PassesIfRequiredPropsProvided() {
$user = new \MangoPay\UserLegal();
$user->HeadquartersAddress = new \MangoPay\Address();
$user->HeadquartersAddress->AddressLine1 = 'AddressLine1';
$user->HeadquartersAddress->AddressLine2 = 'AddressLine2';
$user->HeadquartersAddress->City = 'City';
$user->HeadquartersAddress->Country = 'FR';
$user->HeadquartersAddress->PostalCode = '11222';
$user->HeadquartersAddress->Region = 'Region';
$user->Name = "SomeOtherSampleOrg";
$user->Email = "[email protected]";
$user->LegalPersonType = "BUSINESS";
$user->LegalRepresentativeFirstName = "FirstName";
$user->LegalRepresentativeLastName = "LastName";
$user->LegalRepresentativeAddress = "Address";
$user->LegalRepresentativeAddress = new \MangoPay\Address();
$user->LegalRepresentativeAddress->AddressLine1 = 'AddressLine1';
$user->LegalRepresentativeAddress->AddressLine2 = 'AddressLine2';
$user->LegalRepresentativeAddress->City = 'City';
$user->LegalRepresentativeAddress->Country = 'FR';
$user->LegalRepresentativeAddress->PostalCode = '11222';
$user->LegalRepresentativeAddress->Region = 'Region';
$user->LegalRepresentativeBirthday = mktime(0, 0, 0, 12, 21, 1975);
$user->LegalRepresentativeNationality = "FR";
$user->LegalRepresentativeCountryOfResidence = "FR";
Expand Down

0 comments on commit c4a6a2c

Please sign in to comment.