PHP code example of roduankd / laravel-moyasar

1. Go to this page and download the library: Download roduankd/laravel-moyasar 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/ */

    

roduankd / laravel-moyasar example snippets


return [
    // Required
    // Specify where to render the form
    // Can be a valid CSS selector and a reference to a DOM element
    'element' => '.mysr-form',

    // Required
    // Currency of the payment transaction
    'currency' => env('MOYASAR_CURRENCY', 'USD'),

    // Required
    // A small description of the current payment process
    'description' => 'default description',

    // Required
    'publishable_key' => env('MOYASAR_API_PUBLISHABLE_KEY', null),

    // Required
    // This URL is used to redirect the user when payment process has completed
    // Payment can be either a success or a failure, which you need to verify on you system (We will show this in a couple of lines)
    'callback_url' => 'moyasar.callback',

    // Highly recommended
    // This URL is use by moyasar to send to save the payment ID before redirecting the user to 3-D Secure
    // this is the default on complete route name
    'on_complete_url' => 'moyasar.complete',

    // Optional
    // Required payments methods
    // Default: ['creditcard', 'applepay', 'stcpay']
    'methods' => ['creditcard', 'applepay', 'stcpay'],
];


Route::get('memberships/{membership}/payment/thanks', [MembershipController::class, 'thanks'])->name('moyasar.callback');

Route::post('memberships/{membership}/payment/completed', [RoduanKD\LaravelMoyasar\Controllers\PaymentController::class, 'store'])->name('moyasar.complete');

/**
 * Handle the event.
 *
 * @param  \RoduanKD\LaravelMoyasar\Events\TransactionCreated  $event
 * @return void
 */
public function handle(TransactionCreated $event)
{
    $membership = Membership::find($event->parameters['membership']);
    $membership->paid_at = now();
    $membership->update();
}

<x-moyasar-init amount="100" :on-complete="route('moyasar.complete', $membership)" />

@

<x-moyasar-init amount="100" />
bash
php artisan vendor:publish --tag="laravel-moyasar-config"
bash
php artisan make:listener MarkMembershipAsPaid --event=\RoduanKD\LaravelMoyasar\Events\TransactionCreated
bash
php artisan vendor:publish --tag="laravel-moyasar-views"