ronnie/tra-crawler

A package to crawl TRA web receipts and return the data in necessary format

v1.0.0-beta.2 2023-10-16 18:46 UTC

This package is auto-updated.

Last update: 2024-04-19 08:09:43 UTC


README

Logo

TRA Crawler

A PHP package for crawling TRA receipts and returning its data as a collection, array or json.

Badges

Add badges from somewhere like: shields.io

MIT License

Installation

Install TRA crawler with composer.

  composer require ronnie/tra-crawler

The project also make use of puppeteer to access JS content on the receipt.

  npm install puppeteer

Authors

Usage/Examples

Plain PHP

When using this package in plain PHP, a simple setup like this can help you get started:

  use Ronnie\TRA\Crawler;
  
  ...
  
  $crawler = new Crawler();
  // For URI or QR Scanned receipts you can use the URI method
  $receipt = $crawler->setUri($yourURI)->crawl();

  // For Physical receipt, Receipt verification code and the time is to be used in conjuction with the code method
  $receipt = $crawler->setCode($yourCode, $yourTime)->crawl();

Do note that the time ($yourTime) should be in hhMMss format (124453).

Laravel / Dependency Injection

When using this package in a Laravel/Symfony Project or any project that has a DI container, a better solution would be to use the container to inject an instance of the Ronnie\TRA\Crawler class into whatever class or method you need. A singleton works best for such scenarios.

It is also possible to extend the Ronnie\TRA\Crawler class or write your own implementation as long as they obey the Ronnie\TRA\Contracts\ResourceCrawler contract/interface.

Run Locally

Clone the project

  git clone https://github.com/RonnieTaz/tra-crawler

Go to the project directory

  cd tra-crawler

Install NPM dependencies

  npm install puppeteer

Install Composer dependencies

  composer install

Use CLI app to test output

  php bin/console app:test-output -i url -u the_receipt_url

Also, few sample receipts have been added to the project to simplify testing. Head over to config.php to set which sample you want to use.