Skip to content

Commit

Permalink
Issue #7 Get Direct Debit Mandate and Mandate Collection.
Browse files Browse the repository at this point in the history
not yet tested or tried against sandbox.
  • Loading branch information
judgej committed Apr 26, 2018
1 parent 038c165 commit 840e287
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ GetSettlementCycleCurrent | SettlementCycle
GetSettlementCycleLast | SettlementCycle
GetSettlementCyclePayments | PaymentDetailsCollection
UpdatePaymentAccountAddressStatus | ChangeStatusPaymentAccountAddressResponse
GetDirectDebitMandate | DirectDebitMandate
GetDirectDebitMandates | DirectDebitMandateCollection
ActivateMandateRequest | ActivateMandateResponse
CancelMandateRequest | CancelMandateResponse
TBC | PaymentOriginatingOverseasInstructionResponse
Expand Down Expand Up @@ -273,5 +275,7 @@ Webhooks are supported:
* ServerRequest\FpsInboundNotification
* ServerRequest\FpsRedirectionNotification
* ServerRequest\FpsReversalNotification (no tests yet)

* ServerRequest\AccountTransactionNotification (no tests yet)

* TODO: six BACS web hooks
8 changes: 7 additions & 1 deletion src/ModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface ModelInterface extends \JsonSerializable


/**
* @var mandate cancellation reasons
* @var Direct debit mandate cancellation reasons
*/
const MANDATE_CANCELLATION_REASON_INSTRUCTION_CANCELLED =
'INSTRUCTION_CANCELLED';
Expand All @@ -122,6 +122,12 @@ interface ModelInterface extends \JsonSerializable
const MANDATE_CANCELLATION_REASON_INSTRUCTION_AMENDED =
'INSTRUCTION_AMENDED';

/**
* @var mandate Direct debit mandate status
*/
const DIRECT_DEBIT_STATUS_ACTIVE = 'ACTIVE';
const DIRECT_DEBIT_STATUS_CANCELLED = 'CANCELLED';

/**
* API accepted date format example: 2017-06-05T11:47:58.801Z
* ISO 8601 or "Zulu time" when expressing UTC "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
Expand Down
8 changes: 0 additions & 8 deletions src/Request/ActivateMandateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,4 @@ protected function setMandateUid($value)

$this->mandateUid = $value;
}

/**
* @return CreatePaymentAccountAddressRequest for serializing
*/
public function jsonSerialize()
{
return [];
}
}
67 changes: 67 additions & 0 deletions src/Request/GetDirectDebitMandate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Consilience\Starling\Payments\Request;

/**
* Gets a specific direct debit mandate associated with the specified address.
*/

use Consilience\Starling\Payments\Request\Models\Endpoint;
use Consilience\Starling\Payments\AbstractRequest;
use UnexpectedValueException;

class GetDirectDebitMandate extends AbstractRequest
{
/**
* @inherit
*/
protected $pathTemplate = 'account/{accountUid}/address/{addressUid}/mandate/{mandateUid}';

protected $httpMethod = 'GET';

protected $accountUid;
protected $addressUid;
protected $mandateUid;

/**
* @param string $paymentBusinessUid
* @param string $accountUid the accound to retrieve
*/
public function __construct(Endpoint $endpoint, $accountUid, $addressUid, $mandateUid)
{
$this->setEndpoint($endpoint);
$this->setAccountUid($accountUid);
$this->setAddressUid($addressUid);
$this->setMandateUid($mandateUid);
}

/**
* @param string UID
*/
protected function setAccountUid($value)
{
$this->assertUid($value);

$this->accountUid = $value;
}

/**
* @param string UID
*/
protected function setAddressUid($value)
{
$this->assertUid($value);

$this->addressUid = $value;
}

/**
* @param string UID
*/
protected function setMandateUid($value)
{
$this->assertUid($value);

$this->mandateUid = $value;
}
}
55 changes: 55 additions & 0 deletions src/Request/GetDirectDebitMandates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Consilience\Starling\Payments\Request;

