PHP code example of paystream / sdk

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

    

paystream / sdk example snippets


use WeMiscPay\Sdk\WeMiscPayClient;
use WeMiscPay\Sdk\Exceptions\ValidationException;
use WeMiscPay\Sdk\Exceptions\ApiException;

$client = new WeMiscPayClient(
    apiToken: 'wm_...',                                         // Companies > Edit in the WeMiscPay dashboard
    baseUrl: 'https://your-wemisc-pay-instance.test/api/v1/integrations',
);

try {
    $checkout = $client->checkout(
        amount: 250.00,
        successUrl: 'https://your-app.test/orders/123/paid',
        failUrl: 'https://your-app.test/orders/123/failed',
        reference: 'order-123',                                 // your own id, echoed back later
    );

    // Send the customer here — WeMiscPay hosts the actual card entry page.
    header("Location: {$checkout->checkoutUrl}");
} catch (ValidationException $e) {
    // $e->errors() is a field => [messages] map, same shape as Laravel validation errors.
} catch (ApiException $e) {
    // e.g. 503 — no payment gateway configured on the WeMiscPay side yet.
    // $e->statusCode(), $e->body()
}

use WeMiscPay\Sdk\Laravel\Facades\WeMiscPay;

$checkout = WeMiscPay::checkout(250.00, route('orders.paid', $order), route('orders.failed', $order), (string) $order->id);

return redirect($checkout->checkoutUrl);

$invoice = $client->getInvoice((int) $request->query('invoice_id'));

if ($invoice->isPaid()) {
    // fulfil the order
}

use WeMiscPay\Sdk\WeMiscPayDashboardClient;

$dashboard = new WeMiscPayDashboardClient('https://your-wemisc-pay-instance.test/api');

$dashboard->login('[email protected]', 'your-password'); // stores the token on $dashboard for you

$profile = $dashboard->companyProfile();
echo $profile->name, ' — balance: ', $profile->balance;

foreach ($profile->paymentProfiles as $method) {
    echo "{$method->paymentMethod}: {$method->successCount} successful, {$method->commissionTotal} commission\n";
}

$page = $dashboard->invoices(); // DTO\PaginatedResult of DTO\DashboardInvoice
foreach ($page->items as $invoice) {
    echo "{$invoice->invoiceSerial}: {$invoice->status}\n";
}

$one = $dashboard->invoice(42);
$sessions = $dashboard->paymentSessions();

$rows = $dashboard->monthlyPaidPerCompany(); // raw arrays — see "Reports" below

$dashboard->logout();

$dashboard = (new WeMiscPayDashboardClient($baseUrl))->withToken($storedToken);

use WeMiscPay\Sdk\Laravel\Facades\WeMiscPayDashboard;

WeMiscPayDashboard::login($request->email, $request->password);
$profile = WeMiscPayDashboard::companyProfile();