PHP code example of moyasar / moyasar-php

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

    

moyasar / moyasar-php example snippets




\Moyasar\Moyasar::setApiKey('api-key');

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

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

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

$paginationResult = $paymentService->all();

$payments = $paginationResult->result;

$search = \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 \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();

app(PaymentService::class)

app(InvoiceService::class)

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

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