PHP code example of wonderfulpaymentsltd / one-api-sdk-php

1. Go to this page and download the library: Download wonderfulpaymentsltd/one-api-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wonderfulpaymentsltd / one-api-sdk-php example snippets


use Wonderful\OneApi\OneApiClient;

$client = OneApiClient::make('your-api-key');

use OneApi;

OneApi::customers()->list();

use Wonderful\OneApi\OneApiClient;

class PaymentController
{
    public function __construct(protected OneApiClient $oneApi) {}

    public function index()
    {
        return $this->oneApi->payments()->list();
    }
}

$payment = $client->quickPay()
    ->amount(1000)                           // £10.00 in GB pence
    ->reference('ORDER-1234')                // Shown on bank statement (max 18 chars, A-Z, 0-9, -)
    ->description('Website Order #1234')      // Order description
    ->customerEmail('[email protected]')       // Links order to customer
    ->redirectUrl('https://mysite.com/success')
    ->webhookUrl('https://mysite.com/webhooks')
    ->create();

echo $payment->pay_link; // Send customer to this URL to pay

$payment = $client->quickPay()
    ->amount(500)
    ->reference('ORDER-1')
    ->redirectUrl('https://mysite.com/success')
    ->create();

$payment = $client->quickPay()
    ->amount(1000)
    ->reference('ORDER-1234')
    ->bankId('natwest')                     // Pre-select the customer's bank
    ->skipConfirmation(true)                // Skip the confirmation page
    ->sendToTap('a1b2c3d4')                 // Send to a Tap device
    ->create();

$qrCode = $client->qrCodes()->create([
    'amount' => 2000,
    'label' => 'Donation - General Fund',
    'customer_data_collection' => 'email_only',
]);

echo $qrCode->pay_link;   // Payment URL
echo $qrCode->image_link;  // QR code image URL

$qrCodes = $client->qrCodes()->list();
$qrCode  = $client->qrCodes()->find('0e261265');
$client->qrCodes()->update('0e261265', ['amount' => 3000, 'label' => 'Updated']);
$client->qrCodes()->delete('0e261265');

// Create
$customer = $client->customers()->create([
    'first_name' => 'John',
    'last_name' => 'Smith',
    'email' => '[email protected]',
    'telephone' => '01234 567890',
    'marketing_consent' => true,
    'address' => '123 Some Street, London, SW1A 1AA',
]);

// Find
$customer = $client->customers()->find('1d368e62');

// Update (pass all fields - the API replaces the entire record)
$client->customers()->update('1d368e62', [
    'first_name' => 'Jonathan',
    'last_name' => 'Smith',
    'email' => '[email protected]',
    'telephone' => '01234 567890',
]);

// Delete (soft-delete)
$client->customers()->delete('1d368e62');

// List with filters
$list = $client->customers()->list([
    'search' => 'John',
    'sort' => 'last_name_asc',
    'start_date' => '2024-01-01',
    'end_date' => '2024-12-31',
    'per_page' => 50,
]);

foreach ($list->data as $customer) {
    echo $customer->full_name . ' - ' . $customer->email . "\n";
}

// List orders
$orders = $client->orders()->list([
    'payment_status' => 'paid',
    'sort' => 'created_desc',
    'per_page' => 25,
]);

// Find a specific order
$order = $client->orders()->find('ed6d3016');

// Access related data
echo $order->total_formatted;
echo $order->customer->email;
echo $order->payments[0]->pay_link;
echo $order->order_lines[0]->description;

// Create a refund (amount in GB pence)
$refund = $client->orders()->refund(
    id: 'ed6d3016',
    amount: 500,
    reference: 'REF-001',          // Optional, max 18 chars
    reason: 'Item returned, too big.' // Optional, internal note
);

echo "Refunded: {$refund->refund_amount_formatted} ({$refund->status})";

// List payments
$payments = $client->payments()->list([
    'sort' => 'created_desc',
    'per_page' => 10,
]);

// Find a specific payment
$payment = $client->payments()->find('e2611865');

// Stop a payment (before it's authorised at the bank)
$payment = $client->payments()->stop('e2611865');

// Delete a payment (only if status is 'created')
$client->payments()->delete('e2611865');

// List all tap devices
$devices = $client->tapDevices()->list();

// Filter by action type
$tapDevices = $client->tapDevices()->list(['tap_payments']);
$reusableLinkDevices = $client->tapDevices()->list(['reusable_payment']);
$merchantLinkDevices = $client->tapDevices()->list(['merchant_link']);

$banks = $client->banks()->list();

foreach ($banks->data as $bank) {
    echo "{$bank->bank_name} ({$bank->bank_id}) - {$bank->status}\n";
}

use Wonderful\OneApi\Exceptions\AuthenticationException;
use Wonderful\OneApi\Exceptions\ValidationException;
use Wonderful\OneApi\Exceptions\NotFoundException;
use Wonderful\OneApi\Exceptions\OneApiException;

try {
    $payment = $client->quickPay()
        ->amount(1000)
        ->reference('ORDER-1234')
        ->redirectUrl('https://mysite.com/success')
        ->create();
} catch (AuthenticationException $e) {
    // 401 - Invalid or missing API key
    echo $e->getMessage();
} catch (ValidationException $e) {
    // 422 - Validation failed (check invalid fields)
    print_r($e->getInvalidFields());
} catch (NotFoundException $e) {
    // 404 - Resource not found
} catch (OneApiException $e) {
    // Other API errors (4xx, 5xx)
    echo "{$e->getMessage()} (code: {$e->getCode()})";
}
bash
php artisan vendor:publish --tag=one-api-config