承接 visualr/omnipay-tillpayments 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

visualr/omnipay-tillpayments

Composer 安装命令:

composer require visualr/omnipay-tillpayments

包简介

Till Payments driver for the Omnipay payment processing library

README 文档

README

Till Payments driver for the Omnipay PHP payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements eWAY support for Omnipay.

Till Payments was founded in 2012 with the primary focus of helping technology vendors and their customers streamline their payments acceptance and operations.

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

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

And run composer to update your dependencies:

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

Basic Usage

For general usage instructions, please see the main Omnipay repository.

Initializing Gateway

// 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)
));

Remember! You will have different API Key for different connectors

Purchase Transaction

This is called Debit on Till Documentation

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code

You can also pass transactionToken on the payload if you receive a token using Till Payment's payment.js

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Authorize Transaction

This is called Preauthorize on Till Documentation

A Preauthorize reserves the payment amount on the customer's payment instrument.

Depending on the payment method you have up to 7 days until you must Capture the transaction before the authorization expires.

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code

You can also pass transactionToken on the payload if you receive a token using Till Payment's payment.js

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Capture Transaction

A Capture completes the payment which was previously authorized with the Preauthorize method.

Depending on the payment method you can even capture only a partial amount of the authorized amount.

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code
referenceUuid UUID / transaction reference of a preauthorize

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Purchase Transaction

This is called Debit on Till Documentation

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Authorize Transaction

This is called Preauthorize on Till Documentation

A Preauthorize reserves the payment amount on the customer's payment instrument.

Depending on the payment method you have up to 7 days until you must Capture the transaction before the authorization expires.

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Capture Transaction

A Capture completes the payment which was previously authorized with the Preauthorize method.

Depending on the payment method you can even capture only a partial amount of the authorized amount.

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code
referenceUuid UUID / transaction reference of a preauthorize

For more information about the payload, refer to: Till Payment Documentation

Void Transaction

A Void cancels a previously performed authorization made with the Preauthorize method.

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
referenceUuid UUID / transaction reference of a preauthorize

For more information about the payload, refer to: Till Payment Documentation

Create Card Transaction

This is called Register on Till Documentation

Registers a customer's payment instrument for future charges (Debits or Preauthorizations)

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Delete Card Transaction

This is called Deregister on Till Documentation

A Deregister deletes a previously registered payment instrument using Register.

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
referenceUuid UUID of a register, debit-with-register or preauthorize-with-register

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Refund Transaction

A Refund reverses a payment which was previously performed with Debit or Capture.

Depending on the payment method you can even refund only a partial amount of the original transaction amou

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)

}
Required Fields Notes
merchantTransactionId Your unique transaction ID. If left blank, default one will be used
amount Decimals separated by ., max. 3 decimals
currency 3 letter currency code
referenceUuid UUID of a register, debit-with-register or preauthorize-with-register

For more information about the payload, refer to: Till Payment Documentation

For more information about the card data, refer to: Omnipay Credit Card Documentation

Payout Transaction

Coming soon

Incremental Authorization

Coming soon

The Payment Responses

Successful Response

For a successful responses, a reference will normally be generated, which can be used to capture or refund the transaction at a later date. The following methods are always available:

$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

If you are going to implement refund and void, you will need to always save the transaction reference since it is often used as referenceUuid.

Redirect Response

After processing a payment, the cart should check whether the response requires a redirect, and if so, redirect accordingly:

$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
}

The customer isn't automatically forwarded on, because often the cart or developer will want to customize the redirect method (or if payment processing is happening inside an AJAX call they will want to return JS to the browser instead).

To display your own redirect page, simply call getRedirectUrl() on the response, then display it accordingly:

$url = $response->getRedirectUrl();

Error Response

You can test for a successful response by calling isSuccessful() on the response object. If there was an error communicating with the gateway, or your request was obviously invalid, an exception will be thrown. In general, if the gateway does not throw an exception, but returns an unsuccessful response, it is a message you should display to the customer. If an exception is thrown, it is either a bug in your code (missing required fields), or a communication error with the gateway.

The simplest way is to wrap the entire request in a try-catch block.

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)

}

Advanced Usage

Using Customer instead of CreditCard

Coming soon

Schedule

Coming soon

Accepting Notification

Coming soon

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release announcements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

visualr/omnipay-tillpayments 适用场景与选型建议

visualr/omnipay-tillpayments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.58k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「pay」 「gateway」 「merchant」 「omnipay」 「till」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 visualr/omnipay-tillpayments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 visualr/omnipay-tillpayments 我们能提供哪些服务?
定制开发 / 二次开发

基于 visualr/omnipay-tillpayments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-06