ixopay/ixopay-php-client

PHP Ixopay 客户端

v3.17.0 2024-07-30 19:45 UTC

This package is auto-updated.

Last update: 2024-08-30 21:26:37 UTC


README

Packagist PHP Version License

在您的 PHP 后端接受支付并集成 100 多种支付方式:IXOPAY PHP SDK 提供方便地访问 IXOPAY REST APIs

目录

安装

要求

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

Composer

将 IXOPAY PHP SDK 添加到您的 composer.json 文件中。

composer require ixopay/ixopay-php-client

文档

有关如何使用交易处理 API 的通用信息,请参阅 IXOPAY 网关文档

有关所有交易处理 API 调用的参考,请参阅 IXOPAY API 参考

用法

先决条件

  • IXOPAY 账户
  • API 用户 - 包括
    • 用户名,和
    • 密码
  • 连接器 - 包括
    • API 密钥,和
    • 可选:共享密钥

设置凭证

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

<?php

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

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

// Instantiate the "Ixopay\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($api_user, $api_password, $connector_api_key, $connector_shared_secret);

处理借记交易

一旦您创建了一个具有凭证的客户端,您就可以使用该实例来调用交易 API。

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

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

// 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 = $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();
    }
}

?>

支持

如果您对新增功能有建议,发现了错误,或遇到了技术问题,请在此创建问题。此外,您还可以根据您的合同联系 IXOPAY 的支持团队。

许可证

此存储库可在 MIT 许可证下使用。

另请参阅