PHP code example of tuurosung / switch8583

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

    

tuurosung / switch8583 example snippets


use Tuurosung\switch8583\Message;
use Tuurosung\switch8583\Definitions\Iso8583v1987;

$request = Message::make('0200', new Iso8583v1987())
    ->withField(3, '000000')            // Processing code (purchase)
    ->withField(4, '000000012500')      // Amount: 125.00
    ->withField(11, '000001')           // System trace audit number
    ->withField(41, 'TERM0001')         // Terminal ID
    ->withField(49, '936');             // Currency (GHS)

$raw = $request->toBytes();             // binary, ready for a socket
$hex = $request->toHex();               // uppercase hex, ready for a log

$parsed = Message::parse($raw, new Iso8583v1987());
$parsed->getField(4);                   // '000000012500'

$request = Message::parse($raw, new Iso8583v1987());

$response = $request
    ->withMti($request->mti()->response())   // 0200 -> 0210
    ->withoutField(35)                        // track data never returns
    ->withField(39, '00');                    // approved

$response->mti()->value;                      // '0210'

use Tuurosung\switch8583\Definitions\FieldDefinition;
use Tuurosung\switch8583\Definitions\FieldEncoding;
use Tuurosung\switch8583\Codec\BcdPadding;

$network = (new Iso8583v1987())->withField(
    FieldDefinition::llvar(2, 'Primary Account Number', 19, FieldEncoding::Bcd)
        ->withBcdPadding(BcdPadding::Right, 0xF),
);

$message = Message::make('0100', $network)
    ->withField(2, '4111111111111111112')     // 19-digit PAN
    ->withField(3, '000000');

// F2 on the wire: prefix 0x19, ten packed bytes, last nibble the 0xF pad.

$message = Message::make('0200', new Iso8583v1987(), FieldEncoding::Bcd);
// The MTI now occupies 2 bytes instead of 4; field encodings still
// come from the catalogue, per field.

// config/iso8583.php -> version, mti_encoding
use Tuurosung\switch8583\Iso8583Factory;

$factory = app(Iso8583Factory::class);
$request = $factory->make('0200')->withField(3, '000000');
$parsed  = $factory->parse($raw);

php artisan vendor:publish --tag=iso8583-config