PHP code example of barion / barion-web-php

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

    

barion / barion-web-php example snippets



$myPosKey = "9c165cfccbd1452f830721a3a9cee664";

$apiVersion = 2;

// Test environment
$environment = \Barion\Enumerations\BarionEnvironment::Test;

// Production environment
$environment = \Barion\Enumerations\BarionEnvironment::Prod;

$BC = new \Barion\BarionClient(
    poskey: $myPosKey,
    version: $apiVersion,
    env: $environment,
    useBundledRootCerts: false
);

$item = new \Barion\Models\Common\ItemModel();
$item->Name = "TestItem";
$item->Description = "A test product";
$item->Quantity = 1;
$item->Unit = "piece";
$item->UnitPrice = 1000;
$item->ItemTotal = 1000;
$item->SKU = "ITEM-01";

$trans = new \Barion\Models\Payment\PaymentTransactionModel();
$trans->POSTransactionId = "TRANS-01";
$trans->Payee = "[email protected]";
$trans->Total = 1000;
$trans->Comment = "Test transaction containing the product";
$trans->AddItem($item);

$ppr = new \Barion\Models\Payment\PreparePaymentRequestModel();
$ppr->GuestCheckout = true;
$ppr->PaymentType = \Barion\Enumerations\PaymentType::Immediate;
$ppr->FundingSources = array(FundingSourceType::All);
$ppr->PaymentRequestId = "PAYMENT-01";
$ppr->PayerHint = "[email protected]";
$ppr->Locale = \Barion\Enumerations\UILocale::EN;
$ppr->OrderNumber = "ORDER-0001";
$ppr->Currency = \Barion\Enumerations\Currency::HUF;
$ppr->RedirectUrl = "https://webshop.example.com/afterpayment";
$ppr->CallbackUrl = "https://webshop.example.com/processpayment";
$ppr->AddTransaction($trans);

$myPayment = $BC->PreparePayment($ppr);

$BC->SetVersion(4);
$paymentDetails = $BC->PaymentState("64157032d3dc4296aedafd4b0994c64e");

composer