定制 amplifycode/transact 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amplifycode/transact

最新稳定版本:v1.0.0

Composer 安装命令:

composer require amplifycode/transact

包简介

Payment Transaction Handling

README 文档

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

  1. Implement the iTransactable interface 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();
    }
}
  1. Process a payment:
use AmplifyCode\Transact\Transact;

$order = Order::find(1);
$paymentIntent = Transact::pay($order, $paymentMethodId);

Subscriptions

  1. Implement the iSubscribable interface 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
    }
}
  1. Set up a subscription:
use AmplifyCode\Transact\Transact;

$subscription = Subscription::find(1);
$setupIntent = Transact::setup($subscription, $paymentMethodId);
  1. 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.succeeded
  • payment_intent.payment_failed
  • invoice.payment_succeeded (for subscriptions)
  • invoice.payment_failed (for subscriptions)

License

This package is developed by Amplify Code and Ascent Creative.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-11-27