PHP code example of ahmedebead / moyasar-laravel

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

    

ahmedebead / moyasar-laravel example snippets


app(PaymentService::class)

app(InvoiceService::class)

public function __construct(PaymentService $paymentService)
{
    $this->paymentService = $paymentService;
}

$paymentService = new \AhmedEbead\Moyasar\Providers\PaymentService();

$data = [
            "amount" => 100,
            "currency" => "SAR",
            "description" => "Payment for order #",
            "callback_url" => "https://example.com/thankyou",
            "source" => [
                "type" => "creditcard",
                "name" => "Mohammed Ali",
                "number" => "4111111111111111",
                "cvc" => "123",
                "month" => "12",
                "year" => "26"
            ]
        ];
        $payment = $paymentService->create($data);

$payment = $paymentService->fetch('ae5e8c6a-1622-45a5-b7ca-9ead69be722e');

$payment = $paymentService->all();

$paymentService = new \AhmedEbead\Moyasar\Providers\PaymentService();

$paginationResult = $paymentService->all();

$payments = $paginationResult->result;

$search = \AhmedEbead\Moyasar\Search::query()->status('paid')->page(2);

$paginationResult = $paymentService->all($search);

$payment->update('new description here');

// OR

$payment->refund(1000); // 10.00 SAR

// OR

$payment->capture(1000);

// OR

$payment->void();

$invoiceService = new \AhmedEbead\Moyasar\Providers\InvoiceService();

$invoiceService->create([
    'amount' => 1000000, // 10000.00 SAR
    'currency' => 'SAR',
    'description' => 'iPhone XII Purchase',
    'callback_url' => 'http://www.example.com/invoice-status-changed', // Optional
    'expired_at' => '2020-01-20' // Optional
]);

$invoice->update([
    'amount' => 900000, // 9000.00 SAR
    'currency' => 'SAR',
    'description' => 'iPhone XII Purchase (Updated)',
    'callback_url' => 'http://www.example.com/invoice-status-changed', // Optional
    'expired_at' => '2020-01-25' // Optional
]);

// OR

$invoice->cancel();

$payment = \AhmedEbead\Moyasar\Facades\Payment::fetch('id');