Skip to content

Commit

Permalink
Add direct debits and mandates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Bailey committed Apr 12, 2016
1 parent fb533d8 commit 06bdc06
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 14 deletions.
53 changes: 53 additions & 0 deletions MangoPay/ApiMandates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
namespace MangoPay;

/**
* Class to management MangoPay API for mandates
*/
class ApiMandates extends Libraries\ApiBase
{
/**
* Create new mandate
* @param Mandate $mandate
* @return \MangoPay\Mandate Mandate object returned from API
*/
public function Create($mandate, $idempotencyKey = null)
{
return $this->CreateObject('mandates_create', $mandate, '\MangoPay\Mandate', null, null, $idempotencyKey);
}

/**
* Get mandate
* @param int $mandateId Mandate identifier
* @return \MangoPay\Mandate Mandate object returned from API
*/
public function Get($mandateId)
{
return $this->GetObject('mandates_get', $mandateId, '\MangoPay\Mandate');
}

/**
* Cancel mandate
* @param Mandate $mandateId Id of mandate object to cancel
* @return \MangoPay\Mandate Mandate object returned from API
*/
public function Cancel($mandateId)
{
$mandate = new \MangoPay\Mandate();
$mandate->Id = $mandateId;

return $this->SaveObject('mandates_save', $mandate, '\MangoPay\Mandate');
}

/**
* Get all mandates
* @param \MangoPay\Pagination $pagination Pagination object
* @param \MangoPay\FilterTransactions $filter Object to filter data
* @param \MangoPay\Sorting $sorting Object to sorting data
* @return array Array with mandates
*/
public function GetAll(& $pagination = null, $filter = null, $sorting = null)
{
return $this->GetList('mandates_all', $pagination, 'MangoPay\Mandate', null, $filter, $sorting);
}
}
31 changes: 30 additions & 1 deletion MangoPay/ApiUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,35 @@ public function GetKycDocument($userId, $kycDocumentId)
return $this->GetObject('kyc_documents_get', $userId, '\MangoPay\KycDocument', $kycDocumentId);
}

/**
* Get all mandates for user
* @param int $userId User Id
* @param \MangoPay\Pagination $pagination Pagination object
* @param \MangoPay\FilterTransactions $filter Object to filter data
* @param \MangoPay\Sorting $sorting Object to sorting data
*
* @return array Array with mandate entities
*/
public function GetMandates($userId, & $pagination = null, $filter = null, $sorting = null)
{
return $this->GetList('users_allmandates', $pagination, 'MangoPay\Mandate', $userId, $filter, $sorting);
}

/**
* Get mandates for user and bank account
* @param int $userId User Id
* @param int $bankAccountId Bank account Id
* @param \MangoPay\Pagination $pagination Pagination object
* @param \MangoPay\FilterTransactions $filter Object to filter data
* @param \MangoPay\Sorting $sorting Object to sorting data
*
* @return array Array with mandate entities
*/
public function GetMandatesForBankAccount($userId, $bankAccountId, & $pagination = null, $filter = null, $sorting = null)
{
return $this->GetList('users_allbankaccount_mandates', $pagination, 'MangoPay\Mandate', $userId, $filter, $sorting, $bankAccountId);
}

