Skip to content

Order Transaction Model

DB Table Name{wp_db_prefix}_fct_order_transactions
SchemaCheck Schema
Source Filefluent-cart/app/Models/OrderTransaction.php
Name SpaceFluentCart\App\Models
ClassFluentCart\App\Models\OrderTransaction

Attributes

AttributeData TypeComment
idIntegerPrimary Key
order_idIntegerReference to order
order_typeStringOrder type (onetime, subscription, signup_fee)
vendor_charge_idStringPayment gateway transaction ID
payment_methodStringPayment method key
payment_modeStringPayment mode (live, test)
payment_method_typeStringPayment method type (card, bank, etc.)
currencyStringTransaction currency
transaction_typeStringTransaction type (charge, refund, partial_refund)
subscription_idIntegerReference to subscription (if applicable)
card_last_4StringLast 4 digits of card
card_brandStringCard brand (visa, mastercard, etc.)
statusStringTransaction status
totalBigintTransaction amount in cents
rateBigintExchange rate
metaJSONAdditional transaction data
uuidStringUnique transaction identifier
created_atDate TimeCreation timestamp
updated_atDate TimeLast update timestamp

Usage

Please check Model Basic for Common methods.

Accessing Attributes

php
$transaction = FluentCart\App\Models\OrderTransaction::find(1);

$transaction->id; // returns id
$transaction->order_id; // returns order ID
$transaction->total; // returns total amount
$transaction->status; // returns status
$transaction->payment_method; // returns payment method

Scopes

This model has the following scopes that you can use

ofOrder($orderId)

Filter transactions by order ID

  • Parameters
    • $orderId - integer

Usage:

php
// Get all transactions for a specific order
$transactions = FluentCart\App\Models\OrderTransaction::ofOrder(123)->get();

ofStatus($status)

Filter transactions by status

  • Parameters
    • $status - string

Usage:

php
// Get all successful transactions
$transactions = FluentCart\App\Models\OrderTransaction::ofStatus('succeeded')->get();

ofPaymentMethod($paymentMethod)

Filter transactions by payment method

  • Parameters
    • $paymentMethod - string

Usage:

php
// Get all Stripe transactions
$transactions = FluentCart\App\Models\OrderTransaction::ofPaymentMethod('stripe')->get();

ofTransactionType($type)

Filter transactions by transaction type

  • Parameters
    • $type - string

Usage:

php
// Get all charge transactions
$transactions = FluentCart\App\Models\OrderTransaction::ofTransactionType('charge')->get();

ofSubscription($subscriptionId)

Filter transactions by subscription ID

  • Parameters
    • $subscriptionId - integer

Usage:

php
// Get all transactions for a specific subscription
$transactions = FluentCart\App\Models\OrderTransaction::ofSubscription(456)->get();

ofCurrency($currency)

Filter transactions by currency

  • Parameters
    • $currency - string

Usage:

php
// Get all USD transactions
$transactions = FluentCart\App\Models\OrderTransaction::ofCurrency('USD')->get();

ofPaymentMode($mode)

Filter transactions by payment mode

  • Parameters
    • $mode - string

Usage:

php
// Get all live transactions
$transactions = FluentCart\App\Models\OrderTransaction::ofPaymentMode('live')->get();

Relations

This model has the following relationships that you can use

order

Access the associated order

  • return FluentCart\App\Models\Order Model

Example:

php
// Accessing Order
$order = $transaction->order;

// For Filtering by order relationship
$transactions = FluentCart\App\Models\OrderTransaction::whereHas('order', function($query) {
    $query->where('status', 'completed');
})->get();

subscription

Access the associated subscription

  • return FluentCart\App\Models\Subscription Model

Example:

php
// Accessing Subscription
$subscription = $transaction->subscription;

// For Filtering by subscription relationship
$transactions = FluentCart\App\Models\OrderTransaction::whereHas('subscription', function($query) {
    $query->where('status', 'active');
})->get();

Methods

Along with Global Model methods, this model has few helper methods.

getMetaAttribute($value)

Get meta as array (accessor)

  • Parameters
    • $value - mixed
  • Returns array

Usage

php
$meta = $transaction->meta; // Returns array

setMetaAttribute($value)

Set meta from array (mutator)

  • Parameters
    • $value - array|object
  • Returns void

Usage

