Compare commits

..

19 Commits

Author SHA1 Message Date
Nicolas Dorier
4c0bf5a5bf
Update README.md 2021-11-08 21:02:40 +09:00
nicolas.dorier
75bd0f95f5
bump version 2021-10-03 10:42:34 +09:00
Nicolas Dorier
d59411a396
Merge pull request #23 from ndeet/patch-1
Fix Lets Encrypt root cert error
2021-10-03 10:40:16 +09:00
Andreas Tasch
16862d2ed6
Fix Lets Encrypt root cert error
@NicolasDorier 

Do not use the custom ca-bundle.crt as it contains outdated certs and there is no obvious reason imo to why even use it at all. Normally the system ssl library is good enough for major SSL certs to work. Maybe Bitpay had some need for self signed certs or something to even do that.

Note: just did edit in the web UI and not delete the ca-bundle.crt file for now.

Context:
https://chat.btcpayserver.org/btcpayserver/pl/cm9itj98hfbr9jgiq4t38hkeuw

including the comments afterwards of another user that tried this fix successfully.

Todo: after merging this somebody needs to do a WooCommerce plugin release, not sure who is in charge of that atm.
2021-10-02 22:52:09 +02:00
Andrew Camilleri
3b161c5d00
Merge pull request #22 from ndeet/allow-any-currency
Allow any currency symbol via overloaded class.
2021-01-29 12:24:57 +01:00
Andrew Camilleri
ca9e77e5df
Merge pull request #21 from ndeet/payment-currencies
Support for payment currencies.
2021-01-29 12:24:28 +01:00
Andreas Tasch
01057e8da8 Make sure to use CurrencyUnrestricted here to not break IPN callback. 2021-01-26 14:22:46 +01:00
Andreas Tasch
5522adcf5e Allow any currency symbol via overloaded class. 2021-01-26 13:28:07 +01:00
Andreas Tasch
c41360a6e2 Support for payment currencies. 2021-01-26 13:24:33 +01:00
nicolas.dorier
7815bc0312
bump ca 2020-07-17 21:07:10 +09:00
nicolas.dorier
79ac751e54 fix version 2019-04-23 16:33:13 +09:00
nicolas.dorier
3e0425497c do not try to clean orderId 2019-04-23 15:35:12 +09:00
Nicolas Dorier
1e08ee7c91
Merge pull request #16 from kakaska/fix-get-invoice-tutorial
Fix getInvoice.php and IPNlogger.php tutorial
2019-02-26 13:44:43 +09:00
kakaska
f04618c667 Fix IPNlogger.php tutorial 2019-02-25 22:27:17 +01:00
kakaska
8b3f1663f1 Fix getInvoice.php tutorial 2019-02-25 19:00:35 +01:00
Nicolas Dorier
43076fdd9b
Merge pull request #12 from psyb0t/fix/remove-null-props-when-creating-invoice
Check body object keys for null value and unset them if found
2019-02-21 18:21:35 +09:00
Ciprian Mandache
79d1f1e51b Check body object keys for null value and unset them if found 2019-02-21 11:07:40 +02:00
Nicolas Dorier
36578f803c
Merge pull request #8 from kakaska/update-readme
Update README.md installation section
2019-02-17 20:34:00 +09:00
kakaska
dbc3aeec94 Update README.md installation section 2019-02-17 11:40:35 +01:00
106 changed files with 2771 additions and 2695 deletions

View File

@ -26,9 +26,6 @@ after_script:
notifications:
email: false
sudo:
false
matrix:
fast_finish: true

View File

@ -83,25 +83,6 @@ Included buyer notify field (when creating an invoice)
- HTTP 100 messages not parsed correctly when doing payouts
## [Unreleased][unreleased]
## [3.0.0] - 2016-03-10
###Fixed
- should respect that numbers coming from the api might not have decimal points at all, but they are still valid
- Bug fixes that include proper type checking for invoice object creation
- Fixed invoice, expiration, and current time error
- Repaired tests based on current changes to the code.
###Added
- Using this library with Symfony >=2.3 or Symfony 3.0.x should work. So if you are already using Symfony 3.0, then this library should work with it too.
- Leo Hochberg added PaymentUrl support to the library since the BitPay backend support it. Thanks Leo.
## [2.2.7] - 2015-10-28
###Fixed
- btcPaid on invoice responses now contains the amount paid instead of the price
## [2.2.6] - 2015-07-31
###Fixed
- The fixes several issues, including "Price only accepts .00 precision" and "Invoice exception state"
### Changed
- Refactored function calls out of loops

View File

@ -1,5 +1,5 @@
setup:
./composer.phar install
composer.phar install
npm install
test:

View File

