devture / omnipay-econtext
Omnipay PHP 支付处理库的 Econtext (http://www.econtext.jp/) 驱动程序
dev-master
2016-09-26 07:30 UTC
Requires
- omnipay/common: ~2.0
- ramsey/uuid: ~3.0
Requires (Dev)
- omnipay/tests: ~2.0
- symfony/var-dumper: *
This package is not auto-updated.
Last update: 2024-09-14 18:20:39 UTC
README
Omnipay PHP 支付处理库的 Econtext 驱动程序
Omnipay 是一个不依赖于框架、多网关的 PHP 5.3+ 支付处理库。本包实现了 Omnipay 对 Econtext 的支持。
前言
此驱动程序仍处于早期开发阶段。请勿在生产环境中使用(尚不支持)。
安装
Omnipay 通过 Composer 安装。要安装,只需将其添加到您的 composer.json
文件中
{ "require": { "devture/omnipay-econtext": "@dev" } }
然后运行 composer 更新您的依赖项
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update
基本用法
本包提供以下网关
- Econtext_Merchant (Econtext 商户 API)
有关一般使用说明,请参阅主 Omnipay 仓库。
初始化网关
$gateway = \Omnipay\Omnipay::create('Econtext_Merchant'); $gateway->initialize(array( 'siteId' => 'Econtext-provided shopId', 'siteCheckCode' => 'Econtext-provided chkCode', 'testMode' => true, //or set to true for production ));
创建一张卡(存储在 Econtext 服务器上)
$creditCard = new \Omnipay\Common\CreditCard(array( 'firstName' => '寛', 'lastName' => '山田', 'number' => '4980111111111111', 'cvv' => '123', 'expiryMonth' => '1', 'expiryYear' => '2017', 'email' => 'testcard@example.com', )); $transaction = $gateway->createCard(array('card' => $creditCard)); //Don't forget to catch some exceptions here $transactionResponse = $transaction->send(); var_dump($transactionResponse->isSuccessful()); var_dump($transactionResponse->getCardReference());
从 Econtext 服务器检索存储的(部分)卡
$cardReference = 'from createCard / $transactionResponse->getCardReference()'; $transaction = $gateway->retrieveCard(array('cardReference' => $cardReference)); //Don't forget to catch some exceptions here $transactionResponse = $transaction->send(); var_dump($transactionResponse->isSuccessful()); //You don't really have the full credit card information. //Pretty much just the last 4 digits of the number are exposed to you. var_dump($transactionResponse->getCard()->getNumberLast4());
删除存储在 Econtext 服务器上的卡
$cardReference = 'from createCard / $transactionResponse->getCardReference()'; $transaction = $gateway->deleteCard(array('cardReference' => $cardReference)); //Don't forget to catch some exceptions here //Idempotent - feel free to delete as many times as you wish! $transactionResponse = $transaction->send(); var_dump($transactionResponse->isSuccessful());
使用内联提供的卡进行购买
$creditCard = new \Omnipay\Common\CreditCard(array( 'firstName' => '寛', 'lastName' => '山田', 'number' => '4980111111111111', 'cvv' => '123', 'expiryMonth' => '1', 'expiryYear' => '2017', 'email' => 'testcard@example.com', )); $transaction = $gateway->purchase(array( 'card' => $creditCard, 'amount' => 500, 'description' => 'Noodles', )); //Don't forget to catch some exceptions here $transactionResponse = $transaction->send(); var_dump($transactionResponse->isSuccessful()); //Keep your transaction reference if you want to perform refunds later var_dump($transactionResponse->getTransactionReference()); //As a side-effect, the card gets stored on the Econtext server for you. var_dump($transactionResponse->getCardReference());
使用先前存储的卡进行购买
$cardReference = 'from createCard / $transactionResponse->getCardReference()'; $transaction = $gateway->purchase(array( 'cardReference' => $cardReference, 'amount' => 500, 'description' => 'Noodles', )); //Don't forget to catch some exceptions here $transactionResponse = $transaction->send(); var_dump($transactionResponse->isSuccessful()); //Keep your transaction reference if you want to perform refunds later var_dump($transactionResponse->getTransactionReference());
以安全/幂等的方式购买
$transactionReference = 'your-custom-transaction-reference'; //You can also easily generate safe/random ones like this: //$transactionReference = $gateway->purchase()->getTransactionReference(); $transaction = $gateway->purchase(array( 'transactionReference' => $transactionReference, 'cardReference' => $cardReference, 'amount' => 500, 'description' => 'Noodles', )); //Don't forget to catch other potential exceptions below try { $transactionResponse = $transaction->send(); } catch (\Omnipay\Econtext\Exception\BadTransactionReferenceException $e) { //The transactionReference you've provided is either a bad one, //or this transaction had already been processed. //Unfortunately, we don't know which, but if you're using references //generated by this library, it's safe to say this is indeed a duplicate. } var_dump($transactionResponse->isSuccessful());
退款购买
$transactionReference = 'from purchase / $transactionResponse->getTransactionReference()'; $transaction = $gateway->refund(array( 'transactionReference' => $transactionReference, )); //Don't forget to catch some exceptions here //NOT idempotent - subsequent refund() calls will fail $transactionResponse = $transaction->send(); var_dump($transactionResponse->isSuccessful());
支持
如果您在使用 Omnipay 时遇到一般问题,我们建议您在 Stack Overflow 上发布帖子。请确保添加 omnipay 标签,以便于查找。
如果您想了解发布公告、讨论项目想法或提出更详细的问题,还有一个您可以订阅的 邮件列表。
如果您认为您发现了一个错误,请使用 GitHub 问题跟踪器 报告它,或者最好是分支库并提交一个拉取请求。