Giter Club home page Giter Club logo

bitpayclient's Introduction

BitPayClient

The purpose of this library is to be an object orientated alternative to the official BitPay PHP library.

The library is designed to make it easier to integrate BitPay in to more heavy PHP frameworks that use composer as a package manager such as Symfony2 and Laravel.

The library is written by myself, Peter Fox.

Version

1.1.0 - 16th March 2014 - Allows for throwing exception when an error api response is returned 1.0.0 - 5th Feburary 2014

Installation

Add to your projects composer.json

{
    "require": {
        "peterfox/bitpayclient":"1.0.*"
    }
}

Then run composer install or composer update to install this package.

Usage

The most basic use is as follows:

$client = new BitPayClient('YOUR-API-KEY');

$invoiceResponse = $client->createInvoice(0.0001, 'BTC');

You can supply further parameters for creating an invoice via a third array parameter (to see all possible parameters read the BitPay API):

$client = new BitPayClient('YOUR-API-KEY');

$invoiceResponse = $client->createInvoice(0.0001, 'BTC', ['redirectUrl' => 'http://somewhere']);

You can also supply a PosData value as an array and it will be sent as a Base64 encoded string (please note that other data will be modified to be base64 as well):

$client = new BitPayClient('YOUR-API-KEY');

$invoiceResponse = $client->createInvoice(0.0001, 'BTC', ['posData' => ['some_id' => 100]]);

The library also allows for making responses from Array (like from a $_POST):

$client = new BitPayClient('YOUR-API-KEY');

$invoiceData = [
            'id'=> 'CNRWBUPUZs9foP2ysZBBc',
            'url'=> 'https://bitpay.com/invoice?CNRWBUPUZs9foP2ysZBBc',
            'status' => 'new',
            'btcPrice' => '0.0001',
            'price' => 0.0001,
            'currency' => 'BTC',
            'invoiceTime' => 1391301679184,
            'expirationTime' => 1391302579184,
            'currentTime' => 1391302121888
            ];

$invoiceResponse = $client->getInvoiceFromArray($invoiceData);

There's also the functionality of getting an invoice from BitPay's API if you so wish:

$client = new BitPayClient('YOUR-API-KEY');

$invoiceGetResponse = $client->getInvoice('CNRWBUPUZs9foP2ysZBBc');

Testing

After cloning and installing this repo you can run /vendor/bin/phpunit in the root of the project and test it.

You will have to create a file called apikey.txt in the root directory of the project containing your api to actually run these tests.

The testing of this project uses PHP-VCR which is useful for running the tests multiple times as testCreateInvoice_LimitExceeded() test will cause BitPay to send you an email as a warning which can be a bit tedious. The fixtures are all stored in test/fixtures/.

License

GNU GPL Version 3

bitpayclient's People

Contributors

peterfox avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.