From 6622ee002b882e10f7bf39b2fe4d56f9b442496e Mon Sep 17 00:00:00 2001 From: Antonio Buedo Date: Mon, 15 Jun 2020 14:03:25 +0200 Subject: [PATCH] #v1.3.2006.0-rc - Mayor Security Updates (#11) - Php required version lowered - Added missing Http headers - XRP and BUSD to currency model - Fixed JsonMapper compatibility PHP 7.4 - invoice:PaymentTotals deprecated and removed on next version - invoice:PaymentCodes deprecated and removed on next version - Sub-version upgrade --- composer.lock | 301 +++++++-- src/BitPaySDKLight/Client.php | 4 +- src/BitPaySDKLight/Env.php | 2 +- src/BitPaySDKLight/Model/Currency.php | 2 + src/BitPaySDKLight/Model/Invoice/Invoice.php | 106 +++- .../Model/Invoice/PaymentCodes.php | 2 +- .../Model/Invoice/PaymentTotal.php | 5 + .../Util/JsonMapper/JsonMapper.php | 580 ++++++++++-------- src/BitPaySDKLight/Util/RESTcli/RESTcli.php | 20 +- 9 files changed, 667 insertions(+), 355 deletions(-) diff --git a/composer.lock b/composer.lock index a3406d1..4224a88 100644 --- a/composer.lock +++ b/composer.lock @@ -8,23 +8,24 @@ "packages": [ { "name": "guzzlehttp/guzzle", - "version": "6.5.2", + "version": "6.5.4", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "43ece0e75098b7ecd8d13918293029e555a50f82" + "reference": "a4a1b6930528a8f7ee03518e6442ec7a44155d9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/43ece0e75098b7ecd8d13918293029e555a50f82", - "reference": "43ece0e75098b7ecd8d13918293029e555a50f82", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a4a1b6930528a8f7ee03518e6442ec7a44155d9d", + "reference": "a4a1b6930528a8f7ee03518e6442ec7a44155d9d", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.0", "guzzlehttp/psr7": "^1.6.1", - "php": ">=5.5" + "php": ">=5.5", + "symfony/polyfill-intl-idn": "1.17.0" }, "require-dev": { "ext-curl": "*", @@ -32,7 +33,6 @@ "psr/log": "^1.1" }, "suggest": { - "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", @@ -71,7 +71,7 @@ "rest", "web service" ], - "time": "2019-12-23T11:57:10+00:00" + "time": "2020-05-25T19:35:05+00:00" }, { "name": "guzzlehttp/promises", @@ -284,25 +284,201 @@ ], "description": "A polyfill for getallheaders.", "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/polyfill-intl-idn", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "3bff59ea7047e925be6b7f2059d60af31bb46d6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/3bff59ea7047e925be6b7f2059d60af31bb46d6a", + "reference": "3bff59ea7047e925be6b7f2059d60af31bb46d6a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-php72": "^1.10" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Laurent Bassin", + "email": "laurent@bassin.info" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "idn", + "intl", + "polyfill", + "portable", + "shim" + ], + "time": "2020-05-12T16:47:27+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "fa79b11539418b02fc5e1897267673ba2c19419c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fa79b11539418b02fc5e1897267673ba2c19419c", + "reference": "fa79b11539418b02fc5e1897267673ba2c19419c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2020-05-12T16:47:27+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.17.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "f048e612a3905f34931127360bdd2def19a5e582" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/f048e612a3905f34931127360bdd2def19a5e582", + "reference": "f048e612a3905f34931127360bdd2def19a5e582", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2020-05-12T16:47:27+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" + "reference": "f350df0268e904597e3bd9c4685c53e0e333feea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f350df0268e904597e3bd9c4685c53e0e333feea", + "reference": "f350df0268e904597e3bd9c4685c53e0e333feea", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^6.0", @@ -341,7 +517,7 @@ "constructor", "instantiate" ], - "time": "2019-10-21T16:45:58+00:00" + "time": "2020-05-29T17:27:14+00:00" }, { "name": "myclabs/deep-copy", @@ -495,24 +671,21 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/6568f4687e5b41b054365f9ae03fcb1ed5f2069b", + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b", "shasum": "" }, "require": { "php": ">=7.1" }, - "require-dev": { - "phpunit/phpunit": "~6" - }, "type": "library", "extra": { "branch-alias": { @@ -543,45 +716,42 @@ "reflection", "static analysis" ], - "time": "2018-08-07T13:53:10+00:00" + "time": "2020-04-27T09:25:28+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.4", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c" + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/da3fd972d6bafd628114f7e7e036f45944b62e9c", - "reference": "da3fd972d6bafd628114f7e7e036f45944b62e9c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", "shasum": "" }, "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", - "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", - "webmozart/assert": "^1.0" + "ext-filter": "^7.1", + "php": "^7.2", + "phpdocumentor/reflection-common": "^2.0", + "phpdocumentor/type-resolver": "^1.0", + "webmozart/assert": "^1" }, "require-dev": { - "doctrine/instantiator": "^1.0.5", - "mockery/mockery": "^1.0", - "phpdocumentor/type-resolver": "0.4.*", - "phpunit/phpunit": "^6.4" + "doctrine/instantiator": "^1", + "mockery/mockery": "^1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -592,33 +762,36 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-12-28T18:55:12+00:00" + "time": "2020-02-22T12:28:44+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.0.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", "shasum": "" }, "require": { - "php": "^7.1", + "php": "^7.2", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "^7.1", - "mockery/mockery": "~1", - "phpunit/phpunit": "^7.0" + "ext-tokenizer": "^7.2", + "mockery/mockery": "~1" }, "type": "library", "extra": { @@ -642,20 +815,20 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2019-08-22T18:11:29+00:00" + "time": "2020-02-18T18:59:58+00:00" }, { "name": "phpspec/prophecy", - "version": "v1.10.2", + "version": "v1.10.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "b4400efc9d206e83138e2bb97ed7f5b14b831cd9" + "reference": "451c3cd1418cf640de218914901e51b064abb093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b4400efc9d206e83138e2bb97ed7f5b14b831cd9", - "reference": "b4400efc9d206e83138e2bb97ed7f5b14b831cd9", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093", + "reference": "451c3cd1418cf640de218914901e51b064abb093", "shasum": "" }, "require": { @@ -705,7 +878,7 @@ "spy", "stub" ], - "time": "2020-01-20T15:57:02+00:00" + "time": "2020-03-05T15:02:03+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1611,16 +1784,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.13.1", + "version": "v1.17.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3" + "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", - "reference": "f8f0b461be3385e56d6de3dbb5a0df24c0c275e3", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e94c8b1bbe2bc77507a1056cdb06451c75b427f9", + "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9", "shasum": "" }, "require": { @@ -1632,7 +1805,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.13-dev" + "dev-master": "1.17-dev" } }, "autoload": { @@ -1665,7 +1838,7 @@ "polyfill", "portable" ], - "time": "2019-11-27T13:56:44+00:00" + "time": "2020-05-12T16:14:59+00:00" }, { "name": "theseer/tokenizer", @@ -1709,16 +1882,16 @@ }, { "name": "webmozart/assert", - "version": "1.6.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925" + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/573381c0a64f155a0d9a23f4b0c797194805b925", - "reference": "573381c0a64f155a0d9a23f4b0c797194805b925", + "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { @@ -1726,7 +1899,7 @@ "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "vimeo/psalm": "<3.6.0" + "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" @@ -1753,7 +1926,7 @@ "check", "validate" ], - "time": "2019-11-24T13:36:37+00:00" + "time": "2020-04-18T12:12:48+00:00" } ], "aliases": [], diff --git a/src/BitPaySDKLight/Client.php b/src/BitPaySDKLight/Client.php index d2af999..99a13aa 100644 --- a/src/BitPaySDKLight/Client.php +++ b/src/BitPaySDKLight/Client.php @@ -23,9 +23,9 @@ * Class Client * @package Bitpay light * @author Antonio Buedo - * @version 1.2.2002 + * @version 1.3.2006 * See bitpay.com/api for more information. - * date 25.02.2020 + * date 15.06.2020 */ class Client { diff --git a/src/BitPaySDKLight/Env.php b/src/BitPaySDKLight/Env.php index 47404b6..98c55aa 100644 --- a/src/BitPaySDKLight/Env.php +++ b/src/BitPaySDKLight/Env.php @@ -11,7 +11,7 @@ interface Env const TestUrl = "https://test.bitpay.com/"; const ProdUrl = "https://bitpay.com/"; const BitpayApiVersion = "2.0.0"; - const BitpayPluginInfo = "BitPay_PHP_Client_v1.2.2002"; + const BitpayPluginInfo = "BitPay_PHP_Client_v1.3.2006"; const BitpayApiFrame = "custom-light"; const BitpayApiFrameVersion = "1.0.0"; } \ No newline at end of file diff --git a/src/BitPaySDKLight/Model/Currency.php b/src/BitPaySDKLight/Model/Currency.php index 9b7c1d0..53ad129 100644 --- a/src/BitPaySDKLight/Model/Currency.php +++ b/src/BitPaySDKLight/Model/Currency.php @@ -17,6 +17,8 @@ class Currency const USDC = "USDC"; const GUSD = "GUSD"; const PAX = "PAX"; + const XRP = "XRP"; + const BUSD = "BUSD"; // FIAT const AED = "AED"; diff --git a/src/BitPaySDKLight/Model/Invoice/Invoice.php b/src/BitPaySDKLight/Model/Invoice/Invoice.php index 5a01ac8..c7f5b3d 100644 --- a/src/BitPaySDKLight/Model/Invoice/Invoice.php +++ b/src/BitPaySDKLight/Model/Invoice/Invoice.php @@ -64,9 +64,37 @@ class Invoice protected $_transactionCurrency; protected $_amountPaid; protected $_exchangeRates; + + /** + * PaymentTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ protected $_paymentTotals; + + /** + * PaymentSubtotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ protected $_paymentSubtotals; + + /** + * PaymentDisplayTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ protected $_paymentDisplayTotals; + + /** + * PaymentDisplaySubTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ protected $_paymentDisplaySubTotals; /** @@ -86,10 +114,10 @@ public function __construct(float $price = null, string $currency = null) $this->_shopper = new Shopper(); $this->_refundInfo = new RefundInfo(); $this->_paymentCodes = null; - $this->_paymentTotals = new PaymentTotal(); - $this->_paymentSubtotals = new PaymentTotal(); - $this->_paymentDisplayTotals = new PaymentTotal(); - $this->_paymentDisplaySubTotals = new PaymentTotal(); + $this->_paymentTotals = null; + $this->_paymentSubtotals = null; + $this->_paymentDisplayTotals = null; + $this->_paymentDisplaySubTotals = null; } // API fields @@ -471,6 +499,7 @@ public function setRefundInfo(RefundInfo $refundInfo) $this->_refundInfo = $refundInfo; } + /** * PaymentCodes will be deprecated TODO on version 2.0 * @@ -481,13 +510,14 @@ public function getPaymentCodes() return $this->_paymentCodes; } + /** * PaymentCodes will be deprecated TODO on version 2.0 * * @var array * @deprecated */ - public function setPaymentCodes(PaymentCodes $paymentCodes) + public function setPaymentCodes(PaymentCodes $paymentCodes = null) { $this->_paymentCodes = null; } @@ -532,44 +562,92 @@ public function setExchangeRates($exchangeRates) $this->_exchangeRates = $exchangeRates; } + /** + * PaymentTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function getPaymentTotals() { return $this->_paymentTotals; } + /** + * PaymentTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function setPaymentTotals($paymentTotals) { - $this->_paymentTotals = $paymentTotals; + $this->_paymentTotals = null; } + /** + * PaymentSubtotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function getPaymentSubtotals() { return $this->_paymentSubtotals; } + /** + * PaymentSubtotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function setPaymentSubtotals($paymentSubtotals) { - $this->_paymentSubtotals = $paymentSubtotals; + $this->_paymentSubtotals = null; } + /** + * PaymentDisplaySubTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function getPaymentDisplaySubTotals() { return $this->_paymentDisplaySubTotals; } + /** + * PaymentDisplaySubTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function setPaymentDisplaySubTotals($paymentDisplaySubTotals) { - $this->_paymentDisplaySubTotals = $paymentDisplaySubTotals; + $this->_paymentDisplaySubTotals = null; } + /** + * PaymentDisplayTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function getPaymentDisplayTotals() { return $this->_paymentDisplayTotals; } + /** + * PaymentDisplayTotals will be deprecated TODO on version 2.0 + * + * @var array + * @deprecated + */ public function setPaymentDisplayTotals($paymentDisplayTotals) { - $this->_paymentDisplayTotals = $paymentDisplayTotals; + $this->_paymentDisplayTotals = null; } public function toArray() @@ -616,10 +694,10 @@ public function toArray() 'transactionCurrency' => $this->getTransactionCurrency(), 'amountPaid' => $this->getAmountPaid(), 'exchangeRates' => $this->getExchangeRates(), - 'paymentTotals' => $this->getPaymentTotals()->toArray(), - 'paymentSubtotals' => $this->getPaymentSubtotals()->toArray(), - 'paymentDisplayTotals' => $this->getPaymentDisplaySubTotals()->toArray(), - 'paymentDisplaySubTotals' => $this->getPaymentDisplaySubTotals()->toArray(), + 'paymentTotals' => [], + 'paymentSubtotals' => [], + 'paymentDisplayTotals' => [], + 'paymentDisplaySubTotals' => [], ]; foreach ($elements as $key => $value) { @@ -630,4 +708,4 @@ public function toArray() return $elements; } -} +} \ No newline at end of file diff --git a/src/BitPaySDKLight/Model/Invoice/PaymentCodes.php b/src/BitPaySDKLight/Model/Invoice/PaymentCodes.php index 22d470e..5da3d75 100644 --- a/src/BitPaySDKLight/Model/Invoice/PaymentCodes.php +++ b/src/BitPaySDKLight/Model/Invoice/PaymentCodes.php @@ -5,7 +5,7 @@ /** - * PaymentCode will be deprecated TODO on version 2.0 + * PaymentCodes will be deprecated TODO on version 2.0 * * @deprecated */ diff --git a/src/BitPaySDKLight/Model/Invoice/PaymentTotal.php b/src/BitPaySDKLight/Model/Invoice/PaymentTotal.php index 1fde288..a034820 100644 --- a/src/BitPaySDKLight/Model/Invoice/PaymentTotal.php +++ b/src/BitPaySDKLight/Model/Invoice/PaymentTotal.php @@ -4,6 +4,11 @@ namespace BitPaySDKLight\Model\Invoice; +/** + * PaymentTotal will be deprecated TODO on version 2.0 + * + * @deprecated + */ class PaymentTotal { protected $_btc; diff --git a/src/BitPaySDKLight/Util/JsonMapper/JsonMapper.php b/src/BitPaySDKLight/Util/JsonMapper/JsonMapper.php index ccd0973..920382b 100755 --- a/src/BitPaySDKLight/Util/JsonMapper/JsonMapper.php +++ b/src/BitPaySDKLight/Util/JsonMapper/JsonMapper.php @@ -1,5 +1,4 @@ -bEnforceMapType && !is_object($json)) { - throw new InvalidArgumentException( - 'JsonMapper::map() requires first argument to be an object' + throw new JsonMapperException( + 'InvalidArgumentException: JsonMapper::map() requires first argument to be an object' .', '.gettype($json).' given.' ); } if (!is_object($object)) { - throw new InvalidArgumentException( - 'JsonMapper::map() requires second argument to be an object' + throw new JsonMapperException( + 'InvalidArgumentException: JsonMapper::map() requires second argument to be an object' .', '.gettype($object).' given.' ); } @@ -240,6 +260,7 @@ public function map($json, $object) } } + //FIXME: check if type exists, give detailed error message if not if ($type === '') { throw new JsonMapperException( 'Empty type at property "' @@ -268,10 +289,6 @@ public function map($json, $object) } } - if ($key == 'shopper') { - $stop = 0; - } - if ($array !== null) { if (!is_array($jvalue) && $this->isFlatType(gettype($jvalue))) { throw new JsonMapperException( @@ -310,52 +327,179 @@ public function map($json, $object) $this->removeUndefinedAttributes($object, $providedProperties); } + if ($this->postMappingMethod !== null + && $rc->hasMethod($this->postMappingMethod) + ) { + $refDeserializePostMethod = $rc->getMethod( + $this->postMappingMethod + ); + $refDeserializePostMethod->setAccessible(true); + $refDeserializePostMethod->invoke($object); + } + return $object; } /** - * Since hyphens cannot be used in variables we have to uppercase them. + * Convert a type name to a fully namespaced type name. * - * Technically you may use them, but they are awkward to access. + * @param string $type Type name (simple type or class name) + * @param string $strNs Base namespace that gets prepended to the type name * - * @param string $name Property name + * @return string Fully-qualified type name with namespace + */ + protected function getFullNamespace($type, $strNs) + { + if ($type === null || $type === '' || $type[0] == '\\' + || $strNs == '' + ) { + return $type; + } + list($first) = explode('[', $type, 2); + if ($this->isSimpleType($first) || $first === 'mixed') { + return $type; + } + + //create a full qualified namespace + return '\\'.$strNs.'\\'.$type; + } + + /** + * Check required properties exist in json * - * @return string Name without hyphen + * @param array $providedProperties array with json properties + * @param ReflectionClass $rc Reflection class to check + * + * @return void + * @throws JsonMapperException + * @throws ReflectionException */ - protected function getSafeName($name) + protected function checkMissingData($providedProperties, ReflectionClass $rc) { - if (strpos($name, '-') !== false) { - $name = $this->getCamelCaseName($name); + foreach ($rc->getProperties() as $property) { + $rprop = $rc->getProperty($property->name); + $docblock = $rprop->getDocComment(); + $annotations = static::parseAnnotations($docblock); + if (isset($annotations['required']) + && !isset($providedProperties[$property->name]) + ) { + throw new JsonMapperException( + 'Required property "'.$property->name.'" of class ' + .$rc->getName() + .' is missing in JSON data' + ); + } } + } - return $name; + /** + * Remove attributes from object that were not passed in JSON data. + * + * This is to avoid confusion between those that were actually passed + * as NULL, and those that weren't provided at all. + * + * @param object $object Object to remove properties from + * @param array $providedProperties Array with JSON properties + * + * @return void + */ + protected function removeUndefinedAttributes($object, $providedProperties) + { + foreach (get_object_vars($object) as $propertyName => $dummy) { + if (!isset($providedProperties[$propertyName])) { + unset($object->{$propertyName}); + } + } } /** - * Removes - and _ and makes the next letter uppercase + * Map an array * - * @param string $name Property name + * @param array $json JSON array structure from json_decode() + * @param mixed $array Array or ArrayObject that gets filled with + * data from $json + * @param string $class Class name for children objects. + * All children will get mapped onto this type. + * Supports class names and simple types + * like "string" and nullability "string|null". + * Pass "null" to not convert any values + * @param string $parent_key Defines the key this array belongs to + * in order to aid debugging. * - * @return string CamelCasedVariableName + * @return mixed Mapped $array is returned + * @throws JsonMapperException + * @throws ReflectionException */ - protected function getCamelCaseName($name) + public function mapArray($json, $array, $class = null, $parent_key = '') { - return str_replace( - ' ', '', ucwords(str_replace(['_', '-'], ' ', $name)) - ); + $originalClass = $class; + foreach ($json as $key => $jvalue) { + $class = $this->getMappedType($originalClass, $jvalue); + if ($class === null) { + $array[$key] = $jvalue; + } else { + if ($this->isArrayOfType($class)) { + $array[$key] = $this->mapArray( + $jvalue, + [], + substr($class, 0, -2) + ); + } else { + if ($this->isFlatType(gettype($jvalue))) { + //use constructor parameter if we have a class + // but only a flat type (i.e. string, int) + if ($jvalue === null) { + $array[$key] = null; + } else { + if ($this->isSimpleType($class)) { + settype($jvalue, $class); + $array[$key] = $jvalue; + } else { + $array[$key] = $this->createInstance( + $class, true, $jvalue + ); + } + } + } else { + if ($this->isFlatType($class)) { + throw new JsonMapperException( + 'JSON property "'.($parent_key ? $parent_key : '?').'"' + .' is an array of type "'.$class.'"' + .' but contained a value of type' + .' "'.gettype($jvalue).'"' + ); + } else { + if (is_a($class, 'ArrayObject', true)) { + $array[$key] = $this->mapArray( + $jvalue, + $this->createInstance($class) + ); + } else { + $array[$key] = $this->map( + $jvalue, $this->createInstance($class, false, $jvalue) + ); + } + } + } + } + } + } + + return $array; } /** * Try to find out if a property exists in a given class. * Checks property first, falls back to setter method. * - * @param object $rc Reflection class to check - * @param string $name Property name + * @param ReflectionClass $rc Reflection class to check + * @param string $name Property name * * @return array First value: if the property exists * Second value: the accessor to use ( - * ReflectionMethod or \ReflectionProperty, or null) + * ReflectionMethod or ReflectionProperty, or null) * Third value: type of the property + * @throws ReflectionException */ protected function inspectProperty(ReflectionClass $rc, $name) { @@ -390,6 +534,13 @@ protected function inspectProperty(ReflectionClass $rc, $name) if (PHP_MAJOR_VERSION >= 7) { $ptype = $rparams[0]->getType(); if ($ptype !== null) { + // ReflectionType::__toString() is deprecated + if (PHP_VERSION >= 7.1 + && $ptype instanceof ReflectionNamedType + ) { + $ptype = $ptype->getName(); + } + return [true, $rmeth, $ptype.$nullability]; } } @@ -445,57 +596,35 @@ protected function inspectProperty(ReflectionClass $rc, $name) } /** - * Copied from PHPUnit 3.7.29, Util/Test.php + * Removes - and _ and makes the next letter uppercase * - * @param string $docblock Full method docblock + * @param string $name Property name * - * @return array + * @return string CamelCasedVariableName */ - protected static function parseAnnotations($docblock) + protected function getCamelCaseName($name) { - $annotations = []; - // Strip away the docblock header and footer - // to ease parsing of one line annotations - $docblock = substr($docblock, 3, -2); - - $re = '/@(?P[A-Za-z_-]+)(?:[ \t]+(?P.*?))?[ \t]*\r?$/m'; - if (preg_match_all($re, $docblock, $matches)) { - $numMatches = count($matches[0]); - - for ($i = 0; $i < $numMatches; ++$i) { - $annotations[$matches['name'][$i]][] = $matches['value'][$i]; - } - } - - return $annotations; + return str_replace( + ' ', '', ucwords(str_replace(['_', '-'], ' ', $name)) + ); } /** - * Log a message to the $logger object + * Since hyphens cannot be used in variables we have to uppercase them. * - * @param string $level Logging level - * @param string $message Text to log - * @param array $context Additional information + * Technically you may use them, but they are awkward to access. * - * @return null + * @param string $name Property name + * + * @return string Name without hyphen */ - protected function log($level, $message, array $context = []) + protected function getSafeName($name) { - if ($this->logger) { - $this->logger->log($level, $message, $context); + if (strpos($name, '-') !== false) { + $name = $this->getCamelCaseName($name); } - } - /** - * Checks if the given type is nullable - * - * @param string $type type name from the phpdoc param - * - * @return boolean True if it is nullable - */ - protected function isNullable($type) - { - return stripos('|'.$type.'|', '|null|') !== false; + return $name; } /** @@ -505,7 +634,7 @@ protected function isNullable($type) * calling this method. * * @param object $object Object to set property on - * @param object $accessor ReflectionMethod or \ReflectionProperty + * @param object $accessor ReflectionMethod or ReflectionProperty * @param mixed $value Value of property * * @return void @@ -527,64 +656,36 @@ protected function setProperty( } /** - * Remove the 'null' section of a type + * Create a new object of the given type. * - * @param string $type type name from the phpdoc param + * This method exists to be overwritten in child classes, + * so you can do dependency injection or so. * - * @return string The new type value + * @param string $class Class name to instantiate + * @param boolean $useParameter Pass $parameter to the constructor or not + * @param mixed $jvalue Constructor parameter (the json value) + * + * @return object Freshly created object + * @throws ReflectionException */ - protected function removeNullable($type) - { - if ($type === null) { - return null; - } - - return substr( - str_ireplace('|null|', '|', '|'.$type.'|'), - 1, -1 - ); - } + protected function createInstance( + $class, + $useParameter = false, + $jvalue = null + ) { + if ($useParameter) { + return new $class($jvalue); + } else { + $reflectClass = new ReflectionClass($class); + $constructor = $reflectClass->getConstructor(); + if (null === $constructor + || $constructor->getNumberOfRequiredParameters() > 0 + ) { + return $reflectClass->newInstanceWithoutConstructor(); + } - /** - * Convert a type name to a fully namespaced type name. - * - * @param string $type Type name (simple type or class name) - * @param string $strNs Base namespace that gets prepended to the type name - * - * @return string Fully-qualified type name with namespace - */ - protected function getFullNamespace($type, $strNs) - { - if ($type === null || $type === '' || $type[0] == '\\' - || $strNs == '' - ) { - return $type; - } - list($first) = explode('[', $type, 2); - if ($this->isSimpleType($first) || $first === 'mixed') { - return $type; + return $reflectClass->newInstance(); } - - //create a full qualified namespace - return '\\'.$strNs.'\\'.$type; - } - - /** - * Checks if the given type is a "simple type" - * - * @param string $type type name from gettype() - * - * @return boolean True if it is a simple PHP type - * - * @see isFlatType() - */ - protected function isSimpleType($type) - { - return $type == 'string' - || $type == 'boolean' || $type == 'bool' - || $type == 'integer' || $type == 'int' - || $type == 'double' || $type == 'float' - || $type == 'array' || $type == 'object'; } /** @@ -621,6 +722,24 @@ protected function getMappedType($type, $jvalue = null) return $type; } + /** + * Checks if the given type is a "simple type" + * + * @param string $type type name from gettype() + * + * @return boolean True if it is a simple PHP type + * + * @see isFlatType() + */ + protected function isSimpleType($type) + { + return $type == 'string' + || $type == 'boolean' || $type == 'bool' + || $type == 'integer' || $type == 'int' + || $type == 'double' || $type == 'float' + || $type == 'array' || $type == 'object'; + } + /** * Checks if the object is of this type or has this type as one of its parents * @@ -639,188 +758,107 @@ protected function isObjectOfSameType($type, $value) } /** - * Returns true if type is an array of elements - * (bracket notation) + * Checks if the given type is a type that is not nested + * (simple type except array and object) * - * @param string $strType type to be matched + * @param string $type type name from gettype() * - * @return bool + * @return boolean True if it is a non-nested PHP type + * + * @see isSimpleType() */ - protected function isArrayOfType($strType) + protected function isFlatType($type) { - return substr($strType, -2) === '[]'; + return $type == 'NULL' + || $type == 'string' + || $type == 'boolean' || $type == 'bool' + || $type == 'integer' || $type == 'int' + || $type == 'double' || $type == 'float'; } /** - * Create a new object of the given type. - * - * This method exists to be overwritten in child classes, - * so you can do dependency injection or so. + * Returns true if type is an array of elements + * (bracket notation) * - * @param string $class Class name to instantiate - * @param boolean $useParameter Pass $parameter to the constructor or not - * @param mixed $jvalue Constructor parameter (the json value) + * @param string $strType type to be matched * - * @return object Freshly created object + * @return bool */ - public function createInstance( - $class, - $useParameter = false, - $jvalue = null - ) { - if ($useParameter) { - return new $class($jvalue); - } else { - $reflectClass = new ReflectionClass($class); - $constructor = $reflectClass->getConstructor(); - if (null === $constructor - || $constructor->getNumberOfRequiredParameters() > 0 - ) { - return $reflectClass->newInstanceWithoutConstructor(); - } - - return $reflectClass->newInstance(); - } + protected function isArrayOfType($strType) + { + return substr($strType, -2) === '[]'; } /** - * Checks if the given type is a type that is not nested - * (simple type except array and object) - * - * @param string $type type name from gettype() + * Checks if the given type is nullable * - * @return boolean True if it is a non-nested PHP type + * @param string $type type name from the phpdoc param * - * @see isSimpleType() + * @return boolean True if it is nullable */ - protected function isFlatType($type) + protected function isNullable($type) { - return $type == 'NULL' - || $type == 'string' - || $type == 'boolean' || $type == 'bool' - || $type == 'integer' || $type == 'int' - || $type == 'double' || $type == 'float'; + return stripos('|'.$type.'|', '|null|') !== false; } /** - * Map an array + * Remove the 'null' section of a type * - * @param array $json JSON array structure from json_decode() - * @param mixed $array Array or ArrayObject that gets filled with - * data from $json - * @param string $class Class name for children objects. - * All children will get mapped onto this type. - * Supports class names and simple types - * like "string" and nullability "string|null". - * Pass "null" to not convert any values - * @param string $parent_key Defines the key this array belongs to - * in order to aid debugging. + * @param string $type type name from the phpdoc param * - * @return mixed Mapped $array is returned + * @return string The new type value */ - public function mapArray($json, $array, $class = null, $parent_key = '') + protected function removeNullable($type) { - $originalClass = $class; - foreach ($json as $key => $jvalue) { - $class = $this->getMappedType($originalClass, $jvalue); - if ($class === null) { - $array[$key] = $jvalue; - } else { - if ($this->isArrayOfType($class)) { - $array[$key] = $this->mapArray( - $jvalue, - [], - substr($class, 0, -2) - ); - } else { - if ($this->isFlatType(gettype($jvalue))) { - //use constructor parameter if we have a class - // but only a flat type (i.e. string, int) - if ($jvalue === null) { - $array[$key] = null; - } else { - if ($this->isSimpleType($class)) { - settype($jvalue, $class); - $array[$key] = $jvalue; - } else { - $array[$key] = $this->createInstance( - $class, true, $jvalue - ); - } - } - } else { - if ($this->isFlatType($class)) { - throw new JsonMapperException( - 'JSON property "'.($parent_key ? $parent_key : '?').'"' - .' is an array of type "'.$class.'"' - .' but contained a value of type' - .' "'.gettype($jvalue).'"' - ); - } else { - if (is_a($class, 'ArrayObject', true)) { - $array[$key] = $this->mapArray( - $jvalue, - $this->createInstance($class) - ); - } else { - $array[$key] = $this->map( - $jvalue, $this->createInstance($class, false, $jvalue) - ); - } - } - } - } - } + if ($type === null) { + return null; } - return $array; + return substr( + str_ireplace('|null|', '|', '|'.$type.'|'), + 1, -1 + ); } /** - * Check required properties exist in json - * - * @param array $providedProperties array with json properties - * @param object $rc Reflection class to check + * Copied from PHPUnit 3.7.29, Util/Test.php * - * @return void - * @throws JsonMapperException + * @param string $docblock Full method docblock * + * @return array */ - protected function checkMissingData($providedProperties, ReflectionClass $rc) + protected static function parseAnnotations($docblock) { - foreach ($rc->getProperties() as $property) { - $rprop = $rc->getProperty($property->name); - $docblock = $rprop->getDocComment(); - $annotations = $this->parseAnnotations($docblock); - if (isset($annotations['required']) - && !isset($providedProperties[$property->name]) - ) { - throw new JsonMapperException( - 'Required property "'.$property->name.'" of class ' - .$rc->getName() - .' is missing in JSON data' - ); + $annotations = []; + // Strip away the docblock header and footer + // to ease parsing of one line annotations + $docblock = substr($docblock, 3, -2); + + $re = '/@(?P[A-Za-z_-]+)(?:[ \t]+(?P.*?))?[ \t]*\r?$/m'; + if (preg_match_all($re, $docblock, $matches)) { + $numMatches = count($matches[0]); + + for ($i = 0; $i < $numMatches; ++$i) { + $annotations[$matches['name'][$i]][] = $matches['value'][$i]; } } + + return $annotations; } /** - * Remove attributes from object that were not passed in JSON data. - * - * This is to avoid confusion between those that were actually passed - * as NULL, and those that weren't provided at all. + * Log a message to the $logger object * - * @param object $object Object to remove properties from - * @param array $providedProperties Array with JSON properties + * @param string $level Logging level + * @param string $message Text to log + * @param array $context Additional information * - * @return void + * @return null */ - protected function removeUndefinedAttributes($object, $providedProperties) + protected function log($level, $message, array $context = []) { - foreach (get_object_vars($object) as $propertyName => $dummy) { - if (!isset($providedProperties[$propertyName])) { - unset($object->{$propertyName}); - } + if ($this->logger) { + $this->logger->log($level, $message, $context); } } @@ -835,4 +873,4 @@ public function setLogger($logger) { $this->logger = $logger; } -} +} \ No newline at end of file diff --git a/src/BitPaySDKLight/Util/RESTcli/RESTcli.php b/src/BitPaySDKLight/Util/RESTcli/RESTcli.php index 88ef170..e401479 100644 --- a/src/BitPaySDKLight/Util/RESTcli/RESTcli.php +++ b/src/BitPaySDKLight/Util/RESTcli/RESTcli.php @@ -36,8 +36,8 @@ public function init() 'base_url' => $this->_baseUrl, 'defaults' => [ 'headers' => [ - "x-accept-version" => Env::BitpayApiVersion, - 'X-BitPay-Plugin-Info' => Env::BitpayPluginInfo, + 'x-accept-version' => Env::BitpayApiVersion, + 'x-bitpay-plugin-info' => Env::BitpayPluginInfo, 'x-bitpay-api-frame' => Env::BitpayApiFrame, 'x-bitpay-api-frame-version' => Env::BitpayApiFrameVersion, ], @@ -54,6 +54,10 @@ public function post($uri, array $formData = []): string $fullURL = $this->_baseUrl.$uri; $headers = [ 'Content-Type' => 'application/json', + 'x-accept-version' => Env::BitpayApiVersion, + 'x-bitpay-plugin-info' => Env::BitpayPluginInfo, + 'x-bitpay-api-frame' => Env::BitpayApiFrame, + 'x-bitpay-api-frame-version' => Env::BitpayApiFrameVersion, ]; /** @@ -80,6 +84,10 @@ public function get($uri, array $parameters = null): string $fullURL = $this->_baseUrl.$uri; $headers = [ 'Content-Type' => 'application/json', + 'x-accept-version' => Env::BitpayApiVersion, + 'x-bitpay-plugin-info' => Env::BitpayPluginInfo, + 'x-bitpay-api-frame' => Env::BitpayApiFrame, + 'x-bitpay-api-frame-version' => Env::BitpayApiFrameVersion, ]; if ($parameters) { @@ -113,6 +121,10 @@ public function delete($uri, array $parameters = null): string } $headers = [ + 'x-accept-version' => Env::BitpayApiVersion, + 'x-bitpay-plugin-info' => Env::BitpayPluginInfo, + 'x-bitpay-api-frame' => Env::BitpayApiFrame, + 'x-bitpay-api-frame-version' => Env::BitpayApiFrameVersion, 'Content-Type' => 'application/json', ]; @@ -139,6 +151,10 @@ public function update($uri, array $formData = []): string try { $fullURL = $this->_baseUrl.$uri; $headers = [ + 'x-accept-version' => Env::BitpayApiVersion, + 'x-bitpay-plugin-info' => Env::BitpayPluginInfo, + 'x-bitpay-api-frame' => Env::BitpayApiFrame, + 'x-bitpay-api-frame-version' => Env::BitpayApiFrameVersion, 'Content-Type' => 'application/json', ];