Ejemplo n.º 1
0
<?php

// http://addons.invipay.localhost/PHP%20API/examples/webhooks/Listener.example.php
require_once dirname(__FILE__) . "/../../common/WebHooksClient.class.php";
require_once dirname(__FILE__) . "/../config.php";
require_once dirname(__FILE__) . "/../../contractors/ContractorsApiWebHooks.class.php";
require_once dirname(__FILE__) . "/../../transactions/TransactionsApiWebHooks.class.php";
require_once dirname(__FILE__) . "/../../protection/ProtectionApiWebHooks.class.php";
require_once dirname(__FILE__) . "/../../liabilities/LiabilitiesApiWebHooks.class.php";
Logger::setWriter(new FileLoggerWriter(dirname(__FILE__) . '/Listener.log.txt'));
$client = new WebHooksClient(INVIPAY_PARTNER_API_KEY, INVIPAY_PARTNER_SIGNATURE_KEY);
// Note that here we're using PARTNER account so we can listen to events issued on behalf of other Contractors related to our platform
$client->onEvent(ContractorsApiWebHooks::getDefinition('ContractorVerificationCompletedEvent'), 'onContractorVerificationCompletedEvent');
$client->onEvent(ContractorsApiWebHooks::getDefinition('AccountCreationCompletedEvent'), 'onAccountCreationCompletedEvent');
$client->onEvent(ContractorsApiWebHooks::getDefinition('ContractorProfileChangedEvent'), 'onContractorProfileChangedEvent');
$client->onEvent(TransactionsApiWebHooks::getDefinition('TransactionDeletedEvent'), 'onTransactionDeletedEvent');
$client->onEvent(ProtectionApiWebHooks::getDefinition('TransactionProtectionCompletedEvent'), 'onTransactionProtectionCompletedEvent');
$client->onEvent(LiabilitiesApiWebHooks::getDefinition('NewCommissionInvoiceCreatedEvent'), 'onNewCommissionInvoiceCreatedEvent');
$client->onEvent(LiabilitiesApiWebHooks::getDefinition('NewInterestInvoiceCreatedEvent'), 'onNewInterestInvoiceCreatedEvent');
$client->onEvent(LiabilitiesApiWebHooks::getDefinition('NewInterestNoteCreatedEvent'), 'onNewInterestNoteCreatedEvent');
$client->handle();
function onContractorVerificationCompletedEvent($data)
{
    Logger::info('Contractor verification completed with data: {0}', $data);
}
function onAccountCreationCompletedEvent($data)
{
    Logger::info('Account creation completed with data: {0}', $data);
}
function onContractorProfileChangedEvent($data)
{
*	ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
*	TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
*	USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
*	DAMAGE.
*/
require_once dirname(__FILE__) . "/../common/WebHookDefinition.class.php";
require_once dirname(__FILE__) . "/dto/VerificationResults.class.php";
require_once dirname(__FILE__) . "/dto/AccountCreationResult.class.php";
require_once dirname(__FILE__) . "/dto/AccountDetails.class.php";
class ContractorsApiWebHooks
{
    const ContractorVerificationCompletedEvent = 'ContractorVerificationCompletedEvent';
    const AccountCreationCompletedEvent = 'AccountCreationCompletedEvent';
    const ContractorProfileChangedEvent = 'ContractorProfileChangedEvent';
    private static $mapping = array();
    public static function initialize()
    {
        self::$mapping[self::ContractorVerificationCompletedEvent] = new WebHookDefinition(self::ContractorVerificationCompletedEvent, new VerificationResult());
        self::$mapping[self::AccountCreationCompletedEvent] = new WebHookDefinition(self::AccountCreationCompletedEvent, new AccountCreationResult());
        self::$mapping[self::ContractorProfileChangedEvent] = new WebHookDefinition(self::ContractorProfileChangedEvent, new AccountDetails());
    }
    public static function getDefinition($key)
    {
        if (!array_key_exists($key, self::$mapping)) {
            throw new Exception('WebHook event definition for [' . $key . '] not found.');
        }
        return self::$mapping[$key];
    }
}
ContractorsApiWebHooks::initialize();