/**
* Save KYC document
* @param int $userId User Id
Expand Down Expand Up @@ -309,4 +338,4 @@ private function GetBankAccountType($bankAccount)
$className = str_replace('MangoPay\\BankAccountDetails', '', get_class($bankAccount->Details));
return strtolower($className);
}
}
}
7 changes: 5 additions & 2 deletions MangoPay/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class EventType
const PayoutRefundFailed = "PAYOUT_REFUND_FAILED";
const TransferRefundCreated = "TRANSFER_REFUND_CREATED";
const TransferRefundSucceeded = "TRANSFER_REFUND_SUCCEEDED";
const TransferRefundFailed = "TRANSFER_REFUND_FAILED";

const TransferRefundFailed = "TRANSFER_REFUND_FAILED";
const PayinRepudiationCreated = "PAYIN_REPUDIATION_CREATED";
const PayinRepudiationSucceeded = "PAYIN_REPUDIATION_SUCCEEDED";
const PayinRepudiationFailed = "PAYIN_REPUDIATION_FAILED";
Expand All @@ -45,4 +44,8 @@ class EventType
const TransferSettlementCreated = "TRANSFER_SETTLEMENT_CREATED";
const TransferSettlementSucceeded = "TRANSFER_SETTLEMENT_SUCCEEDED";
const TransferSettlementFailed = "TRANSFER_SETTLEMENT_FAILED";
const MandateCreated = "MANDATE_CREATED";
const MandatedFailed = "MANDATED_FAILED";
const MandateActivated = "MANDATE_ACTIVATED";
const MandateSubmitted = "MANDATE_SUBMITTED";
}
12 changes: 10 additions & 2 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function getLogger()
'payins_preauthorized-direct_create' => array( '/payins/preauthorized/direct/', RequestType::POST ),
'payins_bankwire-direct_create' => array( '/payins/bankwire/direct/', RequestType::POST ),
'payins_directdebit-web_create' => array( '/payins/directdebit/web', RequestType::POST ),
'payins_directdebit-direct_create' => array( '/payins/directdebit/direct', RequestType::POST ),
'payins_get' => array( '/payins/%s', RequestType::GET ),
'payins_createrefunds' => array( '/payins/%s/refunds', RequestType::POST ),

Expand Down Expand Up @@ -81,6 +82,8 @@ protected function getLogger()
'users_allcards' => array( '/users/%s/cards', RequestType::GET ),
'users_alltransactions' => array( '/users/%s/transactions', RequestType::GET ),
'users_allkycdocuments' => array( '/users/%s/KYC/documents', RequestType::GET ),
'users_allmandates' => array( '/users/%s/mandates', RequestType::GET ),
'users_allbankaccount_mandates' => array( '/users/%s/bankaccounts/%s/mandates', RequestType::GET ),
'users_get' => array( '/users/%s', RequestType::GET ),
'users_getnaturals' => array( '/users/natural/%s', RequestType::GET ),
'users_getlegals' => array( '/users/legal/%s', RequestType::GET ),
Expand Down Expand Up @@ -129,6 +132,11 @@ protected function getLogger()
'temp_paymentcards_get' => array( '/temp/paymentcards/%s', RequestType::GET ),
'temp_immediatepayins_create' => array( '/temp/immediate-payins', RequestType::POST ),

'mandates_create' => array( '/mandates/directdebit/web', RequestType::POST ),
'mandates_save' => array( '/mandates/%s/cancel', RequestType::PUT ),
'mandates_get' => array( '/mandates/%s', RequestType::GET ),
'mandates_all' => array( '/mandates', RequestType::GET ),

'client_get' => array( '/clients', RequestType::GET ),
'client_save' => array( '/clients', RequestType::PUT ),
'client_upload_logo' => array( '/clients/logo', RequestType::PUT ),
Expand Down Expand Up @@ -228,9 +236,9 @@ protected function GetObject($methodKey, $entityId, $responseClassName = null, $
* @param \MangoPay\Sorting $sorting Object to sorting data
* @return object Response data
*/
protected function GetList($methodKey, & $pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null)
protected function GetList($methodKey, & $pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null, $secondEntityId = null)
{
$urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId);
$urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId);

