Compare commits

..

185 Commits

Author SHA1 Message Date
Nicolas Dorier
57922eea0c
Merge pull request #17 from kakaska/remove-behat
Remove behat and integration tests
2019-03-01 23:52:39 +09:00
kakaska
54b169ecb1 Remove behat and integration tests 2019-03-01 13:10:41 +01:00
Nicolas Dorier
4deeb7dcb7
Merge pull request #14 from kakaska/remove-autoloader
Remove \Bitpay\Autoloader class and references
2019-02-21 23:23:01 +09:00
kakaska
2bfef47d65 Remove \Bitpay\Autoloader class and references 2019-02-21 15:13:09 +01:00
Nicolas Dorier
21187ecb7c
Merge pull request #10 from kakaska/3.0.x
Merge master into 3.0.x
2019-02-20 10:37:14 +09:00
kakaska
84324e9f9c Merge branch 'master' into 3.0.x
# Conflicts:
#	.travis.yml
#	README.md
#	VERSION
#	composer.json
#	src/Bitpay/Client/Client.php
#	src/Bitpay/Client/ClientInterface.php
#	src/Bitpay/Client/Request.php
#	src/Bitpay/Client/Response.php
#	src/Bitpay/Config/Configuration.php
#	src/Bitpay/Currency.php
#	src/Bitpay/DependencyInjection/services.xml
#	src/Bitpay/Invoice.php
#	src/Bitpay/InvoiceInterface.php
#	src/Bitpay/Item.php
#	src/Bitpay/Network/Testnet.php
#	src/Bitpay/PrivateKey.php
#	src/Bitpay/Storage/EncryptedFilesystemStorage.php
#	src/Bitpay/Util/Util.php
#	tests/Bitpay/BitpayTest.php
#	tests/Bitpay/Client/Adapter/CurlAdapterTest.php
#	tests/Bitpay/Client/ClientTest.php
#	tests/Bitpay/Client/RequestTest.php
#	tests/Bitpay/Crypto/McryptExtensionTest.php
#	tests/Bitpay/ItemTest.php
#	tests/Bitpay/Math/BcEngineTest.php
#	tests/Bitpay/Network/LivenetTest.php
#	tests/Bitpay/Network/NetworkAwareTest.php
#	tests/Bitpay/Network/TestnetTest.php
#	tests/Bitpay/Storage/EncryptedFilesystemStorageTest.php
#	tests/DataFixtures/invoices/5NxFkXcJbCSivtQRJa4kHP.json
2019-02-19 13:40:58 +01:00
kakaska
a1deccd995 Merge remote-tracking branch 'origin/master' 2019-02-18 07:36:52 +01:00
kakaska
0fb3a8cc24 Merge remote-tracking branch 'remotes/origin/fix-unit-tests'
# Conflicts:
#	tests/Bitpay/Client/ClientTest.php
2019-02-15 09:07:01 +01:00
Chris Kleeschulte
cf0ae957cb updated README 2016-03-10 16:32:22 -05:00
Chris Kleeschulte
4f370def47 Updated Changelog for 3.0.0. 2016-03-10 16:03:17 -05:00
Chris Kleeschulte
5967bd115c Bumped version. 2016-03-10 15:58:09 -05:00
Chris Kleeschulte
75ec2a8512 Added references to new version. 2016-03-04 12:59:43 -05:00
Kellen Presley
9c83ef4788 Merge pull request #189 from kleetus/bug/checkPrice
checkPriceAndCurrency
2016-03-03 10:06:51 -05:00
Chris Kleeschulte
c2e2048505 checkPriceAndCurrency
- should respect that numbers coming from the api might not have decimal points at all, but they are still valid
2016-03-02 15:30:12 -05:00
Chris Kleeschulte
b2c805099a checkPriceAndCurrency
- should respect that numbers coming from the api might not have decimal points at all, but they are still valid
2016-03-02 15:17:25 -05:00
Chris Kleeschulte
4fce92814a Merge pull request #184 from jameswalpole/patch-2
Remove Outdated Link
2016-02-19 11:13:46 -05:00
James Walpole
871debbbb4 Remove Outdated Link 2016-02-19 09:12:08 -05:00
Patrick Nagurny
66537e588f Merge pull request #181 from kleetus/bug/field_types
Bug/field types
2016-02-16 10:43:30 -05:00
Chris Kleeschulte
8a228cdda6 Merge pull request #183 from marcod85/master
fix timezone ids for case-sensitive systems
2016-02-15 13:32:51 -05:00
Chris Kleeschulte
a0dd12b860 Merge pull request #182 from jameswalpole/patch-1
Update Configuration Doc Links
2016-02-15 13:32:05 -05:00
Marco Dania
366a62065f fix timezone ids for case-sensitive systems 2016-02-15 15:04:35 +01:00
James Walpole
a4bd4a2733 Update Configuration Doc Links 2016-02-14 21:47:46 -05:00
Chris Kleeschulte
b6b12087d5 Invoice class mutator type-checking
- Model classes will/should test types on mutators, a sane model is calling is_numeric followed by floatval for float types

Rationale: 

