cmpayments / ideal
适用于PHP 5.4+的iDEAL实现
v1.3.2
2021-03-02 09:52 UTC
Requires
- php: >=5.4.0
- ext-curl: *
- ext-dom: *
- ext-libxml: *
- ramsey/uuid: ^4.1
- robrichards/xmlseclibs: >=3.0.2
Suggests
- roave/security-advisories: Consider adding roave/security-advisories:dev-master as a firewall for vulnerable components.
Replaces
- bravesheep/ideal: v0.1.0
- interexperts/ideal: v1.0.3
README
此库实现了iDEAL协议,可用于与所有主要iDEAL收购银行进行iDEAL交易。以下收购银行得到支持
- ABN AMRO Bank
- BNP Paribas Fortis
- Rabobank
- Deutsche Bank
- ING
- PPRO Financial Limited
此库与PHP 5.4+和PHP 7.0兼容
安装
要安装cmpayments/ideal,只需使用composer要求即可
# composer require cmpayments/ideal
使用示例
初始化库并提供连接配置选项
<?php require __DIR__ . '/../vendor/autoload.php'; $ideal = new CMPayments\IDeal\IDeal('https://ideal.acquirer.nl/ideal/iDEALv3'); $ideal->setOptions([ 'acquirerCertificate' => 'acq_cert.pem', 'merchantCertificate' => 'mer_cert.pem', 'merchantPrivateKey' => 'mer_cert.key', 'password' => 'private_key_password', 'merchantId' => '002099999', 'merchantSubId' => 1 ]);
检索所有发行银行的列表
<?php $request = $ideal->createDirectoryRequest(); $response = $request->send(); $issuers = $response->getAllIssuers();
启动iDEAL交易
<?php $transactionRequest = $ideal->createTransactionRequest('INGBNL2A', 'http://yourwebsite.nl/returnpath', 'purchaseId', 123456, 'Description'); try { $transactionResponse = $transactionRequest->send(); } catch (CMPayments\IDeal\Exception\ResponseException $e) { // Handle an error response here var_dump($e->getSuggestedAction()); exit(); } // Store these values in your local database: $entranceCode = $transactionRequest->getEntranceCode(); $transactionId = $transactionResponse->getTransactionId(); // redirect the user to the bank environment header('Location: ' . $transactionResponse->getAuthenticationUrl());
返回后验证iDEAL交易状态
<?php // retrieve and sanitize transaction id from the querystring $transactionId = preg_replace('/[^0-9]/','',$_GET['trxid']); // at this point the entrance code ($_GET['ec']) should be checked against // the value that was returned upon creation of the transaction // Request the transaction status. $statusRequest = $ideal->createStatusRequest($transactionId); $statusResponse = $statusRequest->send(); // Get the transaction status. switch ($statusResponse->getStatus()) { case \CMPayments\IDeal\IDeal::SUCCESS: // consumerIBAN and consumerName are available on 'Success'. $consumerIban = $statusResponse->getConsumerIBAN(); $consumerName = $statusResponse->getConsumerName(); break; case \CMPayments\IDeal\IDeal::OPEN: // When the transaction status is still 'Open' it should be retried later. // According to the iDEAL implementation guidelines the next attempt should only be performed after 5 minutes. // In total, 5 attempts are allowed and only if a non final status is returned. break; case \CMPayments\IDeal\IDeal::FAILURE: case \CMPayments\IDeal\IDeal::CANCELLED: case \CMPayments\IDeal\IDeal::EXPIRED: // The transaction has failed with either a Failure, Cancelled or Expired status // This is the moment where the user needs to be informed and the transaction should possibly be retried. break; }
提交bug和功能请求
bug和功能请求在GitHub上跟踪
版权和许可
cmpayment/ideal库版权所有© CM Payments,interexperts和bravesheep,并许可在MIT许可(MIT)下使用。请参阅LICENSE获取更多信息。