beakerboy/cashid-library

CashID library for PHP

v0.1.0 2019-06-26 23:33 UTC

This package is auto-updated.

Last update: 2022-04-29 01:04:55 UTC


README

Build Status Coverage Status Documentation

Dependencies

  • Any PSR-16 compatible cache (such as paillechat/apcu-simple-cache)
  • BitcoinPHP ECDSA Library
  • CashaddrConverter

Specifications

Setup

Add this library and your selection of cache implementations to your composer.json file in your project:

{
  "require": {
      "beakerboy/cashid-library": "0.*",
      "paillechat/apcu-simple-cache": "*"
  }
}

Use composer to install the library:

$ php composer.phar install

Composer will install CashID inside your vendor folder. Then you can add the following to your .php files to use the library with Autoloading.

require_once(__DIR__ . '/vendor/autoload.php');

Alternatively, use composer on the command line to require and install CashID:

$ php composer.phar require beakerboy/cashid-library:0.* paillechat/apcu-simple-cache:*

Minimum Requirements

  • PHP 7.1

Examples

Create CashID request

<?php
    use CashID\Services\RequestGenerator;
    use Paillechat\ApcuSimpleCache\ApcuCache;

    // Specify your server details
    $domain = 'mydomain.com';
    $listener_script = '/api/parse.php';
    
    // Create your cache
    $cache = new ApcuCache();
    
    // Create a request generator
    $generator = new RequestGenerator($domain, $listener_script, $cache);

    // Create a minimal request
    $requestURI = $generator->createRequest();

    // Validate that the request was created
    if($requestURI !== false)
    {
        // Show a QR code / share with NFC the $requestURI
    }

Validate CashID response

<?php
    use CashID\Services\ResponseHandler;
    use Paillechat\ApcuSimpleCache\ApcuCache;

    // Specify your server details
    $domain = 'mydomain.com';
    $listener_script = '/api/parse.php';

    // Create your cache
    $cache = new ApcuCache();

    // Create a response handler
    $handler = new ResponseHandler($domain, $listener_script, $cache);

    // Capture the response
    $response = file_get_contents('php://input');

    // Parse the request.
    $request = $handler->validateRequest($response);

    // Validate the request.
    if($request !== false)
    {
        // Perform the $request['action'] using $request['data'] and $request['metadata'].
    }

    // Send the request confirmation.
    $handler->confirmRequest();