Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: mikegogulski on November 23, 2010, 08:12:12 PM



Title: Bitcoin library for PHP (alpha release)
Post by: mikegogulski on November 23, 2010, 08:12:12 PM
https://github.com/mikegogulski/bitcoin-php

(untested) Drupal usage example:
Code:
  include_once("bitcoin.inc");
  $bitcoin_client = new BitcoinClient($scheme, $username, $password, $hostname, $port, $certificate_path, $debuglevel);
  if (TRUE !== ($fault = $bitcoin_client->can_connect()))
    return watchdog('uc_bitcoin_cron', 'Unable to access Bitcoin server. Fault: !fault', $fault);
  // loop through the open transactions
  while ($my_order = db_fetch_object($result)) {
    // check for transaction completion
    $address = $my_order->bitcoin_address;
    try {
      $paid = $bitcoin_client->query("getreceivedbyaddress", $address, variable_get("uc_bitcoin_transaction_confirms", 1));
    } catch (BitcoinClientException $e) {
      return watchdog('uc_bitcoin', "Bitcoin server communication failed on getreceivedbyaddress !address with fault string !fault", array("!address" => $address, '!fault' => $e . message), WATCHDOG_ALERT);
    }

  • Abstracts away the underlying JSON-RPC interface
  • Incorporates theymos's ports of the address and hash handling functions
  • Includes unit tests

Forks welcome!


Title: Re: Bitcoin library for PHP (alpha release)
Post by: Hiro Protagonist on December 30, 2010, 08:14:38 PM
Hey Mike,

Thanks for the library. I was looking to roll a module for Ubercart to accept Bitcoin this weekend, and you saved me a lot of work. Any updates on your library? Or are there any other modules in the works already to do this?


Title: Re: Bitcoin library for PHP (alpha release)
Post by: mikegogulski on December 31, 2010, 12:16:22 AM
Hello Hiro,

Check around here for uc_bitcoin, which uses the library and is already a working payment method for Ubercart.

I'm a bit behind on keeping the library synced to the latest API version, but that shouldn't be a problem as yet, since the deprecated label functions are still in bitcoin.

Peace,
Mike


Title: Re: Bitcoin library for PHP (alpha release)
Post by: fabianhjr on December 31, 2010, 04:02:11 AM
Hey, by any chance had you seen a PrestaShop module? I am not a great coder and need this to get my shop to accept Bitcoins.

Thanks for the library Mike. :D


Title: Re: Bitcoin library for PHP (alpha release)
Post by: mizerydearia on December 31, 2010, 07:09:05 PM
Ah, I didn't notice this library before working on my Bitcoin Control Panel project.  Nice job!


Title: Re: Bitcoin library for PHP (alpha release)
Post by: dduane on January 03, 2011, 06:18:45 AM
Also check out the btc_address module (http://github.com/DarrellDuane/btc_address)  for holding bitcoin addresses.

I've also made a very rough release of the mtgox drupal module for being able to utilize the Mt. Gox Tradiing API.   
http://github.com/DarrellDuane/mtgox

I've just added code the the btc_address to check for the Bitcoin library and provide instructions for downloading it if it isn't downloaded on the Drupal status report.  I'd encourage someone who's working on uc_bitcoin to copy my code and my README.txt and separate the bitcoin.inc library from the uc_bitcoin distribution.   Not sure if Mike wants to do that or perhaps MizeryDearia might want to. 


Title: Re: Bitcoin library for PHP (alpha release)
Post by: Hiro Protagonist on January 03, 2011, 09:04:15 PM
Hey, thanks for heads up on uc_bitcoin. I didn't find it in my initial search but found it by name. Thanks!


Title: Re: Bitcoin library for PHP (alpha release)
Post by: mikegogulski on January 21, 2011, 01:05:50 AM
Pushed an update to Github today to bring this in line with the 0.3.19 API. Some functions lack unit tests, so be warned!