Skip to content

Latest commit

 

History

History
68 lines (48 loc) · 2.02 KB

index.md

File metadata and controls

68 lines (48 loc) · 2.02 KB

DOCUMENTATION

Please have a look at an example application based on Slim3 framework.

You can also create your own classes.

  • Implement MessageRepository class based on \AS2\MessageRepositoryInterface
  • Implement Message class based on \AS2\MessageInterface
  • Implement PartnerRepository class based on \AS2\PartnerRepositoryInterface
  • Implement Partner class based on \AS2\PartnerInterface

Example Receive AS2 Message

$manager = new \AS2\Management();

/** @var /AS2/MessageRepositoryInterface $messageRepository */
$messageRepository = new App\Repositories\MessageRepository();

/** @var /AS2/PartnerRepositoryInterface $partnerRepository */
$partnerRepository = new App\Repositories\PartnerRepository();

$server = new \AS2\Server($manager, $partnerRepository, $messageRepository);

/** @var \GuzzleHttp\Psr7\Response $response */
$response = $server->excecute();

Example Send AS2 Message

$manager = new \AS2\Management();

//loading conf files
$partners          = require __DIR__ . '/config/partners.php';

/** @var /AS2/MessageRepositoryInterface $messageRepository */
$messageRepository = new App\Repositories\MessageRepository(['path' => $storagePath . DIRECTORY_SEPARATOR . 'sent']);

/** @var /AS2/PartnerRepositoryInterface $partnerRepository */
$partnerRepository = new App\Repositories\PartnerRepository($partners);

// Init partners
$sender = $partnerRepository->findPartnerById('A');
$receiver = $partnerRepository->findPartnerById('B');

// Generate new message ID
$messageId = \AS2\Utils::generateMessageID($sender);
$rawMessage = '
Content-type: Application/EDI-X12
Content-disposition: attachment; filename=payload
Content-id: <[email protected]>

ISA*00~';

// Init new Message
$message = $messageRepository->createMessage();
$message->setMessageId($messageId);
$message->setSender($sender);
$message->setReceiver($receiver);

$payload = $manager->buildMessage($message, $rawMessage);
if ($response = $manager->sendMessage($message, $payload)){
    echo "OK \n";
}

$messageRepository->saveMessage($message);