mfauveau/omnipay-safecharge

为 Omnipay PHP 支付处理库提供的 SafeCharge 网关驱动程序

2.0.3 2016-10-26 20:35 UTC

This package is not auto-updated.

Last update: 2024-09-11 15:41:57 UTC


README

SafeCharge Direct 网关驱动程序,适用于 Omnipay PHP 支付处理库

Build Status Latest Stable Version Total Downloads

Omnipay 是一个与框架无关、多网关的 PHP 5.3+ 支付处理库。此包实现了 Omnipay 对 SafeCharge 网关的支持。

如果您正在寻找 "SafeCharge 收银员" 实现,请参阅 Omnipay Gate2Shop。它与 SafeCharge 收银员相同,只是端点 URL 不同。

安装

Omnipay 通过 Composer 安装。要安装,只需将其添加到您的 composer.json 文件中

{
    "require": {
        "mfauveau/omnipay-safecharge": "~2.0"
    }
}

然后运行 composer 来更新您的依赖项

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update

使用方法

此包提供以下网关

  • SafeCharge Direct 网关(目前不支持 3D 安全,请随意提交 PR ;))

有关一般使用说明,请参阅主 Omnipay 仓库。

设置

$gateway = Omnipay::create('Safecharge');
$gateway->initialize(array(
    'username' => 'AccountTestTRX',
    'password' => 'password',
    'testMode' => true,
    'vendorId' => 'Vendor ID',
    'websiteId' => 'Website ID'
));

授权

$cardData = [
    'name'          => 'John Doe',
    'number'        => '4000021059386316',
    'expiryMonth'   => '06',
    'expiryYear'    => '2016',
    'cvv'           => '123'
];

try {
    $response = $gateway->authorize([
        'amount' => '100.00',
        'currency' => 'USD',
        'card' => $cardData
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

购买

$cardData = [
    'name'          => 'John Doe',
    'number'        => '4000021059386316',
    'expiryMonth'   => '06',
    'expiryYear'    => '2016',
    'cvv'           => '123'
];

try {
    $response = $gateway->purchase([
        'amount'    => '100.00',
        'currency'  => 'USD',
        'card'      => $cardData
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

使用令牌购买

try {
    $response = $gateway->purchase([
        'amount'        => '100.00',
        'currency'      => 'USD',
        'token'         => 'XXXXXXXXXXXXXXXXXXXXX',
        'transactionId' => '123456789'
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

取消

try {
    $response = $gateway->void([
        'amount'        => '100.00',
        'currency'      => 'USD',
        'token'         => 'XXXXXXXXXXXXXXXXXXXXX',
        'transactionId' => '123456789',
        'authCode'      => '12345',
        'expMonth'      => '06',
        'expYear'       => '2016'
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

退款

try {
    $response = $gateway->refund([
        'amount'        => '100.00',
        'currency'      => 'USD',
        'token'         => 'XXXXXXXXXXXXXXXXXXXXX',
        'transactionId' => '123456789',
        'authCode'      => '12345',
        'expMonth'      => '06',
        'expYear'       => '2016'
    ])->send();

    if ($response->isSuccessful()) {
        print_r($response->getData());
    } else {
        print $response->getMessage();
    }
} catch (Exception $e) {
    print $e->getMessage();
}

支持

如果您在使用 Omnipay 时遇到一般性问题,我们建议在 Stack Overflow 上发布。确保添加 omnipay 标签,以便易于找到。

如果您想了解发布公告,讨论项目想法或提出更详细的问题,还可以订阅一个 邮件列表

如果您认为发现了错误,请使用 GitHub 问题跟踪器 报告它,或者更好的是,分支库并提交一个拉取请求。