Commit 7ecfba69 authored by Tibor Katelbach's avatar Tibor Katelbach
Browse files

adding mangoPay testing context

parent 82e9b3c3
......@@ -623,6 +623,8 @@ class CommunecterController extends Controller
$this->notifications = ActivityStream::getNotifications( array( "notify.id" => Yii::app()->session["userId"] ) );
CornerDev::addWorkLog("communecter",Yii::app()->session["userId"],Yii::app()->controller->id,Yii::app()->controller->action->id);
}
Application::loadDBAppConfig();
}
protected function beforeAction($action){
......
......@@ -9,6 +9,93 @@ class TestController extends CommunecterController {
echo count($userNotifcations);
}
public function actionMango() {
require_once '../../pixelhumain/ph/vendor/autoload.php';
$api = new MangoPay\MangoPayApi();
// configuration
$api->Config->ClientId = Yii::app()->params["mangoPay"]["ClientId"];
$api->Config->ClientPassword = Yii::app()->params["mangoPay"]["ClientPassword"];
$api->Config->TemporaryFolder = Yii::app()->params["mangoPay"]["TemporaryFolder"];
/*define('MangoPayDemo_ClientId', Yii::app()->params["mangoPay"]["ClientId"]);
define('MangoPayDemo_ClientPassword', Yii::app()->params["mangoPay"]["ClientPassword"]);
define('TemporaryFolder',Yii::app()->params["mangoPay"]["TemporaryFolder"]);
*/
// call some API methods...
echo "inside Mango ";
/*try {
$john = $api->Users->Get("xx");
if(!@$john){
$User = new MangoPay\UserNatural();
$User->Email = "test_natural@testmangopay.com";
$User->FirstName = "xxx";
$User->LastName = "yyyy";
$User->Birthday = 121271;
$User->Nationality = "FR";
$User->CountryOfResidence = "RE";
$result = $api->Users->Create($User);
$_SESSION["MangoPayDemo"]["UserNatural"] = $result->Id;
echo '<pre>' . var_export($result, true) . '</pre>';
echo "<br/>".$_SESSION["MangoPayDemo"]["UserNatural"]."<br/><br/>";
$Wallet = new \MangoPay\Wallet();
$Wallet->Owners = array($_SESSION["MangoPayDemo"]["UserNatural"]);
$Wallet->Description = "Demo wallet for User 1";
$Wallet->Currency = "EUR";
$result = $api->Wallets->Create($Wallet);
echo '<pre>' . var_export($result, true) . '</pre>';
echo "<br/><br/><br/>";
} else {
echo '<pre>' . var_export($john, true) . '</pre>';
$wal = $api->Users->GetWallets("35027132");
//echo '<pre>' . var_export($wal, true) . '</pre>';
foreach ($wal as $k => $v) {
echo $v->Id." : ".$v->Description."<br/>";
}
echo "<br/><br/><br/>";
}
} catch(MangoPay\Libraries\ResponseException $e) {
// handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails()
echo "<br/><br/><br/>";
//echo '<pre>' . var_export($e, true) . '</pre>';
echo $e->GetCode()."<br/><br/>";
echo $e->GetMessage()."<br/><br/>";
echo $e->GetErrorDetails()."<br/><br/>";
} catch(MangoPay\Libraries\Exception $e) {
// handle/log the exception $e->GetMessage()
echo "<br/><br/><br/>";
echo $e->GetMessage()."<br/>";
}*/
$params = array( "ClientId" => $api->Config->ClientId );
//$this->renderPartial( "doc/mango" , $params );
//$this->renderPartial( "api/index" , $params );
$this->renderPartial( "paymentDirect/index" , $params );
}
public function actionPay() {
require_once '../../pixelhumain/ph/vendor/autoload.php';
$api = new MangoPay\MangoPayApi();
// configuration
$api->Config->ClientId = Yii::app()->params["mangoPay"]["ClientId"];
$api->Config->ClientPassword = Yii::app()->params["mangoPay"]["ClientPassword"];
$api->Config->TemporaryFolder = Yii::app()->params["mangoPay"]["TemporaryFolder"];
$params = array( "ClientId" => $api->Config->ClientId );
//$this->renderPartial( "doc/mango" , $params );
//$this->renderPartial( "api/index" , $params );
$this->renderPartial( "paymentDirect/payment" , $params );
}
// VoteDown
public static function actionRefactorModerateVoteDown($collection){
......
<?php $this->renderPartial('../docs/panels/menuLink',array("url"=>"default/view/page/links")); ?>
<div class="panel-heading border-light center text-dark partition-white radius-10">
<span class="panel-title homestead"> <i class='fa text-red fa-heart faa-pulse animated fa-3x '></i> <span style="font-size: 48px">OPEN SOURCE PROJECTS WE LOVE AND USE</span></span>
</div>
<div class="space20"></div>
<div class="keywordList col-xs-12"></div>
<script type="text/javascript">
var keywords = [
{
"project" : "Yii PHP Framework",
"url" : "http://www.yiiframework.com",
"comment" : "Yii is a high-performance PHP framework best for developing Web 2.0 applications Yii comes with rich features: MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc. It can reduce your development time significantly.",
"image" : "https://www.javatpoint.com/yii/images/yii-framework.jpg"
},
{
"project" : "Mongo DB",
"url" : "https://www.mongodb.com/fr",
"comment" : "Réinventons la gestion de l’information, Devenez plus rapide et évolutif grâce à MongoDB, la première base de données NoSQL",
"image" : "https://webassets.mongodb.com/_com_assets/cms/MongoDB-Logo-5c3a7405a85675366beb3a5ec4c032348c390b3f142f5e6dddf1d78e2df5cb5c.png"
},
{
"project" : "JQuery",
"url" : "https://jquery.com/",
"comment" : "jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.",
"image" : "https://blog.netapsys.fr/wp-content/uploads/2016/07/jquery.gif"
},
{
"project" : "Bootstrap",
"url" : "http://getbootstrap.com/",
"comment" : "Build responsive, mobile-first projects on the web with the world's most popular front-end component library.Bootstrap is an open source toolkit for developing with HTML, CSS, and JS. Quickly prototype your ideas or build your entire app with our Sass variables and mixins, responsive grid system, extensive prebuilt components, and powerful plugins built on jQuery.",
"image" : "http://getbootstrap.com/assets/img/bootstrap-stack.png"
},
];
jQuery(document).ready(function()
{
$(".keywordList").html('');
$.each(keywords,function(i,obj) {
icon = (obj.icon) ? obj.icon : "fa-tag" ;
color = (obj.color) ? obj.color : "#E33551" ;
$(".keywordList").append(
'<div class="col-xs-3"><div class="keypan panel panel-white">'+
'<div class="panel-heading border-light ">'+
'<span class="panel-title ">'+
'<img class="img-circle" width="50" height="50" src="'+obj.image+'"/> '+
'<a href="'+obj.url+'" target="_blank" style="font-size: 18px; "><br/>'+obj.project.toUpperCase()+'</a>'+
'<span style="font-size: 14px; "><br/>'+obj.comment+'</span>'+
'</span>'+
'</div></div></div>');
});
});
</script>
<?php
/**
* Setting for client: client Id, client password
*/
define('MangoPayDemo_BaseUrl', 'https://api.sandbox.mangopay.com');
define('MangoPayDemo_ClientId', 'sdk-unit-tests');
define('MangoPayDemo_ClientPassword', 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju');
/**
* Path to folder to store temporary files (with permissions to write)
*/
define('MangoPayDemo_TemporaryFolder', __dir__);
\ No newline at end of file
body {
font-size: 12px;
}
#menu {
min-width: 250px;
}
#menu h3 {
font-weight: bold;
font-size: 100%;
}
#menu ul{
padding: 8px 8px 8px 14px;
}
#menu ul li{
padding: 3px 0px;
}
input[type=text] {
width: 250px;
}
select {
width: 256px;
}
\ No newline at end of file
$(document).ready(function(){
$("#menu").accordion( { active: selectedModuleIndex >= 0 ? selectedModuleIndex : false, collapsible : true, heightStyle: "content" } );
});
\ No newline at end of file
<?php
namespace MangoPay\Demo;
//require_once '../../vendor/autoload.php';
require_once 'htmlHelper.php';
require_once 'config.php';
$module = @$_GET['module'];
if (!isset($module))
return;
HtmlHelper::getHeader($module);
$details = explode('_', $module);
$entityName = @$details[0];
$subApiName = @$details[1];
$operation = @$details[2];
$subEntityName = @$details[3];
$filterName = @$details[4];
$subSubEntityName = @$details[5];
$entityId = @$_POST['Id'];
$subEntityId = @$_POST['IdSubEntity'];
if (isset($_POST['_postback']) && $_POST['_postback'] == '1') {
try {
$api = new \MangoPay\MangoPayApi();
$api->Config->BaseUrl = MangoPayDemo_BaseUrl;
$api->Config->ClientId = MangoPayDemo_ClientId;
$api->Config->ClientPassword = MangoPayDemo_ClientPassword;
$api->Config->TemporaryFolder = TemporaryFolder;
$module = @$_GET['module'];
if (isset($module) && strpos($module, '$Sort') !== false) {
if (isset($_POST["_sort_"]) && !empty($_POST["_sort_"])){
$sortFieldName = $_POST["_sort_"];
$sortDirection = $_POST["_sort_direction_"];
if (!isset($sortDirection)) {
$sortDirection = \MangoPay\SortDirection::ASC;
}
$sorting = new \MangoPay\Sorting();
$sorting->AddField($sortFieldName, $sortDirection);
}
}
// normal cases
switch ($operation) {
case '|NoParams|':
$methodName = $subEntityName;
$apiResult = $api->$subApiName->$methodName();
break;
case '|GetWalletTransactions|':
$pagination = HtmlHelper::getEntity('Pagination');
$filter = null;
if (isset($filterName) && $filterName != ""){
$filter = HtmlHelper::getEntity($filterName);
}
$apiResult = $api->$subApiName->GetWalletTransactions(null, null, $pagination, $filter);
print '<pre>';print_r($pagination);print '</pre>';
break;
case '|EnumParams|':
$methodName = $subEntityName;
$enums = explode('$', $subSubEntityName);
if (count($enums) == 1){
$apiResult = $api->$subApiName->$methodName($_POST[$enums[0]]);
} else if (count($enums) == 2) {
$apiResult = $api->$subApiName->$methodName($_POST[$enums[0]], $_POST[$enums[1]]);
}
break;
case '|EnumParamsList|':
$pagination = HtmlHelper::getEntity('Pagination');
$filter = null;
if (isset($filterName) && $filterName != ""){
$filter = HtmlHelper::getEntity($filterName);
}
$methodName = $subEntityName;
$enums = explode('$', $subSubEntityName);
if (count($enums) == 1){
$apiResult = $api->$subApiName->$methodName($_POST[$enums[0]], $pagination, $filter);
} else if (count($enums) == 2) {
$apiResult = $api->$subApiName->$methodName($_POST[$enums[0]], $_POST[$enums[1]], $pagination, $filter);
}
break;
case 'Create':
$entity = HtmlHelper::getEntity($entityName);
$apiResult = $api->$subApiName->Create($entity);
break;
case 'Get':
$apiResult = $api->$subApiName->Get($entityId);
break;
case 'Save':
$entity = HtmlHelper::getEntity($entityName, $entityId);
$apiResult = $api->$subApiName->Update($entity);
break;
case 'SaveNoId':
$entity = HtmlHelper::getEntity($entityName);
$apiResult = $api->$subApiName->Update($entity);
break;
case 'All':
$pagination = HtmlHelper::getEntity('Pagination');
$filter = null;
if (isset($filterName) && $filterName != "")
$filter = HtmlHelper::getEntity($filterName);
if (isset($filter) && !isset($sorting))
$apiResult = $api->$subApiName->GetAll($pagination, $filter);
else if (!isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->GetAll($pagination, $sorting);
else if (isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->GetAll($pagination, $filter, $sorting);
else
$apiResult = $api->$subApiName->GetAll($pagination);
print '<pre>';print_r($pagination);print '</pre>';
if (isset($sorting)) {
print '<pre>Sort: ';print_r($sorting);print '</pre>';
}
break;
case 'CreateSubEntity':
$entity = HtmlHelper::getEntity($subEntityName);
$methodName = 'Create'. $subEntityName;
$apiResult = $api->$subApiName->$methodName($entityId, $entity);
break;
case 'CreateSubSubEntity':
$entity = HtmlHelper::getEntity($subEntityName);
$methodName = 'Create' . $subEntityName;
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId, $entity);
break;
case 'GetSubEntity':
$methodName = 'Get' . $subEntityName;
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId);
break;
case 'SaveSubEntity':
$entity = HtmlHelper::getEntity($subEntityName);
$methodName = 'Update' . $subEntityName;
$apiResult = $api->$subApiName->$methodName($subEntityId, $entity);
break;
case 'ListSubEntity':
case 'ListSubSubEntity':
$pagination = HtmlHelper::getEntity('Pagination');
$methodName = $subEntityName;
$filter = null;
if (isset($filterName) && $filterName != "")
$filter = HtmlHelper::getEntity($filterName);
if ($operation == 'ListSubSubEntity') {
if (isset($filter) && !isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId, $pagination, $filter);
else if (!isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId, $pagination, null, $sorting);
else if (isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId, $pagination, $filter, $sorting);
else
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId, $pagination);
}else{
if (isset($filter) && !isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $pagination, $filter);
else if (!isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $pagination, null, $sorting);
else if (isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $pagination, $filter, $sorting);
else
$apiResult = $api->$subApiName->$methodName($entityId, $pagination);
}
print '<pre>';print_r($pagination);print '</pre>';
if (isset($sorting))
print '<pre>Sort: ';print_r($_POST["_sort_"]);print '</pre>';
break;
case 'CreatePageByFile':
$methodName = 'Create' . $subEntityName . 'FromFile';
$apiResult = $api->$subApiName->$methodName($entityId, $subEntityId, $_FILES['page_file']);
break;
case 'ContestDispute':
$entity = HtmlHelper::getEntity($subEntityName);
$apiResult = $api->$subApiName->$operation($entityId, $entity);
break;
case 'CloseDispute':
$apiResult = $api->$subApiName->$operation($entityId);
break;
case 'Upload':
$entity = HtmlHelper::getEntity($subEntityName);
$apiResult = $api->$subApiName->$subSubEntityName($entity);
break;
case 'UploadFromFile':
$apiResult = $api->$subApiName->$subSubEntityName($_FILES['page_file']);
break;
}
print '<pre>';print_r($apiResult);print '</pre>';
} catch (\MangoPay\Libraries\ResponseException $e) {
echo '<div style="color: red;">\MangoPay\ResponseException: Code: ' . $e->getCode();
echo '<br/>Message: ' . $e->getMessage();
$details = $e->GetErrorDetails();
if (!is_null($details))
echo '<br/><br/>Details: '; print_r($details);
echo '</div>';
} catch (\MangoPay\Libraries\Exception $e) {
echo '<div style="color: red;">\MangoPay\Exception: ' . $e->getMessage() . '</div>';
}
} else {
HtmlHelper::renderForm($entityName, $operation, array($subEntityName, $subSubEntityName), $filterName);
}
\ No newline at end of file
<?php
namespace MangoPay\Demo;
class HtmlHelper {
public static function getHeader($module) {
foreach ($GLOBALS['MangoPay_Demo_Menu'] as $moduleText => $subMenu) {
$key = array_search($module, $subMenu);
if ($key) {
echo '<h2 style="margin: 0 0 20px 0;">' . $key . '</h2>';
return;
}
}
}
public static function renderForm($entityName, $operation, $subEntityName, $filterName) {
echo '<form name="input" action="" method="post" enctype="multipart/form-data">';
echo '<table>';
switch ($operation) {
case '|EnumParams|':
case '|EnumParamsList|':
$enums = explode('$', $subEntityName[1]);
foreach ($enums as $enum) {
echo '<tr><td>';
echo $enum;
echo '</td>';
echo '<td>';
self::renderEnum('\MangoPay\\' . $enum, $enum, "");
echo '</td></tr>';
}
if ($operation == '|EnumParams|'){
break;
}
case 'All':
case '|GetWalletTransactions|':
if (isset($filterName) && $filterName != "") {
self::renderFormRow('<i>Optional filters:</i>');
self::renderEntity($filterName);
}
self::renderFormRow('<i>Pagination:</i>');
self::renderEntity('Pagination');
break;
case 'Create':
self::renderEntity($entityName);
break;
case 'Get':
case 'CloseDispute':
case 'Cancel':
self::renderId($entityName);
break;
case 'Save':
self::renderId($entityName);
self::renderEntity($entityName);
break;
case 'SaveNoId':
self::renderEntity($entityName);
break;
case 'CreateSubEntity':
self::renderId($entityName);
self::renderEntity($subEntityName[0]);
break;
case 'CreateSubSubEntity':
self::renderId($entityName);
self::renderId($subEntityName[1], 'IdSubEntity');
self::renderEntity($subEntityName[0]);
break;
case 'GetSubEntity':
self::renderId($entityName);
self::renderId($subEntityName[0], 'IdSubEntity');
break;
case 'SaveSubEntity':
self::renderId($entityName, 'IdSubEntity');
self::renderId($subEntityName[0]);
self::renderEntity($subEntityName[0]);
break;
case 'ListSubEntity':
self::renderId($entityName);
if (isset($filterName) && $filterName != "") {
self::renderFormRow('<i>Optional filters:</i>');
self::renderEntity($filterName);
}
self::renderFormRow('<i>Pagination:</i>');
self::renderEntity('Pagination');
break;
case 'ListSubSubEntity':
self::renderId($entityName);
self::renderId($subEntityName[1], 'IdSubEntity');
if (isset($filterName) && $filterName != "") {
self::renderFormRow('<i>Optional filters:</i>');
self::renderEntity($filterName);
}
self::renderFormRow('<i>Pagination:</i>');
self::renderEntity('Pagination');
break;
case 'CreatePageByFile':
self::renderId($entityName);
self::renderId($subEntityName[1], 'IdSubEntity');
self::renderFormRow('<tr><td></td><td><input type="file" name="page_file" /></td></tr>');
break;
case 'ContestDispute':
self::renderId($entityName, 'IdSubEntity');
self::renderEntity($subEntityName[0]);
break;
case 'Upload':
self::renderEntity($subEntityName[0]);
break;
case 'UploadFromFile':
self::renderFormRow('<tr><td></td><td><input type="file" name="page_file" /></td></tr>');
break;
}
$module = @$_GET['module'];
if (isset($module) && strpos($module, '$Sort')) {
self::renderSort();
}
$buttonText = $operation;
if ($operation == "|NoParams|" || $operation == "|EnumParams|"){
$buttonText = $subEntityName[0];
} else if ($operation == "SaveNoId"){
$buttonText = "Save";
}
echo '<tr><td></td><td><input type="submit" value="' . $buttonText . '" /></td></tr>';
echo '</table>';
echo '<input type="hidden" name="_postback" value="1"/>';
echo '</form>';
}
public static function renderEntity($entityName, $prefix = '') {
$className = '\\MangoPay\\' . $entityName;
$entity = new $className();
$blackList = $entity->GetReadOnlyProperties();
$entityObject = new \ReflectionObject($entity);
$module = @$_GET['module'];
$subObjects = $entity->GetSubObjects();
$dependsObjects = $entity->GetDependsObjects();
$depTypesInModule = explode(':', $module);
$properties = $entityObject->getProperties();
foreach ($properties as $property) {
$name = $property->getName();
if (in_array($name, $blackList))
continue;
// is sub object?
$cls = @$subObjects[$name];
if ($cls) {
self::renderEntity(str_replace('\\MangoPay\\', '', $cls), "$name:");
continue;
}
// is dependent object?
$handled = false;
foreach ($dependsObjects as $dep) {
if ($dep['_property_name'] == $name) {
foreach ($depTypesInModule as $dt) {
$cls = @$dep[$dt];
if ($cls) {
self::renderEntity(str_replace('\\MangoPay\\', '', $cls), "$name:");
$handled = true;