Skip to main content

Overview

The ApiTransfers class provides methods to create transfers between wallets, retrieve transfer details, and manage transfer refunds. Transfers allow you to move funds from one wallet to another within your Mangopay platform.

Methods

Create

Create a new transfer between two wallets.
public function Create($transfer, $idempotencyKey = null)
transfer
Transfer
required
The transfer object to create
idempotencyKey
string
Optional idempotency key to prevent duplicate requests
Returns: Transfer - The created transfer object Example:
$api = new MangoPay\MangoPayApi();
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-api-key';

$transfer = new MangoPay\Transfer();
$transfer->AuthorId = 'user_id_123';
$transfer->CreditedUserId = 'user_id_456';
$transfer->DebitedWalletId = 'wallet_id_source';
$transfer->CreditedWalletId = 'wallet_id_destination';

$transfer->DebitedFunds = new MangoPay\Money();
$transfer->DebitedFunds->Currency = 'EUR';
$transfer->DebitedFunds->Amount = 1000; // €10.00

$transfer->Fees = new MangoPay\Money();
$transfer->Fees->Currency = 'EUR';
$transfer->Fees->Amount = 0; // No fees

$transfer->Tag = 'payment for services';

$createdTransfer = $api->Transfers->Create($transfer);
echo $createdTransfer->Id;
echo $createdTransfer->Status;

Get

Retrieve a transfer by its ID.
public function Get($transferId)
transferId
string
required
The transfer identifier
Returns: Transfer - The transfer object Example:
$api = new MangoPay\MangoPayApi();
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-api-key';

$transfer = $api->Transfers->Get('transfer_id_123');
echo 'Status: ' . $transfer->Status;
echo 'Amount: ' . $transfer->DebitedFunds->Amount;
echo 'Result: ' . $transfer->ResultMessage;

CreateRefund

Create a refund for a transfer.
public function CreateRefund($transferId, $refund, $idempotencyKey = null)
transferId
string
required
The transfer identifier to refund
refund
Refund
required
The refund object to create
idempotencyKey
string
Optional idempotency key to prevent duplicate requests
Returns: Refund - The created refund object Example:
$api = new MangoPay\MangoPayApi();
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-api-key';

$refund = new MangoPay\Refund();
$refund->AuthorId = 'user_id_123';
$refund->Tag = 'refund for transfer';

$createdRefund = $api->Transfers->CreateRefund('transfer_id_123', $refund);
echo $createdRefund->Id;
echo $createdRefund->Status;

GetRefunds

Retrieve all refunds for a specific transfer.
public function GetRefunds($transferId, & $pagination = null, $filter = null, $sorting = null)
transferId
string
required
The transfer identifier
pagination
Pagination
Pagination object to control page size and number
filter
FilterRefunds
Filter object to filter refunds by specific criteria
sorting
Sorting
Sorting object to sort the results
Returns: Refund[] - Array of refund objects Example:
$api = new MangoPay\MangoPayApi();
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-api-key';

$pagination = new MangoPay\Pagination(1, 10);
$refunds = $api->Transfers->GetRefunds('transfer_id_123', $pagination);

foreach ($refunds as $refund) {
    echo $refund->Id . ' - ' . $refund->Status;
}

echo 'Total items: ' . $pagination->TotalItems;

Transfer Entity

The Transfer class extends the Transaction class and represents a transfer between wallets.

Properties

Id
string
Unique identifier for the transfer (read-only)
Tag
string
Custom data for the transfer
CreationDate
int
Unix timestamp of when the transfer was created (read-only)
AuthorId
string
The ID of the user who initiated the transfer
CreditedUserId
string
The ID of the user who receives the funds
DebitedFunds
Money
The amount debited from the source walletContains:
  • Amount (int): The amount in the smallest currency unit
  • Currency (string): ISO 4217 currency code
CreditedFunds
Money
The amount credited to the destination walletContains:
  • Amount (int): The amount in the smallest currency unit
  • Currency (string): ISO 4217 currency code
Fees
Money
The fees taken by the platformContains:
  • Amount (int): The fee amount in the smallest currency unit
  • Currency (string): ISO 4217 currency code
Status
string
The status of the transfer (read-only)Possible values:
  • CREATED - Transfer has been created
  • SUCCEEDED - Transfer completed successfully
  • FAILED - Transfer failed
ResultCode
string
The result code of the transfer (read-only)
ResultMessage
string
The result message explaining the result code (read-only)
ExecutionDate
int
Unix timestamp of when the transfer was executed (read-only)
Type
string
The type of transaction (always “TRANSFER” for transfers)
Nature
string
The nature of the transaction
DebitedWalletId
string
The ID of the wallet from which funds are debited
CreditedWalletId
string
The ID of the wallet to which funds are credited
DepositId
string
The ID of the related deposit, if applicable
ScaContext
string
Strong Customer Authentication context for the transfer
PendingUserAction
PendingUserAction
Information about any pending user action required (e.g., SCA redirect)

Example Object

$transfer = new MangoPay\Transfer();
$transfer->AuthorId = 'user_123';
$transfer->CreditedUserId = 'user_456';
$transfer->DebitedWalletId = 'wallet_source';
$transfer->CreditedWalletId = 'wallet_destination';

// Set debited funds
$transfer->DebitedFunds = new MangoPay\Money();
$transfer->DebitedFunds->Currency = 'EUR';
$transfer->DebitedFunds->Amount = 5000; // €50.00

// Set fees (if any)
$transfer->Fees = new MangoPay\Money();
$transfer->Fees->Currency = 'EUR';
$transfer->Fees->Amount = 100; // €1.00

$transfer->Tag = 'Monthly payment';

Read-Only Properties

The following properties are read-only and cannot be modified:
  • Id
  • CreationDate
  • Status
  • ResultCode
  • ResultMessage
  • ExecutionDate

Money Object

The Money object is used throughout transfers to represent monetary values:
$money = new MangoPay\Money();
$money->Currency = 'EUR'; // ISO 4217 currency code
$money->Amount = 1000;     // Amount in smallest unit (cents)
Amounts are always represented in the smallest currency unit. For example:
  • €10.00 = 1000 cents
  • $25.50 = 2550 cents
  • £100.00 = 10000 pence

Transfer Flow

  1. Create Transfer: Use Create() to initiate a transfer between two wallets
  2. Check Status: Use Get() to check the transfer status
  3. Handle SCA: If PendingUserAction is present, redirect the user for authentication
  4. Refund (if needed): Use CreateRefund() to refund a transfer
  5. Track Refunds: Use GetRefunds() to list all refunds for a transfer
// Complete transfer example
$api = new MangoPay\MangoPayApi();
$api->Config->ClientId = 'your-client-id';
$api->Config->ClientPassword = 'your-api-key';

// Create transfer
$transfer = new MangoPay\Transfer();
$transfer->AuthorId = 'user_123';
$transfer->CreditedUserId = 'user_456';
$transfer->DebitedWalletId = 'wallet_source';
$transfer->CreditedWalletId = 'wallet_destination';

$transfer->DebitedFunds = new MangoPay\Money();
$transfer->DebitedFunds->Currency = 'EUR';
$transfer->DebitedFunds->Amount = 1000;

$transfer->Fees = new MangoPay\Money();
$transfer->Fees->Currency = 'EUR';
$transfer->Fees->Amount = 0;

$result = $api->Transfers->Create($transfer);

if ($result->Status == 'SUCCEEDED') {
    echo 'Transfer completed successfully';
} elseif ($result->Status == 'FAILED') {
    echo 'Transfer failed: ' . $result->ResultMessage;
}

Build docs developers (and LLMs) love