nordsoftware/yii-paymentmanager

此包已被废弃且不再维护。未建议替代包。

Yii PHP 框架的支付管理器。

1.0.3 2014-10-17 07:08 UTC

README

Yii PHP 框架的支付管理器。

支付管理器的目标是提供一套易于使用的API,以便通过Yii应用程序中的任何支付网关进行支付。它包含一组用于存储统一支付数据的模型,可用于实现必要的任何支付网关。它为实际支付网关的实现留有大量空间,因为每个支付网关的工作方式都有所不同。

使用

安装和配置

安装支付管理器最简单的方式是使用Composer。将以下内容添加到您的composer.json文件中

.....
"require": {
	"nordsoftware/yii-paymentmanager": "1.0.*"
}

运行以下命令下载扩展

php composer.phar update

将以下内容添加到您的应用程序配置中

.....
'components' => array(
    .....
    'payment' => array(
        'class' => 'PaymentManager',
        'contexts' => array(
            'context1' => array(
                'successUrl' => array('/context1/done'),
                'failureUrl' => array('/context1/failure'),
            ),
        ),
        'gateways' => array(
            .....
        ),
    ),
),
.....

请注意,支付管理器不包含任何实际的支付网关实现。例如,请参阅我们的Paytrail实现: http://github.com/nordsoftware/yii-paytrail

如果您不使用Composer的自动加载,则需要在您的应用程序配置中添加以下导入

.....
'import' => array(
    .....
    'webroot.vendor.nordsoftware.yii-paymentmanager.components.*',
    'webroot.vendor.nordsoftware.yii-paymentmanager.models.*',
    'webroot.vendor.nordsoftware.yii-paymentmanager.migrations.*',
    'webroot.vendor.nordsoftware.yii-audit.behaviors.*',
    'webroot.vendor.nordsoftware.yii-audit.models.*',
    'webroot.vendor.crisu83.yii-arbehaviors.behaviors.*',
    .....
),
.....

请注意,您需要将 "webroot" 更改为与您的配置匹配。

创建交易

使用支付管理器,可以轻松创建统一的交易,并使用您选择的支付网关进行支付。以下是一个简单的示例,说明如何创建交易并使用支付管理器处理它。

$transaction = PaymentTransaction::create(
    array(
        'context' => 'context1', // the context name from the configuration
        'gateway' => 'paytrail', // requires the yii-paytrail extension
        'orderIdentifier' => 1, // order id or similar
        'description' => 'Test payment',
        'price' => 100.00,
        'currency' => 'EUR',
    )
);

$transaction->addShippingContact(
    array(
        'firstName' => 'Foo',
        'lastName' => 'Bar',
        'email' => 'foo@bar.com',
        'phoneNumber' => '1234567890',
        'mobileNumber' => '0400123123',
        'companyName' => 'Test company',
        'streetAddress' => 'Test street 1',
        'postalCode' => '12345',
        'postOffice' => 'Helsinki',
        'countryCode' => 'FIN',
    )
);

$transaction->addItem(
    array(
        'description' => 'Test product',
        'code' => '01234',
        'quantity' => 5,
        'price' => 19.90,
        'vat' => 23.00,
        'discount' => 10.00,
    )
);

$transaction->addItem(
    array(
        'description' => 'Another test product',
        'code' => '43210',
        'quantity' => 1,
        'price' => 49.90,
        'vat' => 23.00,
        'discount' => 50.00,
    )
);

Yii::app()->payment->process($transaction);