allsecure-pay/php-exchange

适用于PHP的AllSecure eXchange客户端

v3.9.0 2023-10-25 14:19 UTC

This package is auto-updated.

Last update: 2024-09-25 16:42:01 UTC


README

Packagist PHP Version License

API文档

通过阅读我们的文档了解更多关于AllSecure Exchange平台的信息。

通过composer安装

要求

  • PHP 5.6或更高版本
  • 已安装[Composer][composer]

Composer

将ALLSECURE EXCHANGE PHP SDK添加到您的composer.json中。

composer require allsecure-pay/php-exchange

如果您不熟悉composer,请参阅Composer文档

使用测试参数的使用

PHP客户端是为LIVE环境设计的。如果您需要在沙盒环境中测试,您应该按照以下方式修改客户端:

  • 将src/Client.php中的第46行取消注释,并将第47行注释掉
  • 将src/Client.php中的第70行取消注释,并将第71行注释掉
  • 将src/Xml/Generator.php中的第43行取消注释,并将第44行注释掉

使用方法

先决条件

  • [ALLSECURE EXCHANGE]账户
  • API用户 - 包括
    • 用户名,以及
    • 密码
  • 连接器 - 包括
    • API密钥,以及
    • 可选:共享密钥

设置凭证

通过您的API用户名和密码实例化一个新的Exchange\Client\Client,将其连接到由API密钥标识的支付适配器,并使用共享密钥进行身份验证。

<?php

use Exchange\Client\Client;
use Exchange\Client\Data\Customer;
use Exchange\Client\Transaction\Debit;
use Exchange\Client\Transaction\Result;

// Include the autoloader (if not already done via Composer autoloader)
require_once('path/to/initClientAutoload.php');

// Instantiate the "Exchange\Client\Client" with your credentials
$api_user = "your_username";
$api_password = "your_username";
$connector_api_key = "your_chosen_connector_api_key";
$connector_shared_secret = "your_generated_connector_shared_secret";
$client = new Client("username", "password", "apiKey", "sharedSecret");
### Process a debit transaction

Once you instantiated a [client with credentials](#setting-up-credentials),
you can use the instance to make transaction API calls.

```php
// define your transaction ID: e.g. 'myId-'.date('Y-m-d').'-'.uniqid()
$merchantTransactionId = 'your_transaction_id'; // must be unique

$customer = new Customer();
$customer->setBillingCountry("AT")
	->setEmail("customer@email.test");

// after the payment flow the user is redirected to the $redirectUrl
$redirectUrl = 'https://example.org/success';
// all payment state changes trigger the $callbackUrl hook
$callbackUrl = 'https://api.example.org/payment-callback';

$debit = new Debit();
$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();
    }
}

状态请求

<?php

use Exchange\Client\Client;
use Exchange\Client\StatusApi\StatusRequestData;

$username = 'Your Username';
$password = 'Your password';
$apiKey = 'Connector API Key';
$sharedSecret = 'Connector Shared Secret';

require_once __DIR__ . '/vendor/autoload.php';

$client = new Client($username, $password, $apiKey, $sharedSecret);

$statusRequestData = new StatusRequestData();

// use either the UUID or your merchantTransactionId but not both
//$statusRequestData->setTransactionUuid($transactionUuid);
$statusRequestData->setMerchantTransactionId($merchantTransactionId);

$statusResult = $client->sendStatusRequest($statusRequestData);

// dump all data 
var_dump($statusResult);

// dump card data
$cardData = $statusResult->getreturnData();
var_dump($cardData);

// dump & echo error data
$errorData = $statusResult->getFirstError();

echo $errorData->getMessage();
echo $errorData->getCode();
echo $errorData->getAdapterCode();
echo $errorData->getAdapterMessage();