Skip to content

A PHP library for generating and validating CashID requests and responses.

License

Notifications You must be signed in to change notification settings

Beakerboy/CashID

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CashID PHP library

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:https://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();

About

A PHP library for generating and validating CashID requests and responses.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages