sescandell/bitpay-client

There is no license information available for the latest version (v1.1.0) of this package.

BitPay PHP Client

v1.1.0 2014-01-19 16:48 UTC

This package is not auto-updated.

Last update: 2024-11-05 02:53:35 UTC


README

Powerful, flexible, lightweight interface to the BitPay Bitcoin Payment Gateway API.

Installing via Composer

The recommended way to install the BitPay PHP Client is through Composer.

# Install Composer
$ curl -sS https://getcomposer.org/installer | php

# Add BitPay as a dependency
$ php composer.phar require bitpay/php-client

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

The library requires PHP 5.3+ and is PSR-0 compatible.

Basic Usage

To create an invoice:

<?php

require 'vendor/autoload.php';

$bitPay = new BitPay\BitPay(
  new BitPay\Request\Curl,
  new BitPay\Encrypter\Hash('API-KEY'),
  'API-KEY',
  $options // array, optional
);

$invoice = $bitPay->createInvoice($orderID, $price); // returns Invoice Object

With invoice creation, orderID and currency are the only required fields. If you are sending a customer from your website to make a purchase, setting redirectURL on BitPay constructor options is required.

Response will be an object with information on your newly created invoice. Send your customer to the url to complete payment:

class stdClass#5 (10) {
  public $id =>
  string(10) "EXAMPLE-ID"
  public $url =>
  string(40) "https://bitpay.com/invoice?id=EXAMPLE-ID"
  public $posData =>
  string(67) "{"posData":[],"hash":"HASH"}"
  public $status =>
  string(3) "new"
  public $btcPrice =>
  string(6) "1.0000"
  public $price =>
  int(1)
  public $currency =>
  string(3) "BTC"
  public $invoiceTime =>
  int(1386958726781)
  public $expirationTime =>
  int(1386959626781)
  public $currentTime =>
  int(1386958726861)
}

There are many options available when creating invoices, which are listed in the BitPay API documentation.

To get updated information on this invoice, make a get call with the ID returned:

<?php

require 'vendor/autoload.php';

$bitPay = new BitPay\BitPay(
  new BitPay\Request\Curl,
  new BitPay\Encrypter\Hash('API-KEY'),
  'API-KEY',
  $options // array, optional
);

$invoice = $bitPay->createInvoice($orderID); // returns Invoice Object

Options

When you instantiate BitPay you can pass options as a fourth argument. You can also set this options dinamically with setOptions(). Please look carefully through these options and adjust according to your installation.

API Documentation

API Documentation is available on the BitPay site.

Running the Tests

$ composer install --dev
$ ./vendor/bin/phpunit

In addition to a full test suite, there is Travis integration.

Found a bug?

Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. We will respond to all filed issues.

Authors

  • Fede Isas
  • Escandell Stéphane