diff --git a/composer.lock b/composer.lock index 1f054906..60547104 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a54038a9842f8776f6679ea1d030209f", + "content-hash": "143a35c65b5c27c77f2fdcf64059a11d", "packages": [ { "name": "bitpay/key-utils", @@ -49,23 +49,24 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.4.1", + "version": "6.5.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "0895c932405407fd3a7368b6910c09a24d26db11" + "reference": "aab4ebd862aa7d04f01a4b51849d657db56d882e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0895c932405407fd3a7368b6910c09a24d26db11", - "reference": "0895c932405407fd3a7368b6910c09a24d26db11", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/aab4ebd862aa7d04f01a4b51849d657db56d882e", + "reference": "aab4ebd862aa7d04f01a4b51849d657db56d882e", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.0", "guzzlehttp/psr7": "^1.6.1", - "php": ">=5.5" + "php": ">=5.5", + "symfony/polyfill-intl-idn": "^1.11" }, "require-dev": { "ext-curl": "*", @@ -78,7 +79,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.3-dev" + "dev-master": "6.5-dev" } }, "autoload": { @@ -111,7 +112,7 @@ "rest", "web service" ], - "time": "2019-10-23T15:58:00+00:00" + "time": "2020-04-18T10:38:46+00:00" }, { "name": "guzzlehttp/promises", @@ -327,16 +328,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.12.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "550ebaac289296ce228a706d0867afc34687e3f4" + "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", - "reference": "550ebaac289296ce228a706d0867afc34687e3f4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/4719fa9c18b0464d399f1a63bf624b42b6fa8d14", + "reference": "4719fa9c18b0464d399f1a63bf624b42b6fa8d14", "shasum": "" }, "require": { @@ -348,7 +349,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -381,20 +382,196 @@ "polyfill", "portable" ], - "time": "2019-08-06T08:03:45+00:00" + "time": "2020-02-27T09:26:54+00:00" + }, + { + "name": "symfony/polyfill-intl-idn", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-idn.git", + "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", + "reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf", + "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.15-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-03-09T19:04:49+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/81ffd3a9c6d707be22e3012b827de1c9775fc5ac", + "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.15-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-03-09T19:04:49+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "37b0976c78b94856543260ce09b460a7bc852747" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/37b0976c78b94856543260ce09b460a7bc852747", + "reference": "37b0976c78b94856543260ce09b460a7bc852747", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.15-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-02-27T09:26:54+00:00" }, { "name": "symfony/yaml", - "version": "v4.3.8", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "324cf4b19c345465fad14f3602050519e09e361d" + "reference": "b385dce1c0e9f839b384af90188638819433e252" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/324cf4b19c345465fad14f3602050519e09e361d", - "reference": "324cf4b19c345465fad14f3602050519e09e361d", + "url": "https://api.github.com/repos/symfony/yaml/zipball/b385dce1c0e9f839b384af90188638819433e252", + "reference": "b385dce1c0e9f839b384af90188638819433e252", "shasum": "" }, "require": { @@ -405,7 +582,7 @@ "symfony/console": "<3.4" }, "require-dev": { - "symfony/console": "~3.4|~4.0" + "symfony/console": "^3.4|^4.0|^5.0" }, "suggest": { "symfony/console": "For validating YAML files using the lint command" @@ -413,7 +590,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.3-dev" + "dev-master": "4.4-dev" } }, "autoload": { @@ -440,7 +617,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2019-10-30T12:58:49+00:00" + "time": "2020-04-28T17:55:16+00:00" } ], "packages-dev": [ @@ -502,16 +679,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.9.3", + "version": "1.9.5", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", - "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef", + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef", "shasum": "" }, "require": { @@ -546,7 +723,7 @@ "object", "object graph" ], - "time": "2019-08-09T12:45:53+00:00" + "time": "2020-01-17T21:11:47+00:00" }, { "name": "phar-io/manifest", @@ -652,24 +829,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": { @@ -700,44 +874,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.2", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "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", - "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/", @@ -748,33 +920,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-09-12T14:27:41+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": { @@ -798,37 +973,37 @@ } ], "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": "1.9.0", + "version": "v1.10.3", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" + "reference": "451c3cd1418cf640de218914901e51b064abb093" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", - "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093", + "reference": "451c3cd1418cf640de218914901e51b064abb093", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", - "sebastian/comparator": "^1.1|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" + "sebastian/comparator": "^1.2.3|^2.0|^3.0|^4.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0|^4.0" }, "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", + "phpspec/phpspec": "^2.5 || ^3.2", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.10.x-dev" } }, "autoload": { @@ -861,7 +1036,7 @@ "spy", "stub" ], - "time": "2019-10-03T11:07:50+00:00" + "time": "2020-03-05T15:02:03+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1117,16 +1292,16 @@ }, { "name": "phpunit/phpunit", - "version": "7.5.17", + "version": "7.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4c92a15296e58191a4cd74cff3b34fc8e374174a" + "reference": "9467db479d1b0487c99733bb1e7944d32deded2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4c92a15296e58191a4cd74cff3b34fc8e374174a", - "reference": "4c92a15296e58191a4cd74cff3b34fc8e374174a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9467db479d1b0487c99733bb1e7944d32deded2c", + "reference": "9467db479d1b0487c99733bb1e7944d32deded2c", "shasum": "" }, "require": { @@ -1197,7 +1372,7 @@ "testing", "xunit" ], - "time": "2019-10-28T10:37:36+00:00" + "time": "2020-01-08T08:45:45+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1366,16 +1541,16 @@ }, { "name": "sebastian/environment", - "version": "4.2.2", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" + "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", - "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", + "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", "shasum": "" }, "require": { @@ -1415,7 +1590,7 @@ "environment", "hhvm" ], - "time": "2019-05-05T09:05:15+00:00" + "time": "2019-11-20T08:46:58+00:00" }, { "name": "sebastian/exporter", @@ -1807,31 +1982,29 @@ }, { "name": "webmozart/assert", - "version": "1.5.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", - "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", + "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { "php": "^5.3.3 || ^7.0", "symfony/polyfill-ctype": "^1.8" }, + "conflict": { + "vimeo/psalm": "<3.9.1" + }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" @@ -1853,7 +2026,7 @@ "check", "validate" ], - "time": "2019-08-24T08:43:50+00:00" + "time": "2020-04-18T12:12:48+00:00" } ], "aliases": [], @@ -1863,7 +2036,7 @@ "prefer-lowest": false, "platform": { "php": "^7.1", - "ext-json": "^1.5", + "ext-json": "*", "ext-reflection": "*" }, "platform-dev": [] diff --git a/src/BitPaySDK/Client.php b/src/BitPaySDK/Client.php index 7cb3a2d8..dc8b0c55 100644 --- a/src/BitPaySDK/Client.php +++ b/src/BitPaySDK/Client.php @@ -44,9 +44,9 @@ * Class Client * @package Bitpay * @author Antonio Buedo - * @version 3.5.2003 + * @version 3.6.2005 * See bitpay.com/api for more information. - * date 25.03.2020 + * date 02.05.2020 */ class Client { diff --git a/src/BitPaySDK/Env.php b/src/BitPaySDK/Env.php index 0c328bd4..abb0ca2b 100644 --- a/src/BitPaySDK/Env.php +++ b/src/BitPaySDK/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_v3.5.2003"; + const BitpayPluginInfo = "BitPay_PHP_Client_v3.6.2005"; const BitpayApiFrame = "custom"; const BitpayApiFrameVersion = "1.0.0"; } \ No newline at end of file diff --git a/src/BitPaySDK/Model/Currency.php b/src/BitPaySDK/Model/Currency.php index 68875370..e927cf74 100644 --- a/src/BitPaySDK/Model/Currency.php +++ b/src/BitPaySDK/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/BitPaySDK/Model/Invoice/Invoice.php b/src/BitPaySDK/Model/Invoice/Invoice.php index 7d3fa3c1..e34a145f 100644 --- a/src/BitPaySDK/Model/Invoice/Invoice.php +++ b/src/BitPaySDK/Model/Invoice/Invoice.php @@ -64,9 +64,37 @@ class Invoice protected $_transactionCurrency; protected $_amountPaid; protected $_exchangeRates; + + /** + * PaymentTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ protected $_paymentTotals; + + /** + * PaymentSubtotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ protected $_paymentSubtotals; + + /** + * PaymentDisplayTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ protected $_paymentDisplayTotals; + + /** + * PaymentDisplaySubTotals will be deprecated TODO on version 4.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 @@ -534,44 +562,92 @@ public function setExchangeRates($exchangeRates) $this->_exchangeRates = $exchangeRates; } + /** + * PaymentTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function getPaymentTotals() { return $this->_paymentTotals; } + /** + * PaymentTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function setPaymentTotals($paymentTotals) { - $this->_paymentTotals = $paymentTotals; + $this->_paymentTotals = null; } + /** + * PaymentSubtotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function getPaymentSubtotals() { return $this->_paymentSubtotals; } + /** + * PaymentSubtotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function setPaymentSubtotals($paymentSubtotals) { - $this->_paymentSubtotals = $paymentSubtotals; + $this->_paymentSubtotals = null; } + /** + * PaymentDisplaySubTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function getPaymentDisplaySubTotals() { return $this->_paymentDisplaySubTotals; } + /** + * PaymentDisplaySubTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function setPaymentDisplaySubTotals($paymentDisplaySubTotals) { - $this->_paymentDisplaySubTotals = $paymentDisplaySubTotals; + $this->_paymentDisplaySubTotals = null; } + /** + * PaymentDisplayTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function getPaymentDisplayTotals() { return $this->_paymentDisplayTotals; } + /** + * PaymentDisplayTotals will be deprecated TODO on version 4.0 + * + * @var array + * @deprecated + */ public function setPaymentDisplayTotals($paymentDisplayTotals) { - $this->_paymentDisplayTotals = $paymentDisplayTotals; + $this->_paymentDisplayTotals = null; } public function toArray() @@ -618,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) { diff --git a/src/BitPaySDK/Model/Invoice/PaymentCodes.php b/src/BitPaySDK/Model/Invoice/PaymentCodes.php index d53e99f9..f3b1cfa2 100644 --- a/src/BitPaySDK/Model/Invoice/PaymentCodes.php +++ b/src/BitPaySDK/Model/Invoice/PaymentCodes.php @@ -5,7 +5,7 @@ /** - * PaymentCode will be deprecated TODO on version 4.0 + * PaymentCodes will be deprecated TODO on version 4.0 * * @deprecated */ diff --git a/src/BitPaySDK/Model/Invoice/PaymentTotal.php b/src/BitPaySDK/Model/Invoice/PaymentTotal.php index db800b96..d7adfb43 100644 --- a/src/BitPaySDK/Model/Invoice/PaymentTotal.php +++ b/src/BitPaySDK/Model/Invoice/PaymentTotal.php @@ -4,6 +4,11 @@ namespace BitPaySDK\Model\Invoice; +/** + * PaymentTotal will be deprecated TODO on version 4.0 + * + * @deprecated + */ class PaymentTotal { protected $_btc; diff --git a/src/BitPaySDK/Util/JsonMapper/JsonMapper.php b/src/BitPaySDK/Util/JsonMapper/JsonMapper.php old mode 100755 new mode 100644 index 631fd359..1ba305de --- a/src/BitPaySDK/Util/JsonMapper/JsonMapper.php +++ b/src/BitPaySDK/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.' ); } @@ -269,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( @@ -311,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) { @@ -391,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]; } } @@ -446,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; } /** @@ -506,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 @@ -528,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'; } /** @@ -622,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 * @@ -640,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); } }