Instantiators of models should take care to construct fields of the appropriate type, but model's should have a bit of checking as well for safety.
2016-02-12 13:52:20 -05:00
Chris Kleeschulte
e96fcd3447 Merge branch 'master' of github.com:bitpay/php-client 2016-02-05 12:48:49 -05:00
Chris Kleeschulte
66e1269a92 Merge pull request #177 from kleetus/leonar15_master
Adding paymentUrls to Invoices
2016-02-05 12:48:15 -05:00
Chris Kleeschulte
0f8c3abd27 Fixed scope of PaymentUrlSet. 2016-02-05 12:42:44 -05:00
Leo Hochberg
f52511c7d2 fixed an issue where bitpay API doesn't return paymentUrls when an invoice is already paid 2016-02-05 12:17:29 -05:00
Leo Hochberg
c0ab518282 updated test data for invoices 2016-02-05 12:17:29 -05:00
Leo Hochberg
f5cf55eed6 fixed clientTest to add newly required invoice interface method
added new test to make sure payment urls are accessed correctly
2016-02-05 12:15:04 -05:00
Leo Hochberg
dba40cf579 more PSR fixes 2016-02-05 12:14:02 -05:00
Leo Hochberg
d8d23fcbd8 fixed PSR issues 2016-02-05 12:14:02 -05:00
Leo Hochberg
4a0f0f969b set paymentUrls when creating or loading an invoice via client 2016-02-05 12:14:02 -05:00
Leo Hochberg
9a2250c71d updated the invoiceintercae and invoice class to support the new paymentUrlSet object 2016-02-05 12:14:02 -05:00
Leo Hochberg
37cc9f97f0 created paymentUrlInterface and PaymentUrlSet to hold the various payment urls returned for an invoice 2016-02-05 12:14:02 -05:00
Chris Kleeschulte
f539f435b3 Updated package for use with Symfony 3.0 or 2.3
- Please note that the integration tests won't work with Symfony 3 due to Behat not supporting this version yet.
- Unit tests are function with both Symfony 2.x or 3.0
2016-01-28 12:44:59 -05:00
Kellen Presley
6ccabf89cd Merge pull request #175 from kleetus/bug/fix_timezone
Fixed invoice, expiration, and current time error
2016-01-25 10:25:41 -05:00
Chris Kleeschulte
8253cd25d2 Manipulated the times from the API in the client class instead of the invoice class. 2016-01-22 19:00:39 -05:00
Chris Kleeschulte
e0ed633d50 Fixed invoice, expiration, and current time error
- client was trying to create objects from unix timestamps with millisecond resolution
- added a test to ensure these time-based objects are always in the past
2016-01-22 11:30:30 -05:00
Chris Kleeschulte
a3bfc4416b Merge pull request #170 from Invision70/patch-1
fixed timezone
2015-12-28 12:59:58 -05:00
Yuriy
dfeeb04b25 Update Token.php 2015-12-25 14:25:16 +05:00
Kellen Presley
c3e89d99e0 Merge pull request #168 from kleetus/version_bump
Bumped version to 2.2.8 from 2.2.6 (it was supposed to be 2.2.7 at th…
2015-12-03 18:05:05 -05:00
Chris Kleeschulte
8d758fa24a Bumped version to 2.2.8 from 2.2.6 (it was supposed to be 2.2.7 at this point). 2015-12-03 16:30:02 -05:00
Kellen Presley
48e0eb2d07 Merge pull request #167 from kleetus/bug/namespaces
Namespaced class name references/ Custom HTTP Accept Version Header
2015-11-17 16:30:24 -05:00
Chris Kleeschulte
63bd1a6a0c Repaired tests based on current changes to the code. 2015-11-16 19:13:28 -05:00
Chris Kleeschulte
5bfcc6026b Namespaced class name references/ Custom HTTP Accept Version Header
1. is_a function is now returning false unless the class name is given
with the namespace reference.
2. X-Accept-Version needs to be 2.0.0, referring to the API version and
not the plugin version.
2015-11-16 15:58:35 -05:00
Patrick Nagurny
ff700ec8ed Merge pull request #162 from gabegattis/bug/btcPaidBtcPrice
change btcPrice to btcPaid
2015-10-23 13:52:03 -04:00
Gabe Gattis
e3de9d9757 change btcPrice to btcPaid 2015-10-23 13:14:10 -04:00
Rich Morgan
aeb965c8f7 Added validation for url parameter 2015-09-22 16:10:14 -04:00
Rich Morgan
8f5625eb3e Corrected transaction speed set test 2015-09-22 16:05:04 -04:00
Rich Morgan
52efd15474 Moved documentation to interface
and refactor for property validation checking, added constructor parameters.
2015-09-22 16:02:18 -04:00
Rich Morgan
9506d425cd Updated copyright year and minor refactoring
also updated the documentation.
2015-09-22 14:22:34 -04:00
Rich Morgan
db61457819 Updated method parameter documenation 2015-09-22 14:14:16 -04:00
Rich Morgan
34de91fa4b Updated method return type documenation 2015-09-22 14:05:58 -04:00
Rich Morgan
b43a8750f1 Updated copyright year and minor refactoring 2015-09-22 13:49:44 -04:00
Rich Morgan
c0fe48e947 Refactor to improve code quality 2015-09-22 13:40:47 -04:00
Rich Morgan
2f9295eb59 Updated method parameter documenation 2015-09-22 13:36:53 -04:00
Rich Morgan
e796d8ee0c Corrected typo in method name 2015-09-22 13:33:36 -04:00
Rich Morgan
35ae47f04f Updated copyright year and minor refactoring
also moved hardcoded default configuration values to class properties.
2015-09-22 13:29:04 -04:00
Rich Morgan
713f46b70b Corrected namespace scope in documentation 2015-09-22 13:27:14 -04:00
Rich Morgan
cde7566614 Corrected exception type 2015-09-22 12:56:19 -04:00
Rich Morgan
261a1f1066 Corrected class types 2015-09-22 12:48:21 -04:00
Rich Morgan
344adcf98f Updated copyright year and minor refactoring 2015-09-22 12:46:18 -04:00
Rich Morgan
e30a00a405 Corrected class types 2015-09-22 12:42:38 -04:00
Rich Morgan
8c02b57175 Corrected class types 2015-09-22 12:42:18 -04:00
Rich Morgan
b4b377c77c Corrected class types 2015-09-22 12:37:16 -04:00
Rich Morgan
d74d6dba11 Corrected class types 2015-09-22 12:36:59 -04:00
Rich Morgan
6827953da0 Updated copyright year and minor refactoring
and corrected parameter type.
2015-09-22 12:32:46 -04:00
Rich Morgan
58dd99921b Corrected class types 2015-09-22 12:32:22 -04:00
Rich Morgan
2486247fd6 Corrected class types 2015-09-22 12:05:08 -04:00
Rich Morgan
2204e5e42a Corrected method parameter types 2015-09-16 20:07:59 -04:00
Rich Morgan
b1382029d2 Updated exception message with more info 2015-09-16 20:05:51 -04:00
Rich Morgan
0fbb661de9 Corrected class types 2015-09-16 20:03:28 -04:00
Rich Morgan
10b8cecaed Updated copyright year and minor refactoring 2015-09-16 20:01:56 -04:00
Rich Morgan
ff7876fe3a Refactor to improve code quality 2015-09-16 19:59:43 -04:00
Rich Morgan
6641f919da Corrected class types 2015-09-16 19:56:26 -04:00
Rich Morgan
5360adc697 Corrected method parameter types 2015-09-16 19:50:55 -04:00
Rich Morgan
654184bc2a Updated currency list with new values 2015-09-16 19:48:43 -04:00
Rich Morgan
91f3a23fe7 Corrected class types 2015-09-16 19:41:53 -04:00
Rich Morgan
5cafe38f80 Updated copyright year and minor refactoring 2015-09-16 19:35:42 -04:00
Rich Morgan
5503814aa6 Corrected class types 2015-09-16 19:34:56 -04:00
Rich Morgan
f9fb38cf55 Corrected class types 2015-09-16 19:33:45 -04:00
Rich Morgan
24573a19e3 Updated copyright year and minor refactoring 2015-09-16 19:32:28 -04:00
Rich Morgan
e58e21db36 Updated copyright year and minor refactoring 2015-09-16 19:31:58 -04:00
Rich Morgan
a0facda4d9 Updated copyright year and minor refactoring 2015-09-16 19:31:21 -04:00
Rich Morgan
f84b9ec3bd Updated copyright year and minor refactoring
also corrected method parameter & return types
2015-09-16 19:30:15 -04:00
Rich Morgan
d4902d9cf0 Corrected class types 2015-09-16 19:29:51 -04:00
Rich Morgan
80e710c521 Corrected method parameter types 2015-09-16 19:23:57 -04:00
Rich Morgan
701129a811 Corrected method parameter types 2015-09-16 19:22:57 -04:00
Rich Morgan
97c4344237 Added param to ignore autloader unregister fails 2015-09-16 19:20:27 -04:00
Rich Morgan
ce450ea8cd Updated copyright year and minor refactoring 2015-09-16 19:17:09 -04:00
Rich Morgan
1e72d49bfc Updated copyright year and minor refactoring
also added return value checks for registering and unregistering the autoloader.
2015-09-16 19:14:06 -04:00
Rich Morgan
70df1190ba Corrected return method types 2015-09-16 19:07:02 -04:00
Rich Morgan
6fad9f6b78 Removed white space for PSR check 2015-09-16 19:03:19 -04:00
Rich Morgan
feef9081de Removed unneeded variables in exception handling 2015-09-16 18:59:10 -04:00
Rich Morgan
2c854bdd44 Corrected camel case method name 2015-09-16 18:46:22 -04:00
Rich Morgan
0ae18e763b Corrected variable name 2015-09-16 18:44:30 -04:00
Rich Morgan
3f95d2fe87 Refactor to improve code quality 2015-09-16 18:39:56 -04:00
Rich Morgan
87614cf494 Fix to load test 2015-09-16 18:13:15 -04:00
Rich Morgan
a360bdeeee Uncommented file creation test 2015-09-16 17:54:26 -04:00
Rich Morgan
9668ccdb93 Moved stream create order 2015-09-16 17:44:24 -04:00
Rich Morgan
2611175288 Update tests to use class-level vars 2015-09-16 17:38:45 -04:00
Rich Morgan
df9a608d07 Added specific openssl error messages 2015-09-16 17:21:52 -04:00
Rich Morgan
f50af5c4f7 Updated exception message with more info 2015-09-16 17:03:10 -04:00
Rich Morgan
597e364d65 Corrected return method types 2015-09-16 16:59:52 -04:00
Rich Morgan
7e7737416e Added base64 encode/decode failure checks 2015-09-16 16:56:50 -04:00
Rich Morgan
58a52f76b5 Added check for encryption failure in persist() 2015-09-16 16:44:17 -04:00
Rich Morgan
347eecf8bb Travis update for new container infrastructure 2015-09-16 16:35:36 -04:00
Rich Morgan
7f840e39bc Updated copyright year and minor refactoring 2015-09-16 16:14:04 -04:00
Rich Morgan
7a27ea32a9 Updated copyright year and minor refactoring
added base64_encode/decode method to ensure proper storage of binary data from the encryption process.  Also added some more value checks to detect failure in the file operations.
2015-09-16 16:11:55 -04:00
Rich Morgan
0b39a2733d Updated copyright year and minor refactoring
also improved error messages to be more informative.
2015-09-16 15:43:21 -04:00
Rich Morgan
e33ae9476a Update MockStorage.php 2015-09-16 15:35:41 -04:00
Rich Morgan
848a9006c2 Updated copyright year and minor refactoring 2015-09-16 15:03:16 -04:00
Rich Morgan
82eade1531 Updated copyright year and minor refactoring 2015-09-15 21:25:03 -04:00
Rich Morgan
43e9b915ae Updated copyright year and minor refactoring 2015-09-15 21:18:40 -04:00
Rich Morgan
a16d119124 Updated copyright year and minor refactoring 2015-09-15 21:16:47 -04:00
Rich Morgan
029d4f847f Updated copyright year and minor refactoring 2015-09-15 21:14:31 -04:00
Rich Morgan
cb8b635480 Updated copyright year and minor refactoring 2015-09-15 21:11:50 -04:00
Rich Morgan
b6e3c4be5d Updated copyright year and minor refactoring 2015-09-15 21:11:23 -04:00
Rich Morgan
0167d42270 Updated copyright year and minor refactoring 2015-09-15 21:09:44 -04:00
Rich Morgan
e3177a10b8 Updated copyright year and minor refactoring 2015-09-15 21:09:03 -04:00
Rich Morgan
37847b5422 Updated copyright year and minor refactoring 2015-09-15 21:08:33 -04:00
Rich Morgan
51c74e5768 New Mozilla cert bundle update 2015-09-15 21:06:29 -04:00
Rich Morgan
6e1bcd2945 Updated copyright year and minor refactoring 2015-09-15 21:02:10 -04:00
Rich Morgan
a925f5a75f Updated copyright year and minor refactoring 2015-09-15 20:59:11 -04:00
Rich Morgan
6fc1aa9384 Updated copyright year and minor refactoring 2015-09-15 20:58:32 -04:00
Rich Morgan
e2a6fae9ed Updated copyright year and minor refactoring 2015-09-15 20:57:49 -04:00
Rich Morgan
9df235b204 Updated copyright year and minor refactoring 2015-09-15 20:56:43 -04:00
Rich Morgan
07af641f4b Updated copyright year and minor refactoring 2015-09-15 20:53:21 -04:00
Rich Morgan
aeb380df5c Updated copyright year and minor refactoring 2015-09-15 20:52:50 -04:00
Rich Morgan
a21df08eb8 Updated copyright year and minor refactoring 2015-09-15 20:52:25 -04:00
Rich Morgan
f923cf2ae3 Removed deprecated nonce method 2015-09-15 20:48:25 -04:00
Rich Morgan
e17cdd3a2f Updated copyright year and minor refactoring 2015-09-15 20:36:00 -04:00
Rich Morgan
3939d2a6b5 Updated copyright year and minor refactoring 2015-09-15 20:33:03 -04:00
Rich Morgan
a7eb7bed6f Updated copyright year and minor refactoring 2015-09-15 20:32:37 -04:00
Rich Morgan
a66d98b3af Updated copyright year and minor refactoring 2015-09-15 20:30:53 -04:00
Rich Morgan
991a869e27 Updated copyright year and minor refactoring 2015-09-15 20:28:24 -04:00
Rich Morgan
715e4cd70b Updated copyright year and minor refactoring 2015-09-15 20:27:34 -04:00
Rich Morgan
8198790488 Removed deprecated nonce method
also cleaned up the inline documentation and minor formatting.
2015-09-15 20:22:04 -04:00
Rich Morgan
7fee602207 Removed deprecated nonce methods & vars
also added parameters to the constructor.
2015-09-15 19:54:40 -04:00
Rich Morgan
03fe25ceee Removed deprecated nonce method 2015-09-15 19:48:37 -04:00
Rich Morgan
31a1283057 Added experimental hhvm build testing 2015-09-15 19:33:46 -04:00
Rich Morgan
31cc0f7a8d Minor formatting 2015-09-15 19:28:02 -04:00
Rich Morgan
98981dfa8c Updated description 2015-09-15 19:19:53 -04:00
Rich Morgan
198b304dd7 Minor formatting
Removed deprecated docs badge.
2015-09-15 19:17:47 -04:00
Rich Morgan
a6e5b5f436 Updated copyright year and minor refactoring
cleaned up unnecessary inverted logic checks
2015-09-15 19:14:27 -04:00
Rich Morgan
5f22e8208b Minor formatting 2015-09-15 19:07:37 -04:00
Rich Morgan
7736734033 Update currencies.json 2015-09-15 19:04:47 -04:00
Rich Morgan
4d59247fc0 Update with_tokens.json 2015-09-15 19:03:23 -04:00
Rich Morgan
e211ed5834 Updated copyright year and minor refactoring 2015-09-15 19:02:41 -04:00
Rich Morgan
82f1ea62b4 Updated copyright year and minor refactoring 2015-09-15 19:02:02 -04:00
Rich Morgan
56d8804f40 Updated copyright year and minor refactoring 2015-09-15 18:58:50 -04:00
Rich Morgan
5b46f35260 Updated copyright year and minor refactoring 2015-09-15 18:57:49 -04:00
Rich Morgan
4ae7392e8c Updated copyright year and minor refactoring 2015-09-15 18:56:48 -04:00
Rich Morgan
9a28b90f60 Updated copyright year and minor refactoring 2015-09-15 18:56:03 -04:00
Rich Morgan
971f65c584 Updated copyright year and minor refactoring 2015-09-15 18:53:46 -04:00
Rich Morgan
e6aa1c44b2 Updated copyright year and minor refactoring 2015-09-15 18:47:56 -04:00
Rich Morgan
7fa8139380 Updated copyright year and minor refactoring 2015-09-15 18:33:27 -04:00
Rich Morgan
7364d7cd42 Updated copyright year and minor refactoring 2015-09-15 18:30:14 -04:00
Rich Morgan
dfa099e381 Updated copyright year and minor refactoring 2015-09-15 18:29:44 -04:00
Rich Morgan
b424b2ae90 Updated copyright year and minor refactoring 2015-09-15 18:29:07 -04:00
Rich Morgan
effcee7a15 Updated copyright year and minor refactoring 2015-09-15 18:28:12 -04:00
Rich Morgan
ba83f555ea Updated copyright year and minor refactoring 2015-09-15 18:26:47 -04:00
Rich Morgan
1d9e7c4664 Updated copyright year and minor refactoring 2015-09-15 18:19:05 -04:00
Rich Morgan
18d8219ca6 Updated copyright year and minor refactoring 2015-09-15 18:18:16 -04:00
Rich Morgan
a8ebc01d9d Updated copyright year and minor refactoring 2015-09-15 18:17:06 -04:00
Rich Morgan
6b67fbab84 Updated copyright year and minor refactoring 2015-09-15 18:16:01 -04:00
Rich Morgan
65bc02b4d9 Updated copyright year and minor refactoring 2015-09-15 18:07:59 -04:00
Rich Morgan
281a2625e5 Updated copyright year and minor refactoring 2015-09-15 18:06:52 -04:00
Rich Morgan
6689dd3344 Updated copyright year and minor refactoring
and removed empty tests.
2015-09-15 18:04:44 -04:00
Rich Morgan
5f7b18ccb0 Updated copyright year and minor refactoring 2015-09-15 17:59:38 -04:00
Rich Morgan
580d4a5b27 Updated copyright year and minor refactoring 2015-09-15 17:57:58 -04:00
Rich Morgan
8bf7a62e97 Updated copyright year and minor refactoring 2015-09-15 17:54:14 -04:00
Rich Morgan
ed7b4a2ffc Updated copyright year and minor refactoring 2015-09-15 17:53:07 -04:00
Rich Morgan
4d12f6aa65 Updated copyright year and minor refactoring 2015-09-15 17:50:23 -04:00
Rich Morgan
2f60d3acb7 Updated copyright year and minor refactoring 2015-09-15 17:49:29 -04:00
Rich Morgan
c6503e0233 Updated copyright year and minor refactoring 2015-09-15 17:45:11 -04:00
Rich Morgan
014da0dc55 Updated copyright year and minor refactoring 2015-09-15 17:41:24 -04:00
Rich Morgan
5766d8a67f Updated copyright year and minor refactoring 2015-09-15 17:36:57 -04:00
Rich Morgan
8da8aeda2c Updated copyright year and minor refactoring 2015-09-15 17:35:34 -04:00
Rich Morgan
97162a5cd5 Updated copyright year and minor refactoring 2015-09-15 17:34:52 -04:00
Rich Morgan
f8a7a98d4a Updated copyright year and minor refactoring 2015-09-15 17:31:44 -04:00
Rich Morgan
4f61601b85 Updated copyright year and minor refactoring 2015-09-15 17:30:43 -04:00
Rich Morgan
9efe33beb1 Updated copyright year and minor refactoring 2015-09-15 17:29:41 -04:00
Rich Morgan
e3e6beb176 Removed deprecated nonce tests 2015-09-15 17:28:39 -04:00
Rich Morgan
d49bf1f7f4 Removed deprecated nonce tests 2015-09-15 17:21:39 -04:00
106 changed files with 2695 additions and 2771 deletions

View File

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

View File

@ -83,6 +83,25 @@ 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,7 +1,3 @@
# === 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
=================
@ -12,11 +8,10 @@ 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 new cryptographically secure API: https://bitpay.com/api
This is a self-contained PHP implementation of BitPay's cryptographically secure API: https://bitpay.com/api
# Installation
@ -37,15 +32,8 @@ Add to your composer.json file by hand.
...
"require": {
...
"bitpay/php-client": "dev-master"
},
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/btcpayserver/php-bitpay-client"
}
],
"bitpay/php-client": "^3.0"
}
...
}
```
@ -68,24 +56,6 @@ 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 @@
2.2.20
3.0.0

View File

@ -1,32 +0,0 @@
# 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,12 +3,11 @@
<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>

View File

@ -1,10 +0,0 @@
<?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 new cryptographically secure BitPay API",
"description": "PHP Library to work with the cryptographically secure BitPay API",
"license": "MIT",
"minimum-stability": "stable",
"keywords": ["bitpay", "bitcoin"],
@ -32,13 +32,8 @@
"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",
"behat/mink-goutte-driver": "1.*",
"phpmd/phpmd": "~2.1.3",
"phpmd/phpmd": "master-dev",
"phpunit/phpunit": "~4.3.1",
"fzaninotto/faker": "~1.4.0",
"mikey179/vfsStream": "~1.4.0",
@ -53,7 +48,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.2.x-dev"
"dev-master": "3.0.x-dev"
}
}
}

View File

@ -3,25 +3,6 @@ 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,20 +42,15 @@ 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,19 +15,13 @@ 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,24 +27,20 @@ class AccessToken implements AccessTokenInterface
protected $label;
/**
* @var boolean
* Set various defaults for this object.
*/
protected $useNonce;
/**
*/
public function __construct()
public function __construct($id = null, $email = null, $label = null)
{
/**
* Set various defaults for this object.
*/
$this->useNonce = true;
$this->id = $id;
$this->email = $email;
$this->label = $label;
}
/**
* @param string $id
* Setter for the id.
*
* @return AccessTokenInterface
* @param string $id
* @return AccessToken
*/
public function setId($id)
{
@ -64,9 +60,10 @@ class AccessToken implements AccessTokenInterface
}
/**
* @param string $email
* Setter for the email address.
*
* @return AccessTokenInterface
* @param string $email
* @return AccessToken
*/
public function setEmail($email)
{
@ -86,9 +83,10 @@ class AccessToken implements AccessTokenInterface
}
/**
* @param string $label
* Setter for the label.
*
* @return AccessTokenInterface
* @param string $label
* @return AccessToken
*/
public function setLabel($label)
{
@ -106,36 +104,4 @@ 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;
/**
* Creates an access token for the given client
* Interface for an access token for the given client
*
* @package Bitpay
*/
@ -27,9 +27,4 @@ interface AccessTokenInterface
* @return string
*/
public function getLabel();
/**
* @return boolean
*/
public function isNonceDisabled();
}

View File

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

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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
*/

View File

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

View File

@ -1,13 +1,13 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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;
/**
* Setups container and is ready for some dependency injection action
* Sets up container and prepares for dependency injection.
*
* @package Bitpay
*/
class Bitpay
{
/**
* @var ContainerInterface
* @var ContainerBuilder
*/
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 ContainerInterface $container
* @param null|ContainerBuilder $container
*/
public function __construct($config = array(), ContainerInterface $container = null)
public function __construct($config = array(), ContainerBuilder $container = null)
{
$this->container = $container;
@ -50,6 +50,8 @@ class Bitpay
/**
* Initialize the container
*
* @param array|string $config
*/
protected function initializeContainer($config)
{
@ -58,7 +60,10 @@ class Bitpay
}
/**
* Build the container of services and parameters
* Build the container of services and parameters.
*
* @param array|string $config
* @return ContainerBuilder
*/
protected function buildContainer($config)
{
@ -70,16 +75,20 @@ 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(ContainerInterface $container)
private function prepareContainer(ContainerBuilder $container)
{
foreach ($this->getDefaultExtensions() as $ext) {
$container->registerExtension($ext);
@ -88,10 +97,10 @@ class Bitpay
}
/**
* @param ContainerInterface $container
* @return LoaderInterface
* @param ContainerBuilder $container
* @return DelegatingLoader
*/
private function getContainerLoader(ContainerInterface $container)
private function getContainerLoader(ContainerBuilder $container)
{
$locator = new FileLocator();
$resolver = new LoaderResolver(
@ -105,9 +114,9 @@ class Bitpay
}
/**
* Returns an array of the default extensions
* Returns an array of the default extensions.
*
* @return array
* @return BitpayExtension[]
*/
private function getDefaultExtensions()
{
@ -117,7 +126,7 @@ class Bitpay
}
/**
* @return ContainerInterface
* @return ContainerBuilder
*/
public function getContainer()
{
@ -125,7 +134,7 @@ class Bitpay
}
/**
* @return mixed
* @return object|null
*/
public function get($service)
{

View File

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

View File

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

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -11,9 +11,7 @@ use Bitpay\Client\ResponseInterface;
use Bitpay\Client\Response;
/**
* Adapter that sends Request objects using CURL
*
* @TODO add way to configure curl with options
* Adapter class that sends Request objects using cURL.
*
* @package Bitpay
*/
@ -33,7 +31,7 @@ class CurlAdapter implements AdapterInterface
}
/**
* Returns an array of curl settings to use
* Returns an array of cURL settings to use
*
* @return array
*/
@ -45,14 +43,18 @@ class CurlAdapter implements AdapterInterface
/**
* @inheritdoc
*/
public function sendRequest(RequestInterface $request)
public function sendRequest(\Bitpay\Client\Request $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)) {
if (is_null($curl_option_value) === false) {
$default_curl_options[$curl_option_key] = $curl_option_value;
}
}
@ -71,13 +73,14 @@ class CurlAdapter implements AdapterInterface
$raw = curl_exec($curl);
if (false === $raw) {
if ($raw === false) {
$errorMessage = curl_error($curl);
curl_close($curl);
throw new \Bitpay\Client\ConnectionException($errorMessage);
throw new \Bitpay\Client\ConnectionException('[ERROR] In CurlAdapter::sendRequest(): curl_exec failed with the error "' . $errorMessage . '".');
}
/** @var ResponseInterface */
/** @var Response */
$response = Response::createFromRawResponse($raw);
// For some unknown reason, on some machine, the status code is equal to 0
@ -89,12 +92,12 @@ class CurlAdapter implements AdapterInterface
}
/**
* Returns an array of default curl settings to use
* Returns an array of default cURL settings to use.
*
* @param RequestInterface $request
* @param \Bitpay\Client\Request $request
* @return array
*/
private function getCurlDefaultOptions(RequestInterface $request)
private function getCurlDefaultOptions(\Bitpay\Client\Request $request)
{
return array(
CURLOPT_URL => $request->getFullUri(),
@ -103,6 +106,7 @@ 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,7 +1,14 @@
<?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,7 +1,14 @@
<?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,13 +1,12 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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;
@ -15,8 +14,9 @@ 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 uri
* @var string
*/
protected $uri;
@ -84,6 +84,8 @@ class Client implements ClientInterface
}
/**
* Set the network adapter object to use.
*
* @param AdapterInterface $adapter
*/
public function setAdapter(AdapterInterface $adapter)
@ -92,6 +94,8 @@ class Client implements ClientInterface
}
/**
* Assigns the token to use for a request.
*
* @param TokenInterface $token
* @return ClientInterface
*/
@ -111,8 +115,10 @@ 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();
$invoice
->setToken($invoiceToken->setToken($data['token']))
->setUrl($data['url'])
@ -121,7 +127,7 @@ class Client implements ClientInterface
->setBtcPrice(array_key_exists('btcPrice', $data) ? $data['btcPrice'] : '')
->setPrice($data['price'])
->setTaxIncluded($data['taxIncluded'])
->setCurrency(new \Bitpay\CurrencyUnrestricted($data['currency']))
->setCurrency(new \Bitpay\Currency($data['currency']))
->setOrderId(array_key_exists('orderId', $data) ? $data['orderId'] : '')
->setInvoiceTime($invoiceTime)
->setExpirationTime($expirationTime)
@ -136,6 +142,12 @@ 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;
}
@ -156,56 +168,53 @@ 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(),
'nonce' => Util::nonce(),
'token' => $this->token->getToken(),
'paymentCurrencies' => $invoice->getPaymentCurrencies(),
'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(),
);
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);
@ -221,12 +230,17 @@ 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
@ -239,6 +253,7 @@ class Client implements ClientInterface
->setPluralName($value['plural'])
->setAlts($value['alts'])
->setPayoutFields($value['payoutFields']);
$value = $currency;
});
@ -267,12 +282,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();
}
@ -288,21 +303,26 @@ 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'])
@ -323,9 +343,11 @@ 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);
@ -333,11 +355,14 @@ 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);
}
@ -405,12 +430,13 @@ 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']);
@ -425,19 +451,22 @@ 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'];
$data = $body['data'];
$payout = new \Bitpay\Payout();
$payout
->setId($data['id'])
->setAccountId($data['account'])
@ -488,12 +517,15 @@ 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');
}
@ -520,19 +552,22 @@ 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 \InvalidArgumentException("pairing code is not legal");
throw new \Exception('[ERROR] In Client::createToken(): The pairing code provided 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) {
@ -542,13 +577,13 @@ class Client implements ClientInterface
$tkn = $body['data'][0];
$createdAt = new \DateTime();
$pairingExpiration = new \DateTime();
$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']);
@ -556,15 +591,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
*/
@ -574,7 +609,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
*/
@ -590,6 +625,7 @@ 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);
@ -597,7 +633,9 @@ 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'])) {
@ -605,17 +643,13 @@ class Client implements ClientInterface
}
$data = $body['data'];
$invoice = new \Bitpay\Invoice();
$invoice = $this->fillInvoiceData($invoice, $data);
return $invoice;
}
/**
* @param RequestInterface $request
* @return ResponseInterface
@ -632,11 +666,12 @@ class Client implements ClientInterface
/**
* @param RequestInterface $request
* @throws \Exception
*/
protected function addIdentityHeader(RequestInterface $request)
{
if (null === $this->publicKey) {
throw new \Exception('Please set your Public Key.');
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.');
}
$request->setHeader('x-identity', (string) $this->publicKey);
@ -644,6 +679,7 @@ class Client implements ClientInterface
/**
* @param RequestInterface $request
* @throws \Exception
*/
protected function addSignatureHeader(RequestInterface $request)
{
@ -684,20 +720,25 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -10,34 +10,20 @@ use Bitpay\InvoiceInterface;
use Bitpay\PayoutInterface;
/**
* Sends request(s) to bitpay server
* Interface for class that sends request(s) to BitPay.
*
* @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 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);
const NAME = 'BitPay PHP-Client';
const VERSION = '2.2.20';
public function getCurrencies();
@ -47,7 +33,6 @@ interface ClientInterface
* @throws \Exception
*/
public function createInvoice(InvoiceInterface $invoice);
//public function getInvoices();
/**
* @param $invoiceId
@ -56,17 +41,9 @@ 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
@ -94,18 +71,11 @@ 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,7 +1,13 @@
<?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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -44,8 +44,6 @@ class Request implements RequestInterface
*/
protected $path;
/**
*/
public function __construct()
{
// Set some sane default headers
@ -62,7 +60,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
*/
@ -93,7 +91,7 @@ class Request implements RequestInterface
/**
* Set the method of the request, for known methods see the
* RequestInterface
* RequestInterface.
*
* @param string $method
*/
@ -110,7 +108,7 @@ class Request implements RequestInterface
return $this->uri;
}
/**
/**
* @inheritdoc
*/
public function getFullUri()
@ -130,6 +128,7 @@ class Request implements RequestInterface
public function setUri($uri)
{
$this->uri = $uri;
return $this;
}
@ -140,6 +139,7 @@ class Request implements RequestInterface
{
// remove invalid headers
$headers = $this->headers;
foreach ($headers as $header => $value) {
if (empty($header) || empty($value)) {
unset($headers[$header]);
@ -149,9 +149,13 @@ 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);
}
@ -171,20 +175,22 @@ 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;
}
@ -197,9 +203,10 @@ class Request implements RequestInterface
}
/**
* The the body of the request
* Sets the body of the request.
*
* @param string $body
* @return Request
*/
public function setBody($body)
{
@ -219,6 +226,7 @@ class Request implements RequestInterface
/**
* @param string $host
* @return Request
*/
public function setPath($path)
{

View File

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

View File

@ -1,13 +1,12 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -15,35 +15,42 @@ 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(getenv('HOME').'/.bitpay/api.pub')
->defaultValue($this->getPubKeyFilename())
->end()
->scalarNode('private_key')
->info('Private Key Filename')
->defaultValue(getenv('HOME').'/.bitpay/api.key')
->defaultValue($this->getPriKeyFilename())
->end()
->scalarNode('sin_key')
->info('Private Key Filename')
->defaultValue(getenv('HOME').'/.bitpay/api.sin')
->info('SIN Filename')
->defaultValue($this->getSinFilename())
->end()
->enumNode('adapter')
->values(array('curl', 'mock'))
->values($this->adapters)
->info('Client Adapter')
->defaultValue('curl')
->defaultValue($this->adapters[0])
->end()
->append($this->addKeyStorageNode())
->scalarNode('key_storage_password')
@ -56,11 +63,13 @@ 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()
{
@ -69,7 +78,7 @@ class Configuration implements ConfigurationInterface
$node
->info('Class that is used to store your keys')
->defaultValue('Bitpay\Storage\EncryptedFilesystemStorage')
->defaultValue($this->defstorage)
->validate()
->always()
->then(function ($value) {
@ -83,13 +92,8 @@ class Configuration implements ConfigurationInterface
}
// requires PHP >= 5.3.7
if (!is_subclass_of($value, 'Bitpay\Storage\StorageInterface')) {
throw new \Exception(
sprintf(
'"%s" does not implement "Bitpay\Storage\StorageInterface"',
$value
)
);
if (is_subclass_of($value, 'Bitpay\Storage\StorageInterface') === false) {
throw new \Exception('[ERROR] In Configuration::addKeyStorageNode(): "' . $value . '" does not implement "Bitpay\Storage\StorageInterface".');
}
return $value;
@ -98,4 +102,28 @@ 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,13 +1,11 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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,15 +1,14 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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 pricing currencies
* currently supported are USD, EUR, BTC, and all of the codes listed on this page:
* https://bitpay.com/bitcoin­exchange­rates
* 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
*
* @package Bitpay
*/

View File

@ -1,16 +0,0 @@
<?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,13 +1,17 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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
@ -20,7 +24,7 @@ class Invoice implements InvoiceInterface
/**
* @var string
*/
protected $orderId;
protected $orderId = '';
/**
* @var ItemInterface
@ -30,32 +34,32 @@ class Invoice implements InvoiceInterface
/**
* @var string
*/
protected $transactionSpeed = self::TRANSACTION_SPEED_MEDIUM;
protected $transactionSpeed = '';
/**
* @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
@ -70,26 +74,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;
protected $btcPrice = 0.000000;
/**
* @var \DateTime
* @var DateTime
*/
protected $invoiceTime;
/**
* @var \DateTime
* @var DateTime
*/
protected $expirationTime;
@ -104,15 +108,15 @@ class Invoice implements InvoiceInterface
protected $buyer;
/**
* @var
* @var string
*/
protected $exceptionStatus;
protected $exceptionStatus = '';
/**
* @deprecated Deprecated with introduction of BCH
* @var
* @var float
*/
protected $btcPaid;
protected $btcPaid = 0.000000;
/**
* @var
@ -121,12 +125,12 @@ class Invoice implements InvoiceInterface
/**
* @deprecated Deprecated with introduction of BCH
* @var
* @var float
*/
protected $rate;
protected $rate = 0.000000;
/**
* @var
* @var Token
*/
protected $token;
@ -156,16 +160,36 @@ class Invoice implements InvoiceInterface
protected $paymentTotals;
/**
* @var array
*/
protected $paymentCurrencies;
* @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;
}
/**
* @inheritdoc
*/
public function getPrice()
{
return $this->getItem()->getPrice();
if (is_a($this->item, '\Bitpay\Item')) {
return $this->getItem()->getPrice();
}
return 0.000000;
}
/**
@ -178,13 +202,12 @@ class Invoice implements InvoiceInterface
/**
* @param float $price
*
* @return InvoiceInterface
* @return Invoice
*/
public function setPrice($price)
{
if (!empty($price)) {
$this->getItem()->setPrice($price);
if (is_numeric($price)) {
$this->getItem()->setPrice(floatval($price));
}
return $this;
@ -209,17 +232,20 @@ class Invoice implements InvoiceInterface
*/
public function getCurrency()
{
if ($this->currency === null) {
$this->currency = new Currency('BTC');
}
return $this->currency;
}
/**
* @param CurrencyInterface $currency
*
* @return InvoiceInterface
* @return Invoice
*/
public function setCurrency(CurrencyInterface $currency)
{
if (!empty($currency)) {
if (is_a($currency, '\Bitpay\Currency')) {
$this->currency = $currency;
}
@ -231,10 +257,7 @@ class Invoice implements InvoiceInterface
*/
public function getItem()
{
// 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) {
if (null === $this->item) {
$this->item = new Item();
}
@ -243,12 +266,11 @@ class Invoice implements InvoiceInterface
/**
* @param ItemInterface $item
*
* @return InvoiceInterface
* @return Invoice
*/
public function setItem(ItemInterface $item)
{
if (!empty($item)) {
if (is_a($item, '\Bitpay\Item')) {
$this->item = $item;
}
@ -260,8 +282,7 @@ class Invoice implements InvoiceInterface
*/
public function getBuyer()
{
// Same logic as getItem method
if (null == $this->buyer) {
if ($this->buyer === null) {
$this->buyer = new Buyer();
}
@ -270,12 +291,11 @@ class Invoice implements InvoiceInterface
/**
* @param BuyerInterface $buyer
*
* @return InvoiceInterface
* @return Invoice
*/
public function setBuyer(BuyerInterface $buyer)
{
if (!empty($buyer)) {
if (is_a($buyer, '\Bitpay\Buyer')) {
$this->buyer = $buyer;
}
@ -292,13 +312,20 @@ class Invoice implements InvoiceInterface
/**
* @param string $transactionSpeed
*
* @return InvoiceInterface
* @return Invoice
*/
public function setTransactionSpeed($transactionSpeed)
{
if (!empty($transactionSpeed) && ctype_print($transactionSpeed)) {
$this->transactionSpeed = trim($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;
}
return $this;
@ -314,12 +341,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $notificationEmail
*
* @return InvoiceInterface
* @return Invoice
*/
public function setNotificationEmail($notificationEmail)
{
if (!empty($notificationEmail) && ctype_print($notificationEmail)) {
if (filter_var($notificationEmail, FILTER_VALIDATE_EMAIL)) {
$this->notificationEmail = trim($notificationEmail);
}
@ -336,12 +362,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $notificationUrl
*
* @return InvoiceInterface
* @return Invoice
*/
public function setNotificationUrl($notificationUrl)
{
if (!empty($notificationUrl) && ctype_print($notificationUrl)) {
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $notificationUrl)) {
$this->notificationUrl = trim($notificationUrl);
}
@ -358,12 +383,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $redirectUrl
*
* @return InvoiceInterface
* @return Invoice
*/
public function setRedirectUrl($redirectUrl)
{
if (!empty($redirectUrl) && ctype_print($redirectUrl)) {
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $redirectUrl)) {
$this->redirectUrl = trim($redirectUrl);
}
@ -380,12 +404,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $posData
*
* @return InvoiceInterface
* @return Invoice
*/
public function setPosData($posData)
{
if (!empty($posData)) {
if (is_string($posData)) {
$this->posData = $posData;
}
@ -402,12 +425,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $status
*
* @return InvoiceInterface
* @return Invoice
*/
public function setStatus($status)
{
if (!empty($status) && ctype_print($status)) {
if (is_string($status)) {
$this->status = trim($status);
}
@ -454,12 +476,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $id
*
* @return InvoiceInterface
* @return Invoice
*/
public function setId($id)
{
if (!empty($id) && ctype_print($id)) {
if (is_string($id)) {
$this->id = trim($id);
}
@ -476,12 +497,11 @@ class Invoice implements InvoiceInterface
/**
* @param string $url
*
* @return InvoiceInterface
* @return Invoice
*/
public function setUrl($url)
{
if (!empty($url) && ctype_print($url)) {
if (preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)) {
$this->url = trim($url);
}
@ -500,13 +520,12 @@ class Invoice implements InvoiceInterface
/**
* @deprecated Deprecated with introduction of BCH
* @param float $btcPrice
*
* @return InvoiceInterface
* @return Invoice
*/
public function setBtcPrice($btcPrice)
{
if (!empty($btcPrice)) {
$this->btcPrice = $btcPrice;
if (is_numeric($btcPrice)) {
$this->btcPrice = floatval($btcPrice);
}
return $this;
@ -522,18 +541,18 @@ class Invoice implements InvoiceInterface
/**
* @param DateTime $invoiceTime
*
* @return InvoiceInterface
* @return Invoice
*/
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;
}
@ -547,18 +566,18 @@ class Invoice implements InvoiceInterface
/**
* @param DateTime $expirationTime
*
* return InvoiceInterface
* return Invoice
*/
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;
}
@ -572,18 +591,18 @@ class Invoice implements InvoiceInterface
/**
* @param DateTime $currentTime
*
* @return InvoiceInterface
* @return Invoice
*/
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;
}
@ -597,12 +616,14 @@ class Invoice implements InvoiceInterface
/**
* @param string $orderId
*
* @return InvoiceInterface
* @return Invoice
*/
public function setOrderId($orderId)
{
$this->orderId = $orderId;
if (is_string($orderId)) {
$this->orderId = trim($orderId);
}
return $this;
}
@ -638,7 +659,7 @@ class Invoice implements InvoiceInterface
$firstName = $this->getBuyer()->getFirstName();
$lastName = $this->getBuyer()->getLastName();
return trim($firstName.' '.$lastName);
return trim($firstName . ' ' . $lastName);
}
/**
@ -719,8 +740,7 @@ class Invoice implements InvoiceInterface
/**
* @param
*
* @return InvoiceInterface
* @return Invoice
*/
public function setExceptionStatus($exceptionStatus)
{
@ -745,7 +765,7 @@ class Invoice implements InvoiceInterface
*/
public function setBtcPaid($btcPaid)
{
if (isset($btcPaid)) {
if (is_numeric($btcPaid)) {
$this->btcPaid = $btcPaid;
}
@ -791,8 +811,8 @@ class Invoice implements InvoiceInterface
*/
public function setRate($rate)
{
if (!empty($rate)) {
$this->rate = $rate;
if (is_numeric($rate)) {
$this->rate = floatval($rate);
}
return $this;
@ -828,15 +848,20 @@ class Invoice implements InvoiceInterface
{
return $this->token;
}
/**
* @param TokenInterface $token
* @return InvoiceInterface
* @return Invoice
*/
public function setToken(TokenInterface $token)
{
$this->token = $token;
if (is_a($token, '\Bitpay\Token')) {
$this->token = $token;
}
return $this;
}
/**
* @inheritdoc
*/
@ -924,20 +949,35 @@ class Invoice implements InvoiceInterface
return $this;
}
/**
* @inheritdoc
* @return PaymentUrlInterface
*/
public function getPaymentCurrencies() {
return $this->paymentCurrencies;
public function getPaymentUrls()
{
if ($this->paymentUrls === null) {
$this->paymentUrls = new PaymentUrlSet();
}
return $this->paymentUrls;
}
/**
* @inheritdoc
* @param PaymentUrlInterface $paymentUrls
* @return Invoice
*/
public function setPaymentCurrencies($paymentCurrencies) {
$this->paymentCurrencies = $paymentCurrencies;
public function setPaymentUrls(PaymentUrlInterface $paymentUrls)
{
$this->paymentUrls = $paymentUrls;
return $this;
return $this;
}
/**
* @param string $paymentUrlType
* @return string
*/
public function getPaymentUrl($paymentUrlType)
{
return $this->getPaymentUrls()->getUrl($paymentUrlType);
}
}

View File

@ -1,14 +1,12 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* Invoice
*
* @package Bitpay
*/
interface InvoiceInterface
@ -80,7 +78,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 string
* @return float
*/
public function getPrice();
@ -96,6 +94,10 @@ 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();
@ -204,7 +206,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 string
* @return float
*/
public function getBtcPrice();
@ -353,18 +355,22 @@ 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();
@ -381,20 +387,9 @@ interface InvoiceInterface
public function getRefundAddresses();
/**
* Get the enforced transaction currencies.
* Returns a set of payment urls.
*
* @return array|null
* @return PaymentUrlInterface
*/
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);
public function getPaymentUrls();
}

View File

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

View File

@ -0,0 +1,31 @@
<?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

@ -0,0 +1,51 @@
<?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,6 +6,8 @@
namespace Bitpay;
date_default_timezone_set('UTC');
/**
* Class Payout
* @package Bitpay

View File

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

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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 Bitcore
* @package Bitpay
* @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,9 +117,11 @@ class PrivateKey extends Key
}
/**
* Creates an ECDSA signature of $message
* Creates an ECDSA signature of $data.
*
* @param string
* @return string
* @throws \Exception
*/
public function sign($data)
{
@ -135,19 +137,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);
@ -155,11 +157,10 @@ 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));
@ -211,42 +212,44 @@ 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]), '0'.'x80') >= 0) {
$byte = chr(0x00).$byte;
if (Math::cmp('0x' . bin2hex($byte[0]), '0x80') >= 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]), '0'.'x80') >= 0) {
$byte = chr(0x00).$byte;
if (Math::cmp('0x' . bin2hex($byte[0]), '0x80') >= 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;
@ -257,6 +260,7 @@ class PrivateKey extends Key
*
* @param string $pem_data The data to decode.
* @return array The keypair info.
* @throws \Exception
*/
public function pemDecode($pem_data)
{
@ -306,6 +310,7 @@ class PrivateKey extends Key
*
* @param array $keypair The keypair info.
* @return string The data to decode.
* @throws \Exception
*/
public function pemEncode($keypair)
{
@ -342,7 +347,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-----';
@ -354,16 +359,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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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 Bitcore
* @package Bitpay
*/
class PublicKey extends Key
{
@ -36,7 +36,7 @@ class PublicKey extends Key
return '';
}
if (Math::mod('0x'.$this->y, '0'.'x02') == '1') {
if (Math::mod('0x'.$this->y, '0x02') == '1') {
return sprintf('03%s', $this->x);
} else {
return sprintf('02%s', $this->x);
@ -45,6 +45,7 @@ class PublicKey extends Key
/**
* @param PrivateKey
* @return PublicKey
*/
public static function createFromPrivateKey(PrivateKey $private)
{
@ -55,7 +56,8 @@ class PublicKey extends Key
}
/**
* @return KeyInterface
* @param PrivateKey
* @return PublicKey
*/
public function setPrivateKey(PrivateKey $privateKey)
{
@ -68,8 +70,8 @@ class PublicKey extends Key
* Generates an uncompressed and compressed EC public key.
*
* @param \Bitpay\PrivateKey $privateKey
*
* @return Bitpay\PublicKey
* @return \Bitpay\PublicKey
* @throws \Exception
*/
public function generate(PrivateKey $privateKey = null)
{
@ -111,6 +113,7 @@ class PublicKey extends Key
$this->x = $RxHex;
$this->y = $RyHex;
$this->hex = sprintf('%s%s', $RxHex, $RyHex);
$this->dec = Util::decodeHex($this->hex);
@ -139,6 +142,7 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -11,15 +11,19 @@ use Bitpay\Util\Gmp;
use Bitpay\Util\Util;
/**
* @package Bitcore
* @package BitPay
*/
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';
/**
@ -56,6 +60,7 @@ class SinKey extends Key
* https://en.bitcoin.it/wiki/Identity_protocol_v1
*
* @return SinKey
* @throws \Exception
*/
public function generate()
{
@ -70,7 +75,6 @@ class SinKey extends Key
}
$step1 = Util::sha256(Util::binConv($compressedValue), true);
$step2 = Util::ripe160($step1);
$step3 = sprintf(
@ -81,10 +85,8 @@ 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,12 +1,13 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Storage;
/**
* @package Bitpay
*/
class EncryptedFilesystemStorage implements StorageInterface
{
@ -15,11 +16,6 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
private $password;
/**
* @var string
*/
private $unencoded_password;
/**
* Initialization Vector
*/
@ -40,10 +36,7 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
public function __construct($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;
$this->password = $password;
}
/**
@ -51,17 +44,13 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
public function persist(\Bitpay\KeyInterface $key)
{
$path = $key->getId();
$data = serialize($key);
$encoded = bin2hex(openssl_encrypt(
$data,
self::METHOD,
$this->password,
1,
self::IV
));
$path = $key->getId();
$data = serialize($key);
file_put_contents($path, $encoded);
$encrypted = $this->dataEncrypt($data);
$encoded = $this->dataEncode($encrypted);
$this->saveToFile($encoded, $path);
}
/**
@ -69,25 +58,120 @@ class EncryptedFilesystemStorage implements StorageInterface
*/
public function load($id)
{
if (!is_file($id)) {
throw new \Exception(sprintf('Could not find "%s"', $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_readable($id)) {
throw new \Exception(sprintf('"%s" cannot be read, check permissions', $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() . '".');
}
$encoded = file_get_contents($id);
$decoded = openssl_decrypt(\Bitpay\Util\Util::binConv($encoded), self::METHOD, $this->password, 1, self::IV);
return $decrypted;
}
if (false === $decoded) {
$decoded = openssl_decrypt(\Bitpay\Util\Util::binConv($encoded), self::METHOD, $this->unencoded_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) {
throw new \Exception('Could not decode key');
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 . '".');
}
return unserialize($decoded);
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;
}
}

View File

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

View File

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

View File

@ -1,11 +1,13 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
date_default_timezone_set('UTC');
/**
* @package Bitpay
*/
@ -46,8 +48,6 @@ 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,6 +69,10 @@ class Token implements TokenInterface
return $this->token;
}
/**
* @param string
* @return Token
*/
public function setToken($token)
{
$this->token = $token;
@ -84,6 +88,10 @@ class Token implements TokenInterface
return $this->resource;
}
/**
* @param string
* @return Token
*/
public function setResource($resource)
{
$this->resource = $resource;
@ -99,6 +107,10 @@ class Token implements TokenInterface
return $this->facade;
}
/**
* @param string
* @return Token
*/
public function setFacade($facade)
{
$this->facade = $facade;
@ -114,6 +126,10 @@ class Token implements TokenInterface
return $this->createdAt;
}
/**
* @param \DateTime
* @return Token
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
@ -129,6 +145,10 @@ class Token implements TokenInterface
return $this->policies;
}
/**
* @param string
* @return Token
*/
public function setPolicies($policies)
{
$this->policies = $policies;
@ -143,11 +163,15 @@ class Token implements TokenInterface
{
return $this->pairingCode;
}
/**
* @param string
* @return Token
*/
public function setPairingCode($pairingCode)
{
$this->pairingCode = $pairingCode;
return $this;
}
@ -159,6 +183,10 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -76,8 +76,7 @@ class User implements UserInterface
/**
* @param string $phone
*
* @return UserInterface
* @return User
*/
public function setPhone($phone)
{
@ -98,8 +97,7 @@ class User implements UserInterface
/**
* @param string $email
*
* @return UserInterface
* @return User
*/
public function setEmail($email)
{
@ -120,8 +118,7 @@ class User implements UserInterface
/**
* @param string $firstName
*
* @return UserInterface
* @return User
*/
public function setFirstName($firstName)
{
@ -142,8 +139,7 @@ class User implements UserInterface
/**
* @param string $lastName
*
* @return UserInterface
* @return User
*/
public function setLastName($lastName)
{
@ -164,8 +160,7 @@ class User implements UserInterface
/**
* @param array $address
*
* @return UserInterface
* @return User
*/
public function setAddress(array $address)
{
@ -186,8 +181,7 @@ class User implements UserInterface
/**
* @param string $city
*
* @return UserInterface
* @return User
*/
public function setCity($city)
{
@ -208,8 +202,7 @@ class User implements UserInterface
/**
* @param string $state
*
* @return UserInterface
* @return User
*/
public function setState($state)
{
@ -230,8 +223,7 @@ class User implements UserInterface
/**
* @param string $zip
*
* @return UserInterface
* @return User
*/
public function setZip($zip)
{
@ -252,8 +244,7 @@ class User implements UserInterface
/**
* @param string $country
*
* @return UserInterface
* @return User
*/
public function setCountry($country)
{
@ -266,7 +257,6 @@ class User implements UserInterface
/**
* @param bool $boolvalue
*
* @return User
*/
public function setAgreedToTOSandPP($boolvalue)
@ -277,6 +267,7 @@ class User implements UserInterface
return $this;
}
/**
* @return bool
*/

View File

@ -1,13 +1,12 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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 Bitcore
* @package Bitpay
*/
final class Base58
{
@ -21,17 +21,18 @@ final class Base58
const BASE58_CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
/**
* Encodes $data into BASE-58 format
* Encodes a numeric string into BASE-58 format.
*
* @param string $data
*
* @return string
* @return string $output_string
* @throws \Exception
*/
public static function encode($data)
{
$dataLen = strlen($data);
if ($dataLen % 2 != 0 || $dataLen == 0) {
throw new \Exception('Invalid Length');
throw new \Exception('Invalid length data string provided to Base58::encode() method.');
}
$code_string = self::BASE58_CHARS;
@ -39,8 +40,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;
}
@ -55,11 +56,10 @@ final class Base58
}
/**
* Decodes $data from BASE-58 format
* Decodes a numeric string from BASE-58 format.
*
* @param string $data
*
* @return string
* @return string $return
*/
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,13 +1,11 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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,11 +1,16 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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
{
/**
@ -97,6 +102,7 @@ class Error
if (empty($error_types)) {
$error_types = E_ALL | E_STRICT;
}
switch (strtolower($type)) {
case 'error':
switch (strtolower($action)) {

View File

@ -1,13 +1,15 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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
* Utility class for generating an operating system & enivironment fingerprint.
*
* @package Bitpay
*/
class Fingerprint
{
@ -19,7 +21,6 @@ class Fingerprint
* takes the hash of that value to use as the env
* fingerprint.
*
* @param void
* @return string
*/
final public static function generate()
@ -47,11 +48,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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -12,8 +12,7 @@ namespace Bitpay\Util;
* also:
*
* @see https://en.bitcoin.it/wiki/Secp256k1
*
* @package Bitcore
* @package Bitpay
*/
class Secp256k1 implements CurveParameterInterface
{

View File

@ -1,13 +1,15 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
* Generates secure random numbers
* Generates cryptographically-secure random numbers using the OpenSSL extension.
*
* @package Bitpay
*/
class SecureRandom
{
@ -17,7 +19,12 @@ class SecureRandom
protected static $hasOpenSSL;
/**
* @return string
* 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
*/
public static function generateRandom($bytes = 32)
{
@ -35,6 +42,8 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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 Bitcore
* @package Bitpay
*/
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, see:
* http://us1.php.net/manual/en/function.openssl-digest.php
* string. Uses the OpenSSL extension.
*
* @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,11 +40,10 @@ class Util
/**
* Computes a digest hash value for the given data using
* the given method, and returns a raw or binhex encoded
* string, see:
* http://us1.php.net/manual/en/function.openssl-digest.php
* string. Uses the OpenSSL extension.
*
* @see http://us1.php.net/manual/en/function.openssl-digest.php
* @param string $data
*
* @return string
*/
public static function sha512($data)
@ -54,11 +53,10 @@ 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)
@ -67,10 +65,12 @@ class Util
}
/**
* Returns a RIPDEMD160 hash of a value.
* Uses the OpenSSL extention to calculate the 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,7 +82,6 @@ class Util
* Returns a SHA256 hash of a RIPEMD160 hash of a value.
*
* @param string $data
*
* @return string
*/
public static function sha256ripe160($data)
@ -94,7 +93,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)
@ -102,23 +101,10 @@ 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()
@ -138,6 +124,7 @@ class Util
*
* @param string $dec
* @return string
* @throws \Exception
*/
public static function encodeHex($dec)
{
@ -151,12 +138,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;
@ -167,6 +154,7 @@ class Util
*
* @param string $hex
* @return string
* @throws \Exception
*/
public static function decodeHex($hex)
{
@ -174,7 +162,7 @@ class Util
throw new \Exception('Argument must be a string of hex digits.');
}
$hex = strtolower($hex);
$hex = strtolower(trim($hex));
// if it has a prefix of 0x this needs to be trimed
if (substr($hex, 0, 2) == '0x') {
@ -182,31 +170,40 @@ 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);
$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--;
}
@ -217,10 +214,9 @@ 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
* @return string
* @see http://php.net/manual/en/function.decbin.php (but for large numbers)
* @param string $dec
* @return string $bin
*/
public static function decToBin($dec)
{
@ -229,12 +225,14 @@ 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
@ -252,9 +250,10 @@ class Util
* xR = s2 - 2xP mod p
* yR = -yP + s(xP - xR) mod p
*
* @param PointInterface $point
* @param CurveParameterInterface
* @param PointInterface $point
* @param CurveParameterInterface $parameters
* @return PointInterface
* @throws \Exception
*/
public static function pointDouble(PointInterface $point, CurveParameterInterface $parameters = null)
{
@ -278,41 +277,38 @@ 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
* @param PointInterface
*
* @param PointInterface $P
* @param PointInterface $Q
* @return PointInterface
*/
public static function pointAdd(PointInterface $P, PointInterface $Q)
@ -329,8 +325,9 @@ 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,
@ -356,10 +353,11 @@ class Util
),
$p
);
$R['y'] = Math::mod(
Math::add(
Math::sub(
0,
'0',
$P->getY()
),
Math::mul(
@ -375,18 +373,17 @@ 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
*
* @return string
* @param string $hex
* @return string $byte
*/
public static function binConv($hex)
{
@ -400,21 +397,21 @@ class Util
}
if (substr(strtolower($hex), 0, 2) != '0x') {
$hex = '0x'.strtolower($hex);
$hex = '0x' . strtolower(trim($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
*/
@ -427,6 +424,7 @@ 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 {
@ -452,8 +450,9 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -13,9 +13,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
$token = new AccessToken();
$this->assertNotNull($token);
$token->setId('test');
$this->assertSame('test', $token->getId());
}
@ -24,9 +22,7 @@ class AccessTokenTest extends \PHPUnit_Framework_TestCase
$token = new AccessToken();
$this->assertNotNull($token);
$token->setEmail('support@bitpay.com');
$this->assertSame('support@bitpay.com', $token->getEmail());
}
@ -35,40 +31,7 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -13,7 +13,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$this->assertInternalType('array', $application->getUsers());
$this->assertEmpty($application->getUsers());
}
@ -26,7 +25,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$application->addUser($this->getMockUser());
$this->assertInternalType('array', $application->getUsers());
@ -38,7 +36,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$this->assertInternalType('array', $application->getOrgs());
$this->assertEmpty($application->getOrgs());
}
@ -51,7 +48,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$this->assertNotNull($application);
$application->addOrg($this->getMockOrg());
$this->assertInternalType('array', $application->getOrgs());
@ -60,11 +56,11 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
private function getMockUser()
{
return $this->getMock('Bitpay\UserInterface');
return $this->getMock('Bitpay\User');
}
private function getMockOrg()
{
return $this->getMock('Bitpay\OrgInterface');
return $this->getMock('Bitpay\Org');
}
}

View File

@ -1,66 +0,0 @@
<?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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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\CurrencyInterface', $this->bill->getCurrency());
$this->assertInstanceOf('Bitpay\Currency', $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\CurrencyInterface', $this->bill->getCurrency());
$this->assertInstanceOf('Bitpay\Currency', $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('support@bitpay.com');
$this->assertSame('support@bitpay.com', $this->bill->getEmail());
$this->bill->setEmail('integrations@bitpay.com');
$this->assertSame('integrations@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\ItemInterface');
return $this->getMock('Bitpay\Item');
}
private function getMockCurrency()
{
return $this->getMock('Bitpay\CurrencyInterface');
return $this->getMock('Bitpay\Currency');
}
}

View File

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

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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('support@bitpay.com');
$this->assertSame('support@bitpay.com', $this->user->getEmail());
$this->user->setEmail('integrations@bitpay.com');
$this->assertSame('integrations@bitpay.com', $this->user->getEmail());
}
public function testGetFirstName()

View File

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

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -31,7 +31,8 @@ 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);
@ -97,7 +98,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
->setEffectiveDate("1415853007000")
->setPricingMethod('bitcoinbestbuy')
->setNotificationUrl('https://bitpay.com')
->setNotificationEmail('support@bitpay.com')
->setNotificationEmail('integrations@bitpay.com')
->setPricingMethod('bitcoinbestbuy')
->setReference('your reference, can be json')
->setAmount(5625)
@ -107,6 +108,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
\Bitpay\PayoutInstruction::STATUS_UNPAID => null,
\Bitpay\PayoutInstruction::STATUS_PAID => '0'
);
$instruction0 = new \Bitpay\PayoutInstruction();
$instruction0
->setId('Sra19AFU57Rx53rKQbbRKZ')
@ -158,7 +160,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('support@bitpay.com', $payout->getNotificationEmail());
$this->assertEquals('integrations@bitpay.com', $payout->getNotificationEmail());
$this->assertEquals('8mZ37Gt91Wr7GXGPnB9zj1zwTcLGweRDka4axVBPi9Uxiiv7zZWvEKSgmFddQZA1Jy', $payout->getResponseToken());
$instructions = $payout->getInstructions();
$this->assertSame($instruction0, $instructions[0]);
@ -195,15 +197,24 @@ 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());
}
/**
@ -331,7 +342,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$payouts = $this->client->getPayouts();
$this->assertInternalType('array', $payouts);
$this->assertInstanceOf('Bitpay\PayoutInterface', $payouts[0]);
}
/**
@ -347,7 +357,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->client->setAdapter($adapter);
$payouts = $this->client->getPayouts();
}
public function testGetTokens()
@ -503,7 +512,6 @@ 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'));
@ -513,7 +521,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->client->setAdapter($adapter);
$payout = $this->client->deletePayout($payout);
$this->assertSame($payout->getStatus(), \Bitpay\Payout::STATUS_CANCELLED);
}
@ -533,7 +540,6 @@ 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"}');
@ -545,7 +551,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$this->assertSame($payout->getStatus(), \Bitpay\Payout::STATUS_CANCELLED);
}
private function getMockInvoice()
{
$invoice = $this->getMockBuilder('Bitpay\InvoiceInterface')
@ -557,10 +562,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', 'getRefundAddresses',
'setId', 'setUrl', 'setStatus', 'setBtcPrice', 'setPrice', 'setInvoiceTime', 'setExpirationTime',
'setCurrentTime', 'setBtcPaid', 'setRate', 'setToken', 'setExceptionStatus', 'isExtendedNotifications',
'setPosData',
'getExceptionStatus', 'getBtcPaid', 'getRate', 'getToken', 'setId', 'setUrl',
'setStatus', 'setBtcPrice', 'setPrice', 'setInvoiceTime', 'setExpirationTime',
'setCurrentTime', 'setBtcPaid', 'setRate', 'setToken', 'setExceptionStatus', 'getRefundAddresses',
'getPaymentUrls', 'isExtendedNotifications', 'setPosData'
)
)
->getMock();

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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('Dodge Coin');
new Currency('Foo 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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->assertNull($this->invoice->getPrice());
$this->assertSame($this->invoice->getPrice(), 0.0);
}
/**
@ -34,7 +34,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetCurrency()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getCurrency());
$this->assertInstanceOf('Bitpay\Currency', $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_MEDIUM);
$this->assertSame(Invoice::TRANSACTION_SPEED_MEDIUM, $this->invoice->getTransactionSpeed());
$this->invoice->setTransactionSpeed(Invoice::TRANSACTION_SPEED_LOW);
$this->assertSame(Invoice::TRANSACTION_SPEED_LOW, $this->invoice->getTransactionSpeed());
}
public function testGetNotificationEmail()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getNotificationEmail());
$this->assertSame($this->invoice->getNotificationEmail(), '');
}
/**
@ -110,14 +110,14 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testSetNotificationEmail()
{
$this->assertNotNull($this->invoice);
$this->invoice->setNotificationEmail('support@bitpay.com');
$this->assertSame('support@bitpay.com', $this->invoice->getNotificationEmail());
$this->invoice->setNotificationEmail('integrations@bitpay.com');
$this->assertSame('integrations@bitpay.com', $this->invoice->getNotificationEmail());
}
public function testGetNotificationUrl()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getNotificationUrl());
$this->assertSame($this->invoice->getNotificationUrl(), '');
}
/**
@ -133,7 +133,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetRedirectUrl()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getRedirectUrl());
$this->assertSame($this->invoice->getRedirectUrl(), '');
}
/**
@ -149,7 +149,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetPosData()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getPosData());
$this->assertSame($this->invoice->getPosData(), '');
}
/**
@ -165,7 +165,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetStatus()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getStatus());
$this->assertSame($this->invoice->getStatus(), '');
}
/**
@ -187,7 +187,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetId()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getId());
$this->assertSame($this->invoice->getId(), '');
}
/**
@ -203,7 +203,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetUrl()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getUrl());
$this->assertSame($this->invoice->getUrl(), '');
}
/**
@ -219,7 +219,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetBtcPrice()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBtcPrice());
$this->assertSame($this->invoice->getBtcPrice(), 0.0);
}
/**
@ -294,7 +294,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetOrderId()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getOrderId());
$this->assertSame($this->invoice->getOrderId(), '');
}
/**
@ -313,26 +313,12 @@ 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);
@ -345,121 +331,58 @@ 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->assertNull($this->invoice->getExceptionStatus());
$this->assertSame($this->invoice->getExceptionStatus(), '');
}
/**
@ -475,7 +398,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetBtcPaid()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getBtcPaid());
$this->assertSame($this->invoice->getBtcPaid(), 0.0);
}
/**
@ -491,7 +414,7 @@ class InvoiceTest extends \PHPUnit_Framework_TestCase
public function testGetRate()
{
$this->assertNotNull($this->invoice);
$this->assertNull($this->invoice->getRate());
$this->assertSame($this->invoice->getRate(), 0.0);
}
/**

View File

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

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -9,15 +9,13 @@ 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()
@ -78,7 +76,6 @@ 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));
@ -179,7 +176,8 @@ 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]));
}
}
@ -219,5 +217,4 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,119 +8,96 @@ namespace Bitpay\Math;
class GmpEngineTest extends \PHPUnit_Framework_TestCase
{
private $a;
private $b;
private $c;
private $math;
/**
* @requires extension gmp
*/
protected function setUp()
{
if (!extension_loaded('gmp'))
{
$this->markTestSkipped('The GMP extension is NOT loaded! You must enable it to run this test');
}
$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();
}
}
public function testadd()
public function testAdd()
{
$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));
$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));
}
public function testcmp()
public function testCmp()
{
$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));
$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));
}
public function testdiv()
public function testDiv()
{
$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));
$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));
}
public function testinvertm()
public function testInvertm()
{
$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));
$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));
$o = '2';
$p = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f';
$this->assertEquals('57896044618658097711785492504343953926634992332820282019728792003954417335832', $math->invertm($o, $p));
$this->assertEquals('57896044618658097711785492504343953926634992332820282019728792003954417335832', $this->math->invertm($o, $p));
$o = '-207267379875244730201206352791949018434229233557197871725317424106240926035466';
$p = '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f';
$this->assertEquals('93736451599995461267424215486556527005103980679329099329644578865571485201981', $math->invertm($o, $p));
$this->assertEquals('93736451599995461267424215486556527005103980679329099329644578865571485201981', $this->math->invertm($o, $p));
}
public function testmod()
public function testMod()
{
$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));
$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));
}
public function testmul()
public function testMul()
{
$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));
$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));
}
public function testpow()
public function testPow()
{
$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));
$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));
}
public function testsub()
public function testSub()
{
$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));
$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));
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,47 +8,48 @@ 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');
Math::setEngine($engine);
$this->assertInstanceOf('Bitpay\Math\EngineInterface', Math::getEngine());
}
public function testIsEngineSet()
{
Math::setEngine(null);
$this->assertNull(Math::getEngine());
$engine = $this->getMock('Bitpay\Math\EngineInterface');
/**
* @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());
}
Math::setEngine($engine);
$this->assertInstanceOf('Bitpay\Math\EngineInterface', 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());
}
/**
* @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());
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -125,6 +125,7 @@ class PayoutInstructionTest extends \PHPUnit_Framework_TestCase
$this->assertNotNull($this->instruction->getBtc());
$this->assertSame($btc, $this->instruction->getBtc());
}
/**
* @depends testGetAmount
*/
@ -140,6 +141,7 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -77,7 +77,6 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,8 +8,6 @@ namespace Bitpay;
class PointTest extends \PHPUnit_Framework_TestCase
{
/**
*/
public function testConstruct()
{
$point = new Point(1, 2);
@ -66,6 +64,7 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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);
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNull($priKey->getHex());
$this->assertNull($priKey->getDec());
@ -44,8 +44,11 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateCannotHappenTwice()
{
$privateKey = new PrivateKey();
$privateKey->generate();
$hex = $privateKey->getHex();
$privateKey->generate();
$this->assertSame($hex, $privateKey->getHex());
}
@ -53,10 +56,9 @@ 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();
@ -71,6 +73,7 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testToString()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
// Make sure this is a string
@ -87,10 +90,9 @@ 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();
@ -101,8 +103,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testIsValid()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNotNull($priKey);
$this->assertFalse($priKey->isValid());
$priKey->generate();
@ -113,6 +115,7 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testSign()
{
$priKey = new PrivateKey();
$priKey->generate();
// Make sure not exceptions are thrown
@ -122,8 +125,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testHasValidHex()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNotNull($priKey);
$this->assertFalse($priKey->hasValidHex());
$priKey->generate();
@ -134,8 +137,8 @@ class PrivateKeyTest extends \PHPUnit_Framework_TestCase
public function testHasValidDec()
{
$priKey = new PrivateKey();
$this->assertNotNull($priKey);
$this->assertNotNull($priKey);
$this->assertFalse($priKey->hasValidDec());
$priKey->generate();
@ -163,9 +166,11 @@ 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
@ -190,11 +195,12 @@ 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,17 +1,13 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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',
@ -78,6 +74,7 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testId()
{
$key = new PublicKey('/path/to/key.pub');
$this->assertSame('/path/to/key.pub', $key->getId());
}
@ -90,6 +87,7 @@ 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);
@ -99,6 +97,7 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateOnlyOnce()
{
$key = new PublicKey();
$key->setPrivateKey($this->getMockPrivateKey());
$key->generate();
@ -107,10 +106,7 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
$key->generate();
// Make sure values do not change
$this->assertSame(
$hexValue,
$key->getHex()
);
$this->assertSame($hexValue, $key->getHex());
}
/**
@ -119,6 +115,7 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGetHex()
{
$pubKey = new PublicKey();
$pubKey->setPrivateKey($this->getMockPrivateKey());
$this->assertNull($pubKey->getHex());
$pubKey->generate();
@ -131,46 +128,41 @@ 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());
@ -181,6 +173,7 @@ 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());
@ -190,12 +183,14 @@ 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();
@ -205,7 +200,9 @@ class PublicKeyTest extends \PHPUnit_Framework_TestCase
public function testGetSin()
{
$pub = new PublicKey();
$pub->setPrivateKey($this->getMockPrivateKey());
$sin = $pub->getSin();
$this->assertInstanceOf('Bitpay\SinKey', $sin);
@ -214,19 +211,18 @@ 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();
@ -237,13 +233,10 @@ 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('isValid')->will($this->returnValue(true));
$key->method('getHex')->will($this->returnValue($hex));
return $key;
}
}

View File

@ -1,34 +1,30 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay;
/**
* @package Bitcore
* @package Bitpay
*/
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));
}
@ -38,6 +34,7 @@ class SinKeyTest extends \PHPUnit_Framework_TestCase
public function testGenerateWithException()
{
$sinKey = new SinKey();
$this->assertNotNull($sinKey);
$sinKey->generate();
}
@ -48,27 +45,24 @@ 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));
}
@ -78,21 +72,17 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -10,89 +10,83 @@ 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()
{
$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);
$this->storage->persist(new \Bitpay\PublicKey($this->pubkeyStream));
$this->assertTrue($this->root->hasChild($this->pubkeyName));
}
public function testLoad()
{
$storage = new EncryptedFilesystemStorage('dN$8WNaT}j<gD3*q');
vfsStream::newFile('public.key')
->at($this->root)
->setContent('222464cf5e76807259205ed98a1114e3164ecada597352259f9e09ce06524cdf7eaf862bff208d44163b8b24719afbfe031344d97a44502955b63158e012c09f604f66f3c7ca99290e9991a4a1413c3a4095fb6522653ceda25d831d115be3de6756fd7511ed91d970dac0e4e01a5df91ce9b412a0c8a42eb266cf2a93e1d1b50090b3eb89c93fcd85ed2cee6ee08499a6d69c3ffe7836878e30a37df92226fc78a2936f6037d8bf4b0a33bb11dad77b544a1baaf1c097be38d04f6b642285811b9c9e27c51d460a57e298851bb047f6fa2a02f501e7902a660fa66630240cf8586f6cf774b6b0a6e62a06de6eee328b3dfaa3658fd692b0e7590ea58281c8a563e3fe09a1209de96c7919a3b92c5307b782b4729a68b08f220b03df02c15e7742977a48b48c4bff7d060020e3b4717d5ae05d630e9e5f1374d2bb9ac04652ee12ef9de37c67cd07461ae7a201ddd04975ec4f60e781e214b50ca1b756988b7a1868fdbf2b07db66e0e7c9a29526c7d11127bb58c606c515325d7375a21c9d1db63167fb34106c87c49d238fc1eb41309eb5f23d946743534bf8d454729dd94ac9c3d18cb7261fd773c913e674a4427c0b90b4f9a541b77363d43f957445fff395ad5c48b51131913917882413ce8084db0d20ab308b3504d43e8f67afb4f6611324d07d8980ffc8d9ae6817bfe1be5e4f5ad6e5155b9767d15c01c96fc101538071f9bef40978f805e52e31a8e169bf');
->setContent('i8A7jkJy1H6oHWPGVxuBcrB360Krq8aZD8g3Ef4JYaLSZIJjhV+Kob1kNYL6091jRA3LpC1C7Tb19FDY80VXuHsd2zTn9QMgfQnl85awBzLdEBxh5Vx/Xv9FQSq9VDrKb2/jhZAnBjBC13rP2KuwS6fj8PNKz4BeVPENh09ADHo0uGhj5tzdXr80E09TkxcmRR2Ss2sGUCiCGWdjFM0AdwmEXDHqSPBHqBF7GuxzG5Ozuh7YLU4sHQoGWLRHKhaWsSyPMvuWLuEN13H7EcyKeHN/RrHP1aXbIJ6YgJWxQ7a4QEe0UH7xkhMJD0eIZM1uowNWpO0+lHUglxtqyU87ILPt2gtAGlXGuuxQqlPnKumNTdE7ji1PL/gClW6gEtACEdqVsAH5pv7EYVFqOhGakzAP2WtF2/SiNEgbu+j2dUYe4KuJ0sxir+v3LknVZ+fR1YdwNoKCbXMArLe8if2rjeNrjHOjs/FbNGIxMoPcPC0L24d3sQxzb2Lw7vJ0bu4zM4D6PoK1AiWYrR6NQuI0lvnH77Roav4qDw23Gs2SdysyCObQzoJboj1+hojEF888u+fBW9ZdqRRwhrwLwqiRC+q5XD1n79pRqh7Y6icJe6iSSLqrUbO/gGKmXguM7Ef55NYmVYESgZHgDtSVmTnk790EiEy2qA71j3UbxbgWH8DlZtMf6rEwqp/7401I1iym');
$key = $storage->load(vfsStream::url('tmp/public.key'));
$key = $this->storage->load($this->pubkeyStream);
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
/**
* @expectedException Exception
* @expectedException \Exception
* @expectedExceptionMessage [ERROR] In EncryptedFilesystemStorage::readFromFile(): The file "vfs://tmp/public.key" does not exist or cannot be read, check permissions.
*/
public function testNotFileException()
{
$storage = new EncryptedFilesystemStorage('satoshi');
$storage->load(vfsStream::url('tmp/public.key'));
$this->storage->load($this->pubkeyStream);
}
/**
* @expectedException Exception
* @expectedException \Exception
*/
public function testLoadNotReadableException()
{
$storage = new EncryptedFilesystemStorage('satoshi');
vfsStream::newFile('public.key', 0600)
if (stripos(PHP_OS, 'WIN') === 0) {
$this->markTestSkipped('Skip \Bitpay\Storage\EncryptedFilesystemStorageTest::testLoadNotReadableException() test on Windows system');
}
vfsStream::newFile('badpublic.key', 0600)
->at($this->root)
->setContent('')
->chown(vfsStream::OWNER_ROOT)
->chgrp(vfsStream::GROUP_ROOT);
$storage->load(vfsStream::url('tmp/public.key'));
$this->storage->load(vfsStream::url('tmp/badpublic.key'));
}
/**
* @expectedException Exception
* @expectedException \Exception
* @expectedExceptionMessage [ERROR] In EncryptedFilesystemStorage::dataDecode(): Could not decode data "\".
*/
public function testLoadCouldNotDecode()
{
$storage = new EncryptedFilesystemStorage('satoshi');
vfsStream::newFile('public.key')
vfsStream::newFile('badpublic.key')
->at($this->root)
->setContent('00');
->setContent('\\');
$key = $storage->load(vfsStream::url('tmp/public.key'));
$key = $this->storage->load(vfsStream::url('tmp/badpublic.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'));
$key = $storage->load(vfsStream::url('tmp/public.key'));
$storage->persist(new \Bitpay\PublicKey($this->pubkeyStream));
$this->assertTrue($this->root->hasChild($this->pubkeyName));
$key = $storage->load($this->pubkeyStream);
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
}

View File

@ -1,59 +1,71 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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()
{
$storage = new FilesystemStorage();
$storage->persist(new \Bitpay\PublicKey(vfsStream::url('tmp/public.key')));
$this->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('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;}}');
->setContent($this->key_file_content);
$key = $storage->load(vfsStream::url('tmp/public.key'));
$key = $this->storage->load(vfsStream::url('tmp/public.key'));
$this->assertInstanceOf('Bitpay\PublicKey', $key);
}
/**
* @expectedException Exception
* @expectedException \Exception
*/
public function testNotFileException()
{
$storage = new FilesystemStorage();
$storage->load(vfsStream::url('tmp/public.key'));
$this->storage->load(vfsStream::url('tmp/public.key'));
}
/**
* @expectedException Exception
* @expectedException \Exception
*/
public function testLoadNotReadableException()
{
$storage = new FilesystemStorage();
if (stripos(PHP_OS, 'WIN') === 0) {
$this->markTestSkipped('Skip \Bitpay\Storage\EncryptedFilesystemStorageTest::testLoadNotReadableException() test on Windows system');
}
vfsStream::newFile('public.key', 0600)
->at($this->root)
->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;}}')
->setContent($this->key_file_content)
->chown(vfsStream::OWNER_ROOT)
->chgrp(vfsStream::GROUP_ROOT);
$storage->load(vfsStream::url('tmp/public.key'));
$this->storage->load(vfsStream::url('tmp/public.key'));
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -27,7 +27,6 @@ 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());
@ -45,7 +44,6 @@ 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());
@ -63,7 +61,6 @@ 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());
@ -81,7 +78,6 @@ 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());
@ -122,7 +118,6 @@ 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());
@ -140,7 +135,6 @@ 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());
@ -158,7 +152,6 @@ 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());
@ -176,7 +169,6 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -23,6 +23,7 @@ class Base58Test extends \PHPUnit_Framework_TestCase
$data = array(
array('', '', '3QJmnh'),
);
foreach ($data as $datum) {
$this->assertSame($datum[1], Base58::encode($datum[0]));
}
@ -44,6 +45,7 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -8,7 +8,6 @@ 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-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
namespace Bitpay\Util;
/**
* @package Bitcore
* @package Bitpay
*
* @requires function openssl_random_pseudo_bytes
*/

View File

@ -1,6 +1,6 @@
<?php
/**
* @license Copyright 2011-2014 BitPay Inc., MIT License
* @license Copyright 2011-2015 BitPay Inc., MIT License
* see https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
*/
@ -9,11 +9,10 @@ namespace Bitpay\Util;
use Bitpay\Point;
/**
* @package Bitcore
* @package Bitpay
*/
class UtilTest extends \PHPUnit_Framework_TestCase
{
public function testSha256()
{
$data = array(
@ -94,16 +93,6 @@ 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();
@ -173,6 +162,7 @@ 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)
@ -182,6 +172,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
'0xb7dafe35d7d1aab78b53982c8ba554584518f86d50af565c98e053613c8f15e0',
$point
);
$this->assertEquals('14976827122927988984909748681266837395089399768482149532452617485742004777865', $R->getX());
$this->assertEquals('5009713401941157350243425146365130573323232660945282226881202857781593637456', $R->getY());
@ -189,6 +180,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
'0xfd7c6914790d3bbf3184d9830e3f1a327e951e3478dd0b28f0fd3b0e774bbd68',
$point
);
$this->assertEquals('65041784833307054098962518952641430476519680065454324565175938819000678523383', $R->getX());
$this->assertEquals('53140314933116045874248958072587249546886301333167874306830834776596206062743', $R->getY());
}
@ -199,6 +191,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
array('123456789', '101010001011001111011010111'),
array('0x123456789', '100100011110011010100010110001001'),
);
foreach ($data as $datum) {
$this->assertSame($datum[1], Util::decToBin($datum[0]));
}
@ -229,6 +222,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
new Point(1, 1),
new Point(1, 1)
);
$expectedpoint = new Point("28948022309329048855892746252171976963317496166410141009864396001977208667916", "14474011154664524427946373126085988481658748083205070504932198000988604333958");
$this->assertEquals($expectedpoint, $point);
@ -236,6 +230,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
new Point(0, 0),
new Point(1, 1)
);
$expectedpoint = new Point("0", "0");
$this->assertEquals($expectedpoint, $point);
@ -243,6 +238,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
new Point(1, 0),
new Point(0, 1)
);
$expectedpoint = new Point("0", "115792089237316195423570985008687907853269984665640564039457584007908834671662");
$this->assertEquals($expectedpoint, $point);
}
@ -253,6 +249,7 @@ class UtilTest extends \PHPUnit_Framework_TestCase
array('7361746f736869', 'satoshi'),
array('0x7361746f736869', 'satoshi'),
);
foreach ($data as $datum) {
$this->assertSame($datum[1], Util::binConv($datum[0]));
}
@ -267,6 +264,7 @@ 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 {
@ -292,6 +290,7 @@ 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 {
@ -309,5 +308,4 @@ class UtilTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_string($requirements['Math']));
}
}
}

View File

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

View File

@ -1 +1 @@
{"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"}}
{"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"}}

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