Skip to content

Commit

Permalink
Changes for update client object
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-puslecki committed Sep 20, 2016
1 parent ee68459 commit 6e62b23
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 27 deletions.
28 changes: 6 additions & 22 deletions MangoPay/ApiClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
*/
class ApiClients extends Libraries\ApiBase
{
/**
* Get client data for Basic Access Authentication
* @param string $clientId Client identifier
* @param string $clientName Beautiful name for presentation
* @param string $clientEmail Client's email
* @return \MangoPay\Client Client object
*/
public function Create($clientId, $clientName, $clientEmail)
{
$urlMethod = $this->GetRequestUrl('authentication_base');
$requestType = $this->GetRequestType('authentication_base');
$requestData = array(
'ClientId' => $clientId,
'Name' => $clientName,
'Email' => $clientEmail,
);

$rest = new Libraries\RestTool(false, $this->_root);
$response = $rest->Request($urlMethod, $requestType, $requestData);
return $this->CastResponseToEntity($response, '\MangoPay\Client');
}

/**
* Get client information
*
Expand All @@ -45,6 +23,12 @@ public function Get()
*/
public function Update($client)
{
if (!is_null($client->HeadquartersAddress)
&& is_a($client->HeadquartersAddress, "MangoPay\Address")
&& $client->HeadquartersAddress->CanBeNull()) {
$client->HeadquartersAddress = null;
}

return $this->SaveObject('client_save', $client, '\MangoPay\Client');
}

Expand Down
95 changes: 91 additions & 4 deletions MangoPay/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,101 @@ class Client extends Libraries\EntityBase
public $Name;

/**
* Email of client
* The primary branding colour to use for your merchant
* @var string
*/
public $Email;
public $PrimaryThemeColour;


/**
* The primary branding colour to use for buttons for your merchant
* @var string
*/
public $PrimaryButtonColour;

/**
* The URL of the logo of your client
* @var string
*/
public $Logo;

/**
* A list of email addresses to use when contacting you for technical issues/communications
* @var array
*/
public $TechEmails;

/**
* A list of email addresses to use when contacting you for admin/commercial issues/communications
* @var array
*/
public $AdminEmails;

/**
* A list of email addresses to use when contacting you for fraud/compliance issues/communications
* @var array
*/
public $FraudEmails;

/**
* A list of email addresses to use when contacting you for billing issues/communications
* @var string
*/
public $BillingEmails;

/**
* Password for client
* A description of what your platform does
* @var string
*/
public $Passphrase;
public $PlatformDescription;

/**
* The type of platform
* @var \MangoPay\PlatformType
*/
public $PlatformType;

/**
* The URL for your website
* @var string
*/
public $PlatformURL;

/**
* The address of the company’s headquarters
* @var \MangoPay\Address
*/
public $HeadquartersAddress;

/**
* The tax (or VAT) number for your company
* @var string
*/
public $TaxNumber;

/**
* 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';

return $subObjects;
}

/**
* Get array with read-only properties
* @return array
*/
public function GetReadOnlyProperties()
{
$properties = parent::GetReadOnlyProperties();
array_push($properties, 'ClientId');
array_push($properties, 'Name');
array_push($properties, 'Logo');

return $properties;
}
}
16 changes: 16 additions & 0 deletions MangoPay/PlatformType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace MangoPay;

/**
* Platform types
*/
class PlatformType
{
const Marketplace = 'MARKETPLACE';
const P2pPayment = 'P2P_PAYMENT';
const CrowdfundingDonation = 'CROWDFUNDING_DONATION';
const CrowdfundingReward = 'CROWDFUNDING_REWARD';
const CrowdfundingEquity = 'CROWDFUNDING_EQUITY';
const CrowdfundingLoan = 'CROWDFUNDING_LOAN';
const Other = 'OTHER';
}
10 changes: 9 additions & 1 deletion demos/api/htmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public static function renderEntity($entityName, $prefix = '') {
self::renderEnum("\\MangoPay\\DisputeDocumentStatus", $name, $prefix);
} elseif ($className == "\\MangoPay\\ReportRequest" && $name == "ReportType") {
self::renderEnum("\\MangoPay\\ReportType", $name, $prefix);
} elseif ($className == "\\MangoPay\\Client" && $name == "PlatformType") {
self::renderEnum("\\MangoPay\\PlatformType", $name, $prefix);
}
else
echo '<input type="text" name="' . $prefix . $name . '" value="' . $value . '"/>';
Expand Down Expand Up @@ -283,8 +285,14 @@ public static function getEntity($entityName, $entityId = 0, $returnNullIfNoProp
if (isset($_POST[$frmName]) && strlen($_POST[$frmName]) > 0) {

// special fields for Owners property
if ($entityName == 'Wallet' && $name == 'Owners')
if ($entityName == 'Wallet' && $name == 'Owners'
|| $entityName == 'Client' && $name == 'TechEmails'
|| $entityName == 'Client' && $name == 'AdminEmails'
|| $entityName == 'Client' && $name == 'FraudEmails'
|| $entityName == 'Client' && $name == 'BillingEmails'){

$entity->$name = explode(';', $_POST[$frmName]);
}
// special cast to int for Birthday property in UserNatural
// and UserLegal class
elseif (($entityName == 'UserNatural' && $name == 'Birthday')
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ function test_Clients_Save() {
$clients = new \MangoPay\Client();
$clients->PrimaryButtonColour = "#afafae";
$clients->PrimaryThemeColour = "#afafae";
$clients->PlatformDescription = "platform description";
$clients->PlatformType = \MangoPay\PlatformType::Other;
$clients->PlatformURL = "http://sdk-unit-tests.com";
$clients->HeadquartersAddress = new \MangoPay\Address();
$clients->HeadquartersAddress->AddressLine1 = "AddressLine1";
$clients->HeadquartersAddress->AddressLine2 = "AddressLine2";
$clients->HeadquartersAddress->City = "City";
$clients->HeadquartersAddress->Region = "Region";
$clients->HeadquartersAddress->PostalCode = "11222";
$clients->HeadquartersAddress->Country = "FR";
$clients->TaxNumber = "12345";
$clients->TechEmails = array("[email protected]", "[email protected]");
$clients->AdminEmails = array("[email protected]", "[email protected]");
$clients->FraudEmails = array("[email protected]", "[email protected]");
$clients->BillingEmails = array("[email protected]", "[email protected]");

$saveClients = $this->_api->Clients->Update($clients);

Expand Down

0 comments on commit 6e62b23

Please sign in to comment.