PHP code example of useepay / useepay-php

1. Go to this page and download the library: Download useepay/useepay-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/ */

    

useepay / useepay-php example snippets



UseePay\UseePayClient;
use UseePay\Model\Authentication\Authentication;
use UseePay\Net\ApiEnvironment;

// Initialize authentication
$authentication = new Authentication(
    'YOUR_MERCHANT_NO',
    'YOUR_APP_ID',
    'YOUR_API_KEY'
);

// Create client (Production)
$client = new UseePayClient($authentication);

// Or use Sandbox environment
$client = UseePayClient::withEnvironment(
    ApiEnvironment::SANDBOX,
    $authentication
);


use UseePay\UseePay;

// Optional: Configure timeouts
UseePay::setConnectTimeout(30);
UseePay::setReadTimeout(60);

// Create payment
$paymentParams = array(
    'amount' => 100.00,
    'currency' => 'USD',
    'description' => 'Order #12345',
    'merchant_order_id' => 'ORDER_12345',
    'customer' => array(
        'merchant_customer_id' => 'CUST_001',
        'first_name' => 'John',
        'last_name' => 'Doe',
        'email' => '[email protected]',
        'phone' => '+1234567890',
        'address' => array(
            'line1' => '123 Main St',
            'city' => 'New York',
            'state' => 'NY',
            'postal_code' => '10001',
            'country' => 'US'
        )
    )
);

$paymentIntent = $client->paymentIntents()->create($paymentParams);

// Handle redirect for payment
if ($paymentIntent['status'] === '


use UseePay\Param\Customer\CustomerCreateParams;

$params = new CustomerCreateParams();
$params->merchantCustomerId = 'CUST_' . time();
$params->firstName = 'John';
$params->lastName = 'Doe';
$params->email = '[email protected]';
$params->phone = '+1234567890';

$customer = $client->customers()->create($params);
echo "Customer ID: " . $customer['id'];


$customerId = 'cus_xxxxxxxxxxxxx';
$customer = $client->customers()->retrieve($customerId);
print_r($customer);


use UseePay\Param\Customer\CustomerListParams;

$params = new CustomerListParams();
$params->limit = 10;
$params->startingAfter = null;

$customers = $client->customers()->list($params);
foreach ($customers['data'] as $customer) {
    echo $customer['email'] . "\n";
}


use UseePay\UseePay;

// Disable SSL verification (NOT recommended for production)
UseePay::setVerifySslCerts(false);

// Set custom CA bundle path
UseePay::setCaBundlePath('/path/to/cacert.pem');


use UseePay\UseePay;

// Set connection timeout (default: 6 seconds)
UseePay::setConnectTimeout(30);

// Set read timeout (default: 30 seconds)
UseePay::setReadTimeout(60);

// Set max network retries (default: 0)
UseePay::setMaxNetworkRetries(3);


use UseePay\Exception\ApiException;
use UseePay\Exception\AuthenticationException;

try {
    $paymentIntent = $client->paymentIntents()->create($params);
} catch (AuthenticationException $e) {
    // Handle authentication errors
    echo "Authentication failed: " . $e->getMessage();
} catch (ApiException $e) {
    // Handle API errors
    echo "API error: " . $e->getMessage();
    echo "Error code: " . $e->getCode();
} catch (Exception $e) {
    // Handle other errors
    echo "Error: " . $e->getMessage();
}
bash
composer