marcguyer / assembly-callback

与Assembly Payments发送的回调进行交互的库

0.0.3 2017-05-01 17:06 UTC

This package is auto-updated.

Last update: 2024-09-21 20:25:52 UTC


README

Build Status

Assembly Payments回调对象

一组结构化的对象,旨在允许对Assembly Payments回调负载进行某些抽象处理。

安装

composer require assembly-callback

使用示例

基本使用

基本使用简单地实例化一个由您的监听器提供的类型的新回调对象。

use Assembly\Callback;

// get the request body in your preferred way
$requestBody = file_get_contents("php://input");

// use the factory to create an object of the proper type
$callback = Callback\CallbackFactory::factory($requestBody);

带有效载荷验证

您可以选择使用验证功能,该功能默认需要stock SDK可用。这使用回调负载中的id从Assembly API请求相同类型的对象。

use Assembly\Callback;
use PromisePay\PromisePay;

// get the request body in your preferred way
$requestBody = file_get_contents("php://input");

// use the factory to create an object of the proper type
$callback = Callback\CallbackFactory::factory($requestBody);

// config the PromisePay client
PromisePay::Configuration()->environment('prelive');
PromisePay::Configuration()->login('<username>');
PromisePay::Configuration()->password('<api key>');

// validate the callback
$callback->validate();

扩展回调类型

您可能想向对象添加一些功能。为此,您可以定义自己的类型处理器。

示例扩展

use Assembly\Callback\Transaction;

class MyTransaction extends Transaction
{
    public function someSpecialHandling() {
        // do something extra special
    }
}

使用扩展

use Assembly\Callback;

// get the request body in your preferred way
$requestBody = file_get_contents("php://input");

// when the type is "transactions", use this extention
Callback\CallbackFactory::registerType(
    'transactions',
    'My_Assembly_Callback_Transaction'
);

// use the factory to create an object of the proper type
$callback = Callback\CallbackFactory::factory($requestBody);

贡献

鼓励提交拉取请求。 了解如何