php
$transaction->meta = ['gateway_response' => 'success', 'fee' => 2.9];

getUrlAttribute()

Get transaction URL (accessor)

  • Parameters
    • none
  • Returns string

Usage

php
$url = $transaction->url; // Returns transaction URL

getFormattedTotal()

Get formatted total amount with currency

  • Parameters
    • none
  • Returns string

Usage

php
$formattedTotal = $transaction->getFormattedTotal(); // Returns: "$99.99"

getFormattedTotalAmount()

Get formatted total amount without currency symbol

  • Parameters
    • none
  • Returns string

Usage

php
$formattedAmount = $transaction->getFormattedTotalAmount(); // Returns: "99.99"

isSuccessful()

Check if transaction is successful

  • Parameters
    • none
  • Returns boolean

Usage

php
$isSuccessful = $transaction->isSuccessful();

isFailed()

Check if transaction failed

  • Parameters
    • none
  • Returns boolean

Usage

php
$isFailed = $transaction->isFailed();

isPending()

Check if transaction is pending

  • Parameters
    • none
  • Returns boolean

Usage

php
$isPending = $transaction->isPending();

isRefund()

Check if transaction is a refund

  • Parameters
    • none
  • Returns boolean

Usage

php
$isRefund = $transaction->isRefund();

isPartialRefund()

Check if transaction is a partial refund

  • Parameters
    • none
  • Returns boolean

Usage

php
$isPartialRefund = $transaction->isPartialRefund();

isCharge()

Check if transaction is a charge

  • Parameters
    • none
  • Returns boolean

Usage

php
$isCharge = $transaction->isCharge();

isSubscriptionTransaction()

Check if transaction is related to subscription

  • Parameters
    • none
  • Returns boolean

Usage

php
$isSubscriptionTransaction = $transaction->isSubscriptionTransaction();

getCardDisplayInfo()

Get card display information

  • Parameters
    • none
  • Returns string

Usage

php
$cardInfo = $transaction->getCardDisplayInfo(); // Returns: "Visa ****1234"

getPaymentMethodTitle()

Get payment method display title

  • Parameters
    • none
  • Returns string

Usage

php
$paymentTitle = $transaction->getPaymentMethodTitle(); // Returns: "Credit Card"

getGatewayTransactionId()

Get gateway transaction ID

  • Parameters
    • none
  • Returns string

Usage

php
$gatewayId = $transaction->getGatewayTransactionId();

getMetaValue($key, $default = null)

Get specific meta value

  • Parameters
    • $key - string
    • $default - mixed
  • Returns mixed

Usage

php
$gatewayResponse = $transaction->getMetaValue('gateway_response', 'unknown');

setMetaValue($key, $value)

Set specific meta value

  • Parameters
    • $key - string
    • $value - mixed
  • Returns void

Usage

php
$transaction->setMetaValue('processing_fee', 2.9);

Transaction Statuses

Common transaction statuses in FluentCart:

  • pending - Transaction is pending
  • processing - Transaction is being processed
  • succeeded - Transaction succeeded
  • failed - Transaction failed
  • cancelled - Transaction was cancelled
  • refunded - Transaction was refunded
  • partially_refunded - Transaction was partially refunded

Transaction Types

Common transaction types in FluentCart:

  • charge - Initial charge/payment
  • refund - Full refund
  • partial_refund - Partial refund
  • subscription_charge - Subscription payment
  • signup_fee - Subscription signup fee

Usage Examples

Get Order Transactions

php
$order = FluentCart\App\Models\Order::find(123);
$transactions = $order->transactions()->orderBy('created_at', 'desc')->get();

foreach ($transactions as $transaction) {
    echo "Transaction: " . $transaction->getFormattedTotal() . " - " . $transaction->status;
}

Get Successful Transactions for Date Range

php
$transactions = FluentCart\App\Models\OrderTransaction::where('status', 'succeeded')
    ->whereBetween('created_at', ['2024-01-01', '2024-01-31'])
    ->get();

Get Refund Transactions

php
$refunds = FluentCart\App\Models\OrderTransaction::whereIn('transaction_type', ['refund', 'partial_refund'])
    ->get();

Get Subscription Transactions

php
$subscriptionTransactions = FluentCart\App\Models\OrderTransaction::whereNotNull('subscription_id')
    ->get();

FluentCart developer documentation