PHP code example of amreljako / cybercart

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

    

amreljako / cybercart example snippets


return [
    // Bind the polymorphic customer entity to your primary application's User model
    'customer_model' => App\Models\User::class,

    // Flat-rate logistics shipping cost default
    'shipping_flat_rate' => 50.00,

    // Default active payment gateway driver
    'payment_driver' => env('CYBERCART_PAYMENT_DRIVER', 'paymob'),

    'payments' => [
        'paymob' => [
            'api_key'        => env('PAYMOB_API_KEY'),
            'integration_id' => env('PAYMOB_INTEGRATION_ID'),
            'iframe_id'      => env('PAYMOB_IFRAME_ID'),
            'hmac_secret'    => env('PAYMOB_HMAC_SECRET'),
        ],
        'tamara' => [
            'api_token' => env('TAMARA_API_TOKEN'),
            'sandbox'   => env('TAMARA_SANDBOX', true),
        ],
        'mada' => [
            'secret_key' => env('MADA_SECRET_KEY'),
            'sandbox'    => env('MADA_SANDBOX', true),
        ],
    ],
];

namespace Amreljako\CyberCart\Models;

use Illuminate\Database\Eloquent\Model;
use Amreljako\CyberCart\Traits\HasBarcode;

class ProductVariant extends Model
{
    use HasBarcode;
}

use Amreljako\CyberCart\Facades\Cart;

// Add an item, running pessimistic row-level validation checks
Cart::addToCart($productVariantId = 1, $quantity = 2);

// Retrieve verified cart contents, checked directly against the product table
$cart = Cart::getCartContent();

$subtotal = $cart['subtotal'];
$items = $cart['items'];

use Amreljako\CyberCart\Facades\Checkout;

$shippingAddress = [
    'first_name' => 'Amr',
    'last_name'  => 'Elsayed',
    'email'      => '[email protected]',
    'phone'      => '+201000000000',
    'address'    => 'Alexandria, Egypt',
];

try {
    $response = Checkout::execute($shippingAddress, $paymentDriver = 'paymob');

    // Redirect the customer to the provider's payment iframe
    return redirect()->away($response['redirect_url']);
} catch (\Exception $e) {
    return response()->json(['error' => $e->getMessage()], 422);
}

{{-- Render a Code 128 barcode inline as SVG --}}
{!! $productVariant->renderBarcodeSvg() !!}

{{-- Render a QR code linking to the order's tracking page --}}
{!! $productVariant->renderQrCodeSvg('https://yourdomain.com/orders/' . $order->order_number) !!}
bash
php artisan vendor:publish --tag=cybercart-config
bash
php artisan migrate