visualr/omnipay-tillpayments

Omnipay支付处理库的Till Payments驱动程序

v2.1.1 2021-11-22 02:27 UTC

This package is auto-updated.

Last update: 2024-09-22 08:47:51 UTC


README

Omnipay PHP支付处理库的Till Payments驱动程序

Omnipay 是一个适用于 PHP 5.3+ 的框架无关的多网关支付处理库。此软件包实现了 Omnipay 的 eWAY 支持。

Till Payments 于 2012 年成立,主要致力于帮助技术供应商及其客户简化支付接受和运营。

安装

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

{
    "require": {
        "visualr/omnipay-tillpayments": "~2.0"
    }
}

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

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

基本用法

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

初始化网关

// Create a gateway
$gateway = Omnipay::create('TillPayments');

// Initialise the gateway
$gateway->initialize(array(
    'apiKey' => 'your-api-key',
    'secretKey' => 'your-secret-key',
    'username' => 'your-username',
    'password' => 'your-password',
    'testMode'  => TRUE, // or FALSE when you are ready for live transactions
    'defaultMerchantTransactionIdPrefix'  => 'omnipay-', // prefix of the merchantTransactionId (optional)
));

注意! 您将拥有不同连接器的不同 API密钥

购买交易

这在 Till 文档中称为 借记

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->purchase([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

如果您使用 Till 支付的 payment.js 接收令牌,您也可以在有效载荷中传递 transactionToken

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

授权交易

这在 Till 文档中称为 预授权

预授权在客户的支付工具上预留支付金额。

根据您的支付方式,您有最多 7 天的时间在授权过期之前必须完成交易。

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->authorize([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

如果您使用 Till 支付的 payment.js 接收令牌,您也可以在有效载荷中传递 transactionToken

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

捕获交易

捕获交易完成之前通过预授权方法授权的支付。

根据您的支付方式,您甚至可以只捕获授权金额的一部分。

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->capture([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
        'referenceUuid' => 'bcdef23456bcdef23456', // UUID / transaction reference of a preauthorize
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

购买交易

这在 Till 文档中称为 借记

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->purchase([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
        'returnUrl' => 'https://www.example.com/return', // optional
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

授权交易

这在 Till 文档中称为 预授权

预授权在客户的支付工具上预留支付金额。

根据您的支付方式,您有最多 7 天的时间在授权过期之前必须完成交易。

try {
    // You need to define your own $formData array
    $card = new CreditCard($formData);
    
    $request = $gateway->authorize([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'card' => $card,
        'returnUrl' => 'https://www.example.com/return', // optional
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

捕获交易

捕获交易完成之前通过预授权方法授权的支付。

根据您的支付方式,您甚至可以只捕获授权金额的一部分。

try {

    $request = $gateway->capture([
        'amount' => '10.00', // this represents $10.00
        'currency' => 'AUD',
        'referenceUuid' => 'bcdef23456bcdef23456', // UUID / transaction reference of a preauthorize
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

取消交易

取消交易取消之前使用预授权方法执行的先前授权。

try {

    $request = $gateway->void([
        'referenceUuid' => 'bcdef23456bcdef23456', // UUID / transaction reference of a preauthorize
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

创建卡片交易

这在 Till 文档中称为 注册

注册客户的支付工具,以便进行未来的费用(借记或预授权)

try {

    // You need to define your own $formData array
    $card = new CreditCard($formData);

    $request = $gateway->createCard([
        'card' => $card,
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

删除卡片交易

这在 Till 文档中称为 注销

注销使用注册删除之前注册的支付工具。

try {

    // You need to define your own $formData array
    $card = new CreditCard($formData);

    $request = $gateway->deleteCard([
        'referenceUuid' => 'ccf0ddd790db9d7ef41b',
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

退款交易

退款撤销之前使用借记或捕获执行的支付。

根据支付方式,您甚至可以仅部分退还原始交易金额。

try {

    $request = $gateway->refund([
        'amount'                => '1.25',
        'currency'              => 'AUD',
        'referenceUuid'         => '48bbd15cdf9e5b81985d',
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here
        // Use $response->getTransactionReference() to get transaction uuid

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

有关有效载荷的更多信息,请参阅: Till Payment 文档

有关卡片数据的更多信息,请参阅: Omnipay 信用卡文档

付款交易

即将推出

增量授权

即将推出

支付响应

成功响应

对于成功响应,通常将生成一个参考号,该参考号可以用于稍后捕获或退还交易。以下方法始终可用:

$response = $gateway->purchase([
    'amount' => '10.00', 
    'currency' => 'AUD', 
    'card' => $card
])->send();

$response->isSuccessful(); // is the response successful?
$response->isRedirect(); // is the response a redirect?
$response->getTransactionReference(); // a transaction uuid generated by the payment gateway
$response->getMessage(); // a message generated by the payment gateway

如果您要实现退款和取消,您需要始终保存交易参考号,因为它通常用作 referenceUuid

重定向响应

处理付款后,购物车应检查响应是否需要重定向,如果是,则相应地重定向。

$response = $gateway->purchase([
    'amount' => '10.00', 
    'currency' => 'AUD', 
    'card' => $card
])->send();

if ($response->isSuccessful()) {
    // payment is complete
} elseif ($response->isRedirect()) {
    $response->redirect(); // this will automatically forward the customer
} else {
    // not successful
}

客户不会自动跳转,因为通常购物车或开发者会想自定义重定向方法(或者如果支付处理发生在AJAX调用中,他们希望向浏览器返回JS)。

要显示自己的重定向页面,只需在响应上调用 getRedirectUrl(),然后相应地显示它。

$url = $response->getRedirectUrl();

错误响应

您可以通过在响应对象上调用 isSuccessful() 来测试是否成功响应。如果与网关通信出现错误,或者您的请求显然无效,将抛出异常。一般来说,如果网关不抛出异常,但返回不成功响应,则应向客户显示一条消息。如果抛出异常,可能是您的代码中存在错误(缺少必需的字段),或者与网关的通信错误。

最简单的方法是将整个请求包装在 try-catch 块中。

try {

    $request = $gateway->refund([
        'amount'                => '1.25',
        'currency'              => 'AUD',
        'referenceUuid'         => '48bbd15cdf9e5b81985d',
    ]);
    
    $response = $transaction->send();

    if ($response->isSuccessful()) {

        // Do stuff here like marking order as complete

    } else {

        // Handle errors

    }

} catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {

    // Handle Exception Errors (use $e->getResponse()->getBody() to get JSON data)

} catch (\Exception $e) {

    // Handle Exception Errors (use $e->getMessage() to get data)

}

高级用法

使用 Customer 而不是 CreditCard

即将推出

计划

即将推出

接受通知

即将推出

支持

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

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

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