/**
* Gets a specific direct debit mandate associated with the specified address.
*/

use Consilience\Starling\Payments\Request\Models\Endpoint;
use Consilience\Starling\Payments\AbstractRequest;
use UnexpectedValueException;

class GetDirectDebitMandates extends AbstractRequest
{
/**
* @inherit
*/
protected $pathTemplate = 'account/{accountUid}/address/{addressUid}/mandate';

protected $httpMethod = 'GET';

protected $accountUid;
protected $addressUid;

/**
* @param string $paymentBusinessUid
* @param string $accountUid the accound to retrieve
*/
public function __construct(Endpoint $endpoint, $accountUid, $addressUid)
{
$this->setEndpoint($endpoint);
$this->setAccountUid($accountUid);
$this->setAddressUid($addressUid);
}

/**
* @param string UID
*/
protected function setAccountUid($value)
{
$this->assertUid($value);

$this->accountUid = $value;
}

/**
* @param string UID
*/
protected function setAddressUid($value)
{
$this->assertUid($value);

$this->addressUid = $value;
}
}
72 changes: 72 additions & 0 deletions src/Response/DirectDebitMandate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Consilience\Starling\Payments\Response;

/**
* A mandate that allows a specific originator to claim direct debit payments.
*/

use Consilience\Starling\Payments\Response\Models\BacsOriginator;
use Consilience\Starling\Payments\AbstractResponse;

class DirectDebitMandate extends AbstractResponse
{
/**
* @var string UUID
* Unique identifier of the company requesting or receiving the payment.
*/
protected $paymentBusinessUid;

/**
* @var string UUID
* Unique identifier of the account containing the funds sent or received.
*/
protected $paymentAccountUid;

/**
* @var string UUID
* Unique identifier of the payment account address.
*/
protected $addressUid;

/**
* @var string UUID
* Unique identifier of the BACS mandate.
*/
protected $mandateUid;

/**
* @var string one of static::DIRECT_DEBIT_STATUS_*
* Status of the direct debit mandate.
*/
protected $reference;

/**
* @var BacsOriginator
*/
protected $bacsOriginator;

/**
* @var string one of static::DIRECT_DEBIT_STATUS_*
* Status of the direct debit mandate.
*/
protected $status;

/**
* Create a model and set the property.
*
* @param array $data source data to hydrate the model
*/
protected function setBacsOriginator(array $data)
{
$this->bacsOriginator = BacsOriginator::fromArray($data);
}

/**
* @return bool true if the account address is active.
*/
public function isActive()
{
return $this->status === static::DIRECT_DEBIT_STATUS_ACTIVE;
}
}
30 changes: 30 additions & 0 deletions src/Response/DirectDebitMandateCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Consilience\Starling\Payments\Response;

/**
*
*/

use Consilience\Starling\Payments\AbstractCollection;
use Consilience\Starling\Payments\Response\DirectDebitMandate;

class DirectDebitMandateCollection extends AbstractCollection
{
/**
* @param mixed $item
* @return bool
*/
protected function hasExpectedStrictType($item)
{
return $item instanceof DirectDebitMandate;
}

/**
* @inherit
*/
protected function createInstance(array $data)
{
return new DirectDebitMandate($data);
}
}
34 changes: 34 additions & 0 deletions src/Response/Models/BacsOriginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Consilience\Starling\Payments\Response\Models;

/**
* A party that is able to set up direct debit mandates and
* send and receive payments via BACS
*/

use Consilience\Starling\Payments\HydratableTrait;
use Consilience\Starling\Payments\ModelInterface;

class BacsOriginator implements ModelInterface
{
use HydratableTrait;

/**
* @var string UUID
* Starling's unique identifier of the originator.
*/
protected $originatorUid;

/**
* @var string 6 characters; example 987654
* BACS's unique identifier of the originator.
*/
protected $serviceUserNumber;

/**
* @var string 0 to 33 characters; example : "Southern Electric"
* The name of the originator as registered with BACS.
*/
protected $name;
}

0 comments on commit 840e287

Please sign in to comment.