1. Go to this page and download the library: Download abeta-io/abeta-punchout 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/ */
abeta-io / abeta-punchout example snippets
use AbetaIO\Laravel\Models\Product;
use AbetaIO\Laravel\Facades\ReturnCart;
$cart = ReturnCart::builder()->setGeneral([
'cart_id' => '12345',
'total' => 150.00,
'currency' => 'EUR',
'delivery_datetime' => '2024-11-10 20:29'
]);
// Create Product instance
$product = new Product(
id: 1,
sku: 'PROD-001',
name: 'Product Name',
description: 'Product description here',
price_ex_vat: 50.00,
price_inc_vat: 60.00,
vat_percentage: 20.00,
quantity: 2,
price_unit: 30, // The amount of units the product price is denominated in.
unit: 'PCE', // Unit of the product, e.g. KG, PCE, etc.
brand: 'Brand Name',
weight: 1.5, // Weight in kG or G
manufacturer_number: 'MANUF-001',
category_codes: ['47101501'],
image_url: 'http://example.com/image.jpg',
categories: ['Category 1', 'Category 2'],
meta: [
//meta values in preferred array format
],
original_price: 100.00 //Price before discount
);
// Add product to cart
$cart->addProduct($product);
// Optional: Set a custom return URL instead of using session
ReturnCart::setReturnUrl('http://example.com/custom-return-url');
// Execute the Return Cart
ReturnCart::execute();
// Return Customer to Abeta
return ReturnCart::returnCustomer();
namespace App\Listeners;
use AbetaIO\Laravel\Events\OrderReceived;
use Illuminate\Support\Facades\Log;
class HandleOrder
{
public function handle(OrderReceived $event)
{
$order = $event->orderData;
// Access general order information
Log::info('Order Received', [
'Cart ID' => $order->cart_id,
'Total' => $order->total,
'Currency' => $order->currency,
]);
// Access billing address
$billingCity = $order->billTo->city;
Log::info('Billing City', ['City' => $billingCity]);
// Access products
foreach ($order->products as $product) {
Log::info('Product Details', [
'Name' => $product->name,
'Quantity' => $product->quantity,
'Price' => $product->price_ex_vat,
]);
}
}
}
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use AbetaIO\Laravel\Events\OrderReceived;
use App\Listeners\HandleOrder;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
OrderReceived::class => [
HandleOrder::class,
],
];
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Log;
use AbetaIO\Laravel\Services\Order\OrderService;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
OrderService::onOrderProcessed(function ($order) {
Log::info('Order Processed', [
'Cart ID' => $order->cart_id,
'Customer Reference' => $order->customer_reference,
'Total Amount' => $order->total,
]);
foreach ($order->products as $product) {
Log::info('Product Info', [
'Name' => $product->name,
'Quantity' => $product->quantity,
]);
}
});
}
}
use AbetaIO\Laravel\Exceptions\OrderProcessingException;
OrderService::onOrderProcessed(function ($order) {
if (!$order->cart_id) {
throw new OrderProcessingException('Cart ID is missing.');
}
});
$orderArray = $order->toArray();
\Log::info('Order as Array', $orderArray);