dimocopayments/php-client
Composer 安装命令:
composer create-project dimocopayments/php-client
包简介
Payment Gateway Client for PHP
README 文档
README
Installation via composer:
composer require dimocopayments/php-client
Usage:
<?php use PaymentGateway\Client\Client; use PaymentGateway\Client\Data\Customer; use PaymentGateway\Client\Transaction\Debit; use PaymentGateway\Client\Transaction\Result; // Include the autoloader (if not already done via Composer autoloader) require_once('path/to/initClientAutoload.php'); // Instantiate the "PaymentGateway\Client\Client" with your credentials $client = new Client("username", "password", "apiKey", "sharedSecret"); $customer = new Customer(); $customer->setBillingCountry("AT") ->setEmail("customer@email.test"); $debit = new Debit(); // define your transaction ID: e.g. 'myId-'.date('Y-m-d').'-'.uniqid() $merchantTransactionId = 'your_transaction_id'; // must be unique $debit->setTransactionId($merchantTransactionId) ->setSuccessUrl($redirectUrl) ->setCancelUrl($redirectUrl) ->setCallbackUrl($callbackUrl) ->setAmount(10.00) ->setCurrency('EUR') ->setCustomer($customer); // send the transaction $result = $client->debit($debit); // now handle the result if ($result->isSuccess()) { //act depending on $result->getReturnType() $gatewayReferenceId = $result->getReferenceId(); //store it in your database if ($result->getReturnType() == Result::RETURN_TYPE_ERROR) { //error handling $errors = $result->getErrors(); //cancelCart(); } elseif ($result->getReturnType() == Result::RETURN_TYPE_REDIRECT) { //redirect the user header('Location: '.$result->getRedirectUrl()); die; } elseif ($result->getReturnType() == Result::RETURN_TYPE_PENDING) { //payment is pending, wait for callback to complete //setCartToPending(); } elseif ($result->getReturnType() == Result::RETURN_TYPE_FINISHED) { //payment is finished, update your cart/payment transaction //finishCart(); } }
统计信息
- 总下载量: 21.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-26