コード例 #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)
{
コード例 #2
0
*	WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
*	MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
*	NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*	INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*	BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
*	OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
*	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/TransactionDeletedInfo.class.php";
class TransactionsApiWebHooks
{
    const TransactionDeletedEvent = 'TransactionDeletedEvent';
    private static $mapping = array();
    public static function initialize()
    {
        self::$mapping[self::TransactionDeletedEvent] = new WebHookDefinition(self::TransactionDeletedEvent, new TransactionDeletedInfo());
    }
    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];
    }
}
TransactionsApiWebHooks::initialize();