| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/usa_sites/newusafunding.com/vx/lib/ |
Upload File : |
<?php
class FluidPay
{
private string $apiKey;
private string $baseUrl;
public array $responses;
public function __construct(string $apiKey, string $baseUrl = 'https://sandbox.fluidpay.com/api')
{
$this->apiKey = $apiKey;
$this->baseUrl = rtrim($baseUrl, '/');
$this->responses = array();
}
// ── Transactions ─────────────────────────────────────────────
/**
* Run a sale transaction (authorize + capture in one step).
*/
public function sale(float $amount, array $paymentMethod, array $options = []): array
{
return $this->createTransaction('sale', $amount, $paymentMethod, $options);
}
/**
* Authorize a transaction without capturing (hold funds).
*/
public function authorize(float $amount, array $paymentMethod, array $options = []): array
{
return $this->createTransaction('authorize', $amount, $paymentMethod, $options);
}
/**
* Capture a previously authorized transaction.
*/
public function capture(string $transactionId, array $options = []): array
{
return $this->post("/transaction/{$transactionId}/capture", $options);
}
/**
* Void a transaction that has not yet settled.
*/
public function void(string $transactionId): array
{
return $this->post("/transaction/{$transactionId}/void");
}
/**
* Refund a settled transaction. Pass an amount in dollars for a partial refund.
*/
public function refund(string $transactionId, ?float $amount = null): array
{
$payload = [];
if ($amount !== null) {
$payload['amount'] = self::toCents($amount);
}
return $this->post("/transaction/{$transactionId}/refund", $payload);
}
/**
* Verify a card without charging it.
*/
public function verify(array $paymentMethod, array $options = []): array
{
return $this->createTransaction('verification', 0, $paymentMethod, $options);
}
/**
* Issue a credit (unreferenced refund) to a payment method.
*/
public function credit(float $amount, array $paymentMethod, array $options = []): array
{
return $this->createTransaction('credit', $amount, $paymentMethod, $options);
}
/**
* Get a transaction by ID.
*/
public function getTransaction(string $transactionId): array
{
return $this->get("/transaction/{$transactionId}");
}
// ── Payment method helpers ───────────────────────────────────
/**
* Build a card payment method array.
*/
public static function card(
string $number,
string $expirationDate,
string $cvc,
string $entryType = 'keyed'
): array {
return [
'card' => [
'entry_type' => $entryType,
'number' => $number,
'expiration_date' => $expirationDate,
'cvc' => $cvc,
],
];
}
/**
* Build an ACH payment method array.
*/
public static function ach(
string $routingNumber,
string $accountNumber,
string $secCode = 'web',
string $accountType = 'checking'
): array {
return [
'ach' => [
'routing_number' => $routingNumber,
'account_number' => $accountNumber,
'sec_code' => $secCode,
'account_type' => $accountType,
],
];
}
/**
* Build a customer vault payment method array.
*/
public static function customerToken(string $customerId, ?string $paymentMethodId = null): array
{
$data = ['id' => $customerId];
if ($paymentMethodId !== null) {
$data['payment_method_id'] = $paymentMethodId;
}
return ['customer' => $data];
}
// ── Customer Vault ───────────────────────────────────────────
public function createCustomer(array $data): array
{
return $this->post('/vault/customer', $data);
}
public function getCustomer(string $customerId): array
{
return $this->get("/vault/{$customerId}");
}
public function deleteCustomer(string $customerId): array
{
return $this->delete("/vault/{$customerId}");
}
/**
* The vault card endpoint wants number/expiration_date at the top level, not
* wrapped in a 'card' key the way the transaction endpoint does. Accept the
* output of self::card() and unwrap it so callers can use one builder.
*/
public function addCustomerCard(string $customerId, array $cardData): array
{
if (isset($cardData['card']) && is_array($cardData['card'])) {
$cardData = $cardData['card'];
}
return $this->post("/vault/customer/{$customerId}/card", $cardData);
}
public function addCustomerAch(string $customerId, array $achData): array
{
if (isset($achData['ach']) && is_array($achData['ach'])) {
$achData = $achData['ach'];
}
return $this->post("/vault/customer/{$customerId}/ach", $achData);
}
public function updateCustomer(string $customerId, array $data): array
{
return $this->post("/vault/customer/{$customerId}", $data);
}
/**
* Set a stored payment method as the customer's default.
* $type is 'card' or 'ach'.
*/
public function setDefaultPaymentMethod(string $customerId, string $paymentMethodId, string $type = 'card'): array
{
return $this->updateCustomer($customerId, [
'defaults' => [
'payment_method_id' => $paymentMethodId,
'payment_method_type' => $type,
],
]);
}
// ── Internal HTTP ────────────────────────────────────────────
private static function toCents(float $amount): int
{
return (int) round($amount * 100);
}
private function createTransaction(string $type, float $amount, array $paymentMethod, array $options = []): array
{
$payload = array_merge($options, [
'type' => $type,
'amount' => self::toCents($amount),
'payment_method' => $paymentMethod,
]);
return $this->post('/transaction', $payload);
}
private function get(string $endpoint): array
{
return $this->request('GET', $endpoint);
}
private function post(string $endpoint, array $payload = []): array
{
return $this->request('POST', $endpoint, $payload);
}
private function delete(string $endpoint): array
{
return $this->request('DELETE', $endpoint);
}
private function request(string $method, string $endpoint, ?array $payload = null): array
{
$url = $this->baseUrl . $endpoint;
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 180,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
"Authorization: {$this->apiKey}",
],
]);
if ($payload !== null && $method !== 'GET') {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
return [
'status' => 'error',
'msg' => "cURL error: {$error}",
'http_code' => 0,
'data' => null,
];
}
$decoded = json_decode($response, true) ?? [];
$decoded['http_code'] = $httpCode;
return $decoded;
}
}