Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
r-simlinger committed Dec 6, 2016
2 parents 7daf776 + e3a956f commit 7ac3ee6
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 180 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "secucard connect PHP client SDK",
"license": "Apache-2.0",
"homepage": "https://github.com/secucard/secucard-connect-php-sdk",
"version": "v1.0.9",
"version": "v1.1.0",
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "~6.0",
Expand Down
28 changes: 15 additions & 13 deletions src/SecucardConnect/Client/ResourceMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,23 @@ private function findServiceClass($dir, $resource, $classPrefix)
foreach ($files as $file) {
$name = basename($file, '.php');
if (strpos(strtolower($name), $lcres) !== false) {
$cls = $classPrefix . $name;
$rc = new \ReflectionClass($cls);
$parentClassName = $className = $classPrefix . $name;

// collect all in hierarchy
$parents = [];
while (($parent = $rc->getParentClass()) && $parent) {
$parents[] = $parent;
$rc = new \ReflectionClass($parent->getName());
}
do {
$rc = new \ReflectionClass($parentClassName);
$parent = $rc->getParentClass();

foreach ($parents as $parent) {
if (ProductService::class === $parent->getName()) {
return $cls;
}
}
if (!$parent) {
break;
}

$parentClassName = $parent->getName();

if (ProductService::class === $parentClassName) {
return $className;
}

} while (true);
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/SecucardConnect/Event/DefaultEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace SecucardConnect\Event;


use SecucardConnect\Client\ProductService;
use SecucardConnect\Product\General\Model\Event;

/**
* Class DefaultEventHandler
* @package SecucardConnect\Event
*/
abstract class DefaultEventHandler implements EventHandler
{
/**
Expand Down Expand Up @@ -34,7 +37,7 @@ abstract class DefaultEventHandler implements EventHandler
* @param ProductService $service
* @param string $eventType
*/
public function __construct(callable $callback, $service, $eventType = 'changed')
public function __construct(callable $callback, ProductService $service, $eventType = 'changed')
{
$this->callback = $callback;
$this->eventTarget = $service->getResourceId();
Expand All @@ -49,12 +52,17 @@ public function __construct(callable $callback, $service, $eventType = 'changed'
* @param Event $event The event to process.
* @return bool True if can handle, false else.
*/
protected function accept($event)
protected function accept(Event $event)
{
return $event->target === $this->eventTarget && $event->type === $this->eventType;
}

function handle($event)
/**
* @param Event $event
*
* @return bool
*/
function handle(Event $event)
{
if ($this->accept($event)) {
$this->onEvent($event);
Expand Down
7 changes: 5 additions & 2 deletions src/SecucardConnect/Event/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

namespace SecucardConnect\Event;


use Exception;
use SecucardConnect\Client\AbstractError;
use SecucardConnect\Client\ClientError;
use SecucardConnect\Product\General\Model\Event;
use SecucardConnect\Util\MapperUtil;

/**
* Class EventDispatcher
* @package SecucardConnect\Event
*/
class EventDispatcher
{
/**
* @var EventHandler[]
*/
private $handlerMap = array();
private $handlerMap = [];

/**
* Register/Unregister an event handler for a id.
Expand Down
4 changes: 2 additions & 2 deletions src/SecucardConnect/Event/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ interface EventHandler
{
/**
* Handles a given event.
* @param $event Event The event to handle.
* @param Event $event The event to handle.
* @return bool True if the event was handled, false else. In the latter case another available handler may be
* invoked with the given event.
*/
function handle($event);
function handle(Event $event);
}
27 changes: 27 additions & 0 deletions src/SecucardConnect/Product/Payment/Event/PaymentChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace SecucardConnect\Product\Payment\Event;

use SecucardConnect\Client\ClientError;
use SecucardConnect\Event\DefaultEventHandler;

/**
* Internal class to handle a creditcard change event.
* @package SecucardConnect\Product\Payment
*/
class PaymentChanged extends DefaultEventHandler
{
/**
* @param $event
*
* @throws ClientError If the payment transaction id is missing in the event data
*/
function onEvent($event)
{
if (!isset($event->data[0]['id'])) {
throw new ClientError('Invalid event data, payment id not found.');
}

call_user_func($this->callback, $this->service->get($event->data[0]['id']));
}
}
34 changes: 34 additions & 0 deletions src/SecucardConnect/Product/Payment/Model/SecupayCreditcard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Payment Secupaycreditcards Api Model class
*/

namespace SecucardConnect\Product\Payment\Model;

/**
* Payment Secupaycreditcards Api Model class
*
*/
class SecupayCreditcard extends Transaction
{
/**
* @var \SecucardConnect\Product\Payment\Model\Customer
*/
public $customer;

/**
* @var string
*/
public $url_success;

/**
* @var string
*/
public $url_failure;

/**
* @var string
*/
public $iframe_url;

}
14 changes: 14 additions & 0 deletions src/SecucardConnect/Product/Payment/SecupayCreditcardsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace SecucardConnect\Product\Payment;

use SecucardConnect\Product\Payment\Service\PaymentService;

/**
* Operations for the payment.secupaycreditcard resource.
* @package SecucardConnect\Product\Payment
*/
class SecupayCreditcardsService extends PaymentService
{
}

60 changes: 8 additions & 52 deletions src/SecucardConnect/Product/Payment/SecupayDebitsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,19 @@

namespace SecucardConnect\Product\Payment;

use SecucardConnect\Client\ClientError;
use SecucardConnect\Client\ProductService;
use SecucardConnect\Event\DefaultEventHandler;


/**
* Operations for the payment/secupaydebits resource.
* @package SecucardConnect\Product\Payment
*/
class SecupayDebitsService extends ProductService
{
/**
* Cancel an existing transaction.
* @param string $debitId The debit id.
* @param string $contractId The id of the contract that was used to create this transaction. May be null if the
* contract is an parent contract (not cloned).
* @return bool True if successful false else.
*/
public function cancel($debitId, $contractId = null)
{
$o = [['contract' => $contractId]];
$res = $this->execute($debitId, 'cancel', null, $o);

if(is_object($res)) {
return (bool)$res->result;
}

return (bool)$res['result'];
}

/**
* Set a callback to be notified when a debit has changed. Pass null to remove a previous setting.
* @param $fn callable|null Any function which accepts a SecupayDebit class argument.
*
*/
public function onSecupayDebitChanged($fn)
{
$this->registerEventHandler('debitchanged', $fn === null ? null : new DebitChanged($fn, $this));
}
}
use SecucardConnect\Product\Payment\Service\PaymentService;

/**
* Internal class to handle a debit change event.
* Operations for the payment.secupaydebits resource.
* @package SecucardConnect\Product\Payment
*/
class DebitChanged extends DefaultEventHandler
class SecupayDebitsService extends PaymentService
{
/**
* @param $event
*
* @throws ClientError
* @deprecated v1.1.0 Use now onStatusChange($fn).
*/
function onEvent($event)
{
if (empty($event->data) || count($event->data) == 0) {
throw new ClientError('Invalid event data, no debit id found.');
}
call_user_func($this->callback, $this->service->get($event->data[0]['id']));
}
public function onSecupayDebitChanged($fn)
{
$this->onStatusChange($fn);
}
}
60 changes: 8 additions & 52 deletions src/SecucardConnect/Product/Payment/SecupayInvoicesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,19 @@

namespace SecucardConnect\Product\Payment;

use SecucardConnect\Client\ClientError;
use SecucardConnect\Client\ProductService;
use SecucardConnect\Event\DefaultEventHandler;


/**
* Operations for the payment/secupayinvoice resource.
* @package SecucardConnect\Product\Payment
*/
class SecupayInvoicesService extends ProductService
{
/**
* Cancel an existing transaction.
* @param string $invoiceId The invoice id.
* @param string $contractId The id of the contract that was used to create this transaction. May be null if the
* contract is an parent contract (not cloned).
* @return bool True if successful false else.
*/
public function cancel($invoiceId, $contractId = null)
{
$o = [['contract' => $contractId]];
$res = $this->execute($invoiceId, 'cancel', null, $o);

if(is_object($res)) {
return (bool)$res->result;
}

return (bool)$res['result'];
}

/**
* Set a callback to be notified when a invoice has changed. Pass null to remove a previous setting.
* @param $fn callable|null Any function which accepts a SecupayInvoice class argument.
*
*/
public function onSecupayInvoiceChanged($fn)
{
$this->registerEventHandler('invoicechanged', $fn === null ? null : new InvoiceChanged($fn, $this));
}
}
use SecucardConnect\Product\Payment\Service\PaymentService;

/**
* Internal class to handle a invoice change event.
* Operations for the payment.secupayinvoice resource.
* @package SecucardConnect\Product\Payment
*/
class InvoiceChanged extends DefaultEventHandler
class SecupayInvoicesService extends PaymentService
{
/**
* @param $event
*
* @throws ClientError
* @deprecated v1.1.0 Use now onStatusChange($fn).
*/
function onEvent($event)
{
if (empty($event->data) || count($event->data) == 0) {
throw new ClientError('Invalid event data, no invoice id found.');
}
call_user_func($this->callback, $this->service->get($event->data[0]['id']));
}
public function onSecupayInvoiceChanged($fn)
{
$this->onStatusChange($fn);
}
}
Loading

0 comments on commit 7ac3ee6

Please sign in to comment.