@ -1,3 +1,7 @@
# === Warning ===
This is the old BitPay based PHP client and should be considered deprecated (even though it currently still works). If you are building something from scratch, [use the new Greenfield API](https://github.com/btcpayserver/btcpayserver-greenfield-php).
bitpay/php-bitpay-client
=================
@ -8,10 +12,11 @@ bitpay/php-bitpay-client
[![Scrutinizer](https://img.shields.io/scrutinizer/g/bitpay/php-bitpay-client.svg?style=flat-square)](https://scrutinizer-ci.com/g/bitpay/php-bitpay-client/)
[![Coveralls](https://img.shields.io/coveralls/bitpay/php-bitpay-client.svg?style=flat-square)](https://coveralls.io/r/bitpay/php-bitpay-client)
[![Documentation Status](https://readthedocs.org/projects/php-bitpay-client/badge/?version=latest)](https://readthedocs.org/projects/php-bitpay-client/?badge=latest)
[![Total Downloads](https://poser.pugx.org/bitpay/php-client/downloads.svg)](https://packagist.org/packages/bitpay/php-client)
[![Latest Unstable Version](https://poser.pugx.org/bitpay/php-client/v/unstable.svg)](https://packagist.org/packages/bitpay/php-client)
This is a self-contained PHP implementation of BitPay's cryptographically secure API: https://bitpay.com/api
This is a self-contained PHP implementation of BitPay's new cryptographically secure API: https://bitpay.com/api
# Installation
@ -32,8 +37,15 @@ Add to your composer.json file by hand.
...
"require": {
...
"bitpay/php-client": "^3.0"
}
"bitpay/php-client": "dev-master"
},
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/btcpayserver/php-bitpay-client"
}
],
...
}
```
@ -56,6 +68,24 @@ See https://support.bitpay.com/hc/en-us/articles/115003001063-How-do-I-configure
# Usage
## Autoloader
To use the library's autoloader (which doesn't include composer dependencies)
instead of composer's autoloader, use the following code:
```php
<?php
$autoloader = __DIR__ . '/relative/path/to/Bitpay/Autoloader.php';
if (true === file_exists($autoloader) &&
true === is_readable($autoloader))
{
require_once $autoloader;
\Bitpay\Autoloader::register();
} else {
throw new Exception('BitPay Library could not be loaded');
}
```
## Documentation
Please see the ``docs`` directory for information on how to use this library

View File

@ -1 +1 @@
3.0.0
2.2.20

32
behat.yml Normal file
View File

@ -0,0 +1,32 @@
# behat.yml
default:
context:
parameters:
user:
password:
base_url:
driver: 'selenium2'
paths:
features: tests/integrations
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~
phantomjs:
context:
parameters:
user:
password:
base_url:
driver: 'phantomjs'
paths:
features: tests/integrations
bootstrap: %behat.paths.features%/bootstrap
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2:
wd_host: "http://localhost:8643/wd/hub"

View File

@ -3,11 +3,12 @@
<project name="bitpay/package" default="build">
<target name="build" depends="lint,phpunit,phpcs" />
<target name="lint" description="Check the syntax of PHP files">
<target name="lint"
description="Check the syntax of PHP files">
<mkdir dir="${project.basedir}/build/cache" />
<phplint cachefile="${project.basedir}/build/cache/phplint.cache">
<fileset dir="${project.basedir}/src">
<include name="**/*.php" />
<include name="**/*.php"/>
</fileset>
</phplint>
</target>

10
build/stub.php Normal file
View File

@ -0,0 +1,10 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
require_once 'phar://bitpay.phar/src/Bitpay/Autoloader.php';
\Bitpay\Autoloader::register();
require_once 'phar://bitpay.phar/bin/bitpay';
__HALT_COMPILER();

View File

@ -1,6 +1,6 @@
{
"name": "bitpay/php-client",
"description": "PHP Library to work with the cryptographically secure BitPay API",
"description": "PHP Library to work with the new cryptographically secure BitPay API",
"license": "MIT",
"minimum-stability": "stable",
"keywords": ["bitpay", "bitcoin"],
@ -32,8 +32,13 @@
"symfony/dependency-injection": "^2.3 || ^3.0"
},
"require-dev": {
"behat/behat": "2.5.*@stable",
"behat/mink": "1.6.1",
"behat/mink-extension": "1.3.*",
"behat/mink-selenium2-driver": "1.2.0",
"fabpot/goutte": "~1.0.4",
"phpmd/phpmd": "master-dev",
"behat/mink-goutte-driver": "1.*",
"phpmd/phpmd": "~2.1.3",
"phpunit/phpunit": "~4.3.1",
"fzaninotto/faker": "~1.4.0",
"mikey179/vfsStream": "~1.4.0",
@ -48,7 +53,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
"dev-master": "2.2.x-dev"
}
}
}

View File

@ -3,6 +3,25 @@ Please make sure that you have Installed this library and have
Configured it correctly. This section will help guide you on how to use
this library.
Autoloader
==========
To use the library's autoloader (which doesn't include composer dependencies)
instead of composer's autoloader, use the following code:
``` {.sourceCode .php}
<?php
$autoloader = __DIR__ . '/relative/path/to/Bitpay/Autoloader.php';
if (true === file_exists($autoloader) &&
true === is_readable($autoloader))
{
require_once $autoloader;
\Bitpay\Autoloader::register();
} else {
throw new Exception('BitPay Library could not be loaded');
}
```
Dependency Injection
====================

View File

@ -34,7 +34,7 @@ if (true === empty($ipn)) {
throw new \Exception('Could not decode the JSON payload from BitPay.');
}
if (true === empty($ipn -> id)) {
if (true === empty($ipn->id)) {
fwrite($myfile, $date . " : Error. Invalid Bitpay payment notification message received - did not receive invoice ID.\n");
fclose($myfile);
throw new \Exception('Invalid Bitpay payment notification message received - did not receive invoice ID.');
@ -42,15 +42,20 @@ if (true === empty($ipn -> id)) {
// Now fetch the invoice from BitPay
// This is needed, since the IPN does not contain any authentication
$storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword');
$privateKey = $storageEngine->load('/tmp/bitpay.pri');
$publicKey = $storageEngine->load('/tmp/bitpay.pub');
$client = new \Bitpay\Client\Client();
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();
$client->setPrivateKey($privateKey);
$client->setPublicKey($publicKey);
$client->setUri('https://btcpay.server/');
$client->setAdapter($adapter);
$token = new \Bitpay\Token();
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
$client->setToken($token);
$token->setFacade('merchant');
/**
* This is where we will fetch the invoice object

View File

@ -15,13 +15,19 @@ require __DIR__.'/../../vendor/autoload.php';
// Now fetch the invoice from BitPay
$storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPassword');
$privateKey = $storageEngine->load('/tmp/bitpay.pri');
$publicKey = $storageEngine->load('/tmp/bitpay.pub');
$client = new \Bitpay\Client\Client();
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();
$client->setPrivateKey($privateKey);
$client->setPublicKey($publicKey);
$client->setUri('https://btcpay.server/');
$client->setAdapter($adapter);
$token = new \Bitpay\Token();
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
$token->setFacade('merchant');
$client->setToken($token);

View File

@ -27,20 +27,24 @@ class AccessToken implements AccessTokenInterface
protected $label;
/**
* Set various defaults for this object.
* @var boolean
*/
public function __construct($id = null, $email = null, $label = null)
protected $useNonce;
/**
*/
public function __construct()
{
$this->id = $id;
$this->email = $email;
$this->label = $label;
/**
* Set various defaults for this object.
*/
$this->useNonce = true;
}
/**
* Setter for the id.
*
* @param string $id
* @return AccessToken
*
* @return AccessTokenInterface
*/
public function setId($id)
{
@ -60,10 +64,9 @@ class AccessToken implements AccessTokenInterface
}
/**
* Setter for the email address.
*
* @param string $email
* @return AccessToken
*
* @return AccessTokenInterface
*/
public function setEmail($email)
{
@ -83,10 +86,9 @@ class AccessToken implements AccessTokenInterface
}
/**
* Setter for the label.
*
* @param string $label
* @return AccessToken
*
* @return AccessTokenInterface
*/
public function setLabel($label)
{
@ -104,4 +106,36 @@ class AccessToken implements AccessTokenInterface
{
return $this->label;
}
/**
* @inheritdoc
*/
public function isNonceDisabled()
{
return !($this->useNonce);
}
/**
* Enable nonce usage
*
* @return AccessTokenInterface
*/
public function nonceEnable()
{
$this->useNonce = true;
return $this;
}
/**
* Disable nonce usage
*
* @return AccessTokenInterface
*/
public function nonceDisable()
{
$this->useNonce = false;
return $this;
}
}

View File

@ -7,7 +7,7 @@
namespace Bitpay;
/**
* Interface for an access token for the given client
* Creates an access token for the given client
*
* @package Bitpay
*/
@ -27,4 +27,9 @@ interface AccessTokenInterface
* @return string
*/
public function getLabel();
/**
* @return boolean
*/
public function isNonceDisabled();
}

View File

@ -7,6 +7,7 @@
namespace Bitpay;
/**
*
* @package Bitpay
*/
class Application implements ApplicationInterface
@ -21,6 +22,8 @@ class Application implements ApplicationInterface
*/
protected $orgs;
/**
*/
public function __construct()
{
$this->users = array();
@ -46,10 +49,11 @@ class Application implements ApplicationInterface
/**
* Add user to stack
*
* @param User $user
* @return Application
* @param UserInterface $user
*
* @return ApplicationInterface
*/
public function addUser(User $user)
public function addUser(UserInterface $user)
{
if (!empty($user)) {
$this->users[] = $user;
@ -61,10 +65,11 @@ class Application implements ApplicationInterface
/**
* Add org to stack
*
* @param Org $org
* @return Application
* @param OrgInterface $org
*
* @return ApplicationInterface
*/
public function addOrg(Org $org)
public function addOrg(OrgInterface $org)
{
if (!empty($org)) {
$this->orgs[] = $org;

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* Creates an application for a new merchant account.
* Creates an application for a new merchant account
*
* @package Bitpay
*/

58
src/Bitpay/Autoloader.php Normal file
View File

@ -0,0 +1,58 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* @package Bitpay
*/
class Autoloader
{
/**
* Register the autoloader, by default this will put the BitPay autoloader
* first on the stack, to append the autoloader, pass `false` as an argument.
*
* Some applications will throw exceptions if the class isn't found and
* some are not compatible with PSR standards.
*
* @param boolean $prepend
*/
public static function register($prepend = true)
{
spl_autoload_register(array(__CLASS__, 'autoload'), true, (bool) $prepend);
}
/**
* Unregister this autoloader
*/
public static function unregister()
{
spl_autoload_unregister(array(__CLASS__, 'autoload'));
}
/**
* Give a class name and it will require the file.
*
* @param string $class
* @return bool
*/
public static function autoload($class)
{
if (0 === strpos($class, 'Bitpay\\')) {
$classname = substr($class, 7);
$file = __DIR__.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $classname).'.php';
if (is_file($file) && is_readable($file)) {
require_once $file;
return true;
}
throw new \Exception(sprintf('Class "%s" Not Found', $class));
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -18,7 +18,7 @@ class Bill implements BillInterface
protected $items;
/**
* @var Currency
* @var CurrencyInterface
*/
protected $currency;
@ -77,6 +77,8 @@ class Bill implements BillInterface
*/
protected $archived;
/**
*/
public function __construct()
{
$this->address = array();
@ -94,10 +96,11 @@ class Bill implements BillInterface
}
/**
* @param Item $item
* @return Bill
* @param ItemInterface $item
*
* @return BillInterface
*/
public function addItem(Item $item)
public function addItem(ItemInterface $item)
{
if (!empty($item)) {
$this->items[] = $item;
@ -115,10 +118,11 @@ class Bill implements BillInterface
}
/**
* @param Currency $currency
* @return Bill
* @param CurrencyInterface $currency
*
* @return BillInterface
*/
public function setCurrency(Currency $currency)
public function setCurrency(CurrencyInterface $currency)
{
if (!empty($currency)) {
$this->currency = $currency;
@ -137,7 +141,8 @@ class Bill implements BillInterface
/**
* @param string $name
* @return Bill
*
* @return BillInterface
*/
public function setName($name)
{
@ -158,7 +163,8 @@ class Bill implements BillInterface
/**
* @param array $address
* @return Bill
*
* @return BillInterface
*/
public function setAddress($address)
{
@ -179,7 +185,8 @@ class Bill implements BillInterface
/**
* @param string $city
* @return Bill
*
* @return BillInterface
*/
public function setCity($city)
{
@ -200,7 +207,8 @@ class Bill implements BillInterface
/**
* @param string $state
* @return Bill
*
* @return BillInterface
*/
public function setState($state)
{
@ -221,7 +229,8 @@ class Bill implements BillInterface
/**
* @param string $zip
* @return Bill
*
* @return BillInterface
*/
public function setZip($zip)
{
@ -242,7 +251,8 @@ class Bill implements BillInterface
/**
* @param string $country
* @return Bill
*
* @return BillInterface
*/
public function setCountry($country)
{
@ -263,7 +273,8 @@ class Bill implements BillInterface
/**
* @param string $email
* @return Bill
*
* @return BillInterface
*/
public function setEmail($email)
{
@ -284,7 +295,8 @@ class Bill implements BillInterface
/**
* @param string $phone
* @return Bill
*
* @return BillInterface
*/
public function setPhone($phone)
{
@ -305,7 +317,8 @@ class Bill implements BillInterface
/**
* @param string $status
* @return Bill
*
* @return BillInterface
*/
public function setStatus($status)
{
@ -326,7 +339,8 @@ class Bill implements BillInterface
/**
* @param string $showRate
* @return Bill
*
* @return BillInterface
*/
public function setShowRate($showRate)
{
@ -347,7 +361,8 @@ class Bill implements BillInterface
/**
* @param boolean $archived
* @return Bill
*
* @return BillInterface
*/
public function setArchived($archived)
{

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* Creates a bill for the calling merchant.
* Creates a bill for the calling merchant
*
* @package Bitpay
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -18,14 +18,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
/**
* Sets up container and prepares for dependency injection.
* Setups container and is ready for some dependency injection action
*
* @package Bitpay
*/
class Bitpay
{
/**
* @var ContainerBuilder
* @var ContainerInterface
*/
protected $container;
@ -37,9 +37,9 @@ class Bitpay
* The second argument is the container if you want to build one by hand.
*
* @param array|string $config
* @param null|ContainerBuilder $container
* @param ContainerInterface $container
*/
public function __construct($config = array(), ContainerBuilder $container = null)
public function __construct($config = array(), ContainerInterface $container = null)
{
$this->container = $container;
@ -50,8 +50,6 @@ class Bitpay
/**
* Initialize the container
*
* @param array|string $config
*/
protected function initializeContainer($config)
{
@ -60,10 +58,7 @@ class Bitpay
}
/**
* Build the container of services and parameters.
*
* @param array|string $config
* @return ContainerBuilder
* Build the container of services and parameters
*/
protected function buildContainer($config)
{
@ -75,20 +70,16 @@ class Bitpay
return $container;
}
/**
* @return array<string,string>
*/
protected function getParameters()
{
return array(
'bitpay.root_dir' => realpath(__DIR__ . '/..'),
'bitpay.root_dir' => realpath(__DIR__.'/..'),
);
}
/**
* @param ContainerBuilder $container
*/
private function prepareContainer(ContainerBuilder $container)
private function prepareContainer(ContainerInterface $container)
{
foreach ($this->getDefaultExtensions() as $ext) {
$container->registerExtension($ext);
@ -97,10 +88,10 @@ class Bitpay
}
/**
* @param ContainerBuilder $container
* @return DelegatingLoader
* @param ContainerInterface $container
* @return LoaderInterface
*/
private function getContainerLoader(ContainerBuilder $container)
private function getContainerLoader(ContainerInterface $container)
{
$locator = new FileLocator();
$resolver = new LoaderResolver(
@ -114,9 +105,9 @@ class Bitpay
}
/**
* Returns an array of the default extensions.
* Returns an array of the default extensions
*
* @return BitpayExtension[]
* @return array
*/
private function getDefaultExtensions()
{
@ -126,7 +117,7 @@ class Bitpay
}
/**
* @return ContainerBuilder
* @return ContainerInterface
*/
public function getContainer()
{
@ -134,7 +125,7 @@ class Bitpay
}
/**
* @return object|null
* @return mixed
*/
public function get($service)
{

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,12 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
*
* @package Bitpay
*/
interface BuyerInterface extends UserInterface

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -18,10 +18,11 @@ use Bitpay\Client\ResponseInterface;
interface AdapterInterface
{
/**
* Send a request to BitPay.
* Send request to BitPay
*
* @param \Bitpay\Client\Request $request
* @return \Bitpay\Client\Response
* @param RequestInterface $request
*
* @return ResponseInterface
*/
public function sendRequest(\Bitpay\Client\Request $request);
public function sendRequest(RequestInterface $request);
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -11,7 +11,9 @@ use Bitpay\Client\ResponseInterface;
use Bitpay\Client\Response;
/**
* Adapter class that sends Request objects using cURL.
* Adapter that sends Request objects using CURL
*
* @TODO add way to configure curl with options
*
* @package Bitpay
*/
@ -31,7 +33,7 @@ class CurlAdapter implements AdapterInterface
}
/**
* Returns an array of cURL settings to use
* Returns an array of curl settings to use
*
* @return array
*/
@ -43,18 +45,14 @@ class CurlAdapter implements AdapterInterface
/**
* @inheritdoc
*/
public function sendRequest(\Bitpay\Client\Request $request)
public function sendRequest(RequestInterface $request)
{
$curl = curl_init();
if ($curl === false) {
throw new \Exception('[ERROR] In CurlAdapter::sendRequest(): Could not initialize cURL.');
}
$default_curl_options = $this->getCurlDefaultOptions($request);
foreach ($this->getCurlOptions() as $curl_option_key => $curl_option_value) {
if (is_null($curl_option_value) === false) {
if (!is_null($curl_option_value)) {
$default_curl_options[$curl_option_key] = $curl_option_value;
}
}
@ -73,14 +71,13 @@ class CurlAdapter implements AdapterInterface
$raw = curl_exec($curl);
if ($raw === false) {
if (false === $raw) {
$errorMessage = curl_error($curl);
curl_close($curl);
throw new \Bitpay\Client\ConnectionException('[ERROR] In CurlAdapter::sendRequest(): curl_exec failed with the error "' . $errorMessage . '".');
throw new \Bitpay\Client\ConnectionException($errorMessage);
}
/** @var Response */
/** @var ResponseInterface */
$response = Response::createFromRawResponse($raw);
// For some unknown reason, on some machine, the status code is equal to 0
@ -92,12 +89,12 @@ class CurlAdapter implements AdapterInterface
}
/**
* Returns an array of default cURL settings to use.
* Returns an array of default curl settings to use
*
* @param \Bitpay\Client\Request $request
* @param RequestInterface $request
* @return array
*/
private function getCurlDefaultOptions(\Bitpay\Client\Request $request)
private function getCurlDefaultOptions(RequestInterface $request)
{
return array(
CURLOPT_URL => $request->getFullUri(),
@ -106,7 +103,6 @@ class CurlAdapter implements AdapterInterface
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => 1,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CAINFO => __DIR__ . '/ca-bundle.crt',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_FRESH_CONNECT => 1,

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,7 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
/**
* @package Bitpay
*/
class ArgumentException extends \Exception
{

View File

@ -1,14 +1,7 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
/**
* @package Bitpay
*/
class BitpayException extends \Exception
{

View File

@ -1,12 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
use Bitpay\Client\Adapter\AdapterInterface;
use Bitpay\Network\NetworkInterface;
use Bitpay\TokenInterface;
use Bitpay\InvoiceInterface;
use Bitpay\PayoutInterface;
@ -14,9 +15,8 @@ use Bitpay\Util\Util;
use Bitpay\PublicKey;
use Bitpay\PrivateKey;
date_default_timezone_set('UTC');
/**
* Client used to send requests and receive responses for BitPay's Web API.
* Client used to send requests and receive responses for BitPay's Web API
*
* @package Bitpay
*/
@ -53,7 +53,7 @@ class Client implements ClientInterface
protected $privateKey;
/**
* @var string
* @var uri
*/
protected $uri;
@ -84,8 +84,6 @@ class Client implements ClientInterface
}
/**
* Set the network adapter object to use.
*
* @param AdapterInterface $adapter
*/
public function setAdapter(AdapterInterface $adapter)
@ -94,8 +92,6 @@ class Client implements ClientInterface
}
/**
* Assigns the token to use for a request.
*
* @param TokenInterface $token
* @return ClientInterface
*/
@ -115,10 +111,8 @@ class Client implements ClientInterface
$invoiceTime = is_numeric($data['invoiceTime']) ? intval($data['invoiceTime']/1000) : $data['invoiceTime'];
$expirationTime = is_numeric($data['expirationTime']) ? intval($data['expirationTime']/1000) : $data['expirationTime'];
$currentTime = is_numeric($data['currentTime']) ? intval($data['currentTime']/1000) : $data['currentTime'];
$invoiceToken = new \Bitpay\Token();
$paymentUrls = new \Bitpay\PaymentUrlSet();
$invoiceToken = new \Bitpay\Token();
$invoice
->setToken($invoiceToken->setToken($data['token']))
->setUrl($data['url'])
@ -127,7 +121,7 @@ class Client implements ClientInterface
->setBtcPrice(array_key_exists('btcPrice', $data) ? $data['btcPrice'] : '')
->setPrice($data['price'])
->setTaxIncluded($data['taxIncluded'])
->setCurrency(new \Bitpay\Currency($data['currency']))
->setCurrency(new \Bitpay\CurrencyUnrestricted($data['currency']))
->setOrderId(array_key_exists('orderId', $data) ? $data['orderId'] : '')
->setInvoiceTime($invoiceTime)
->setExpirationTime($expirationTime)
@ -142,12 +136,6 @@ class Client implements ClientInterface
->setPaymentTotals(array_key_exists('paymentTotals', $data) ? $data['paymentTotals'] : '')
->setPaymentSubtotals(array_key_exists('paymentSubtotals', $data) ? $data['paymentSubtotals'] : '')
->setExchangeRates(array_key_exists('exchangeRates', $data) ? $data['exchangeRates'] : '');
if (isset($data['paymentUrls'])) {
$invoice
->setPaymentUrls($paymentUrls->setUrls($data['paymentUrls']));
}
return $invoice;
}
@ -168,53 +156,56 @@ class Client implements ClientInterface
$this->checkPriceAndCurrency($item->getPrice(), $currency->getCode());
$body = array(
'price' => $item->getPrice(),
'taxIncluded' => $item->getTaxIncluded(),
'currency' => $currency->getCode(),
'posData' => $invoice->getPosData(),
'notificationURL' => $invoice->getNotificationUrl(),
'transactionSpeed' => $invoice->getTransactionSpeed(),
'fullNotifications' => $invoice->isFullNotifications(),
'price' => $item->getPrice(),
'taxIncluded' => $item->getTaxIncluded(),
'currency' => $currency->getCode(),
'posData' => $invoice->getPosData(),
'notificationURL' => $invoice->getNotificationUrl(),
'transactionSpeed' => $invoice->getTransactionSpeed(),
'fullNotifications' => $invoice->isFullNotifications(),
'extendedNotifications' => $invoice->isExtendedNotifications(),
'notificationEmail' => $invoice->getNotificationEmail(),
'redirectURL' => $invoice->getRedirectUrl(),
'orderID' => $invoice->getOrderId(),
'itemDesc' => $item->getDescription(),
'itemCode' => $item->getCode(),
'physical' => $item->isPhysical(),
'buyerName' => trim(sprintf('%s %s', $buyer->getFirstName(), $buyer->getLastName())),
'buyerAddress1' => isset($buyerAddress[0]) ? $buyerAddress[0] : '',
'buyerAddress2' => isset($buyerAddress[1]) ? $buyerAddress[1] : '',
'buyerCity' => $buyer->getCity(),
'buyerState' => $buyer->getState(),
'buyerZip' => $buyer->getZip(),
'buyerCountry' => $buyer->getCountry(),
'buyerEmail' => $buyer->getEmail(),
'buyerPhone' => $buyer->getPhone(),
'buyerNotify' => $buyer->getNotify(),
'guid' => Util::guid(),
'token' => $this->token->getToken(),
'notificationEmail' => $invoice->getNotificationEmail(),
'redirectURL' => $invoice->getRedirectUrl(),
'orderID' => $invoice->getOrderId(),
'itemDesc' => $item->getDescription(),
'itemCode' => $item->getCode(),
'physical' => $item->isPhysical(),
'buyerName' => trim(sprintf('%s %s', $buyer->getFirstName(), $buyer->getLastName())),
'buyerAddress1' => isset($buyerAddress[0]) ? $buyerAddress[0] : '',
'buyerAddress2' => isset($buyerAddress[1]) ? $buyerAddress[1] : '',
'buyerCity' => $buyer->getCity(),
'buyerState' => $buyer->getState(),
'buyerZip' => $buyer->getZip(),
'buyerCountry' => $buyer->getCountry(),
'buyerEmail' => $buyer->getEmail(),
'buyerPhone' => $buyer->getPhone(),
'buyerNotify' => $buyer->getNotify(),
'guid' => Util::guid(),
'nonce' => Util::nonce(),
'token' => $this->token->getToken(),
'paymentCurrencies' => $invoice->getPaymentCurrencies(),
);
$request->setBody(json_encode($body));
foreach(array_keys($body) as $key) {
if(null === $body[$key]) {
unset($body[$key]);
}
}
$request->setBody(json_encode($body));
$this->addIdentityHeader($request);
$this->addSignatureHeader($request);
$this->request = $request;
$this->response = $this->sendRequest($request);
$body = json_decode($this->response->getBody(), true);
$error_message = false;
$error_message = (!empty($body['error'])) ? $body['error'] : $error_message;
$error_message = (!empty($body['errors'])) ? $body['errors'] : $error_message;
$error_message = (is_array($error_message)) ? implode("\n", $error_message) : $error_message;
if (false !== $error_message) {
throw new \Exception($error_message);
}
$data = $body['data'];
$invoice = $this->fillInvoiceData($invoice, $data);
@ -230,17 +221,12 @@ class Client implements ClientInterface
$this->request = $this->createNewRequest();
$this->request->setMethod(Request::METHOD_GET);
$this->request->setPath('currencies');
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
$body = json_decode($this->response->getBody(), true);
if (empty($body['data'])) {
throw new \Exception('Error with request: no data returned');
}
$currencies = $body['data'];
array_walk($currencies, function (&$value, $key) {
$currency = new \Bitpay\Currency();
$currency
@ -253,7 +239,6 @@ class Client implements ClientInterface
->setPluralName($value['plural'])
->setAlts($value['alts'])
->setPayoutFields($value['payoutFields']);
$value = $currency;
});
@ -282,12 +267,12 @@ class Client implements ClientInterface
'effectiveDate' => $effectiveDate,
'pricingMethod' => $payout->getPricingMethod(),
'guid' => Util::guid(),
'nonce' => Util::nonce()
);
// Optional
foreach (array('reference','notificationURL','notificationEmail') as $value) {
$function = 'get' . ucfirst($value);
if ($payout->$function() != null) {
$body[$value] = $payout->$function();
}
@ -303,26 +288,21 @@ class Client implements ClientInterface
}
$request->setBody(json_encode($body));
$this->addIdentityHeader($request);
$this->addSignatureHeader($request);
$this->request = $request;
$this->response = $this->sendRequest($request);
$body = json_decode($this->response->getBody(), true);
$error_message = false;
$error_message = (!empty($body['error'])) ? $body['error'] : $error_message;
$error_message = (!empty($body['errors'])) ? $body['errors'] : $error_message;
$error_message = (is_array($error_message)) ? implode("\n", $error_message) : $error_message;
if (false !== $error_message) {
throw new \Exception($error_message);
}
$data = $body['data'];
$payout
->setId($data['id'])
->setAccountId($data['account'])
@ -343,11 +323,9 @@ class Client implements ClientInterface
{
$request = $this->createNewRequest();
$request->setMethod(Request::METHOD_GET);
$path = 'payouts?token='
. $this->token->getToken()
. (($status == null) ? '' : '&status=' . $status);
$request->setPath($path);
$this->addIdentityHeader($request);
@ -355,14 +333,11 @@ class Client implements ClientInterface
$this->request = $request;
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
$body = json_decode($this->response->getBody(), true);
$error_message = false;
$error_message = (!empty($body['error'])) ? $body['error'] : $error_message;
$error_message = (!empty($body['errors'])) ? $body['errors'] : $error_message;
$error_message = (is_array($error_message)) ? implode("\n", $error_message) : $error_message;
if (false !== $error_message) {
throw new \Exception($error_message);
}
@ -430,13 +405,12 @@ class Client implements ClientInterface
$this->request = $request;
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
$body = json_decode($this->response->getBody(), true);
if (empty($body['data'])) {
throw new \Exception('Error with request: no data returned');
}
$data = $body['data'];
$data = $body['data'];
$payout->setStatus($data['status']);
@ -451,22 +425,19 @@ class Client implements ClientInterface
$request = $this->createNewRequest();
$request->setMethod(Request::METHOD_GET);
$request->setPath(sprintf('payouts/%s?token=%s', $payoutId, $this->token->getToken()));
$this->addIdentityHeader($request);
$this->addSignatureHeader($request);
$this->request = $request;
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
$body = json_decode($this->response->getBody(), true);
if (empty($body['data'])) {
throw new \Exception('Error with request: no data returned');
}
$data = $body['data'];
$payout = new \Bitpay\Payout();
$payout = new \Bitpay\Payout();
$payout
->setId($data['id'])
->setAccountId($data['account'])
@ -517,15 +488,12 @@ class Client implements ClientInterface
$request = $this->createNewRequest();
$request->setMethod(Request::METHOD_GET);
$request->setPath('tokens');
$this->addIdentityHeader($request);
$this->addSignatureHeader($request);
$this->request = $request;
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
$body = json_decode($this->response->getBody(), true);
if (empty($body['data'])) {
throw new \Exception('Error with request: no data returned');
}
@ -552,22 +520,19 @@ class Client implements ClientInterface
public function createToken(array $payload = array())
{
if (isset($payload['pairingCode']) && 1 !== preg_match('/^[a-zA-Z0-9]{7}$/', $payload['pairingCode'])) {
throw new \Exception('[ERROR] In Client::createToken(): The pairing code provided is not legal.');
throw new \InvalidArgumentException("pairing code is not legal");
}
$this->request = $this->createNewRequest();
$this->request->setMethod(Request::METHOD_POST);
$this->request->setPath('tokens');
$payload['guid'] = Util::guid();
$this->request->setBody(json_encode($payload));
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
$body = json_decode($this->response->getBody(), true);
if (isset($body['error'])) {
throw new \Bitpay\Client\BitpayException($this->response->getStatusCode() . ': ' . $body['error']);
throw new \Bitpay\Client\BitpayException($this->response->getStatusCode().": ".$body['error']);
}
if($this->response->getStatusCode() >= 400) {
@ -577,13 +542,13 @@ class Client implements ClientInterface
$tkn = $body['data'][0];
$createdAt = new \DateTime();
$pairingExpiration = new \DateTime();
$token = new \Bitpay\Token();
$token = new \Bitpay\Token();
$token
->setPolicies($tkn['policies'])
->setToken($tkn['token'])
->setFacade($tkn['facade'])
->setCreatedAt($createdAt->setTimestamp(floor($tkn['dateCreated'] / 1000)));
->setCreatedAt($createdAt->setTimestamp(floor($tkn['dateCreated']/1000)));
if (isset($tkn['resource'])) {
$token->setResource($tkn['resource']);
@ -591,15 +556,15 @@ class Client implements ClientInterface
if (isset($tkn['pairingCode'])) {
$token->setPairingCode($tkn['pairingCode']);
$token->setPairingExpiration($pairingExpiration->setTimestamp(floor($tkn['pairingExpiration'] / 1000)));
$token->setPairingExpiration($pairingExpiration->setTimestamp(floor($tkn['pairingExpiration']/1000)));
}
return $token;
}
/**
* Returns the Response object that BitPay returned from
* the request that was sent.
* Returns the Response object that BitPay returned from the request that
* was sent
*
* @return ResponseInterface
*/
@ -609,7 +574,7 @@ class Client implements ClientInterface
}
/**
* Returns the request object that was sent to BitPay.
* Returns the request object that was sent to BitPay
*
* @return RequestInterface
*/
@ -625,7 +590,6 @@ class Client implements ClientInterface
{
$this->request = $this->createNewRequest();
$this->request->setMethod(Request::METHOD_GET);
if ($this->token && $this->token->getFacade() === 'merchant') {
$this->request->setPath(sprintf('invoices/%s?token=%s', $invoiceId, $this->token->getToken()));
$this->addIdentityHeader($this->request);
@ -633,9 +597,7 @@ class Client implements ClientInterface
} else {
$this->request->setPath(sprintf('invoices/%s', $invoiceId));
}
$this->response = $this->sendRequest($this->request);
$body = json_decode($this->response->getBody(), true);
if (isset($body['error'])) {
@ -643,13 +605,17 @@ class Client implements ClientInterface
}
$data = $body['data'];
$invoice = new \Bitpay\Invoice();
$invoice = $this->fillInvoiceData($invoice, $data);
return $invoice;
}
/**
* @param RequestInterface $request
* @return ResponseInterface
@ -666,12 +632,11 @@ class Client implements ClientInterface
/**
* @param RequestInterface $request
* @throws \Exception
*/
protected function addIdentityHeader(RequestInterface $request)
{
if (null === $this->publicKey) {
throw new \Exception('[ERROR] In Client::addIdentityHeader(): No public key value found. Please set your kublic key first before you can add the x-identity header.');
throw new \Exception('Please set your Public Key.');
}
$request->setHeader('x-identity', (string) $this->publicKey);
@ -679,7 +644,6 @@ class Client implements ClientInterface
/**
* @param RequestInterface $request
* @throws \Exception
*/
protected function addSignatureHeader(RequestInterface $request)
{
@ -720,25 +684,20 @@ class Client implements ClientInterface
/**
* Prepares the request object by adding additional headers
*
* @see http://en.wikipedia.org/wiki/User_agent
* @param RequestInterface $request
*/
protected function prepareRequestHeaders(RequestInterface $request)
{
// @see http://en.wikipedia.org/wiki/User_agent
$request->setHeader(
'User-Agent',
sprintf('%s/%s (PHP %s)', self::NAME, self::VERSION, phpversion())
);
$request->setHeader('X-BitPay-Plugin-Info', sprintf('%s/%s', self::NAME, self::VERSION));
$request->setHeader('Content-Type', 'application/json');
$request->setHeader('X-Accept-Version', '2.0.0');
}
/**
* @param string $price
* @param string $currency
*/
protected function checkPriceAndCurrency($price, $currency)
{
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -10,20 +10,34 @@ use Bitpay\InvoiceInterface;
use Bitpay\PayoutInterface;
/**
* Interface for class that sends request(s) to BitPay.
* Sends request(s) to bitpay server
*
* @package Bitpay
*/
interface ClientInterface
{
const TESTNET = '0x6F';
const LIVENET = '0x00';
/**
* These can be changed/updated so when the request is sent to BitPay it
* gives insight into what is making the calls.
*
* @see RFC2616 section 14.43 for User-Agent Format
*/
const NAME = 'BitPay PHP-Client';
const VERSION = '2.2.20';
const NAME = 'BitPay PHP-Client BTCPAY';
const VERSION = '2.2.23';
//public function createApplication(ApplicationInterface $application);
//public function createBill(BillInterface $bill);
//public function getBills($status = null);
//public function getBill($billId);
//public function updateBill(BillInterface $bill);
//public function createAccessToken(AccessTokenInterface $accessToken);
//public function getAccessTokens();
//public function getAccessToken($keyId);
public function getCurrencies();
@ -33,6 +47,7 @@ interface ClientInterface
* @throws \Exception
*/
public function createInvoice(InvoiceInterface $invoice);
//public function getInvoices();
/**
* @param $invoiceId
@ -41,9 +56,17 @@ interface ClientInterface
*/
public function getInvoice($invoiceId);
//public function getLedgers();
//public function getLedger(CurrencyInterface $currency);
//public function getOrgs();
//public function getOrg($orgId);
//public function updateOrg(OrgInterface $org);
/**
* Create a Payout Request on Bitpay.
*
* Create a Payout Request on Bitpay
* @param PayoutInterface $payout
* @return PayoutInterface|mixed
* @throws \Exception
@ -71,11 +94,18 @@ interface ClientInterface
*/
public function deletePayout(PayoutInterface $payout);
//public function updatePayout(PayoutInterface $payout);
//public function getRates();
//public function getRate(CurrencyInterface $currency);
/**
* Get an array of tokens indexed by facade.
*
* Get an array of tokens indexed by facade
* @return array
* @throws \Exception
*/
public function getTokens();
//public function getUser();
//public function updateUser(UserInterface $user);
}

View File

@ -1,13 +1,7 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
/**
* @package Bitpay
*/
class ConnectionException extends \Exception
{

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -44,6 +44,8 @@ class Request implements RequestInterface
*/
protected $path;
/**
*/
public function __construct()
{
// Set some sane default headers
@ -60,7 +62,7 @@ class Request implements RequestInterface
/**
* Converts this request into a standard HTTP/1.1 message to be sent over
* the wire.
* the wire
*
* @return string
*/
@ -91,7 +93,7 @@ class Request implements RequestInterface
/**
* Set the method of the request, for known methods see the
* RequestInterface.
* RequestInterface
*
* @param string $method
*/
@ -108,7 +110,7 @@ class Request implements RequestInterface
return $this->uri;
}
/**
/**
* @inheritdoc
*/
public function getFullUri()
@ -128,7 +130,6 @@ class Request implements RequestInterface
public function setUri($uri)
{
$this->uri = $uri;
return $this;
}
@ -139,7 +140,6 @@ class Request implements RequestInterface
{
// remove invalid headers
$headers = $this->headers;
foreach ($headers as $header => $value) {
if (empty($header) || empty($value)) {
unset($headers[$header]);
@ -149,13 +149,9 @@ class Request implements RequestInterface
return $headers;
}
/**
* @return array
*/
public function getHeaderFields()
{
$fields = array();
foreach ($this->getHeaders() as $header => $value) {
$fields[] = sprintf('%s: %s', $header, $value);
}
@ -175,22 +171,20 @@ class Request implements RequestInterface
$return .= sprintf("%s: %s\r\n", $h, $v);
}
return $return . "\r\n";
return $return."\r\n";
}
/**
* Set a http header for the request.
* Set a http header for the request
*
* @param string $header
* @param string $value
* @throws \Exception
*/
public function setHeader($header, $value)
{
if (is_array($value)) {
throw new \Exception('Could not set the header: ' . $header);
throw new \Exception('Could not set the header: '.$header);
}
$this->headers[$header] = $value;
}
@ -203,10 +197,9 @@ class Request implements RequestInterface
}
/**
* Sets the body of the request.
* The the body of the request
*
* @param string $body
* @return Request
*/
public function setBody($body)
{
@ -226,7 +219,6 @@ class Request implements RequestInterface
/**
* @param string $host
* @return Request
*/
public function setPath($path)
{

View File

@ -1,12 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
/**
*
* @package Bitpay
*/
interface RequestInterface

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
/**
* Generic Response class used to parse a response from a server.
* Generic Response object used to parse a response from a server
*
* @package Bitpay
*/
@ -33,6 +33,8 @@ class Response implements ResponseInterface
*/
protected $statusCode;
/**
*/
public function __construct($raw = null)
{
$this->headers = array();
@ -46,7 +48,7 @@ class Response implements ResponseInterface
*/
public function __toString()
{
return (string)$this->raw;
return (string) $this->raw;
}
/**
@ -68,7 +70,7 @@ class Response implements ResponseInterface
$linesLen = count($lines);
for ($i = 0; $i < $linesLen; $i++) {
if (0 === $i) {
if (0 == $i) {
preg_match('/^HTTP\/(\d\.\d)\s(\d+)\s(.+)/', $lines[$i], $statusLine);
$response->setStatusCode($statusCode = $statusLine[2]);
@ -102,11 +104,12 @@ class Response implements ResponseInterface
/**
* @param integer
* @return Response
*
* @return ResponseInterface
*/
public function setStatusCode($statusCode)
{
$this->statusCode = (integer)$statusCode;
$this->statusCode = (integer) $statusCode;
return $this;
}
@ -123,7 +126,6 @@ class Response implements ResponseInterface
* Set the body of the response
*
* @param string $body
* @return Response
*/
public function setBody($body)
{
@ -143,7 +145,6 @@ class Response implements ResponseInterface
/**
* @param string $header
* @param string $value
* @return Response
*/
public function setHeader($header, $value)
{

View File

@ -1,12 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Client;
/**
*
* @package Bitpay
*/
interface ResponseInterface

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -15,42 +15,35 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
* documentation as well.
*
* @see http://symfony.com/doc/current/components/config/definition.html
*
* @package Bitpay
*/
class Configuration implements ConfigurationInterface
{
private $pubfilename = '/.bitpay/api.pub';
private $prifilename = '/.bitpay/api.key';
private $sinfilename = '/.bitpay/api.sin';
private $defstorage = 'Bitpay\Storage\EncryptedFilesystemStorage';
private $adapters = array('curl', 'mock');
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('bitpay');
$rootNode
->children()
->scalarNode('public_key')
->info('Public Key Filename')
->defaultValue($this->getPubKeyFilename())
->defaultValue(getenv('HOME').'/.bitpay/api.pub')
->end()
->scalarNode('private_key')
->info('Private Key Filename')
->defaultValue($this->getPriKeyFilename())
->defaultValue(getenv('HOME').'/.bitpay/api.key')
->end()
->scalarNode('sin_key')
->info('SIN Filename')
->defaultValue($this->getSinFilename())
->info('Private Key Filename')
->defaultValue(getenv('HOME').'/.bitpay/api.sin')
->end()
->enumNode('adapter')
->values($this->adapters)
->values(array('curl', 'mock'))
->info('Client Adapter')
->defaultValue($this->adapters[0])
->defaultValue('curl')
->end()
->append($this->addKeyStorageNode())
->scalarNode('key_storage_password')
@ -63,13 +56,11 @@ class Configuration implements ConfigurationInterface
}
/**
* Adds the key_storage node with validation rules.
* Adds the key_storage node with validation rules
*
* key_storage MUST:
* * implement Bitpay\Storage\StorageInterface
* * be a class that can be loaded
*
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition
* @throws \Exception
*/
protected function addKeyStorageNode()
{
@ -78,7 +69,7 @@ class Configuration implements ConfigurationInterface
$node
->info('Class that is used to store your keys')
->defaultValue($this->defstorage)
->defaultValue('Bitpay\Storage\EncryptedFilesystemStorage')
->validate()
->always()
->then(function ($value) {
@ -92,8 +83,13 @@ class Configuration implements ConfigurationInterface
}
// requires PHP >= 5.3.7
if (is_subclass_of($value, 'Bitpay\Storage\StorageInterface') === false) {
throw new \Exception('[ERROR] In Configuration::addKeyStorageNode(): "' . $value . '" does not implement "Bitpay\Storage\StorageInterface".');
if (!is_subclass_of($value, 'Bitpay\Storage\StorageInterface')) {
throw new \Exception(
sprintf(
'"%s" does not implement "Bitpay\Storage\StorageInterface"',
$value
)
);
}
return $value;
@ -102,28 +98,4 @@ class Configuration implements ConfigurationInterface
return $node;
}
/**
* @return string
*/
private function getPubKeyFilename()
{
return getenv('HOME') . $this->pubfilename;
}
/**
* @return string
*/
private function getPriKeyFilename()
{
return getenv('HOME') . $this->prifilename;
}
/**
* @return string
*/
private function getSinFilename()
{
return getenv('HOME') . $this->sinfilename;
}
}

View File

@ -1,11 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
use Bitpay\Client;
/**
* For the most part this should conform to ISO 4217
*

View File

@ -1,14 +1,15 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* This is the currency code set for the price setting. The currencies supported are any
* of the codes listed on this page: https://bitpay.com/bitcoin-exchange-rates
* This is the currency code set for the price setting.  The pricing currencies
* currently supported are USD, EUR, BTC, and all of the codes listed on this page:
* https://bitpay.com/bitcoin­exchange­rates
*
* @package Bitpay
*/

View File

@ -0,0 +1,16 @@
<?php
namespace Bitpay;
class CurrencyUnrestricted extends Currency
{
/**
* Overrides the parent method to allow any currency symbol to be set.
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/**
* @license Copyright 2011-2017 BitPay Inc., MIT License
* @license Copyright 2011-2017 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
-->

View File

@ -1,17 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
use DateTime;
use DateTimeZone;
date_default_timezone_set('UTC');
/**
*
* @package Bitpay
*/
class Invoice implements InvoiceInterface
@ -24,7 +20,7 @@ class Invoice implements InvoiceInterface
/**
* @var string
*/
protected $orderId = '';
protected $orderId;
/**
* @var ItemInterface
@ -34,32 +30,32 @@ class Invoice implements InvoiceInterface
/**
* @var string
*/
protected $transactionSpeed = '';
protected $transactionSpeed = self::TRANSACTION_SPEED_MEDIUM;
/**
* @var string
*/
protected $notificationEmail = '';
protected $notificationEmail;
/**
* @var string
*/
protected $notificationUrl = '';
protected $notificationUrl;
/**
* @var string
*/
protected $redirectUrl = '';
protected $redirectUrl;
/**
* @var string
*/
protected $posData = '';
protected $posData;
/**
* @var string
*/
protected $status = '';
protected $status;
/**
* @var boolean
@ -74,26 +70,26 @@ class Invoice implements InvoiceInterface
/**
* @var string
*/
protected $id = '';
protected $id;
/**
* @var string
*/
protected $url = '';
protected $url;
/**
* @deprecated Deprecated with introduction of BCH
* @var float
*/
protected $btcPrice = 0.000000;
protected $btcPrice;
/**
* @var DateTime
* @var \DateTime
*/
protected $invoiceTime;
/**
* @var DateTime
* @var \DateTime
*/
protected $expirationTime;
@ -108,15 +104,15 @@ class Invoice implements InvoiceInterface
protected $buyer;
/**
* @var string
* @var
*/
protected $exceptionStatus = '';
protected $exceptionStatus;
/**
* @deprecated Deprecated with introduction of BCH
* @var float
* @var
*/
protected $btcPaid = 0.000000;
protected $btcPaid;
/**
* @var
@ -125,12 +121,12 @@ class Invoice implements InvoiceInterface
/**
* @deprecated Deprecated with introduction of BCH
* @var float
* @var
*/
protected $rate = 0.000000;
protected $rate;
/**
* @var Token
* @var
*/
protected $token;
@ -160,36 +156,16 @@ class Invoice implements InvoiceInterface
protected $paymentTotals;
/**
* @var PaymentUrlInterface
*/
protected $paymentUrls;
public function __construct(
$transactionSpeed = self::TRANSACTION_SPEED_MEDIUM,
$fullNotifications = true,
$item = null,
$currency = null,
$orderId = '',
$posData = ''
) {
$this->currency = $currency;
$this->transactionSpeed = $transactionSpeed;
$this->fullNotifications = $fullNotifications;
$this->item = $item;
$this->orderId = $orderId;
$this->posData = $posData;
}
* @var array
*/
protected $paymentCurrencies;
/**
* @inheritdoc
*/
public function getPrice()
{
if (is_a($this->item, '\Bitpay\Item')) {
return $this->getItem()->getPrice();
}
return 0.000000;
return $this->getItem()->getPrice();
}
/**
@ -202,12 +178,13 @@ class Invoice implements InvoiceInterface
/**
* @param float $price
* @return Invoice
*
* @return InvoiceInterface
*/
public function setPrice($price)
{
if (is_numeric($price)) {
$this->getItem()->setPrice(floatval($price));
if (!empty($price)) {
$this->getItem()->setPrice($price);
}
return $this;
@ -232,20 +209,17 @@ class Invoice implements InvoiceInterface
*/
public function getCurrency()
{
if ($this->currency === null) {
$this->currency = new Currency('BTC');
}
return $this->currency;
}
/**
* @param CurrencyInterface $currency
* @return Invoice
*
* @return InvoiceInterface
*/
public function setCurrency(CurrencyInterface $currency)
{
if (is_a($currency, '\Bitpay\Currency')) {
if (!empty($currency)) {
$this->currency = $currency;
}
@ -257,7 +231,10 @@ class Invoice implements InvoiceInterface
*/
public function getItem()
{
if (null === $this->item) {
// If there is not an item already set, we need to use a default item
// so that some methods do not throw errors about methods and
// non-objects.
if (null == $this->item) {
$this->item = new Item();
}
@ -266,11 +243,12 @@ class Invoice implements InvoiceInterface
/**
* @param ItemInterface $item
* @return Invoice
*
* @return InvoiceInterface
*/
public function setItem(ItemInterface $item)
{
if (is_a($item, '\Bitpay\Item')) {
if (!empty($item)) {
$this->item = $item;
}
@ -282,7 +260,8 @@ class Invoice implements InvoiceInterface
*/
public function getBuyer()
{
if ($this->buyer === null) {
// Same logic as getItem method
if (null == $this->buyer) {
$this->buyer = new Buyer();
}
@ -291,11 +270,12 @@ class Invoice implements InvoiceInterface
/**
* @param BuyerInterface $buyer
* @return Invoice
*
* @return InvoiceInterface
*/
public function setBuyer(BuyerInterface $buyer)
{
if (is_a($buyer, '\Bitpay\Buyer')) {
if (!empty($buyer)) {
$this->buyer = $buyer;
}
@ -312,20 +292,13 @@ class Invoice implements InvoiceInterface
/**
* @param string $transactionSpeed
* @return Invoice
*
* @return InvoiceInterface
*/
public function setTransactionSpeed($transactionSpeed)
{
switch (strtolower(trim($transactionSpeed))) {
case 'high':
$this->transactionSpeed = self::TRANSACTION_SPEED_HIGH;
break;
case 'medium':
$this->transactionSpeed = self::TRANSACTION_SPEED_MEDIUM;
break;
case 'low':
default:
$this->transactionSpeed = self::TRANSACTION_SPEED_LOW;
if (!empty($transactionSpeed) && ctype_print($transactionSpeed)) {
$this->transactionSpeed = trim($transactionSpeed);
}
return $this;
@ -341,11 +314,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $notificationEmail
* @return Invoice
*
* @return InvoiceInterface
*/
public function setNotificationEmail($notificationEmail)
{
if (filter_var($notificationEmail, FILTER_VALIDATE_EMAIL)) {
if (!empty($notificationEmail) && ctype_print($notificationEmail)) {
$this->notificationEmail = trim($notificationEmail);
}
@ -362,11 +336,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $notificationUrl
* @return Invoice
*
* @return InvoiceInterface
*/
public function setNotificationUrl($notificationUrl)
{
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $notificationUrl)) {
if (!empty($notificationUrl) && ctype_print($notificationUrl)) {
$this->notificationUrl = trim($notificationUrl);
}
@ -383,11 +358,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $redirectUrl
* @return Invoice
*
* @return InvoiceInterface
*/
public function setRedirectUrl($redirectUrl)
{
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $redirectUrl)) {
if (!empty($redirectUrl) && ctype_print($redirectUrl)) {
$this->redirectUrl = trim($redirectUrl);
}
@ -404,11 +380,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $posData
* @return Invoice
*
* @return InvoiceInterface
*/
public function setPosData($posData)
{
if (is_string($posData)) {
if (!empty($posData)) {
$this->posData = $posData;
}
@ -425,11 +402,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $status
* @return Invoice
*
* @return InvoiceInterface
*/
public function setStatus($status)
{
if (is_string($status)) {
if (!empty($status) && ctype_print($status)) {
$this->status = trim($status);
}
@ -476,11 +454,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $id
* @return Invoice
*
* @return InvoiceInterface
*/
public function setId($id)
{
if (is_string($id)) {
if (!empty($id) && ctype_print($id)) {
$this->id = trim($id);
}
@ -497,11 +476,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $url
* @return Invoice
*
* @return InvoiceInterface
*/
public function setUrl($url)
{
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)) {
if (!empty($url) && ctype_print($url)) {
$this->url = trim($url);
}
@ -520,12 +500,13 @@ class Invoice implements InvoiceInterface
/**
* @deprecated Deprecated with introduction of BCH
* @param float $btcPrice
* @return Invoice
*
* @return InvoiceInterface
*/
public function setBtcPrice($btcPrice)
{
if (is_numeric($btcPrice)) {
$this->btcPrice = floatval($btcPrice);
if (!empty($btcPrice)) {
$this->btcPrice = $btcPrice;
}
return $this;
@ -541,18 +522,18 @@ class Invoice implements InvoiceInterface
/**
* @param DateTime $invoiceTime
* @return Invoice
*
* @return InvoiceInterface
*/
public function setInvoiceTime($invoiceTime)
{
if (is_a($invoiceTime, 'DateTime')) {
$this->invoiceTime = $invoiceTime;
} else if (is_numeric($invoiceTime)) {
$invoiceDateTime = new DateTime('', new DateTimeZone('UTC'));
$invoiceDateTime = new \DateTime('', new \DateTimeZone("UTC"));
$invoiceDateTime->setTimestamp($invoiceTime);
$this->invoiceTime = $invoiceDateTime;
}
return $this;
}
@ -566,18 +547,18 @@ class Invoice implements InvoiceInterface
/**
* @param DateTime $expirationTime
* return Invoice
*
* return InvoiceInterface
*/
public function setExpirationTime($expirationTime)
{
if (is_a($expirationTime, 'DateTime')) {
$this->expirationTime = $expirationTime;
} else if (is_numeric($expirationTime)) {
$expirationDateTime = new DateTime('', new DateTimeZone('UTC'));
$expirationDateTime = new \DateTime('', new \DateTimeZone("UTC"));
$expirationDateTime->setTimestamp($expirationTime);
$this->expirationTime = $expirationDateTime;
}
return $this;
}
@ -591,18 +572,18 @@ class Invoice implements InvoiceInterface
/**
* @param DateTime $currentTime
* @return Invoice
*
* @return InvoiceInterface
*/
public function setCurrentTime($currentTime)
{
if (is_a($currentTime, 'DateTime')) {
$this->currentTime = $currentTime;
} else if (is_numeric($currentTime)) {
$currentDateTime = new DateTime('', new DateTimeZone('UTC'));
$currentDateTime = new \DateTime('', new \DateTimeZone("UTC"));
$currentDateTime->setTimestamp($currentTime);
$this->currentTime = $currentDateTime;
}
return $this;
}
@ -616,14 +597,12 @@ class Invoice implements InvoiceInterface
/**
* @param string $orderId
* @return Invoice
*
* @return InvoiceInterface
*/
public function setOrderId($orderId)
{
if (is_string($orderId)) {
$this->orderId = trim($orderId);
}
$this->orderId = $orderId;
return $this;
}
@ -659,7 +638,7 @@ class Invoice implements InvoiceInterface
$firstName = $this->getBuyer()->getFirstName();
$lastName = $this->getBuyer()->getLastName();
return trim($firstName . ' ' . $lastName);
return trim($firstName.' '.$lastName);
}
/**
@ -740,7 +719,8 @@ class Invoice implements InvoiceInterface
/**
* @param
* @return Invoice
*
* @return InvoiceInterface
*/
public function setExceptionStatus($exceptionStatus)
{
@ -765,7 +745,7 @@ class Invoice implements InvoiceInterface
*/
public function setBtcPaid($btcPaid)
{
if (is_numeric($btcPaid)) {
if (isset($btcPaid)) {
$this->btcPaid = $btcPaid;
}
@ -811,8 +791,8 @@ class Invoice implements InvoiceInterface
*/
public function setRate($rate)
{
if (is_numeric($rate)) {
$this->rate = floatval($rate);
if (!empty($rate)) {
$this->rate = $rate;
}
return $this;
@ -848,20 +828,15 @@ class Invoice implements InvoiceInterface
{
return $this->token;
}
/**
* @param TokenInterface $token
* @return Invoice
* @return InvoiceInterface
*/
public function setToken(TokenInterface $token)
{
if (is_a($token, '\Bitpay\Token')) {
$this->token = $token;
}
$this->token = $token;
return $this;
}
/**
* @inheritdoc
*/
@ -949,35 +924,20 @@ class Invoice implements InvoiceInterface
return $this;
}
/**
* @return PaymentUrlInterface
*/
public function getPaymentUrls()
{
if ($this->paymentUrls === null) {
$this->paymentUrls = new PaymentUrlSet();
}
return $this->paymentUrls;
/**
* @inheritdoc
*/
public function getPaymentCurrencies() {
return $this->paymentCurrencies;
}
/**
* @param PaymentUrlInterface $paymentUrls
* @return Invoice
* @inheritdoc
*/
public function setPaymentUrls(PaymentUrlInterface $paymentUrls)
{
$this->paymentUrls = $paymentUrls;
public function setPaymentCurrencies($paymentCurrencies) {
$this->paymentCurrencies = $paymentCurrencies;
return $this;
}
/**
* @param string $paymentUrlType
* @return string
*/
public function getPaymentUrl($paymentUrlType)
{
return $this->getPaymentUrls()->getUrl($paymentUrlType);
return $this;
}
}

View File

@ -1,12 +1,14 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* Invoice
*
* @package Bitpay
*/
interface InvoiceInterface
@ -78,7 +80,7 @@ interface InvoiceInterface
* specified in a currency other than BTC, the price will be converted into BTC at
* market exchange rates to determine the amount collected from the buyer.
*
* @return float
* @return string
*/
public function getPrice();
@ -94,10 +96,6 @@ interface InvoiceInterface
public function getCurrency();
/**
* If there is not an item already set, we need to use a default item
* so that some methods do not throw errors about methods and
* non-objects.
*
* @return ItemInterface
*/
public function getItem();
@ -206,7 +204,7 @@ interface InvoiceInterface
* The amount of bitcoins being requested for payment of this invoice (same as the
* price if the merchant set the price in BTC).
*
* @return float
* @return string
*/
public function getBtcPrice();
@ -355,22 +353,18 @@ interface InvoiceInterface
public function getBuyerPhone();
/**
* Returns exception status.
*/
public function getExceptionStatus();
/**
* Returns the amount of BTC paid.
*/
public function getBtcPaid();
/**
* Returns the exchange rate.
*/
public function getRate();
/**
* Returns the token for this resource.
*/
public function getToken();
@ -387,9 +381,20 @@ interface InvoiceInterface
public function getRefundAddresses();
/**
* Returns a set of payment urls.
* Get the enforced transaction currencies.
*
* @return PaymentUrlInterface
* @return array|null
*/
public function getPaymentUrls();
public function getPaymentCurrencies();
/**
* Set specific invoice currencies and to enforce them on payment step.
*
* @param array $paymentCurrencies
* The currencies need to match what is supported by BTCPay Server.
* E.g. BTC, BTC_ONCHAIN, BTC_OFFCHAIN, LTC, XMR_MONEROLIKE etc.
*
* @return InvoiceInterface
*/
public function setPaymentCurrencies($paymentCurrencies);
}

View File

@ -6,7 +6,10 @@
namespace Bitpay;
use Bitpay\Client;
/**
*
* @package Bitpay
*/
class Item implements ItemInterface
@ -41,6 +44,8 @@ class Item implements ItemInterface
*/
protected $physical;
/**
*/
public function __construct()
{
$this->physical = false;
@ -56,6 +61,7 @@ class Item implements ItemInterface
/**
* @param string $code
*
* @return ItemInterface
*/
public function setCode($code)
@ -75,6 +81,7 @@ class Item implements ItemInterface
/**
* @param string $description
*
* @return ItemInterface
*/
public function setDescription($description)
@ -86,6 +93,8 @@ class Item implements ItemInterface
/**
* @inheritdoc
*
* @return float
*/
public function getPrice()
{
@ -104,7 +113,8 @@ class Item implements ItemInterface
/**
* @param mixed $price A float, integer, or en_US formatted numeric string
* @return Item
*
* @return ItemInterface
*/
public function setPrice($price)
{
@ -138,7 +148,8 @@ class Item implements ItemInterface
/**
* @param integer $quantity
* @return Item
*
* @return ItemInterface
*/
public function setQuantity($quantity)
{
@ -157,7 +168,8 @@ class Item implements ItemInterface
/**
* @param boolean $physical
* @return Item
*
* @return ItemInterface
*/
public function setPhysical($physical)
{

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -30,12 +30,12 @@ interface ItemInterface
public function getDescription();
/**
* @return float
* @return string
*/
public function getPrice();
/**
* @return integer
* @return string
*/
public function getTaxIncluded();

View File

@ -1,31 +0,0 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* Interface PaymentUrlInterface
* @package Bitpay
*/
interface PaymentUrlInterface
{
/**
* This is a list of returned payment url types
*
*/
const BIP_21 = 'BIP21';
const BIP_72 = 'BIP72';
const BIP_72B = 'BIP72b';
const BIP_73 = 'BIP73';
/**
* Return the account parameter given by Bitpay.
*
* @return string
*/
public function getUrl($urlType);
}

View File

@ -1,51 +0,0 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* @package Bitpay
*/
class PaymentUrlSet implements PaymentUrlInterface
{
/**
* @var array
*/
protected $paymentUrls;
public function __construct(array $paymentUrls = array())
{
$this->paymentUrls = $paymentUrls;
}
/**
* Return the account parameter given by Bitpay.
*
* @return string
*/
public function getUrl($urlType)
{
if (array_key_exists($urlType, $this->paymentUrls)) {
return $this->paymentUrls[$urlType];
}
return null;
}
/**
* Return the account parameter given by Bitpay.
*
* @return PaymentUrlInterface
*/
public function setUrls(array $paymentUrls)
{
$this->paymentUrls = $paymentUrls;
return $this;
}
}

View File

@ -6,8 +6,6 @@
namespace Bitpay;
date_default_timezone_set('UTC');
/**
* Class Payout
* @package Bitpay

View File

@ -6,8 +6,6 @@
namespace Bitpay;
date_default_timezone_set('UTC');
/**
* Class PayoutInstruction
* @package Bitpay

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -12,7 +12,7 @@ use Bitpay\Util\SecureRandom;
use Bitpay\Math\Math;
/**
* @package Bitpay
* @package Bitcore
* @see https://en.bitcoin.it/wiki/List_of_address_prefixes
*/
class PrivateKey extends Key
@ -81,7 +81,7 @@ class PrivateKey extends Key
do {
$privateKey = \Bitpay\Util\SecureRandom::generateRandom(32);
$this->hex = strtolower(bin2hex($privateKey));
} while (Math::cmp('0x'.$this->hex, '1') <= 0 || Math::cmp('0x' . $this->hex, '0x' . Secp256k1::N) >= 0);
} while (Math::cmp('0x'.$this->hex, '1') <= 0 || Math::cmp('0x'.$this->hex, '0x'.Secp256k1::N) >= 0);
$this->dec = Util::decodeHex($this->hex);
@ -117,11 +117,9 @@ class PrivateKey extends Key
}
/**
* Creates an ECDSA signature of $data.
* Creates an ECDSA signature of $message
*
* @param string
* @return string
* @throws \Exception
*/
public function sign($data)
{
@ -137,19 +135,19 @@ class PrivateKey extends Key
do {
if (substr(strtolower($this->hex), 0, 2) != '0x') {
$d = '0x' . $this->hex;
$d = '0x'.$this->hex;
} else {
$d = $this->hex;
}
$k = SecureRandom::generateRandom(32);
$k_hex = '0x' . strtolower(bin2hex($k));
$n_hex = '0x' . Secp256k1::N;
$k_hex = '0x'.strtolower(bin2hex($k));
$n_hex = '0x'.Secp256k1::N;
$Gx = '0x' . substr(Secp256k1::G, 2, 64);
$Gy = '0x' . substr(Secp256k1::G, 66, 64);
$Gx = '0x'.substr(Secp256k1::G, 2, 64);
$Gy = '0x'.substr(Secp256k1::G, 66, 64);
$P = new Point($Gx, $Gy);
@ -157,10 +155,11 @@ class PrivateKey extends Key
$R = Util::doubleAndAdd($k_hex, $P);
$Rx_hex = Util::encodeHex($R->getX());
$Rx_hex = str_pad($Rx_hex, 64, '0', STR_PAD_LEFT);
// r = x1 mod n
$r = Math::mod('0x' . $Rx_hex, $n_hex);
$r = Math::mod('0x'.$Rx_hex, $n_hex);
// s = k^-1 * (e+d*r) mod n
$edr = Math::add($e, Math::mul($d, $r));
@ -212,44 +211,42 @@ class PrivateKey extends Key
$dec = Util::decodeHex($r);
while (Math::cmp($dec, '0') > 0) {
$dv = Math::div($dec, '256');
$rem = Math::mod($dec, '256');
$dec = $dv;
$byte = $byte . $digits[$rem];
$dv = Math::div($dec, '256');
$rem = Math::mod($dec, '256');
$dec = $dv;
$byte = $byte.$digits[$rem];
}
$byte = strrev($byte);
// msb check
if (Math::cmp('0x' . bin2hex($byte[0]), '0x80') >= 0) {
$byte = chr(0x00) . $byte;
if (Math::cmp('0x'.bin2hex($byte[0]), '0'.'x80') >= 0) {
$byte = chr(0x00).$byte;
}
$retval['bin_r'] = bin2hex($byte);
$seq = chr(0x02) . chr(strlen($byte)) . $byte;
$seq = chr(0x02).chr(strlen($byte)).$byte;
$dec = Util::decodeHex($s);
$byte = '';
while (Math::cmp($dec, '0') > 0) {
$dv = Math::div($dec, '256');
$rem = Math::mod($dec, '256');
$dec = $dv;
$byte = $byte . $digits[$rem];
$dv = Math::div($dec, '256');
$rem = Math::mod($dec, '256');
$dec = $dv;
$byte = $byte.$digits[$rem];
}
$byte = strrev($byte);
// msb check
if (Math::cmp('0x' . bin2hex($byte[0]), '0x80') >= 0) {
$byte = chr(0x00) . $byte;
if (Math::cmp('0x'.bin2hex($byte[0]), '0'.'x80') >= 0) {
$byte = chr(0x00).$byte;
}
$retval['bin_s'] = bin2hex($byte);
$seq = $seq . chr(0x02) . chr(strlen($byte)) . $byte;
$seq = chr(0x30) . chr(strlen($seq)) . $seq;
$seq = $seq.chr(0x02).chr(strlen($byte)).$byte;
$seq = chr(0x30).chr(strlen($seq)).$seq;
$retval['seq'] = bin2hex($seq);
return $retval;
@ -260,7 +257,6 @@ class PrivateKey extends Key
*
* @param string $pem_data The data to decode.
* @return array The keypair info.
* @throws \Exception
*/
public function pemDecode($pem_data)
{
@ -310,7 +306,6 @@ class PrivateKey extends Key
*
* @param array $keypair The keypair info.
* @return string The data to decode.
* @throws \Exception
*/
public function pemEncode($keypair)
{
@ -347,7 +342,7 @@ class PrivateKey extends Key
'a1_ele_len' => '44',
'bit_str_beg' => '03',
'bit_str_len' => '42',
'bit_str_val' => '00' . $keypair[1],
'bit_str_val' => '00'.$keypair[1],
);
$beg_ec_text = '-----BEGIN EC PRIVATE KEY-----';
@ -359,16 +354,16 @@ class PrivateKey extends Key
throw new \Exception('Invalid or corrupt secp256k1 keypair provided. Cannot encode the supplied data.');
}
$dec = Util::decodeHex('0x' . $dec);
$dec = Util::decodeHex('0x'.$dec);
while (Math::cmp($dec, '0') > 0) {
$dv = Math::div($dec, '256');
$rem = Math::mod($dec, '256');
$dec = $dv;
$byte = $byte . $digits[$rem];
$dv = Math::div($dec, '256');
$rem = Math::mod($dec, '256');
$dec = $dv;
$byte = $byte.$digits[$rem];
}
$byte = $beg_ec_text . "\r\n" . chunk_split(base64_encode(strrev($byte)), 64) . $end_ec_text;
$byte = $beg_ec_text."\r\n".chunk_split(base64_encode(strrev($byte)), 64).$end_ec_text;
$this->pemEncoded = $byte;

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -11,7 +11,7 @@ use Bitpay\Util\Secp256k1;
use Bitpay\Util\Util;
/**
* @package Bitpay
* @package Bitcore
*/
class PublicKey extends Key
{
@ -36,7 +36,7 @@ class PublicKey extends Key
return '';
}
if (Math::mod('0x'.$this->y, '0x02') == '1') {
if (Math::mod('0x'.$this->y, '0'.'x02') == '1') {
return sprintf('03%s', $this->x);
} else {
return sprintf('02%s', $this->x);
@ -45,7 +45,6 @@ class PublicKey extends Key
/**
* @param PrivateKey
* @return PublicKey
*/
public static function createFromPrivateKey(PrivateKey $private)
{
@ -56,8 +55,7 @@ class PublicKey extends Key
}
/**
* @param PrivateKey
* @return PublicKey
* @return KeyInterface
*/
public function setPrivateKey(PrivateKey $privateKey)
{
@ -70,8 +68,8 @@ class PublicKey extends Key
* Generates an uncompressed and compressed EC public key.
*
* @param \Bitpay\PrivateKey $privateKey
* @return \Bitpay\PublicKey
* @throws \Exception
*
* @return Bitpay\PublicKey
*/
public function generate(PrivateKey $privateKey = null)
{
@ -113,7 +111,6 @@ class PublicKey extends Key
$this->x = $RxHex;
$this->y = $RyHex;
$this->hex = sprintf('%s%s', $RxHex, $RyHex);
$this->dec = Util::decodeHex($this->hex);
@ -142,7 +139,6 @@ class PublicKey extends Key
if (null === $this->sin) {
$this->sin = new SinKey();
$this->sin->setPublicKey($this);
$this->sin->generate();
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -11,19 +11,15 @@ use Bitpay\Util\Gmp;
use Bitpay\Util\Util;
/**
* @package BitPay
* @package Bitcore
*/
class SinKey extends Key
{
/**
* Type 2 (ephemeral)
*/
const SIN_TYPE = '02';
// Type 2 (ephemeral)
const SIN_TYPE = '02';
/**
* Always the prefix!
* (well, right now)
*/
// Always the prefix!
// (well, right now)
const SIN_VERSION = '0F';
/**
@ -60,7 +56,6 @@ class SinKey extends Key
* https://en.bitcoin.it/wiki/Identity_protocol_v1
*
* @return SinKey
* @throws \Exception
*/
public function generate()
{
@ -75,6 +70,7 @@ class SinKey extends Key
}
$step1 = Util::sha256(Util::binConv($compressedValue), true);
$step2 = Util::ripe160($step1);
$step3 = sprintf(
@ -85,8 +81,10 @@ class SinKey extends Key
);
$step4 = Util::twoSha256(Util::binConv($step3), true);
$step5 = substr(bin2hex($step4), 0, 8);
$step6 = $step3 . $step5;
$step6 = $step3.$step5;
$this->value = Base58::encode($step6);

View File

@ -1,13 +1,12 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Storage;
/**
* @package Bitpay
*/
class EncryptedFilesystemStorage implements StorageInterface
{
@ -16,6 +15,11 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
private $password;
/**
* @var string
*/
private $unencoded_password;
/**
* Initialization Vector
*/
@ -36,7 +40,10 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
public function __construct($password)
{
$this->password = $password;
//to make this an non-breaking api change,
//I will have to keep both versions of the password
$this->password = base64_encode($password);
$this->unencoded_password = $password;
}
/**
@ -44,13 +51,17 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
public function persist(\Bitpay\KeyInterface $key)
{
$path = $key->getId();
$data = serialize($key);
$path = $key->getId();
$data = serialize($key);
$encoded = bin2hex(openssl_encrypt(
$data,
self::METHOD,
$this->password,
1,
self::IV
));
$encrypted = $this->dataEncrypt($data);
$encoded = $this->dataEncode($encrypted);
$this->saveToFile($encoded, $path);
file_put_contents($path, $encoded);
}
/**
@ -58,120 +69,25 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
public function load($id)
{
$encoded = $this->readFromFile($id);
$decoded = $this->dataDecode($encoded);
$decrypted = $this->dataDecrypt($decoded);
return unserialize($decrypted);
}
/**
* @param string $data
* @return string
* @throws \Exception
*/
private function dataEncrypt($data)
{
$encrypted = openssl_encrypt($data, self::METHOD, $this->password, self::OPENSSL_RAW_DATA, self::IV);
if ($encrypted === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::dataEncrypt(): Could not encrypt data "' . $data . '". OpenSSL error(s) are: "' . $this->getOpenSslErrors() . '".');
if (!is_file($id)) {
throw new \Exception(sprintf('Could not find "%s"', $id));
}
return $encrypted;
}
/**
* @param string $data
* @return string
* @throws \Exception
*/
private function dataDecrypt($data)
{
$decrypted = openssl_decrypt($data, self::METHOD, $this->password, self::OPENSSL_RAW_DATA, self::IV);
if ($decrypted === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::dataDecrypt(): Could not decrypt data "' . $data . '". OpenSSL error(s) are: "' . $this->getOpenSslErrors() . '".');
if (!is_readable($id)) {
throw new \Exception(sprintf('"%s" cannot be read, check permissions', $id));
}
return $decrypted;
}
$encoded = file_get_contents($id);
$decoded = openssl_decrypt(\Bitpay\Util\Util::binConv($encoded), self::METHOD, $this->password, 1, self::IV);
/**
* @param string $data
* @return string
* @throws \Exception
*/
private function dataEncode($data)
{
$encoded = base64_encode($data);
if ($encoded === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::dataEncode(): Could not encode data "' . $data . '".');
if (false === $decoded) {
$decoded = openssl_decrypt(\Bitpay\Util\Util::binConv($encoded), self::METHOD, $this->unencoded_password, 1, self::IV);
}
return $encoded;
}
/**
* @param string $data
* @return string
* @throws \Exception
*/
private function dataDecode($data)
{
$decoded = base64_decode($data, true);
if ($decoded === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::dataDecode(): Could not decode data "' . $data . '".');
if (false === $decoded) {
throw new \Exception('Could not decode key');
}
return $decoded;
}
/**
* @param string $data
* @param string $path
* @throws \Exception
*/
private function saveToFile($data, $path)
{
if (file_put_contents($path, $data) === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::saveToFile(): Could not write to the file "' . $path . '".');
}
}
/**
* @param string $path
* @return string
* @throws \Exception
*/
private function readFromFile($path)
{
if (is_file($path) === false || is_readable($path) === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::readFromFile(): The file "' . $path . '" does not exist or cannot be read, check permissions.');
}
$data = file_get_contents($path);
if ($data === false) {
throw new \Exception('[ERROR] In EncryptedFilesystemStorage::readFromFile(): The file "' . $path . '" cannot be read, check permissions.');
}
return $data;
}
/**
* @return string
*/
private function getOpenSslErrors()
{
$openssl_error_msg = '';
while ($msg = openssl_error_string()) {
$openssl_error_msg .= $msg . "\r\n";
}
return $openssl_error_msg;
return unserialize($decoded);
}
}

View File

@ -1,15 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Storage;
/**
* Used to persist keys to the filesystem.
*
* @package Bitpay
* Used to persist keys to the filesystem
*/
class FilesystemStorage implements StorageInterface
{
@ -18,12 +16,8 @@ class FilesystemStorage implements StorageInterface
*/
public function persist(\Bitpay\KeyInterface $key)
{
try {
$path = $key->getId();
file_put_contents($path, serialize($key));
} catch (\Exception $e) {
throw new \Exception('[ERROR] In FilesystemStorage::persist(): ' . $e->getMessage());
}
$path = $key->getId();
file_put_contents($path, serialize($key));
}
/**
@ -32,11 +26,11 @@ class FilesystemStorage implements StorageInterface
public function load($id)
{
if (!is_file($id)) {
throw new \Exception(sprintf('[ERROR] In FilesystemStorage::load(): Could not find "%s".', $id));
throw new \Exception(sprintf('Could not find "%s"', $id));
}
if (!is_readable($id)) {
throw new \Exception(sprintf('[ERROR] In FilesystemStorage::load(): "%s" cannot be read, check permissions.', $id));
throw new \Exception(sprintf('"%s" cannot be read, check permissions', $id));
}
return unserialize(file_get_contents($id));

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,21 +8,14 @@ namespace Bitpay\Storage;
/**
* @codeCoverageIgnore
* @package Bitpay
* @package Bitcore
*/
class MockStorage implements StorageInterface
{
/**
* @param Key $key
*/
public function persist(\Bitpay\KeyInterface $key)
{
}
/**
* @param string $id
* @return void
*/
public function load($id)
{
return;

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Storage;
/**
* @package Bitpay
* @package Bitcore
*/
interface StorageInterface
{
@ -18,6 +18,7 @@ interface StorageInterface
/**
* @param string $id
*
* @return KeyInterface
*/
public function load($id);

View File

@ -1,13 +1,11 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
date_default_timezone_set('UTC');
/**
* @package Bitpay
*/
@ -48,6 +46,8 @@ class Token implements TokenInterface
*/
protected $pairingExpiration;
/**
*/
public function __construct()
{
$this->policies = array();
@ -58,7 +58,7 @@ class Token implements TokenInterface
*/
public function __toString()
{
return (string)$this->getToken();
return (string) $this->getToken();
}
/**
@ -69,10 +69,6 @@ class Token implements TokenInterface
return $this->token;
}
/**
* @param string
* @return Token
*/
public function setToken($token)
{
$this->token = $token;
@ -88,10 +84,6 @@ class Token implements TokenInterface
return $this->resource;
}
/**
* @param string
* @return Token
*/
public function setResource($resource)
{
$this->resource = $resource;
@ -107,10 +99,6 @@ class Token implements TokenInterface
return $this->facade;
}
/**
* @param string
* @return Token
*/
public function setFacade($facade)
{
$this->facade = $facade;
@ -126,10 +114,6 @@ class Token implements TokenInterface
return $this->createdAt;
}
/**
* @param \DateTime
* @return Token
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
@ -145,10 +129,6 @@ class Token implements TokenInterface
return $this->policies;
}
/**
* @param string
* @return Token
*/
public function setPolicies($policies)
{
$this->policies = $policies;
@ -163,15 +143,11 @@ class Token implements TokenInterface
{
return $this->pairingCode;
}
/**
* @param string
* @return Token
*/
public function setPairingCode($pairingCode)
{
$this->pairingCode = $pairingCode;
return $this;
}
@ -183,10 +159,6 @@ class Token implements TokenInterface
return $this->pairingExpiration;
}
/**
* @param \DateTime
* @return Token
*/
public function setPairingExpiration(\DateTime $pairingExpiration)
{
$this->pairingExpiration = $pairingExpiration;

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -76,7 +76,8 @@ class User implements UserInterface
/**
* @param string $phone
* @return User
*
* @return UserInterface
*/
public function setPhone($phone)
{
@ -97,7 +98,8 @@ class User implements UserInterface
/**
* @param string $email
* @return User
*
* @return UserInterface
*/
public function setEmail($email)
{
@ -118,7 +120,8 @@ class User implements UserInterface
/**
* @param string $firstName
* @return User
*
* @return UserInterface
*/
public function setFirstName($firstName)
{
@ -139,7 +142,8 @@ class User implements UserInterface
/**
* @param string $lastName
* @return User
*
* @return UserInterface
*/
public function setLastName($lastName)
{
@ -160,7 +164,8 @@ class User implements UserInterface
/**
* @param array $address
* @return User
*
* @return UserInterface
*/
public function setAddress(array $address)
{
@ -181,7 +186,8 @@ class User implements UserInterface
/**
* @param string $city
* @return User
*
* @return UserInterface
*/
public function setCity($city)
{
@ -202,7 +208,8 @@ class User implements UserInterface
/**
* @param string $state
* @return User
*
* @return UserInterface
*/
public function setState($state)
{
@ -223,7 +230,8 @@ class User implements UserInterface
/**
* @param string $zip
* @return User
*
* @return UserInterface
*/
public function setZip($zip)
{
@ -244,7 +252,8 @@ class User implements UserInterface
/**
* @param string $country
* @return User
*
* @return UserInterface
*/
public function setCountry($country)
{
@ -257,6 +266,7 @@ class User implements UserInterface
/**
* @param bool $boolvalue
*
* @return User
*/
public function setAgreedToTOSandPP($boolvalue)
@ -267,7 +277,6 @@ class User implements UserInterface
return $this;
}
/**
* @return bool
*/

View File

@ -1,12 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
*
* @package Bitpay
*/
interface UserInterface

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -11,7 +11,7 @@ use Bitpay\Math\Math;
/**
* Utility class for encoding/decoding BASE-58 data
*
* @package Bitpay
* @package Bitcore
*/
final class Base58
{
@ -21,18 +21,17 @@ final class Base58
const BASE58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
/**
* Encodes a numeric string into BASE-58 format.
* Encodes $data into BASE-58 format
*
* @param string $data
* @return string $output_string
* @throws \Exception
*
* @return string
*/
public static function encode($data)
{
$dataLen = strlen($data);
if ($dataLen % 2 != 0 || $dataLen == 0) {
throw new \Exception('Invalid length data string provided to Base58::encode() method.');
throw new \Exception('Invalid Length');
}
$code_string = self::BASE58_CHARS;
@ -40,8 +39,8 @@ final class Base58
$output_string = '';
while (Math::cmp($x, '0') > 0) {
$q = Math::div($x, '58');
$r = Math::mod($x, '58');
$q = Math::div($x, 58);
$r = Math::mod($x, 58);
$output_string .= substr($code_string, intval($r), 1);
$x = $q;
}
@ -56,10 +55,11 @@ final class Base58
}
/**
* Decodes a numeric string from BASE-58 format.
* Decodes $data from BASE-58 format
*
* @param string $data
* @return string $return
*
* @return string
*/
public static function decode($data)
{
@ -74,11 +74,11 @@ final class Base58
$return = Util::encodeHex($return);
for ($i = 0; $i < $dataLen && substr($data, $i, 1) == '1'; $i++) {
$return = '00' . $return;
$return = '00'.$return;
}
if (strlen($return) % 2 != 0) {
$return = '0' . $return;
$return = '0'.$return;
}
return $return;

View File

@ -1,11 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
*/
interface CurveParameterInterface
{
public function aHex();

View File

@ -1,16 +1,11 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
* General error class.
*
* @package Bitpay
*/
class Error
{
/**
@ -102,7 +97,6 @@ class Error
if (empty($error_types)) {
$error_types = E_ALL | E_STRICT;
}
switch (strtolower($type)) {
case 'error':
switch (strtolower($action)) {

View File

@ -1,15 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
* Utility class for generating an operating system & enivironment fingerprint.
*
* @package Bitpay
* Utility class for generating an operating system & enivironment fingerprint
*/
class Fingerprint
{
@ -21,6 +19,7 @@ class Fingerprint
* takes the hash of that value to use as the env
* fingerprint.
*
* @param void
* @return string
*/
final public static function generate()
@ -48,11 +47,11 @@ class Fingerprint
self::$sigData[] = phpversion();
self::$sigData[] = get_current_user();
self::$sigData[] = php_uname('s') . php_uname('n') . php_uname('m') . PHP_OS . PHP_SAPI . ICONV_IMPL . ICONV_VERSION;
self::$sigData[] = php_uname('s').php_uname('n').php_uname('m').PHP_OS.PHP_SAPI.ICONV_IMPL.ICONV_VERSION;
self::$sigData[] = sha1_file(__FILE__);
self::$finHash = implode(self::$sigData);
self::$finHash = sha1(str_ireplace(' ', '', self::$finHash) . strlen(self::$finHash) . metaphone(self::$finHash));
self::$finHash = sha1(str_ireplace(' ', '', self::$finHash).strlen(self::$finHash).metaphone(self::$finHash));
self::$finHash = sha1(self::$finHash);
return self::$finHash;

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -12,7 +12,8 @@ namespace Bitpay\Util;
* also:
*
* @see https://en.bitcoin.it/wiki/Secp256k1
* @package Bitpay
*
* @package Bitcore
*/
class Secp256k1 implements CurveParameterInterface
{

View File

@ -1,15 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
* Generates cryptographically-secure random numbers using the OpenSSL extension.
*
* @package Bitpay
* Generates secure random numbers
*/
class SecureRandom
{
@ -19,12 +17,7 @@ class SecureRandom
protected static $hasOpenSSL;
/**
* Generates 32 bytes of random data using the OpenSSL extension.
*
* @see http://php.net/manual/en/function.openssl-random-pseudo-bytes.php
* @param integer $bytes
* @return string $random
* @throws \Exception
* @return string
*/
public static function generateRandom($bytes = 32)
{
@ -42,8 +35,6 @@ class SecureRandom
}
/**
* Returns true/false if the OpenSSL extension is installed & enabled.
*
* @return boolean
*/
public static function hasOpenSSL()

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -13,7 +13,7 @@ use Bitpay\Math\Math;
/**
* Utility class used by string and arbitrary integer methods.
*
* @package Bitpay
* @package Bitcore
*/
class Util
{
@ -25,11 +25,11 @@ class Util
/**
* Computes a digest hash value for the given data using
* the given method, and returns a raw or binhex encoded
* string. Uses the OpenSSL extension.
* string, see:
* http://us1.php.net/manual/en/function.openssl-digest.php
*
* @see http://us1.php.net/manual/en/function.openssl-digest.php
* @param string $data
* @param boolean $binary
*
* @return string
*/
public static function sha256($data, $binary = false)
@ -40,10 +40,11 @@ class Util
/**
* Computes a digest hash value for the given data using
* the given method, and returns a raw or binhex encoded
* string. Uses the OpenSSL extension.
* string, see:
* http://us1.php.net/manual/en/function.openssl-digest.php
*
* @see http://us1.php.net/manual/en/function.openssl-digest.php
* @param string $data
*
* @return string
*/
public static function sha512($data)
@ -53,10 +54,11 @@ class Util
/**
* Generate a keyed hash value using the HMAC method.
* http://us1.php.net/manual/en/function.hash-hmac.php
*
* @see http://us1.php.net/manual/en/function.hash-hmac.php
* @param string $data
* @param string $key
*
* @return string
*/
public static function sha512hmac($data, $key)
@ -65,12 +67,10 @@ class Util
}
/**
* Uses the OpenSSL extention to calculate the RIPDEMD160
* hash of a value.
* Returns a RIPDEMD160 hash of a value.
*
* @see http://php.net/manual/en/function.openssl-digest.php
* @param string $data
* @param boolean $binary
*
* @return string
*/
public static function ripe160($data, $binary = false)
@ -82,6 +82,7 @@ class Util
* Returns a SHA256 hash of a RIPEMD160 hash of a value.
*
* @param string $data
*
* @return string
*/
public static function sha256ripe160($data)
@ -93,7 +94,7 @@ class Util
* Returns a double SHA256 hash of a value.
*
* @param string $data
* @param boolean $binary
*
* @return string
*/
public static function twoSha256($data, $binary = false)
@ -101,10 +102,23 @@ class Util
return self::sha256(self::sha256($data, $binary), $binary);
}
/**
* Returns a nonce for use in REST calls.
*
* @see http://en.wikipedia.org/wiki/Cryptographic_nonce
*
* @return string
*/
public static function nonce()
{
return microtime(true);
}
/**
* Returns a GUID for use in REST calls.
*
* @see http://en.wikipedia.org/wiki/Globally_unique_identifier
*
* @return string
*/
public static function guid()
@ -124,7 +138,6 @@ class Util
*
* @param string $dec
* @return string
* @throws \Exception
*/
public static function encodeHex($dec)
{
@ -138,12 +151,12 @@ class Util
$hex = '';
while (Math::cmp($dec, '0') > 0) {
$q = Math::div($dec, '16');
$rem = Math::mod($dec, '16');
while (Math::cmp($dec, 0) > 0) {
$q = Math::div($dec, 16);
$rem = Math::mod($dec, 16);
$dec = $q;
$hex = substr(self::HEX_CHARS, intval($rem), 1) . $hex;
$hex = substr(self::HEX_CHARS, intval($rem), 1).$hex;
}
return $hex;
@ -154,7 +167,6 @@ class Util
*
* @param string $hex
* @return string
* @throws \Exception
*/
public static function decodeHex($hex)
{
@ -162,7 +174,7 @@ class Util
throw new \Exception('Argument must be a string of hex digits.');
}
$hex = strtolower(trim($hex));
$hex = strtolower($hex);
// if it has a prefix of 0x this needs to be trimed
if (substr($hex, 0, 2) == '0x') {
@ -170,40 +182,31 @@ class Util
}
$hexLen = strlen($hex);
for ($dec = '0', $i = 0; $i < $hexLen; $i++) {
$current = strpos(self::HEX_CHARS, $hex[$i]);
$dec = Math::add(Math::mul($dec, '16'), $current);
$dec = Math::add(Math::mul($dec, 16), $current);
}
return $dec;
}
/**
* Calculates a new EC curve point.
*
* @param string $hex
* @param PointInterface $point
* @param CurveParameterInterface $parameters
* @return Point
*/
public static function doubleAndAdd($hex, PointInterface $point, CurveParameterInterface $parameters = null)
{
if (null === $parameters) {
$parameters = new Secp256k1();
}
$tmp = self::decToBin($hex);
$n = strlen($tmp) - 1;
$S = new Point(PointInterface::INFINITY, PointInterface::INFINITY);
while ($n >= 0) {
$S = self::pointDouble($S);
if ($tmp[$n] == 1) {
$S = self::pointAdd($S, $point);
}
$n--;
}
@ -214,9 +217,10 @@ class Util
* This method returns a binary string representation of
* the decimal number. Used for the doubleAndAdd() method.
*
* @see http://php.net/manual/en/function.decbin.php (but for large numbers)
* @param string $dec
* @return string $bin
* @see http://php.net/manual/en/function.decbin.php but for large numbers
*
* @param string
* @return string
*/
public static function decToBin($dec)
{
@ -225,14 +229,12 @@ class Util
}
$bin = '';
while (Math::cmp($dec, '0') > 0) {
if (Math::mod($dec, '2') == '1') {
if (Math::mod($dec, 2) == '1') {
$bin .= '1';
} else {
$bin .= '0';
}
$prevDec = $dec;
$dec = Math::div($dec, 2);
//sanity check to avoid infinite loop
@ -250,10 +252,9 @@ class Util
* xR = s2 - 2xP mod p
* yR = -yP + s(xP - xR) mod p
*
* @param PointInterface $point
* @param CurveParameterInterface $parameters
* @param PointInterface $point
* @param CurveParameterInterface
* @return PointInterface
* @throws \Exception
*/
public static function pointDouble(PointInterface $point, CurveParameterInterface $parameters = null)
{
@ -277,38 +278,41 @@ class Util
// Critical math section
try {
$m = Math::add(Math::mul(3, Math::mul($point->getX(), $point->getX())), $a);
$o = Math::mul('2', $point->getY());
$o = Math::mul(2, $point->getY());
$n = Math::invertm($o, $p);
$n2 = Math::mod($o, $p);
$st = Math::mul($m, $n);
$st2 = Math::mul($m, $n2);
$s = Math::mod($st, $p);
$s2 = Math::mod($st2, $p);
$xmul = Math::mul('2', $point->getX());
$xmul = Math::mul(2, $point->getX());
$smul = Math::mul($s, $s);
$xsub = Math::sub($smul, $xmul);
$xmod = Math::mod($xsub, $p);
$R['x'] = $xmod;
$ysub = Math::sub($point->getX(), $R['x']);
$ymul = Math::mul($s, $ysub);
$ysub2 = Math::sub('0', $point->getY());
$ysub2 = Math::sub(0, $point->getY());
$yadd = Math::add($ysub2, $ymul);
$R['y'] = Math::mod($yadd, $p);
} catch (\Exception $e) {
throw new \Exception('Error in Util::pointDouble(): ' . $e->getMessage());
throw new \Exception('Error in Util::pointDouble(): '.$e->getMessage());
}
return new Point($R['x'], $R['y']);
}
/**
/**
* Point addition method P + Q = R where:
* s = (yP - yQ)/(xP - xQ) mod p
* xR = s2 - xP - xQ mod p
* yR = -yP + s(xP - xR) mod p
*
* @param PointInterface $P
* @param PointInterface $Q
* @param PointInterface
* @param PointInterface
*
* @return PointInterface
*/
public static function pointAdd(PointInterface $P, PointInterface $Q)
@ -325,9 +329,8 @@ class Util
return self::pointDouble(new Point($P->getX(), $P->getY()));
}
$p = '0x' . Secp256k1::P;
$a = '0x' . Secp256k1::A;
$p = '0x'.Secp256k1::P;
$a = '0x'.Secp256k1::A;
$s = 0;
$R = array(
'x' => 0,
@ -353,11 +356,10 @@ class Util
),
$p
);
$R['y'] = Math::mod(
Math::add(
Math::sub(
'0',
0,
$P->getY()
),
Math::mul(
@ -373,17 +375,18 @@ class Util
$R['s'] = $s;
} catch (Exception $e) {
throw new \Exception('Error in Util::pointAdd(): ' . $e->getMessage());
throw new \Exception('Error in Util::pointAdd(): '.$e->getMessage());
}
return new Point($R['x'], $R['y']);
}
/**
* Converts hex value into octet (byte) string.
* Converts hex value into octet (byte) string
*
* @param string $hex
* @return string $byte
* @param string
*
* @return string
*/
public static function binConv($hex)
{
@ -397,21 +400,21 @@ class Util
}
if (substr(strtolower($hex), 0, 2) != '0x') {
$hex = '0x' . strtolower(trim($hex));
$hex = '0x'.strtolower($hex);
}
while (Math::cmp($hex, '0') > 0) {
$dv = Math::div($hex, '256');
$rem = Math::mod($hex, '256');
while (Math::cmp($hex, 0) > 0) {
$dv = Math::div($hex, 256);
$rem = Math::mod($hex, 256);
$hex = $dv;
$byte = $byte . $digits[$rem];
$byte = $byte.$digits[$rem];
}
return strrev($byte);
}
/**
* Checks dependencies for the library.
* Checks dependencies for the library
*
* @return array list of each requirement, boolean true if met, string error message if not as value
*/
@ -424,7 +427,6 @@ class Util
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
if (PHP_VERSION_ID < 50400) {
$requirements['PHP'] = 'Your PHP version, ' . PHP_VERSION . ', is too low. PHP version >= 5.4 is required.';
} else {
@ -450,9 +452,8 @@ class Util
$requirements['cURL'] = 'The cURL PHP extension could not be found.';
} else {
$requirements['cURL'] = true;
$curl_version = curl_version();
$curl_version = curl_version();
$ssl_supported = ($curl_version['features'] & CURL_VERSION_SSL);
if (!$ssl_supported) {
$requirements['cURL.SSL'] = 'The cURL PHP extension does not have SSL support.';
} else {

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -13,7 +13,9 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
$token = new AccessToken();
$this->assertNotNull($token);
$token->setId('test');
$this->assertSame('test', $token->getId());
}
@ -22,7 +24,9 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
$token = new AccessToken();
$this->assertNotNull($token);
$token->setEmail('support@bitpay.com');
$this->assertSame('support@bitpay.com', $token->getEmail());
}
@ -31,7 +35,40 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
$token = new AccessToken();
$this->assertNotNull($token);
$token->setLabel('label');
$this->assertSame('label', $token->getLabel());
}
public function testNonce()
{
$token = new AccessToken();
$this->assertNotNull($token);
$this->assertFalse($token->isNonceDisabled());
}
public function testNonceDisable()
{
$token = new AccessToken();
$this->assertNotNull($token);
$this->assertFalse($token->isNonceDisabled());
$token->nonceDisable();
$this->assertTrue($token->isNonceDisabled());
}
public function testNonceEnable()
{
$token = new AccessToken();
$this->assertNotNull($token);
$this->assertFalse($token->isNonceDisabled());
$token->nonceEnable();
$this->assertFalse($token->isNonceDisabled());
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -13,6 +13,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$this->assertInternalType('array', $application->getUsers());
$this->assertEmpty($application->getUsers());
}
@ -25,6 +26,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$application->addUser($this->getMockUser());
$this->assertInternalType('array', $application->getUsers());
@ -36,6 +38,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$this->assertInternalType('array', $application->getOrgs());
$this->assertEmpty($application->getOrgs());
}
@ -48,6 +51,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$application->addOrg($this->getMockOrg());
$this->assertInternalType('array', $application->getOrgs());
@ -56,11 +60,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
private function getMockUser()
{
return $this->getMock('Bitpay\User');
return $this->getMock('Bitpay\UserInterface');
}
private function getMockOrg()
{
return $this->getMock('Bitpay\Org');
return $this->getMock('Bitpay\OrgInterface');
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
class AutoloaderTest extends \PHPUnit_Framework_TestCase
{
protected function teardown()
{
Autoloader::unregister();
}
/**
* Make sure that our autoloader is first in the queue
*/
public function testRegister()
{
Autoloader::register();
$functions = spl_autoload_functions();
$this->assertSame(array('Bitpay\Autoloader','autoload'), $functions[0]);
}
public function testUnregister()
{
Autoloader::register();
$numOfAutoloaders = count(spl_autoload_functions());
Autoloader::unregister();
$this->assertCount($numOfAutoloaders - 1, spl_autoload_functions());
}
public function testAutoload()
{
Autoloader::register();
Autoloader::autoload('Bitpay\Bitpay');
// Is only required once
Autoloader::autoload('Bitpay\Bitpay');
}
/**
*/
public function testNoClass()
{
Autoloader::autoload('Foo\Bar');
}
/**
* @expectedException Exception
*/
public function testException()
{
Autoloader::autoload('Bitpay\ClassThatWillNeverBeCreated');
}
public function testNoExceptionForBitpayClasslike()
{
Autoloader::register();
// Magento Classes
Autoloader::autoload('Bitpay_Core_Model');
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -35,7 +35,7 @@ class BillTest extends \PHPUnit_Framework_TestCase
public function testGetCurrency()
{
$this->assertNotNull($this->bill);
$this->assertInstanceOf('Bitpay\Currency', $this->bill->getCurrency());
$this->assertInstanceOf('Bitpay\CurrencyInterface', $this->bill->getCurrency());
}
/**
@ -45,7 +45,7 @@ class BillTest extends \PHPUnit_Framework_TestCase
{
$this->assertNotNull($this->bill);
$this->bill->setCurrency($this->getMockCurrency());
$this->assertInstanceOf('Bitpay\Currency', $this->bill->getCurrency());
$this->assertInstanceOf('Bitpay\CurrencyInterface', $this->bill->getCurrency());
}
public function testGetName()
@ -162,8 +162,8 @@ class BillTest extends \PHPUnit_Framework_TestCase
public function testSetEmail()
{
$this->assertNotNull($this->bill);
$this->bill->setEmail('integrations@bitpay.com');
$this->assertSame('integrations@bitpay.com', $this->bill->getEmail());
$this->bill->setEmail('support@bitpay.com');
$this->assertSame('support@bitpay.com', $this->bill->getEmail());
}
public function testGetPhone()
@ -232,11 +232,11 @@ class BillTest extends \PHPUnit_Framework_TestCase
private function getMockItem()
{
return $this->getMock('Bitpay\Item');
return $this->getMock('Bitpay\ItemInterface');
}
private function getMockCurrency()
{
return $this->getMock('Bitpay\Currency');
return $this->getMock('Bitpay\CurrencyInterface');
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -10,16 +10,6 @@ use org\bovigo\vfs\vfsStream;
class BitpayTest extends \PHPUnit_Framework_TestCase
{
private $temp_path_pri;
private $temp_path_pub;
private $temp_path_root;
public function setUp()
{
$this->temp_path_root = 'tmp';
$this->temp_path_pri = $this->temp_path_root . '/key.pri';
$this->temp_path_pub = $this->temp_path_root . '/key.pub';
}
public function testConstruct()
{
@ -33,7 +23,7 @@ class BitpayTest extends \PHPUnit_Framework_TestCase
public function testGetContainer()
{
$bitpay = new \Bitpay\Bitpay();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $bitpay->getContainer());
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $bitpay->getContainer());
}
public function testGet()
@ -53,20 +43,19 @@ class BitpayTest extends \PHPUnit_Framework_TestCase
public function testConfigAbleToPersistAndLoadKeys()
{
$root = vfsStream::setup($this->temp_path_root);
$root = vfsStream::setup('tmp');
$bitpay = new \Bitpay\Bitpay(
array(
'bitpay' => array(
'private_key' => vfsStream::url($this->temp_path_pri),
'public_key' => vfsStream::url($this->temp_path_pub),
'private_key' => vfsStream::url('tmp/key.pri'),
'public_key' => vfsStream::url('tmp/key.pub'),
)
)
);
$pri = new \Bitpay\PrivateKey(vfsStream::url($this->temp_path_pri));
$pri = new \Bitpay\PrivateKey(vfsStream::url('tmp/key.pri'));
$pri->generate();
$pub = new \Bitpay\PublicKey(vfsStream::url($this->temp_path_pub));
$pub = new \Bitpay\PublicKey(vfsStream::url('tmp/key.pub'));
$pub->setPrivateKey($pri)->generate();
/**

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -43,8 +43,8 @@ class BuyerTest extends \PHPUnit_Framework_TestCase
public function testSetEmail()
{
$this->assertNotNull($this->user);
$this->user->setEmail('integrations@bitpay.com');
$this->assertSame('integrations@bitpay.com', $this->user->getEmail());
$this->user->setEmail('support@bitpay.com');
$this->assertSame('support@bitpay.com', $this->user->getEmail());
}
public function testGetFirstName()

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -56,4 +56,5 @@ class CurlAdapterTest extends \PHPUnit_Framework_TestCase
$response = $adapter->sendRequest($this->request);
$this->assertNotNull($response);
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -31,8 +31,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->client->setAdapter($adapter);
}
public function testCheckPriceAndCurrency()
{
public function testCheckPriceAndCurrency() {
$client = new ChildOfClient();
$res = $client->checkPriceAndCurrency(.999999, 'BTC');
$this->assertNull($res);
@ -98,7 +97,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
->setEffectiveDate("1415853007000")
->setPricingMethod('bitcoinbestbuy')
->setNotificationUrl('https://bitpay.com')
->setNotificationEmail('integrations@bitpay.com')
->setNotificationEmail('support@bitpay.com')
->setPricingMethod('bitcoinbestbuy')
->setReference('your reference, can be json')
->setAmount(5625)
@ -108,7 +107,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
\Bitpay\PayoutInstruction::STATUS_UNPAID => null,
\Bitpay\PayoutInstruction::STATUS_PAID => '0'
);
$instruction0 = new \Bitpay\PayoutInstruction();
$instruction0
->setId('Sra19AFU57Rx53rKQbbRKZ')
@ -160,7 +158,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('your reference, can be json', $payout->getReference());
$this->assertEquals('1415853007000', $payout->getEffectiveDate());
$this->assertEquals('https://bitpay.com', $payout->getNotificationUrl());
$this->assertEquals('integrations@bitpay.com', $payout->getNotificationEmail());
$this->assertEquals('support@bitpay.com', $payout->getNotificationEmail());
$this->assertEquals('8mZ37Gt91Wr7GXGPnB9zj1zwTcLGweRDka4axVBPi9Uxiiv7zZWvEKSgmFddQZA1Jy', $payout->getResponseToken());
$instructions = $payout->getInstructions();
$this->assertSame($instruction0, $instructions[0]);
@ -197,24 +195,15 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('abcdefghijkmnopqrstuvw', $invoice->getId());
$this->assertEquals('https://test.bitpay.com/invoice?id=abcdefghijkmnopqrstuvw', $invoice->getUrl());
$this->assertEquals('new', $invoice->getStatus());
$this->assertEquals('0.0632', $invoice->getBtcPrice());
//$this->assertEquals('0.0632', $invoice->getBtcPrice());
$this->assertEquals(19.95, $invoice->getPrice());
$this->assertEquals(1412594514, $invoice->getInvoiceTime()->getTimestamp());
$this->assertEquals(1412595414, $invoice->getExpirationTime()->getTimestamp());
$this->assertEquals(1412594514, $invoice->getCurrentTime()->getTimestamp());
$this->assertInstanceOf('DateTime', $invoice->getInvoiceTime());
$this->assertInstanceOf('DateTime', $invoice->getExpirationTime());
$this->assertInstanceOf('DateTime', $invoice->getCurrentTime());
$this->assertEquals('0.0000', $invoice->getBtcPaid());
//$this->assertEquals('0.0000', $invoice->getBtcPaid());
$this->assertEquals(315.7, $invoice->getRate());
$this->assertEquals(false, $invoice->getExceptionStatus());
$this->assertEquals('abcdefghijklmno', $invoice->getToken()->getToken());
$this->assertEquals('bitcoin:mabcdefghijkmnopqrstuvw123456789AB?amount=0.0632', $invoice->getPaymentUrl(\BitPay\PaymentUrlSet::BIP_21));
//assert that invoice, expiration and currenttime are in the past
//meaning we didn't try to create date objects from unix timestamps including milliseconds
$this->assertLessThan(time(), $invoice->getInvoiceTime()->getTimestamp());
$this->assertLessThan(time(), $invoice->getExpirationTime()->getTimestamp());
$this->assertLessThan(time(), $invoice->getCurrentTime()->getTimestamp());
}
/**
@ -342,6 +331,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$payouts = $this->client->getPayouts();
$this->assertInternalType('array', $payouts);
$this->assertInstanceOf('Bitpay\PayoutInterface', $payouts[0]);
}
/**
@ -357,6 +347,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->client->setAdapter($adapter);
$payouts = $this->client->getPayouts();
}
public function testGetTokens()
@ -512,6 +503,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$payout = $this->client->getPayout('7m7hSF3ws1LhnWUf17CXsJ');
// Test deletePayout
$response = $this->getMockResponse();
$response->method('getBody')->willReturn(file_get_contents(__DIR__ . '/../../DataFixtures/payouts/cancelled.json'));
@ -521,6 +513,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->client->setAdapter($adapter);
$payout = $this->client->deletePayout($payout);
$this->assertSame($payout->getStatus(), \Bitpay\Payout::STATUS_CANCELLED);
}
@ -540,6 +533,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$payout = $this->client->getPayout('7m7hSF3ws1LhnWUf17CXsJ');
// Test with exception
$response = $this->getMockResponse();
$response->method('getBody')->willReturn('{"error":"Object not found"}');
@ -551,6 +545,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertSame($payout->getStatus(), \Bitpay\Payout::STATUS_CANCELLED);
}
private function getMockInvoice()
{
$invoice = $this->getMockBuilder('Bitpay\InvoiceInterface')
@ -562,10 +557,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
'getExpirationTime', 'getCurrentTime', 'getOrderId', 'getItemDesc', 'getItemCode',
'isPhysical', 'getBuyerName', 'getBuyerAddress1', 'getBuyerAddress2', 'getBuyerCity',
'getBuyerState', 'getBuyerZip', 'getBuyerCountry', 'getBuyerEmail', 'getBuyerPhone',
'getExceptionStatus', 'getBtcPaid', 'getRate', 'getToken', 'setId', 'setUrl',
'setStatus', 'setBtcPrice', 'setPrice', 'setInvoiceTime', 'setExpirationTime',
'setCurrentTime', 'setBtcPaid', 'setRate', 'setToken', 'setExceptionStatus', 'getRefundAddresses',
'getPaymentUrls', 'isExtendedNotifications', 'setPosData'
'getExceptionStatus', 'getBtcPaid', 'getRate', 'getToken', 'getRefundAddresses',
'setId', 'setUrl', 'setStatus', 'setBtcPrice', 'setPrice', 'setInvoiceTime', 'setExpirationTime',
'setCurrentTime', 'setBtcPaid', 'setRate', 'setToken', 'setExceptionStatus', 'isExtendedNotifications',
'setPosData',
)
)
->getMock();

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -36,7 +36,7 @@ class CurrencyTest extends \PHPUnit_Framework_TestCase
*/
public function testSetCodeWithExceptionThrown()
{
new Currency('Foo Coin');
new Currency('Dodge Coin');
}
/**
@ -157,8 +157,8 @@ class CurrencyTest extends \PHPUnit_Framework_TestCase
public function testSetAlts()
{
$this->assertNotNull($this->currency);
$this->currency->setAlts('USD Bucks');
$this->assertSame('USD Bucks', $this->currency->getAlts());
$this->currency->setAlts('usd bucks');
$this->assertSame('usd bucks', $this->currency->getAlts());
}
public function testGetPayoutFields()

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -18,7 +18,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetPrice()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getPrice(), 0.0);
$this->assertNull($this->invoice->getPrice());
}
/**
@ -34,7 +34,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetCurrency()
{
$this->assertNotNull($this->invoice);
$this->assertInstanceOf('Bitpay\Currency', $this->invoice->getCurrency());
$this->assertNull($this->invoice->getCurrency());
}
/**
@ -94,14 +94,14 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testSetTransactionSpeed()
{
$this->assertNotNull($this->invoice);
$this->invoice->setTransactionSpeed(Invoice::TRANSACTION_SPEED_LOW);
$this->assertSame(Invoice::TRANSACTION_SPEED_LOW, $this->invoice->getTransactionSpeed());
$this->invoice->setTransactionSpeed(Invoice::TRANSACTION_SPEED_MEDIUM);
$this->assertSame(Invoice::TRANSACTION_SPEED_MEDIUM, $this->invoice->getTransactionSpeed());
}
public function testGetNotificationEmail()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getNotificationEmail(), '');
$this->assertNull($this->invoice->getNotificationEmail());
}
/**
@ -110,14 +110,14 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testSetNotificationEmail()
{
$this->assertNotNull($this->invoice);
$this->invoice->setNotificationEmail('integrations@bitpay.com');
$this->assertSame('integrations@bitpay.com', $this->invoice->getNotificationEmail());
$this->invoice->setNotificationEmail('support@bitpay.com');
$this->assertSame('support@bitpay.com', $this->invoice->getNotificationEmail());
}
public function testGetNotificationUrl()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getNotificationUrl(), '');
$this->assertNull($this->invoice->getNotificationUrl());
}
/**
@ -133,7 +133,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetRedirectUrl()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getRedirectUrl(), '');
$this->assertNull($this->invoice->getRedirectUrl());
}
/**
@ -149,7 +149,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetPosData()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getPosData(), '');
$this->assertNull($this->invoice->getPosData());
}
/**
@ -165,7 +165,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetStatus()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getStatus(), '');
$this->assertNull($this->invoice->getStatus());
}
/**
@ -187,7 +187,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetId()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getId(), '');
$this->assertNull($this->invoice->getId());
}
/**
@ -203,7 +203,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetUrl()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getUrl(), '');
$this->assertNull($this->invoice->getUrl());
}
/**
@ -219,7 +219,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetBtcPrice()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getBtcPrice(), 0.0);
$this->assertNull($this->invoice->getBtcPrice());
}
/**
@ -294,7 +294,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetOrderId()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getOrderId(), '');
$this->assertNull($this->invoice->getOrderId());
}
/**
@ -313,12 +313,26 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
$this->assertNull($this->invoice->getItemDesc());
}
public function testSetItemDesc()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the item description...
}
public function testGetItemCode()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getItemCode());
}
public function testSetItemCode()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the item code...
}
public function testIsPhysical()
{
$this->assertNotNull($this->invoice);
@ -331,58 +345,121 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
$this->assertEmpty($this->invoice->getBuyerName());
}
public function testSetBuyerName()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer name...
}
public function testGetBuyerAddress1()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerAddress1());
}
public function testSetBuyerAddress1()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer address1...
}
public function testGetBuyerAddress2()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerAddress2());
}
public function testSetBuyerAddress2()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer address2...
}
public function testGetBuyerCity()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerCity());
}
public function testSetBuyerCity()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer city...
}
public function testGetBuyerState()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerState());
}
public function testSetBuyerState()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer state...
}
public function testGetBuyerZip()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerZip());
}
public function testSetBuyerZip()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer zip...
}
public function testGetBuyerCountry()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerCountry());
}
public function testSetBuyerCountry()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer country...
}
public function testGetBuyerEmail()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerEmail());
}
public function testSetBuyerEmail()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer email...
}
public function testGetBuyerPhone()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBuyerPhone());
}
public function testSetBuyerPhone()
{
$this->assertNotNull($this->invoice);
// TODO: add a test for setting the buyer phone...
}
public function testGetExceptionStatus()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getExceptionStatus(), '');
$this->assertNull($this->invoice->getExceptionStatus());
}
/**
@ -398,7 +475,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetBtcPaid()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getBtcPaid(), 0.0);
$this->assertNull($this->invoice->getBtcPaid());
}
/**
@ -414,7 +491,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetRate()
{
$this->assertNotNull($this->invoice);
$this->assertSame($this->invoice->getRate(), 0.0);
$this->assertNull($this->invoice->getRate());
}
/**

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -59,7 +59,6 @@ class ItemTest extends \PHPUnit_Framework_TestCase
public function testSetPrice()
{
setlocale(LC_NUMERIC, 'en_US');
// Accepts floats
$this->item->setPrice(9.99);
$this->assertSame(9.99, $this->item->getPrice());
@ -139,6 +138,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase
setlocale(LC_NUMERIC, 'en_US');
}
public function testGetQuantity()
{
$this->assertNotNull($this->item);

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,13 +8,6 @@ namespace Bitpay;
class KeyManagerTest extends \PHPUnit_Framework_TestCase
{
private $temp_path;
public function setUp()
{
$this->temp_path = '/tmp/mock.key';
}
public function testConstruct()
{
$storage = $this->getMockStorage();
@ -48,12 +41,13 @@ class KeyManagerTest extends \PHPUnit_Framework_TestCase
$manager = new KeyManager($storage);
$this->assertNotNull($manager);
$manager->load($this->getMockKey());
}
private function getMockKey()
{
return new \Bitpay\PublicKey($this->temp_path);
return new \Bitpay\PublicKey('/tmp/mock.key');
}
private function getMockStorage()

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -9,13 +9,15 @@ namespace Bitpay\Math;
class BcEngineTest extends \PHPUnit_Framework_TestCase
{
/**
* @requires extension gmp
* @requires extension bcmath
*/
protected function setUp()
{
if (!extension_loaded('bcmath')) {
$this->markTestSkipped('The Bcmath extension is NOT loaded! You must enable it to run this test');
}
if (!extension_loaded('bcmath'))
{
$this->markTestSkipped('The Bcmath extension is NOT loaded! You must enable it to run this test');
}
}
public function testConstruct()
@ -76,6 +78,7 @@ class BcEngineTest extends \PHPUnit_Framework_TestCase
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$this->assertEquals(0, $math->invertm($a, $a));
$this->assertEquals(0, $math->invertm($b, $b));
$this->assertEquals(0, $math->invertm($c, $c));
@ -176,8 +179,7 @@ class BcEngineTest extends \PHPUnit_Framework_TestCase
);
$math = new BcEngine();
for ($i = 0, $size = count($inputs); $i < $size; $i++) {
for($i = 0, $size = count($inputs); $i < $size; $i++) {
$this->assertEquals($outputs[$i], $math->input($inputs[$i]));
}
}
@ -217,4 +219,5 @@ class BcEngineTest extends \PHPUnit_Framework_TestCase
$math = new BcEngine();
$this->assertTrue($math->coprime($a, $b));
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,96 +8,119 @@ namespace Bitpay\Math;
class GmpEngineTest extends \PHPUnit_Framework_TestCase
{
private $a;
private $b;
private $c;
private $math;
/**
* @requires extension gmp
*/
protected function setUp()
{
$this->a = 1234;
$this->b = '1234123412341234123412341234123412412341234213412421341342342';
$this->c = '0x1234123412341234123412341234123412412341234213412421341342342';
if (!extension_loaded('gmp')) {
$this->markTestSkipped('The GMP extension is NOT loaded! You must enable it to run this test');
} else {
$this->math = new GmpEngine();
}
if (!extension_loaded('gmp'))
{
$this->markTestSkipped('The GMP extension is NOT loaded! You must enable it to run this test');
}
}
public function testAdd()
public function testadd()
{
$this->assertEquals(gmp_strval(gmp_add($this->a, $this->a)), $this->math->add($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_add($this->b, $this->b)), $this->math->add($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_add($this->c, $this->c)), $this->math->add($this->c, $this->c));
$this->assertEquals(2, $this->math->add(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_add($a, $a)), $math->add($a, $a));
$this->assertEquals(gmp_strval(gmp_add($b, $b)), $math->add($b, $b));
$this->assertEquals(gmp_strval(gmp_add($c, $c)), $math->add($c, $c));
$this->assertEquals(2, $math->add(1, 1));
}
public function testCmp()
public function testcmp()
{
$this->assertEquals(gmp_strval(gmp_cmp($this->a, $this->a)), $this->math->cmp($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_cmp($this->b, $this->b)), $this->math->cmp($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_cmp($this->c, $this->c)), $this->math->cmp($this->c, $this->c));
$this->assertEquals(0, $this->math->cmp(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_cmp($a, $a)), $math->cmp($a, $a));
$this->assertEquals(gmp_strval(gmp_cmp($b, $b)), $math->cmp($b, $b));
$this->assertEquals(gmp_strval(gmp_cmp($c, $c)), $math->cmp($c, $c));
$this->assertEquals(0, $math->cmp(1, 1));
}
public function testDiv()
public function testdiv()
{
$this->assertEquals(gmp_strval(gmp_div($this->a, $this->a)), $this->math->div($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_div($this->b, $this->b)), $this->math->div($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_div($this->c, $this->c)), $this->math->div($this->c, $this->c));
$this->assertEquals(1, $this->math->div(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_div($a, $a)), $math->div($a, $a));
$this->assertEquals(gmp_strval(gmp_div($b, $b)), $math->div($b, $b));
$this->assertEquals(gmp_strval(gmp_div($c, $c)), $math->div($c, $c));
$this->assertEquals(1, $math->div(1, 1));
}
public function testInvertm()
public function testinvertm()
{
$this->assertEquals(gmp_strval(gmp_invert($this->a, $this->a)), $this->math->invertm($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_invert($this->b, $this->b)), $this->math->invertm($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_invert($this->c, $this->c)), $this->math->invertm($this->c, $this->c));
$this->assertEquals(0, $this->math->invertm(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_invert($a, $a)), $math->invertm($a, $a));
$this->assertEquals(gmp_strval(gmp_invert($b, $b)), $math->invertm($b, $b));
$this->assertEquals(gmp_strval(gmp_invert($c, $c)), $math->invertm($c, $c));
$this->assertEquals(0, $math->invertm(1, 1));
$o = '2';
$p = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f';
$this->assertEquals('57896044618658097711785492504343953926634992332820282019728792003954417335832', $this->math->invertm($o, $p));
$this->assertEquals('57896044618658097711785492504343953926634992332820282019728792003954417335832', $math->invertm($o, $p));
$o = '-207267379875244730201206352791949018434229233557197871725317424106240926035466';
$p = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f';
$this->assertEquals('93736451599995461267424215486556527005103980679329099329644578865571485201981', $this->math->invertm($o, $p));
$this->assertEquals('93736451599995461267424215486556527005103980679329099329644578865571485201981', $math->invertm($o, $p));
}
public function testMod()
public function testmod()
{
$this->assertEquals(gmp_strval(gmp_mod($this->a, $this->a)), $this->math->mod($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_mod($this->b, $this->b)), $this->math->mod($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_mod($this->c, $this->c)), $this->math->mod($this->c, $this->c));
$this->assertEquals(0, $this->math->mod(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_mod($a, $a)), $math->mod($a, $a));
$this->assertEquals(gmp_strval(gmp_mod($b, $b)), $math->mod($b, $b));
$this->assertEquals(gmp_strval(gmp_mod($c, $c)), $math->mod($c, $c));
$this->assertEquals(0, $math->mod(1, 1));
}
public function testMul()
public function testmul()
{
$this->assertEquals(gmp_strval(gmp_mul($this->a, $this->a)), $this->math->mul($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_mul($this->b, $this->b)), $this->math->mul($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_mul($this->c, $this->c)), $this->math->mul($this->c, $this->c));
$this->assertEquals(1, $this->math->mul(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_mul($a, $a)), $math->mul($a, $a));
$this->assertEquals(gmp_strval(gmp_mul($b, $b)), $math->mul($b, $b));
$this->assertEquals(gmp_strval(gmp_mul($c, $c)), $math->mul($c, $c));
$this->assertEquals(1, $math->mul(1, 1));
}
public function testPow()
public function testpow()
{
$this->assertEquals(gmp_strval(gmp_pow($this->a, $this->a)), $this->math->pow($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_pow($this->b, $this->b)), $this->math->pow($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_pow($this->c, $this->c)), $this->math->pow($this->c, $this->c));
$this->assertEquals(1, $this->math->pow(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_pow($a, $a)), $math->pow($a, $a));
$this->assertEquals(gmp_strval(gmp_pow($b, $b)), $math->pow($b, $b));
$this->assertEquals(gmp_strval(gmp_pow($c, $c)), $math->pow($c, $c));
$this->assertEquals(1, $math->pow(1, 1));
}
public function testSub()
public function testsub()
{
$this->assertEquals(gmp_strval(gmp_sub($this->a, $this->a)), $this->math->sub($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_sub($this->b, $this->b)), $this->math->sub($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_sub($this->c, $this->c)), $this->math->sub($this->c, $this->c));
$this->assertEquals(0, $this->math->sub(1, 1));
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_sub($a, $a)), $math->sub($a, $a));
$this->assertEquals(gmp_strval(gmp_sub($b, $b)), $math->sub($b, $b));
$this->assertEquals(gmp_strval(gmp_sub($c, $c)), $math->sub($c, $c));
$this->assertEquals(0, $math->sub(1, 1));
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,48 +8,47 @@ namespace Bitpay\Math;
function function_exists($func)
{
return false;
return false;
}
class MathTest extends \PHPUnit_Framework_TestCase
{
public function testIsEngineSet()
{
Math::setEngine(null);
$this->assertNull(Math::getEngine());
$engine = $this->getMock('Bitpay\Math\EngineInterface');
public function testIsEngineSet()
{
Math::setEngine(null);
$this->assertNull(Math::getEngine());
$engine = $this->getMock('Bitpay\Math\EngineInterface');
Math::setEngine($engine);
$this->assertInstanceOf('Bitpay\Math\EngineInterface', Math::getEngine());
}
Math::setEngine($engine);
$this->assertInstanceOf('Bitpay\Math\EngineInterface', Math::getEngine());
}
/**
* @requires extension gmp
* @runInSeparateProcess
*/
public function testGmpMath()
{
if (!extension_loaded('gmp'))
{
$this->markTestSkipped('The GMP extension is NOT loaded! You must enable it to run this test');
}
Math::add("3324234234234234234", "3324234234234234234");
$this->assertEquals(new GmpEngine(), Math::getEngine());
}
/**
* @requires extension gmp
* @runInSeparateProcess
*/
public function testGmpMath()
{
if (!extension_loaded('gmp')) {
$this->markTestSkipped('The GMP extension is NOT loaded! You must enable it to run this test');
}
Math::add("3324234234234234234", "3324234234234234234");
$this->assertEquals(new GmpEngine(), Math::getEngine());
}
/**
* @requires extension bcmath
* @runInSeparateProcess
*/
public function testBcMath()
{
if (!extension_loaded('bcmath')) {
$this->markTestSkipped('The Bcmath extension is NOT loaded! You must enable it to run this test');
} else if (extension_loaded('gmp')) {
$this->markTestSkipped('The GMP extension is loaded! You must remove it to run this test');
}
Math::add("3324234234234234234", "3324234234234234234");
$this->assertEquals(new BcEngine(), Math::getEngine());
}
/**
* @requires extension bcmath
* @runInSeparateProcess
*/
public function testBcMath()
{
if (!extension_loaded('bcmath'))
{
$this->markTestSkipped('The Bcmath extension is NOT loaded! You must enable it to run this test');
} elseif (extension_loaded('gmp')) {
$this->markTestSkipped('The GMP extension is loaded! You must remove it to run this test');
}
Math::add("3324234234234234234", "3324234234234234234");
$this->assertEquals(new BcEngine(), Math::getEngine());
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -125,7 +125,6 @@ class PayoutInstructionTest extends \PHPUnit_Framework_TestCase
$this->assertNotNull($this->instruction->getBtc());
$this->assertSame($btc, $this->instruction->getBtc());
}
/**
* @depends testGetAmount
*/
@ -141,7 +140,6 @@ class PayoutInstructionTest extends \PHPUnit_Framework_TestCase
$this->assertInternalType('float', $this->instruction->getAmount());
$this->assertSame(10.99, $this->instruction->getAmount());
}
/**
* @depends testGetStatus
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -77,6 +77,7 @@ class PayoutTest extends \PHPUnit_Framework_TestCase
->setLabel($label);
$this->payout->addInstruction($instruction);
$this->assertInternalType('array', $this->payout->getInstructions());
$this->assertTrue(count($this->payout->getInstructions()) == 1);

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,6 +8,8 @@ namespace Bitpay;
class PointTest extends \PHPUnit_Framework_TestCase
{
/**
*/
public function testConstruct()
{
$point = new Point(1, 2);
@ -64,7 +66,6 @@ class PointTest extends \PHPUnit_Framework_TestCase
);
$pointA = unserialize($data);
$this->assertInstanceOf('Bitpay\PointInterface', $pointA);
$this->assertSame('1', $pointA->getX());
$this->assertSame('2', $pointA->getY());

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -28,10 +28,10 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
} else {
\Bitpay\Math\Math::setEngine(new \Bitpay\Math\RpEngine());
}
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNull($priKey->getHex());
$this->assertNull($priKey->getDec());
@ -44,11 +44,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateCannotHappenTwice()
{
$privateKey = new PrivateKey();
$privateKey->generate();
$hex = $privateKey->getHex();
$privateKey->generate();
$this->assertSame($hex, $privateKey->getHex());
}
@ -56,9 +53,10 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testGetHex()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNull($priKey->getHex());
$this->assertEquals(0, strlen($priKey->getHex()));
$priKey->generate();
@ -73,7 +71,6 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testToString()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
// Make sure this is a string
@ -90,9 +87,10 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testGetDec()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNull($priKey->getDec());
$this->assertEquals(0, strlen($priKey->getDec()));
$priKey->generate();
@ -103,8 +101,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testIsValid()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertFalse($priKey->isValid());
$priKey->generate();
@ -115,7 +113,6 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testSign()
{
$priKey = new PrivateKey();
$priKey->generate();
// Make sure not exceptions are thrown
@ -125,8 +122,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testHasValidHex()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertFalse($priKey->hasValidHex());
$priKey->generate();
@ -137,8 +134,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testHasValidDec()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertFalse($priKey->hasValidDec());
$priKey->generate();
@ -166,11 +163,9 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
$public_key = '048d970d6ba29dcfa190c177140fd889fadd6d2590b1ee1a6a06e255dbf22b4017ee7bc8e1f07ed0ff8bd77c002b98d31a1a8b53a63767ca65a531fb33cd726197';
$pkey = new PrivateKey();
$this->assertNotNull($pkey);
$keys = $pkey->pemDecode($data);
$this->assertNotNull($pkey);
// Ensure it's an array
@ -195,12 +190,11 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
$public_key = '048d970d6ba29dcfa190c177140fd889fadd6d2590b1ee1a6a06e255dbf22b4017ee7bc8e1f07ed0ff8bd77c002b98d31a1a8b53a63767ca65a531fb33cd726197';
$keypair = array($private_key, $public_key);
$pkey = new PrivateKey();
$pkey = new PrivateKey();
$this->assertNotNull($pkey);
$pemdata = $pkey->pemEncode($keypair);
$this->assertNotNull($pemdata);
// Ensure it's a string

View File

@ -1,13 +1,17 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* @see https://github.com/bitpay/bitcore/blob/master/test/test.Key.js
*/
class PublicKeyTest extends \PHPUnit_Framework_TestCase
{
private $hexKeys = array(
array(
'private' => '10a2036fd1c8f7aeae1e21cd2a11bb9654f76844d1636809618b5e2cbb00c35d',
@ -74,7 +78,6 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testId()
{
$key = new PublicKey('/path/to/key.pub');
$this->assertSame('/path/to/key.pub', $key->getId());
}
@ -87,7 +90,6 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
{
foreach($this->hexKeys as $hexKey) {
$pubKey = new PublicKey();
$pubKey->setPrivateKey($this->getMockPrivateKey($hexKey['private']));
$pubKey->generate();
$this->assertEquals($hexKey['public'], (string) $pubKey);
@ -97,7 +99,6 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateOnlyOnce()
{
$key = new PublicKey();
$key->setPrivateKey($this->getMockPrivateKey());
$key->generate();
@ -106,7 +107,10 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
$key->generate();
// Make sure values do not change
$this->assertSame($hexValue, $key->getHex());
$this->assertSame(
$hexValue,
$key->getHex()
);
}
/**
@ -115,7 +119,6 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGetHex()
{
$pubKey = new PublicKey();
$pubKey->setPrivateKey($this->getMockPrivateKey());
$this->assertNull($pubKey->getHex());
$pubKey->generate();
@ -128,41 +131,46 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGetDec()
{
$pubKey = new PublicKey();
$this->assertNotNull($pubKey);
$pubKey->setPrivateKey($this->getMockPrivateKey());
$this->assertNull($pubKey->getDec());
$pubKey->generate();
$this->assertGreaterThanOrEqual(154, strlen($pubKey->getDec()));
}
/**
* @see https://github.com/bitpay/bitcore/blob/master/test/test.Key.js
* @depends testGenerate
*/
public function testToString()
{
$pubKey = new PublicKey();
$this->assertNotNull($pubKey);
$pubKey->setPrivateKey(PrivateKey::create()->generate());
$this->assertSame('', (string)$pubKey);
$this->assertSame('', (string) $pubKey);
$pubKey->generate(PrivateKey::create()->generate());
if ('02' . $pubKey->getX() == $pubKey) {
$compressed = '02' . $pubKey->getX();
if ('02'.$pubKey->getX() == $pubKey) {
$compressed = '02'.$pubKey->getX();
} else {
$compressed = '03' . $pubKey->getX();
$compressed = '03'.$pubKey->getX();
}
$this->assertSame($compressed, (string)$pubKey);
$this->assertEquals(66, strlen((string)$pubKey));
$this->assertSame($compressed, (string) $pubKey);
$this->assertEquals(66, strlen((string) $pubKey));
}
public function testGetX()
{
foreach($this->hexKeys as $hexKey) {
$pubKey = new PublicKey();
$pubKey->setPrivateKey($this->getMockPrivateKey($hexKey['private']));
$pubKey->generate();
$this->assertEquals($hexKey['pub_x'], $pubKey->getX());
@ -173,7 +181,6 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
{
foreach($this->hexKeys as $hexKey) {
$pubKey = new PublicKey();
$pubKey->setPrivateKey($this->getMockPrivateKey($hexKey['private']));
$pubKey->generate();
$this->assertEquals($hexKey['pub_y'], $pubKey->getY());
@ -183,14 +190,12 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testCreateFromPrivateKey()
{
$key = PublicKey::createFromPrivateKey($this->getMockPrivateKey());
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
public function testIsValid()
{
$key = new PublicKey();
$this->assertFalse($key->isValid());
$key->setPrivateKey($this->getMockPrivateKey());
$key->generate();
@ -200,9 +205,7 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGetSin()
{
$pub = new PublicKey();
$pub->setPrivateKey($this->getMockPrivateKey());
$sin = $pub->getSin();
$this->assertInstanceOf('Bitpay\SinKey', $sin);
@ -211,18 +214,19 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGetSinOnlyOnce()
{
$pub = new PublicKey();
$pub->setPrivateKey($this->getMockPrivateKey());
$sin = $pub->getSin();
$this->assertSame($sin,$pub->getSin());
$this->assertSame(
$sin,
$pub->getSin()
);
}
public function testIsGenerated()
{
$pub = new PublicKey();
$pub->setPrivateKey($this->getMockPrivateKey());
$this->assertFalse($pub->isGenerated());
$pub->generate();
@ -233,10 +237,13 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
{
$hex = ($hex === null) ? $this->hexKeys[0]['private'] : $hex;
$key = $this->getMock('Bitpay\PrivateKey');
$key->method('isValid')->will($this->returnValue(true));
$key->method('getHex')->will($this->returnValue($hex));
$key
->method('getHex')
->will($this->returnValue($hex));
return $key;
}
}

View File

@ -1,30 +1,34 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* @package Bitpay
* @package Bitcore
*/
class SinKeyTest extends \PHPUnit_Framework_TestCase
{
public function testToString()
{
$pubKey = PublicKey::create();
$this->assertNotNull($pubKey);
$pubKey->setPrivateKey(PrivateKey::create()->generate());
$pubKey->generate();
$sinKey = new SinKey();
$this->assertNotNull($sinKey);
$sinKey->setPublicKey($pubKey);
$this->assertSame('', (string) $sinKey);
$sinKey->generate();
$this->assertEquals(35, strlen((string) $sinKey));
}
@ -34,7 +38,6 @@ class SinKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateWithException()
{
$sinKey = new SinKey();
$this->assertNotNull($sinKey);
$sinKey->generate();
}
@ -45,24 +48,27 @@ class SinKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateWithoutPublicKey()
{
$sinKey = new SinKey();
$this->assertNotNull($sinKey);
$sinKey->generate();
}
public function testGenerateWithoutException()
{
$pubKey = PublicKey::create();
$this->assertNotNull($pubKey);
$pubKey->setPrivateKey(PrivateKey::create()->generate());
$pubKey->generate();
$sinKey = new SinKey();
$this->assertNotNull($sinKey);
$sinKey->setPublicKey($pubKey);
$sinKey->generate();
$this->assertEquals(35, strlen((string) $sinKey));
}
@ -72,17 +78,21 @@ class SinKeyTest extends \PHPUnit_Framework_TestCase
public function testIsValid()
{
$sinKey = new SinKey();
$this->assertNotNull($sinKey);
$this->assertFalse($sinKey->isValid());
$pubKey = PublicKey::create();
$this->assertNotNull($pubKey);
$pubKey->setPrivateKey(PrivateKey::create()->generate());
$pubKey->generate();
$sinKey->setPublicKey($pubKey);
$sinKey->generate();
$this->assertTrue($sinKey->isValid());
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -10,83 +10,89 @@ use org\bovigo\vfs\vfsStream;
class EncryptedFilesystemStorageTest extends \PHPUnit_Framework_TestCase
{
private $root;
private $pubkeyStream;
private $pubkeyName;
private $storage;
public function setUp()
{
$this->pubkeyName = 'tmp/public.key';
$this->root = vfsStream::setup('tmp');
$this->pubkeyStream = vfsStream::url($this->pubkeyName);
$this->storage = new EncryptedFilesystemStorage('satoshi');
}
public function testPersist()
{
$this->storage->persist(new \Bitpay\PublicKey($this->pubkeyStream));
$this->assertTrue($this->root->hasChild($this->pubkeyName));
$storage = new EncryptedFilesystemStorage('dN$8WNaT}j<gD3*q');
$storage->persist(new \Bitpay\PublicKey(vfsStream::url('tmp/public.key')));
$this->assertTrue($this->root->hasChild('tmp/public.key'));
}
public function testUnencodedLoad()
{
$storage = new EncryptedFilesystemStorage('dN$8WNaT}j<gD3*q');
vfsStream::newFile('public.key')
->at($this->root)
->setContent('97f394f4153a75ad7da3d9b8844cf0593c5abbea78695ba41c8528bc7bcd158cdc73a93ba2826d4a9ef1b3552f0f754a2db43010488ebea5648c7d897749df8d27d761683de7c17d225d2464413c89cc5ddc6d0a1b522b0efbeb47cc247a9ecb8d4e5a8790a2eb82cf1a9b6a727b90e3de444f2245b3c6aae7a1f12f3727ad926935f6540a49fd7e7e633b613ee1a196ed56b8c19d2c9353a4d9ee1f94f6a39f0a5bcf6729ea9677e9d9d590e53cdf25e04e2b00ee31f2489b7ae42cb0666dd002b536a95224f11ca0a9dc771b3eaf230b2f2bad72e13837308a58e0acfc03d2ac53522dad3231e754c647c75282bc9882f4b9d4ab712cb901f6d4d03c346df444c4e2a2a2114fd22a3c396c2a0e8ddf6838fa3fc54ea72b5095807c3a6f402cfd7ad15da7b45630bb31ed4c7e95bdfdff477c6b9c0e48fe678266d6b15505eeb2a0e8ff60b400af3f376fd261619fa9c1233efbb75ace29f9dfbc6360f9e4ac7d53e1bf112fa2ab8740f53dd40318da0e7360cb40cbcc15fe3c589bf34fdf7b981800b50d666b2e795438ce22b2640b4d55b98fa08aa37e18d6581e198d5c960574b07ab7daaf89b9e361719d85040a0c1e53b51f96f3119b27f922ab1ae7989bc8d686860f8c2d7201fe427a401be9dba0fd19ced8124d99b1475f75f007bf8cf213065c52544b3dffc126b05c5c3b2965ffacd4a16a395f11341a0149023b9b6df3326a6161cdb28d2e71690560a2');
$key = $storage->load(vfsStream::url('tmp/public.key'));
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
public function testLoad()
{
$storage = new EncryptedFilesystemStorage('dN$8WNaT}j<gD3*q');
vfsStream::newFile('public.key')
->at($this->root)
->setContent('i8A7jkJy1H6oHWPGVxuBcrB360Krq8aZD8g3Ef4JYaLSZIJjhV+Kob1kNYL6091jRA3LpC1C7Tb19FDY80VXuHsd2zTn9QMgfQnl85awBzLdEBxh5Vx/Xv9FQSq9VDrKb2/jhZAnBjBC13rP2KuwS6fj8PNKz4BeVPENh09ADHo0uGhj5tzdXr80E09TkxcmRR2Ss2sGUCiCGWdjFM0AdwmEXDHqSPBHqBF7GuxzG5Ozuh7YLU4sHQoGWLRHKhaWsSyPMvuWLuEN13H7EcyKeHN/RrHP1aXbIJ6YgJWxQ7a4QEe0UH7xkhMJD0eIZM1uowNWpO0+lHUglxtqyU87ILPt2gtAGlXGuuxQqlPnKumNTdE7ji1PL/gClW6gEtACEdqVsAH5pv7EYVFqOhGakzAP2WtF2/SiNEgbu+j2dUYe4KuJ0sxir+v3LknVZ+fR1YdwNoKCbXMArLe8if2rjeNrjHOjs/FbNGIxMoPcPC0L24d3sQxzb2Lw7vJ0bu4zM4D6PoK1AiWYrR6NQuI0lvnH77Roav4qDw23Gs2SdysyCObQzoJboj1+hojEF888u+fBW9ZdqRRwhrwLwqiRC+q5XD1n79pRqh7Y6icJe6iSSLqrUbO/gGKmXguM7Ef55NYmVYESgZHgDtSVmTnk790EiEy2qA71j3UbxbgWH8DlZtMf6rEwqp/7401I1iym');
->setContent('222464cf5e76807259205ed98a1114e3164ecada597352259f9e09ce06524cdf7eaf862bff208d44163b8b24719afbfe031344d97a44502955b63158e012c09f604f66f3c7ca99290e9991a4a1413c3a4095fb6522653ceda25d831d115be3de6756fd7511ed91d970dac0e4e01a5df91ce9b412a0c8a42eb266cf2a93e1d1b50090b3eb89c93fcd85ed2cee6ee08499a6d69c3ffe7836878e30a37df92226fc78a2936f6037d8bf4b0a33bb11dad77b544a1baaf1c097be38d04f6b642285811b9c9e27c51d460a57e298851bb047f6fa2a02f501e7902a660fa66630240cf8586f6cf774b6b0a6e62a06de6eee328b3dfaa3658fd692b0e7590ea58281c8a563e3fe09a1209de96c7919a3b92c5307b782b4729a68b08f220b03df02c15e7742977a48b48c4bff7d060020e3b4717d5ae05d630e9e5f1374d2bb9ac04652ee12ef9de37c67cd07461ae7a201ddd04975ec4f60e781e214b50ca1b756988b7a1868fdbf2b07db66e0e7c9a29526c7d11127bb58c606c515325d7375a21c9d1db63167fb34106c87c49d238fc1eb41309eb5f23d946743534bf8d454729dd94ac9c3d18cb7261fd773c913e674a4427c0b90b4f9a541b77363d43f957445fff395ad5c48b51131913917882413ce8084db0d20ab308b3504d43e8f67afb4f6611324d07d8980ffc8d9ae6817bfe1be5e4f5ad6e5155b9767d15c01c96fc101538071f9bef40978f805e52e31a8e169bf');
$key = $this->storage->load($this->pubkeyStream);
$key = $storage->load(vfsStream::url('tmp/public.key'));
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage [ERROR] In EncryptedFilesystemStorage::readFromFile(): The file "vfs://tmp/public.key" does not exist or cannot be read, check permissions.
* @expectedException Exception
*/
public function testNotFileException()
{
$this->storage->load($this->pubkeyStream);
$storage = new EncryptedFilesystemStorage('satoshi');
$storage->load(vfsStream::url('tmp/public.key'));
}
/**
* @expectedException \Exception
* @expectedException Exception
*/
public function testLoadNotReadableException()
{
if (stripos(PHP_OS, 'WIN') === 0) {
$this->markTestSkipped('Skip \Bitpay\Storage\EncryptedFilesystemStorageTest::testLoadNotReadableException() test on Windows system');
}
vfsStream::newFile('badpublic.key', 0600)
$storage = new EncryptedFilesystemStorage('satoshi');
vfsStream::newFile('public.key', 0600)
->at($this->root)
->setContent('')
->chown(vfsStream::OWNER_ROOT)
->chgrp(vfsStream::GROUP_ROOT);
$this->storage->load(vfsStream::url('tmp/badpublic.key'));
$storage->load(vfsStream::url('tmp/public.key'));
}
/**
* @expectedException \Exception
* @expectedExceptionMessage [ERROR] In EncryptedFilesystemStorage::dataDecode(): Could not decode data "\".
* @expectedException Exception
*/
public function testLoadCouldNotDecode()
{
vfsStream::newFile('badpublic.key')
->at($this->root)
->setContent('\\');
$storage = new EncryptedFilesystemStorage('satoshi');
$key = $this->storage->load(vfsStream::url('tmp/badpublic.key'));
vfsStream::newFile('public.key')
->at($this->root)
->setContent('00');
$key = $storage->load(vfsStream::url('tmp/public.key'));
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
public function testPersistAndLoadWithoutPassword()
{
$storage = new EncryptedFilesystemStorage(null);
$storage->persist(new \Bitpay\PublicKey(vfsStream::url('tmp/public.key')));
$this->assertTrue($this->root->hasChild('tmp/public.key'));
$storage->persist(new \Bitpay\PublicKey($this->pubkeyStream));
$this->assertTrue($this->root->hasChild($this->pubkeyName));
$key = $storage->load($this->pubkeyStream);
$key = $storage->load(vfsStream::url('tmp/public.key'));
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
}

View File

@ -1,71 +1,59 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Storage;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
class FilesystemStorageTest extends \PHPUnit_Framework_TestCase
{
/** @var FilesystemStorage */
private $storage;
/** @var string */
private $key_file_content;
/** @var vfsStreamDirectory */
private $root;
public function setUp()
{
$this->storage = new FilesystemStorage();
$this->key_file_content = 'C:16:"Bitpay\PublicKey":62:{a:5:{i:0;s:20:"vfs://tmp/public.key";i:1;N;i:2;N;i:3;N;i:4;N;}}';
$this->root = vfsStream::setup('tmp');
}
public function testPersist()
{
$this->storage->persist(new \Bitpay\PublicKey(vfsStream::url('tmp/public.key')));
$storage = new FilesystemStorage();
$storage->persist(new \Bitpay\PublicKey(vfsStream::url('tmp/public.key')));
$this->assertTrue($this->root->hasChild('tmp/public.key'));
}
public function testLoad()
{
$storage = new FilesystemStorage();
vfsStream::newFile('public.key')
->at($this->root)
->setContent($this->key_file_content);
->setContent('C:16:"Bitpay\PublicKey":62:{a:5:{i:0;s:20:"vfs://tmp/public.key";i:1;N;i:2;N;i:3;N;i:4;N;}}');
$key = $this->storage->load(vfsStream::url('tmp/public.key'));
$key = $storage->load(vfsStream::url('tmp/public.key'));
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
/**
* @expectedException \Exception
* @expectedException Exception
*/
public function testNotFileException()
{
$this->storage->load(vfsStream::url('tmp/public.key'));
$storage = new FilesystemStorage();
$storage->load(vfsStream::url('tmp/public.key'));
}
/**
* @expectedException \Exception
* @expectedException Exception
*/
public function testLoadNotReadableException()
{
if (stripos(PHP_OS, 'WIN') === 0) {
$this->markTestSkipped('Skip \Bitpay\Storage\EncryptedFilesystemStorageTest::testLoadNotReadableException() test on Windows system');
}
$storage = new FilesystemStorage();
vfsStream::newFile('public.key', 0600)
->at($this->root)
->setContent($this->key_file_content)
->setContent('C:16:"Bitpay\PublicKey":62:{a:5:{i:0;s:20:"vfs://tmp/public.key";i:1;N;i:2;N;i:3;N;i:4;N;}}')
->chown(vfsStream::OWNER_ROOT)
->chgrp(vfsStream::GROUP_ROOT);
$this->storage->load(vfsStream::url('tmp/public.key'));
$storage->load(vfsStream::url('tmp/public.key'));
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -27,6 +27,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetPhone()
{
$this->assertNotNull($this->user);
$this->user->setPhone('555-555-5555');
$this->assertNotNull($this->user->getPhone());
$this->assertSame('555-555-5555', $this->user->getPhone());
@ -44,6 +45,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetEmail()
{
$this->assertNotNull($this->user);
$this->user->setEmail('support@bitpay.com');
$this->assertNotNull($this->user->getEmail());
$this->assertSame('support@bitpay.com', $this->user->getEmail());
@ -61,6 +63,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetFirstName()
{
$this->assertNotNull($this->user);
$this->user->setFirstName('BitPay');
$this->assertNotNull($this->user->getFirstName());
$this->assertSame('BitPay', $this->user->getFirstName());
@ -78,6 +81,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetLastName()
{
$this->assertNotNull($this->user);
$this->user->setLastName('Inc');
$this->assertNotNull($this->user->getLastName());
$this->assertSame('Inc', $this->user->getLastName());
@ -118,6 +122,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetCity()
{
$this->assertNotNull($this->user);
$this->user->setCity('Atlanta');
$this->assertNotNull($this->user->getCity());
$this->assertSame('Atlanta', $this->user->getCity());
@ -135,6 +140,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetState()
{
$this->assertNotNull($this->user);
$this->user->setState('GA');
$this->assertNotNull($this->user->getState());
$this->assertSame('GA', $this->user->getState());
@ -152,6 +158,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetZip()
{
$this->assertNotNull($this->user);
$this->user->setZip('37379');
$this->assertNotNull($this->user->getZip());
$this->assertSame('37379', $this->user->getZip());
@ -169,6 +176,7 @@ class UserTest extends \PHPUnit_Framework_TestCase
public function testSetCountry()
{
$this->assertNotNull($this->user);
$this->user->setCountry('US');
$this->assertNotNull($this->user->getCountry());
$this->assertSame('US', $this->user->getCountry());

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -23,7 +23,6 @@ class Base58Test extends \PHPUnit_Framework_TestCase
$data = array(
array('', '', '3QJmnh'),
);
foreach ($data as $datum) {
$this->assertSame($datum[1], Base58::encode($datum[0]));
}
@ -45,7 +44,6 @@ class Base58Test extends \PHPUnit_Framework_TestCase
array('3e', '25', ''),
array('39', 'z', ''),
);
foreach ($data as $datum) {
$decoded = Base58::decode($datum[1]);
$this->assertSame($datum[0], $decoded, sprintf('%s != %s', $datum[0], $decoded));

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,6 +8,7 @@ namespace Bitpay\Util;
class FingerprintTest extends \PHPUnit_Framework_TestCase
{
public function testGenerate()
{
$finger = Fingerprint::generate();

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
* @package Bitpay
* @package Bitcore
*
* @requires function openssl_random_pseudo_bytes
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2015 BitPay Inc., MIT License
* @license Copyright 2011-2014 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -9,10 +9,11 @@ namespace Bitpay\Util;
use Bitpay\Point;
/**
* @package Bitpay
* @package Bitcore
*/
class UtilTest extends \PHPUnit_Framework_TestCase
{
public function testSha256()
{
$data = array(
@ -93,6 +94,16 @@ class UtilTest extends \PHPUnit_Framework_TestCase
}
}
public function testNonce()
{
$a = Util::nonce();
usleep(1);
$b = Util::nonce();
// ensure a < b
$this->assertGreaterThan($a, $b);
}
public function testGuid()
{
$guid = Util::guid();
@ -162,7 +173,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
$point = Util::doubleAndAdd('1', new Point(1, 1));
$this->assertEquals('1', $point->getX());
$this->assertEquals('1', $point->getY());
$point = new Point(
'0x'.substr(Secp256k1::G, 2, 64),
'0x'.substr(Secp256k1::G, 66, 64)
@ -172,7 +182,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
'0xb7dafe35d7d1aab78b53982c8ba554584518f86d50af565c98e053613c8f15e0',
$point
);
$this->assertEquals('14976827122927988984909748681266837395089399768482149532452617485742004777865', $R->getX());
$this->assertEquals('5009713401941157350243425146365130573323232660945282226881202857781593637456', $R->getY());
@ -180,7 +189,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
'0xfd7c6914790d3bbf3184d9830e3f1a327e951e3478dd0b28f0fd3b0e774bbd68',
$point
);
$this->assertEquals('65041784833307054098962518952641430476519680065454324565175938819000678523383', $R->getX());
$this->assertEquals('53140314933116045874248958072587249546886301333167874306830834776596206062743', $R->getY());
}
@ -191,7 +199,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
array('123456789', '101010001011001111011010111'),
array('0x123456789', '100100011110011010100010110001001'),
);
foreach ($data as $datum) {
$this->assertSame($datum[1], Util::decToBin($datum[0]));
}
@ -222,7 +229,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
new Point(1, 1),
new Point(1, 1)
);
$expectedpoint = new Point("28948022309329048855892746252171976963317496166410141009864396001977208667916", "14474011154664524427946373126085988481658748083205070504932198000988604333958");
$this->assertEquals($expectedpoint, $point);
@ -230,7 +236,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
new Point(0, 0),
new Point(1, 1)
);
$expectedpoint = new Point("0", "0");
$this->assertEquals($expectedpoint, $point);
@ -238,7 +243,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
new Point(1, 0),
new Point(0, 1)
);
$expectedpoint = new Point("0", "115792089237316195423570985008687907853269984665640564039457584007908834671662");
$this->assertEquals($expectedpoint, $point);
}
@ -249,7 +253,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
array('7361746f736869', 'satoshi'),
array('0x7361746f736869', 'satoshi'),
);
foreach ($data as $datum) {
$this->assertSame($datum[1], Util::binConv($datum[0]));
}
@ -264,7 +267,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
if (PHP_VERSION_ID >= 50400) {
$this->assertTrue($requirements['PHP']);
} else {
@ -290,7 +292,6 @@ class UtilTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($requirements['cURL']);
$curl_version = curl_version();
$ssl_supported = ($curl_version['features'] & CURL_VERSION_SSL);
if ($ssl_supported) {
$this->assertTrue($requirements['cURL.SSL']);
} else {
@ -308,4 +309,5 @@ class UtilTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_string($requirements['Math']));
}
}
}

View File

@ -23,6 +23,7 @@
"plural": "Zimbabwean Dollar",
"alts": "",
"payoutFields": [
]
}
]

View File

@ -1 +1 @@
{"facade":"public/invoice","data":{"url":"https://test.bitpay.com/invoice?id=5NxFkXcJbCSivtQRJa4kHP","paymentUrls":{"BIP21":"bitcoin:mgjLEW6oUZ5TeAGMikYsFoBE54dzJybTpH?amount=0.0632","BIP72":"bitcoin:mgjLEW6oUZ5TeAGMikYsFoBE54dzJybTpH?amount=0.0632&r=https://test.bitpay.com/i/5NxFkXcJbCSivtQRJa4kHP","BIP72b":"bitcoin:?r=https://test.bitpay.com/i/5NxFkXcJbCSivtQRJa4kHP","BIP73":"https://test.bitpay.com/i/5NxFkXcJbCSivtQRJa4kHP"},"posData":"{\"posData\":{\"orderId\":\"100000009\"},\"hash\":\"GA.VW7o8puqPA\"}","status":"expired","btcPrice":"0.0032","btcDue":"0.0032","price":1.99,"currency":"USD","exRates":{"USD":619.39},"orderId":"100000009","invoiceTime":1405974404088,"expirationTime":1405975304088,"currentTime":1412886370907,"id":"5NxFkXcJbCSivtQRJa4kHP","btcPaid":"0.0000","rate":619.39,"exceptionStatus":false,"taxIncluded": 0,"token":"9CKEkTYE4VA4skhMPBxUsPQyUqXE36qpmitmYbtKssPnY3p8rYqhTTcEzUeowKwvzL"}}
{"facade":"public/invoice","data":{"url":"https://test.bitpay.com/invoice?id=5NxFkXcJbCSivtQRJa4kHP","posData":"{\"posData\":{\"orderId\":\"100000009\"},\"hash\":\"GA.VW7o8puqPA\"}","status":"expired","btcPrice":"0.0032","btcDue":"0.0032","price":1.99,"taxIncluded":0.0,"currency":"USD","exRates":{"USD":619.39},"orderId":"100000009","invoiceTime":1405974404088,"expirationTime":1405975304088,"currentTime":1412886370907,"id":"5NxFkXcJbCSivtQRJa4kHP","btcPaid":"0.0000","rate":619.39,"exceptionStatus":false,"token":"9CKEkTYE4VA4skhMPBxUsPQyUqXE36qpmitmYbtKssPnY3p8rYqhTTcEzUeowKwvzL"}}

Some files were not shown because too many files have changed in this diff Show More