amplifycode / transact
Payment Transaction Handling
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 1
pkg:composer/amplifycode/transact
Requires
- doctrine/dbal: ^3.0
- illuminate/support: *
- kalnoy/nestedset: ^6.0
- laravel/fortify: ^1.7
- matthiasmullie/minify: ^1.3
- stripe/stripe-php: ^18.1
Requires (Dev)
- larastan/larastan: ^3.0
- orchestra/testbench: ^10.6
This package is auto-updated.
Last update: 2025-11-27 16:13:07 UTC
README
A Laravel package for handling payment transactions and subscriptions with Stripe.
Overview
Transact is a Laravel package that simplifies the integration of payment processing into your Laravel applications. It provides a clean, consistent interface for handling both one-time payments and recurring subscriptions through Stripe, with the architecture designed to support additional payment providers in the future.
Transact was originally developed by Kieran Metcalfe of Ascent Creative until his death in July 2025. This fork is maintained by Colin Cameron of Amplify Code Ltd in order to further develop and maintain websites that rely on this package.
Features
- One-time Payments: Process single payments with Stripe
- Subscriptions: Handle recurring payments and subscription management
- Webhook Support: Process Stripe webhooks for payment status updates
- Blade Components: Ready-to-use UI components for payment forms
- Polymorphic Relationships: Associate transactions with any model in your application
- Transaction Tracking: Built-in database storage for transaction history
Installation
1. Require the package via Composer
composer require amplify-code/transact
2. Publish the configuration and assets
php artisan vendor:publish --provider="AmplifyCode\Transact\TransactServiceProvider"
3. Run migrations
php artisan migrate
4. Configure your environment variables
Add the following to your .env file:
STRIPE_PUBLIC=your_stripe_public_key
STRIPE_SECRET=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_webhook_secret
STRIPE_TEST_CLOCKS=false
Updating assets
When updating this library, or installing your application, you will need to publish the latest js and css asset files to your application's public directory.
1. Update the published asset files
php artisan vendor:publish --tag=public --force
Usage
One-time Payments
- Implement the
iTransactableinterface on your model:
use AmplifyCode\Transact\Contracts\iTransactable; class Order extends Model implements iTransactable { public function getTransactionAmount(): float { return $this->total; } public function getTransactionDescription(): ?string { return "Payment for Order #{$this->id}"; } public function onTransactionComplete() { // Handle successful payment logic $this->status = 'paid'; $this->save(); } }
- Process a payment:
use AmplifyCode\Transact\Transact; $order = Order::find(1); $paymentIntent = Transact::pay($order, $paymentMethodId);
Subscriptions
- Implement the
iSubscribableinterface on your model:
use AmplifyCode\Transact\Contracts\iSubscribable; use Stripe\SubscriptionSchedule; class Subscription extends Model implements iSubscribable { public function getCustomerName(): string { return $this->user->name; } public function getCustomerEmail(): string { return $this->user->email; } public function getSubscriptionAmount(): float { return $this->plan_amount; } public function getSubscriptionDescription(): ?string { return "Subscription to {$this->plan_name}"; } public function getStripeProductId(): string { return $this->stripe_product_id; } public function getInterval(): string { return 'month'; // or 'day', 'week', 'year' } public function getIntervalCount(): int { return 1; // e.g., 1 for monthly, 3 for quarterly } public function getIterations(): int { return 0; // 0 for unlimited, or specific number of billing cycles } public function getSubscriptionPhases(): array { return [ [ 'items' => [ [ 'price_data' => [ 'currency' => 'gbp', 'product' => $this->getStripeProductId(), 'recurring' => [ 'interval' => $this->getInterval(), 'interval_count' => $this->getIntervalCount(), ], 'unit_amount' => $this->getSubscriptionAmount() * 100, ], ], ], 'metadata' => [ 'subscription_id' => $this->id, ], ], ]; } public function onSubscriptionCreated(SubscriptionSchedule $sched) { // Handle subscription creation logic $this->stripe_subscription_id = $sched->id; $this->save(); } public function onRecurringPayment() { // Handle recurring payment logic } }
- Set up a subscription:
use AmplifyCode\Transact\Transact; $subscription = Subscription::find(1); $setupIntent = Transact::setup($subscription, $paymentMethodId);
- Start the subscription (typically called from a frontend callback):
$subscriptionSchedule = Transact::subscribe($setupIntentId);
Using the Blade Components
Stripe Elements
<x-transact-stripe-elements :amount="$amount" :description="$description" :transaction-id="$transactionId" :return-url="$returnUrl" />
Stripe UI
<x-transact-stripe-ui :amount="$amount" :description="$description" :transaction-id="$transactionId" :return-url="$returnUrl" />
Webhook Configuration
Configure your Stripe webhook to point to:
https://your-domain.com/transact/stripe
Ensure the following events are enabled:
payment_intent.succeededpayment_intent.payment_failedinvoice.payment_succeeded(for subscriptions)invoice.payment_failed(for subscriptions)
License
This package is developed by Amplify Code and Ascent Creative.