PHPackages                             m-derakhshi/xpaymen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. m-derakhshi/xpaymen

ActiveLibrary[API Development](/categories/api)

m-derakhshi/xpaymen
===================

Example API SDK for XPaymen (PHP)

1.1.5(9mo ago)10MITPHPPHP &gt;=8.2CI passing

Since Aug 29Pushed 9mo agoCompare

[ Source](https://github.com/m-derakhshi/xpaymen)[ Packagist](https://packagist.org/packages/m-derakhshi/xpaymen)[ RSS](/packages/m-derakhshi-xpaymen/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (18)Used By (0)

XPaymen PHP API Client
======================

[](#xpaymen-php-api-client)

A PHP client library for interacting with the [XPaymen](https://xpaymen.com) cryptocurrency payment gateway API. This library makes it easy to create and manage crypto transactions, wallets, and verify callback data.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Obtaining an API Key](#obtaining-an-api-key)
- [API Documentation](#api-documentation)
- [Usage](#usage)
    - [Create a Crypto Transaction](#create-a-crypto-transaction)
    - [Get Crypto Transactions](#get-crypto-transactions)
    - [Get Transaction Detail](#get-transaction-detail)
    - [Get Crypto Wallets](#get-crypto-wallets)
    - [Verify Callback Data](#verify-callback-data)
- [Testing](#testing)
- [License](#license)

Installation
------------

[](#installation)

Install this package via Composer:

```
composer require m-derakhshi/xpaymen
```

Configuration
-------------

[](#configuration)

Set your **API key** in your environment or pass it directly to the client:

```
$apiKey = 'YOUR_API_KEY_HERE';
$service = new XPaymen\Classes\XPaymenApiService($apiKey);
```

Obtaining an API Key
--------------------

[](#obtaining-an-api-key)

To obtain an API key, visit the official [XPaymen website](https://xpaymen.com). Once registered, you can create and manage crypto payment gateways, and retrieve your API key from the **gateway details page**.

API Documentation
-----------------

[](#api-documentation)

For developers who want to explore the full API specification interactively, we provide a Swagger UI page:

👉 [Open API Documentation (Swagger UI)](https://m-derakhshi.github.io/xpaymen/swagger.html)

This page allows you to browse available endpoints, request/response formats, and test the API directly in your browser.

Usage
-----

[](#usage)

### Create a Crypto Transaction

[](#create-a-crypto-transaction)

```
try {
    $transaction = $service->createCryptoTransaction([
        'order_id' => '1234',                // required
        'source_amount' => 10,               // required
        'source_currency_code' => 'USD',     // required

        'payer_email' => 'user@example.com', // optional
        'payer_message' => 'hi!',            // optional
        'note' => 'Order contains 5 items',  // optional
    ]);
    echo $transaction->transactionId;
    echo $transaction->invoiceUrl;
} catch (Throwable $e) {
    echo "❌ Error creating transaction: ".$e->getMessage();
}
```

### Get Crypto Transactions

[](#get-crypto-transactions)

```
try {
    $paginated = $service->getCryptoTransactions();

    foreach ($paginated->data as $transaction) {
        print_r($transaction->toArray());
    }
} catch (Throwable $e) {
    echo "❌ Error fetching transactions: " . $e->getMessage();
}
```

### Get Transaction Detail

[](#get-transaction-detail)

```
try {
    $transaction = $service->getCryptoTransactionDetail('TX123456');

    print_r($transaction->toArray());
} catch (Throwable $e) {
    echo "❌ Error fetching transaction detail: " . $e->getMessage();
}
```

### Get Crypto Wallets

[](#get-crypto-wallets)

```
try {
    $wallets = $service->getCryptoWallets();
    foreach ($wallets->data as $wallet) {
        print_r($wallet->toArray());
    }
} catch (Throwable $e) {
    echo "❌ Error fetching wallets: " . $e->getMessage();
}
```

### Verify Callback Data

[](#verify-callback-data)

To handle payment callbacks, you need to create a dedicated file or route in your website (for example: `callback.php`).

Place this file on your server and then configure its URL in your **Crypto Payment Gateway settings** on [XPaymen.com](https://xpaymen.com).

**Example `callback.php`:**

```