if (is_null($pagination) || !is_object($pagination) || get_class($pagination) != 'MangoPay\Pagination') {
$pagination = new \MangoPay\Pagination();
Expand Down
81 changes: 81 additions & 0 deletions MangoPay/Mandate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
namespace MangoPay;

/**
* Direct debit mandate entity.
*/
class Mandate extends Libraries\EntityBase
{
/**
* The bank account ID to associate this mandate against
* @var string
*/
public $BankAccountId;

/**
* The type of mandate – it will be « SEPA » or « BACS »
* but will only be completed once the mandate has been submitted
* @var string
*/
public $Scheme;

/**
* The language to use for the confirmation web page presented to your user
* @var string
*/
public $Culture;

/**
* The URL to view/download the mandate document
* @var string
*/
public $DocumentURL;

/**
* Redirect URL
* @var string
*/
public $RedirectURL;

/**
* Return URL
* @var string
*/
public $ReturnURL;

/**
* ID of the user to which this mandate belongs
* @var string
*/
public $UserId;

/**
* Status of the mandate: CREATED, SUBMITTED, ACTIVE, FAILED
* @var string
*/
public $Status;

/**
* The mandate result code
* @var string
*/
public $ResultCode;

/**
* The mandate result Message
* @var string
*/
public $ResultMessage;

/**
* The type of mandate: DIRECT_DEBIT
* @var string
*/
public $MandateType;

/**
* How the mandate has been created: WEB
* @var string
*/
public $ExecutionType;
}
9 changes: 8 additions & 1 deletion MangoPay/MangoPayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ class MangoPayApi
* @var ApiDisputeDocuments
*/
public $DisputeDocuments;

/**
* Provides dispute documents methods
* @var ApiMandates
*/
public $Mandates;

/**
* @var LoggerInterface
Expand Down Expand Up @@ -166,6 +172,7 @@ public function __construct()
$this->KycDocuments = new ApiKycDocuments($this);
$this->Disputes = new ApiDisputes($this);
$this->DisputeDocuments = new ApiDisputeDocuments($this);
$this->Mandates = new ApiMandates($this);

// Setting default NullLogger
$this->logger = new NullLogger();
Expand All @@ -186,4 +193,4 @@ public function getLogger()
{
return $this->logger;
}
}
}
6 changes: 6 additions & 0 deletions MangoPay/PayInPaymentDetailsDirectDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ class PayInPaymentDetailsDirectDebit extends Libraries\Dto implements PayInPayme
* @var string
*/
public $DirectDebitType;

/**
* Mandate Id
* @var string
*/
public $MandateId;
}
1 change: 1 addition & 0 deletions demos/api/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* 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');

Expand Down
29 changes: 21 additions & 8 deletions demos/api/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

try {
$api = new \MangoPay\MangoPayApi();
$api->Config->BaseUrl = MangoPayDemo_BaseUrl;
$api->Config->ClientId = MangoPayDemo_ClientId;
$api->Config->ClientPassword = MangoPayDemo_ClientPassword;
$api->Config->TemporaryFolder = MangoPayDemo_TemporaryFolder;
Expand Down Expand Up @@ -102,20 +103,32 @@
$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 (isset($filter) && !isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $pagination, $filter);
else if (!isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $pagination, $sorting);
else if (isset($filter) && isset($sorting))
$apiResult = $api->$subApiName->$methodName($entityId, $pagination, $filter, $sorting);
else
$apiResult = $api->$subApiName->$methodName($entityId, $pagination);
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))
Expand Down
12 changes: 12 additions & 0 deletions demos/api/htmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function renderForm($entityName, $operation, $subEntityName, $filt
break;
case 'Get':
case 'CloseDispute':
case 'Cancel':
self::renderId($entityName);
break;
case 'Save':
Expand Down Expand Up @@ -67,6 +68,17 @@ public static function renderForm($entityName, $operation, $subEntityName, $filt
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;
Expand Down
9 changes: 9 additions & 0 deletions demos/api/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'Create pay-in direct pre-authorized' => 'PayIn_PayIns_Create_:PREAUTHORIZED:DIRECT',
'Create pay-in direct bank wire' => 'PayIn_PayIns_Create_:BANK_WIRE:DIRECT',
'Create pay-in direct debit web' => 'PayIn_PayIns_Create_:DIRECT_DEBIT:WEB',
'Create pay-in direct debit direct' => 'PayIn_PayIns_Create_:DIRECT_DEBIT:DIRECT',
'Get pay-in' => 'PayIn_PayIns_Get',
),
'Pay-outs' => array(
Expand Down Expand Up @@ -103,6 +104,14 @@
'List all dispute documents' => 'DisputeDocument_DisputeDocuments_All___$Sort',
'List dispute documents for dispute' => 'Dispute_Disputes_ListSubEntity_GetDocumentsForDispute__$Sort',
),
'Mandates' => array(
'Create mandate' => 'Mandate_Mandates_Create',
'Get mandate' => 'Mandate_Mandates_Get',
'Cancel mandate' => 'Mandate_Mandates_Cancel',
'List of mandates' => 'Mandate_Mandates_All__FilterTransactions___$Sort',
'List mandate for user' => 'User_Users_ListSubEntity_GetMandates_FilterTransactions_$Sort',
'List mandate for user and for bank account' => 'User_Users_ListSubSubEntity_GetMandatesForBankAccount_FilterTransactions_BankAccount___$Sort',
),
'Client' => array(
'Get client information' => 'Client_Clients_GetNoParams',
'Update client' => 'Client_Clients_SaveNoId',
Expand Down
Loading

0 comments on commit 06bdc06

Please sign in to comment.