PHP code example of tomatophp / filament-payments

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

    

tomatophp / filament-payments example snippets


->plugin(\TomatoPHP\FilamentPayments\FilamentPaymentsPlugin::make())

use TomatoPHP\FilamentPayments\Facades\FilamentPayments;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentBillingInfo;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentCustomer;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentRequest;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentShippingInfo;
use TomatoPHP\FilamentSubscriptions\Facades\FilamentSubscriptions;

return redirect()->to(
        FilamentPayments::pay(
            data: PaymentRequest::make(Plan::class)
                ->model_id($data['new']->id)
                ->currency('USD')
                ->amount($data['new']->price)
                ->details('Subscription Payment')
                ->success_url(url('/success'))
                ->cancel_url(url('/cancel'))
                ->customer(
                    PaymentCustomer::make('John Doe')
                        ->email('[email protected]')
                        ->mobile('+201207860084')
                )
                ->billing_info(
                    PaymentBillingInfo::make('123 Main St')
                        ->area('Downtown')
                        ->city('Cairo')
                        ->state('Cairo')
                        ->postcode('12345')
                        ->country('EG')
                )
                ->shipping_info(
                    PaymentShippingInfo::make('123 Main St')
                        ->area('Downtown')
                        ->city('Cairo')
                        ->state('Cairo')
                        ->postcode('12345')
                        ->country('EG'
                        )
                )),
    );

use TomatoPHP\FilamentPayments\Filament\Actions\PaymentAction;

public function table(Table $table): $table
{
    return $table
        ->actions([
             PaymentAction::make('payment')
                ->request(function ($record){
                    return PaymentRequest::make(Order::class)
                        ->model_id($record->id)
                        ->currency('USD')
                        ->amount($record->total)
                        ->details($record->ordersItems()->pluck('product_id')->implode(', '))
                        ->success_url(url('/success'))
                        ->cancel_url(url('/cancel'))
                        ->customer(
                            PaymentCustomer::make($record->name)
                                ->email($record->account->email)
                                ->mobile($record->phone)
                        )
                        ->billing_info(
                            PaymentBillingInfo::make($record->address)
                                ->area($record->area->name)
                                ->city($record->city->name)
                                ->state($record->city->name)
                                ->postcode('12345')
                                ->country($record->country->iso3)
                        )
                        ->shipping_info(
                            PaymentShippingInfo::make($record->address)
                                ->area($record->area->name)
                                ->city($record->city->name)
                                ->state($record->city->name)
                                ->postcode('12345')
                                ->country($record->country->iso3)
                        );
                })
                ->pay(),
        ]);
}

use TomatoPHP\FilamentPayments\Facades\FilamentPayments;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentBillingInfo;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentCustomer;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentRequest;
use TomatoPHP\FilamentPayments\Services\Contracts\PaymentShippingInfo;
use TomatoPHP\FilamentSubscriptions\Facades\FilamentSubscriptions;

public function boot(): void
    {
        FilamentSubscriptions::afterSubscription(function ($data) {
            //Payment Here
            return redirect()->to(FilamentPayments::pay(
                data: PaymentRequest::make(Plan::class)
                    ->model_id($data['new']->id)
                    ->currency('USD')
                    ->amount($data['new']->price)
                    ->details('Subscription Payment')
                    ->success_url(url('/success'))
                    ->cancel_url(url('/cancel'))
                    ->customer(
                        PaymentCustomer::make('John Doe')
                            ->email('[email protected]')
                            ->mobile('+201207860084')
                    )
                    ->billing_info(
                        PaymentBillingInfo::make('123 Main St')
                            ->area('Downtown')
                            ->city('Cairo')
                            ->state('Cairo')
                            ->postcode('12345')
                            ->country('EG')
                    )
                    ->shipping_info(
                        PaymentShippingInfo::make('123 Main St')
                            ->area('Downtown')
                            ->city('Cairo')
                            ->state('Cairo')
                            ->postcode('12345')
                            ->country('EG')
                    )
            ));
        });
    }
bash
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"
bash
php artisan filament-payments:install
bash
php artisan vendor:publish --tag="filament-payments-config"
bash
php artisan vendor:publish --tag="filament-payments-views"
bash
php artisan vendor:publish --tag="filament-payments-lang"
bash
php artisan vendor:publish --tag="filament-payments-migrations"