From c9cb8a835363066c036c9ea7470c7175332532b8 Mon Sep 17 00:00:00 2001 From: PK Date: Fri, 21 Jun 2019 16:28:16 -0400 Subject: [PATCH 1/8] update composer.json --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0d20cd4..552737d 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,9 @@ "role": "Developer" } ], - "minimum-stability": "dev", - "prefer-stable": "true", "require": { "php": ">=7.1", + "monolog/monolog": "^1.24", "vlucas/phpdotenv": "^3.3", "guzzlehttp/guzzle": "^6.3" }, From 1ba5fc5114706ade0d6fc1cfef7a7cb93fab5b08 Mon Sep 17 00:00:00 2001 From: SangminLee Date: Wed, 16 Sep 2020 10:55:57 -0400 Subject: [PATCH 2/8] Add CancelPayment() --- src/Constants.php | 9 +++++++++ src/TendoPayClient.php | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Constants.php b/src/Constants.php index fa9c6f6..f1552de 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -25,6 +25,7 @@ class Constants public const DESCRIPTION_ENDPOINT_URI = 'payments/api/v1/paymentDescription'; public const BEARER_TOKEN_ENDPOINT_URI = 'oauth/token'; public const ORDER_STATUS_TRANSITION_ENDPOINT_URI = 'payments/api/v1/orderUpdate'; + public const CANCEL_PAYMENT_ENDPOINT_URI = 'payments/api/v1/cancelPayment'; /** * Gets the transaction detail endpoint uri */ @@ -202,4 +203,12 @@ public static function getTransactionDetailEndpointURI($transactionNumber): stri self::TRANSACTION_DETAIL_ENDPOINT_URI ); } + + /** + * Get cancel payment uri + */ + public static function get_cancel_payment_endpoint_uri(): string + { + return self::CANCEL_PAYMENT_ENDPOINT_URI; + } } diff --git a/src/TendoPayClient.php b/src/TendoPayClient.php index 22e1f9f..83b8d92 100644 --- a/src/TendoPayClient.php +++ b/src/TendoPayClient.php @@ -372,6 +372,25 @@ public function getTransactionDetail($transactionNumber): Transaction $transaction = json_decode($response, true); return new Transaction($transaction); } + + /** + * Cancel transaction + * @param $transactionNumber + * @return mixed|string + * @throws TendoPayConnectionException + */ + public function cancelPayment($transactionNumber) + { + $params = [ + Constants::TRANSACTION_NO_PARAM => $transactionNumber, + ]; + + $body = $this->request('POST', + Constants::get_cancel_payment_endpoint_uri(), + static::appendHash($params), + $this->getAuthorizationHeader()); + return json_decode($body, false) ?? ''; + } } From 14c93f98e9764c924aeb0ac462af966adda5b026 Mon Sep 17 00:00:00 2001 From: SangminLee Date: Thu, 17 Sep 2020 14:53:43 -0400 Subject: [PATCH 3/8] package,TendoPayClient --- composer.json | 5 +- composer.lock | 1077 ++++++++++++---------------------------- src/Constants.php | 6 +- src/TendoPayClient.php | 184 ++++--- 4 files changed, 430 insertions(+), 842 deletions(-) diff --git a/composer.json b/composer.json index 552737d..3cde274 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,7 @@ } ], "require": { - "php": ">=7.1", - "monolog/monolog": "^1.24", - "vlucas/phpdotenv": "^3.3", - "guzzlehttp/guzzle": "^6.3" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^8" diff --git a/composer.lock b/composer.lock index 9ac6d6a..6509e79 100644 --- a/composer.lock +++ b/composer.lock @@ -4,641 +4,25 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "41fa6bef6146bb1eda06c2165ce9bc8c", - "packages": [ - { - "name": "guzzlehttp/guzzle", - "version": "6.3.3", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "shasum": "" - }, - "require": { - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", - "php": ">=5.5" - }, - "require-dev": { - "ext-curl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" - }, - "suggest": { - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.3-dev" - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "rest", - "web service" - ], - "time": "2018-04-22T15:46:56+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "time": "2016-12-20T10:07:11+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "1.5.2", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "9f83dded91781a01c63574e387eaa769be769115" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", - "reference": "9f83dded91781a01c63574e387eaa769be769115", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.5-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "time": "2018-12-04T20:46:45+00:00" - }, - { - "name": "monolog/monolog", - "version": "1.24.0", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/monolog.git", - "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", - "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "psr/log": "~1.0" - }, - "provide": { - "psr/log-implementation": "1.0.0" - }, - "require-dev": { - "aws/aws-sdk-php": "^2.4.9 || ^3.0", - "doctrine/couchdb": "~1.0@dev", - "graylog2/gelf-php": "~1.0", - "jakub-onderka/php-parallel-lint": "0.9", - "php-amqplib/php-amqplib": "~2.4", - "php-console/php-console": "^3.1.3", - "phpunit/phpunit": "~4.5", - "phpunit/phpunit-mock-objects": "2.3.0", - "ruflin/elastica": ">=0.90 <3.0", - "sentry/sentry": "^0.13", - "swiftmailer/swiftmailer": "^5.3|^6.0" - }, - "suggest": { - "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", - "doctrine/couchdb": "Allow sending log messages to a CouchDB server", - "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", - "ext-mongo": "Allow sending log messages to a MongoDB server", - "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", - "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", - "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", - "php-console/php-console": "Allow sending log messages to Google Chrome", - "rollbar/rollbar": "Allow sending log messages to Rollbar", - "ruflin/elastica": "Allow sending log messages to an Elastic Search server", - "sentry/sentry": "Allow sending log messages to a Sentry server" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Monolog\\": "src/Monolog" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Sends your logs to files, sockets, inboxes, databases and various web services", - "homepage": "http://github.com/Seldaek/monolog", - "keywords": [ - "log", - "logging", - "psr-3" - ], - "time": "2018-11-05T09:00:11+00:00" - }, - { - "name": "phpoption/phpoption", - "version": "1.5.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-option.git", - "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/94e644f7d2051a5f0fcf77d81605f152eecff0ed", - "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "4.7.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "psr-0": { - "PhpOption\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Option Type for PHP", - "keywords": [ - "language", - "option", - "php", - "type" - ], - "time": "2015-07-25T16:39:46+00:00" - }, - { - "name": "psr/http-message", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "time": "2016-08-06T14:39:51+00:00" - }, - { - "name": "psr/log", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2018-11-20T15:27:04+00:00" - }, - { - "name": "ralouphie/getallheaders", - "version": "2.0.5", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", - "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", - "shasum": "" - }, - "require": { - "php": ">=5.3" - }, - "require-dev": { - "phpunit/phpunit": "~3.7.0", - "satooshi/php-coveralls": ">=1.0" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "time": "2016-02-11T07:05:27+00:00" - }, - { - "name": "symfony/dotenv", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/symfony/dotenv.git", - "reference": "1774ab31cf121ca7a9d836680a835630ff276473" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/dotenv/zipball/1774ab31cf121ca7a9d836680a835630ff276473", - "reference": "1774ab31cf121ca7a9d836680a835630ff276473", - "shasum": "" - }, - "require": { - "php": "^7.2.9" - }, - "require-dev": { - "symfony/process": "^4.4|^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Dotenv\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Registers environment variables from a .env file", - "homepage": "https://symfony.com", - "keywords": [ - "dotenv", - "env", - "environment" - ], - "time": "2019-05-28T18:01:02+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.11.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.11-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2019-02-06T07:57:58+00:00" - }, - { - "name": "vlucas/phpdotenv", - "version": "v3.3.3", - "source": { - "type": "git", - "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "dbcc609971dd9b55f48b8008b553d79fd372ddde" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/dbcc609971dd9b55f48b8008b553d79fd372ddde", - "reference": "dbcc609971dd9b55f48b8008b553d79fd372ddde", - "shasum": "" - }, - "require": { - "php": "^5.4 || ^7.0", - "phpoption/phpoption": "^1.5", - "symfony/polyfill-ctype": "^1.9" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Dotenv\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Vance Lucas", - "email": "vance@vancelucas.com", - "homepage": "http://www.vancelucas.com" - } - ], - "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", - "keywords": [ - "dotenv", - "env", - "environment" - ], - "time": "2019-03-06T09:39:45+00:00" - } - ], + "content-hash": "f88657f15095c5ce3eb8c06d6385f14d", + "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.2.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "a2c590166b2133a4633738648b6b064edae0814a" + "reference": "f350df0268e904597e3bd9c4685c53e0e333feea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", - "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "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", @@ -677,24 +61,38 @@ "constructor", "instantiate" ], - "time": "2019-03-17T17:37:11+00:00" + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2020-05-29T17:27:14+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.9.1", + "version": "1.10.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72" + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "replace": { "myclabs/deep-copy": "self.version" @@ -725,7 +123,13 @@ "object", "object graph" ], - "time": "2019-04-07T13:18:21+00:00" + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2020-06-29T13:22:24+00:00" }, { "name": "phar-io/manifest", @@ -831,35 +235,30 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", "shasum": "" }, "require": { - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" + "php": "^7.2 || ^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-2.x": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -881,44 +280,41 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2020-06-27T09:03:43+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.1", + "version": "5.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" + "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", - "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d870572532cd70bc3fab58f2e23ad423c8404c44", + "reference": "d870572532cd70bc3fab58f2e23ad423c8404c44", "shasum": "" }, "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", - "webmozart/assert": "^1.0" + "ext-filter": "*", + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.2", + "phpdocumentor/type-resolver": "^1.3", + "webmozart/assert": "^1.9.1" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.4" + "mockery/mockery": "~1.3.2" }, "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/", @@ -929,44 +325,45 @@ { "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-04-30T17:48:53+00:00" + "time": "2020-08-15T11:14:08+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "e878a14a65245fbe78f8080eba03b47c3b705651" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651", + "reference": "e878a14a65245fbe78f8080eba03b47c3b705651", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-1.x": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -979,42 +376,43 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2020-06-27T10:12:23+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b20034be5efcdab4fb60ca3a29cba2949aead160", + "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0|^3.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" + "doctrine/instantiator": "^1.2", + "php": "^7.2", + "phpdocumentor/reflection-docblock": "^5.0", + "sebastian/comparator": "^3.0 || ^4.0", + "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + "phpspec/phpspec": "^6.0", + "phpunit/phpunit": "^8.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.11.x-dev" } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -1042,20 +440,20 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2020-07-08T12:44:21+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "7.0.3", + "version": "7.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707" + "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0317a769a81845c390e19684d9ba25d7f6aa4707", - "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf", + "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf", "shasum": "" }, "require": { @@ -1064,17 +462,17 @@ "php": "^7.2", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0.1", + "phpunit/php-token-stream": "^3.1.1", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.1", + "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" + "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.2.2" }, "suggest": { - "ext-xdebug": "^2.6.1" + "ext-xdebug": "^2.7.2" }, "type": "library", "extra": { @@ -1105,7 +503,7 @@ "testing", "xunit" ], - "time": "2019-02-26T07:38:26+00:00" + "time": "2019-11-20T13:55:58+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1200,16 +598,16 @@ }, { "name": "phpunit/php-timer", - "version": "2.1.1", + "version": "2.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", - "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", + "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", "shasum": "" }, "require": { @@ -1245,20 +643,20 @@ "keywords": [ "timer" ], - "time": "2019-02-20T10:12:59+00:00" + "time": "2019-06-07T04:22:29+00:00" }, { "name": "phpunit/php-token-stream", - "version": "3.0.1", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", + "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", "shasum": "" }, "require": { @@ -1271,7 +669,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1294,46 +692,48 @@ "keywords": [ "tokenizer" ], - "time": "2018-10-30T05:52:18+00:00" + "abandoned": true, + "time": "2019-09-17T06:23:10+00:00" }, { "name": "phpunit/phpunit", - "version": "8.1.4", + "version": "8.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "b534b017daaef2d7f60c6ee61e6aa2e13fdc6910" + "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b534b017daaef2d7f60c6ee61e6aa2e13fdc6910", - "reference": "b534b017daaef2d7f60c6ee61e6aa2e13fdc6910", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/34c18baa6a44f1d1fbf0338907139e9dce95b997", + "reference": "34c18baa6a44f1d1fbf0338907139e9dce95b997", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.1", + "doctrine/instantiator": "^1.2.0", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.7", - "phar-io/manifest": "^1.0.2", - "phar-io/version": "^2.0", + "myclabs/deep-copy": "^1.9.1", + "phar-io/manifest": "^1.0.3", + "phar-io/version": "^2.0.1", "php": "^7.2", - "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^7.0", - "phpunit/php-file-iterator": "^2.0.1", + "phpspec/prophecy": "^1.8.1", + "phpunit/php-code-coverage": "^7.0.7", + "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-timer": "^2.1", - "sebastian/comparator": "^3.0", - "sebastian/diff": "^3.0", - "sebastian/environment": "^4.1", - "sebastian/exporter": "^3.1", - "sebastian/global-state": "^3.0", + "phpunit/php-timer": "^2.1.2", + "sebastian/comparator": "^3.0.2", + "sebastian/diff": "^3.0.2", + "sebastian/environment": "^4.2.2", + "sebastian/exporter": "^3.1.1", + "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^2.0", + "sebastian/resource-operations": "^2.0.1", + "sebastian/type": "^1.1.3", "sebastian/version": "^2.0.1" }, "require-dev": { @@ -1342,7 +742,7 @@ "suggest": { "ext-soap": "*", "ext-xdebug": "*", - "phpunit/php-invoker": "^2.0" + "phpunit/php-invoker": "^2.0.0" }, "bin": [ "phpunit" @@ -1350,7 +750,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.1-dev" + "dev-master": "8.5-dev" } }, "autoload": { @@ -1376,7 +776,17 @@ "testing", "xunit" ], - "time": "2019-05-09T05:13:39+00:00" + "funding": [ + { + "url": "https://phpunit.de/donate.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-22T07:06:58+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1545,16 +955,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": { @@ -1594,20 +1004,20 @@ "environment", "hhvm" ], - "time": "2019-05-05T09:05:15+00:00" + "time": "2019-11-20T08:46:58+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.0", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", - "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", "shasum": "" }, "require": { @@ -1634,6 +1044,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -1642,17 +1056,13 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, { "name": "Adam Harvey", "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -1661,7 +1071,7 @@ "export", "exporter" ], - "time": "2017-04-03T13:19:02+00:00" + "time": "2019-09-14T09:02:43+00:00" }, { "name": "sebastian/global-state", @@ -1904,6 +1314,52 @@ "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "time": "2018-10-04T04:07:39+00:00" }, + { + "name": "sebastian/type", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "time": "2019-07-02T08:10:15+00:00" + }, { "name": "sebastian/version", "version": "2.0.1", @@ -1947,25 +1403,101 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.18.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" + }, { "name": "theseer/tokenizer", - "version": "1.1.2", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8" + "reference": "75a63c33a8577608444246075ea0af0d052e452a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8", - "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", + "reference": "75a63c33a8577608444246075ea0af0d052e452a", "shasum": "" }, "require": { "ext-dom": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": "^7.0" + "php": "^7.2 || ^8.0" }, "type": "library", "autoload": { @@ -1985,36 +1517,40 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2019-04-04T09:56:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2020-07-12T23:59:07+00:00" }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0", + "php": "^5.3.3 || ^7.0 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<3.9.1" + }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" @@ -2036,18 +1572,17 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2020-07-08T17:02:28+00:00" } ], "aliases": [], - "minimum-stability": "dev", - "stability-flags": { - "symfony/dotenv": 20 - }, + "minimum-stability": "stable", + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=7.1" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/src/Constants.php b/src/Constants.php index f1552de..6ecddbf 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -17,7 +17,7 @@ class Constants public const HASH_ALGORITHM = 'sha256'; public const BASE_API_URL = 'https://app.tendopay.ph'; - public const SANDBOX_BASE_API_URL = 'https://sandbox.tendopay.dev'; + public const SANDBOX_BASE_API_URL = 'https://sandbox.tendopay.ph'; public const REDIRECT_URI = 'payments/authorise'; public const VERIFICATION_ENDPOINT_URI = 'payments/api/v1/verification'; @@ -29,7 +29,7 @@ class Constants /** * Gets the transaction detail endpoint uri */ - public const TRANSACTION_DETAIL_ENDPOINT_URI = '/merchants/api/v1/transactions/{transactionNumber}'; + public const TRANSACTION_DETAIL_ENDPOINT_URI = 'merchants/api/v1/transactions/{transactionNumber}'; public const TENDOPAY_ICON = 'https://s3.ca-central-1.amazonaws.com/candydigital/images/tendopay/tp-icon-32x32.png'; public const TENDOPAY_FAQ = 'https://tendopay.ph/page-faq.html'; @@ -116,7 +116,7 @@ public static function get_base_api_url(): string { if (self::is_sandbox_enabled()) { $sandBoxURL = getenv('SANDBOX_HOST_URL', true); - return $sandBoxURL ? $sandBoxURL : self::SANDBOX_BASE_API_URL; + return $sandBoxURL ?: self::SANDBOX_BASE_API_URL; } return self::BASE_API_URL; } diff --git a/src/TendoPayClient.php b/src/TendoPayClient.php index 83b8d92..ce95c39 100644 --- a/src/TendoPayClient.php +++ b/src/TendoPayClient.php @@ -2,16 +2,12 @@ namespace TendoPay\SDK; -use Dotenv\Dotenv; use Exception; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\GuzzleException; use InvalidArgumentException; use TendoPay\SDK\Exception\TendoPayConnectionException; use TendoPay\SDK\Exception\VerifyTransactionException; use TendoPay\SDK\Models\AccessToken; use TendoPay\SDK\Models\Payment; -use TendoPay\SDK\Models\PurchaseTransaction; use TendoPay\SDK\Models\Transaction; use TendoPay\SDK\Models\VerifyTransactionRequest; use TendoPay\SDK\Models\VerifyTransactionResponse; @@ -30,13 +26,14 @@ class TendoPayClient use TendoPayHelper; - private const SRC_PATH = __DIR__ . '/../'; - private const VENDOR_PATH = __DIR__ . '/../../../../vendor'; - public const STATUS_SUCCESS = Constants::STATUS_SUCCESS; public const STATUS_FAILURE = Constants::STATUS_FAILURE; - protected $log; + /** + * Configuration + * @var array + */ + protected $config; /** * @var Payment @@ -65,10 +62,16 @@ class TendoPayClient */ protected $debug = false; - public function __construct($options = []) + /** + * TendoPayClient constructor. + * @param array $config + */ + public function __construct($config = []) { - $this->initEnvironment(); - $this->setSandBoxMode(false); + $this->config = $config; + $this->debug = $config['TENDOPAY_DEBUG'] ?? getenv('TENDOPAY_DEBUG') ?? false; + $this->initCredentials(); + $this->setSandBoxMode($config['TENDOPAY_SANDBOX_ENABLED'] ?? getenv('TENDOPAY_SANDBOX_ENABLED', true) ?? false); $this->initRedirectURL(); } @@ -78,68 +81,116 @@ public function __construct($options = []) */ protected function setSandBoxMode($bool): void { - putenv('TENDOPAY_SANDBOX_ENABLED=' . $bool); + putenv('TENDOPAY_SANDBOX_ENABLED='.$bool); } /** - * + * Set credentials */ - protected function initEnvironment(): void + protected function initCredentials(): void { - $path = file_exists(static::VENDOR_PATH) ? static::VENDOR_PATH . '/../' : static::SRC_PATH; - - $env = Dotenv::create($path); - $env->load(); - $env->required([ - 'MERCHANT_ID', - 'MERCHANT_SECRET', - 'CLIENT_ID', - 'CLIENT_SECRET', - ]); + if (isset($this->config['MERCHANT_ID'])) { + putenv("MERCHANT_ID=".$this->config['MERCHANT_ID']); + } + if (isset($this->config['MERCHANT_SECRET'])) { + putenv("MERCHANT_SECRET=".$this->config['MERCHANT_SECRET']); + } + if (isset($this->config['CLIENT_ID'])) { + putenv("CLIENT_ID=".$this->config['CLIENT_ID']); + } + if (isset($this->config['CLIENT_SECRET'])) { + putenv("CLIENT_SECRET=".$this->config['CLIENT_SECRET']); + } } /** - * + * Set Redirect urls */ protected function initRedirectURL(): void { - $this->redirectURL = (string)getenv('REDIRECT_URL', true); - $this->errorRedirectURL = (string)getenv('ERROR_REDIRECT_URL', true); + $this->redirectURL = $this->config['REDIRECT_URL'] ?? (string) getenv('REDIRECT_URL', true); + $this->errorRedirectURL = $this->config['ERROR_REDIRECT_URL'] ?? (string) getenv('ERROR_REDIRECT_URL', true); + } + + /** + * @param $method + * @param $endPointURL + * @param $data + * @param $headers + * @param false $debug + * @return mixed + */ + protected function requestCurl($method, $endPointURL, $data, $headers, $debug = false) + { + $ch = curl_init(); + + if (strtoupper($method) == 'GET') { + if ($data) { + $endPointURL .= '?'.http_build_query($data); + } + } else { + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + } + + $curlHeaders = []; + foreach ($headers as $k => $v) { + $curlHeaders[] = "$k: $v"; + } + + curl_setopt($ch, CURLOPT_URL, $endPointURL); + curl_setopt($ch, CURLOPT_VERBOSE, $debug); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 4); + curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders); + + $body = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + + if ((int) $status >= 400) { + $response = json_decode($body, false); + $error = $response->error ?? $response->message ?? curl_error($ch); + curl_close($ch); + throw new \UnexpectedValueException($error, $status); + } + + curl_close($ch); + return $body; } /** * @param $method * @param $requestURI * @param $params - * @param array $headers - * @return string + * @param array $headers + * @param bool $rawOutput + * @return mixed * @throws TendoPayConnectionException */ - protected function request($method, $requestURI, $params, $headers = []): string + protected function request($method, $requestURI, $params, $headers = [], $rawOutput = false) { try { - $http = new Client([ - 'base_uri' => Constants::get_base_api_url(), - 'headers' => array_merge([ + $data = $method === 'GET' ? $params : json_encode($params); + $response = $this->requestCurl( + $method, + Constants::get_base_api_url().DIRECTORY_SEPARATOR.$requestURI, + $data, + array_merge([ 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-Using' => 'TendoPay_PHP_SDK_Client/1.0', - ], $headers), - 'debug' => $this->debug, - ]); - - $response = $http->request($method, $requestURI, [ - 'json' => $params - ]); + ], $headers), $this->debug); - return $response->getBody()->getContents(); - } catch (GuzzleException $e) { + return $rawOutput ? $response : json_decode($response, false); + } catch (\Exception $e) { throw new TendoPayConnectionException($e->getMessage(), $e->getCode()); } } /** - * @param bool $usePersonalAccessToken + * @param bool $usePersonalAccessToken * @return array * @throws TendoPayConnectionException */ @@ -150,7 +201,7 @@ protected function getAuthorizationHeader($usePersonalAccessToken = false): arra $this->getAccessToken(); return [ - 'Authorization' => 'Bearer ' . $accessToken, + 'Authorization' => 'Bearer '.$accessToken, ]; } @@ -160,7 +211,6 @@ protected function getAuthorizationHeader($usePersonalAccessToken = false): arra */ protected function getAccessToken(): string { - if ($this->accessToken instanceof AccessToken && !$this->accessToken->isExpired()) { return $this->accessToken->getToken(); @@ -173,10 +223,11 @@ protected function getAccessToken(): string ]; $body = $this->request('POST', Constants::get_bearer_token_endpoint_uri(), - $params); - $token = json_decode($body, true); + $params, [], true); + $token = json_decode($body, true); $this->accessToken = new AccessToken($token); + return $this->accessToken->getToken(); } @@ -186,10 +237,12 @@ protected function getAccessToken(): string */ protected function getPersonalAccessToken(): string { - $token = (string)getenv('MERCHANT_PERSONAL_ACCESS_TOKEN', true); + $token = $this->config['MERCHANT_PERSONAL_ACCESS_TOKEN'] ?? (string) getenv('MERCHANT_PERSONAL_ACCESS_TOKEN', + true); if (!$token) { throw new InvalidArgumentException('MERCHANT_PERSONAL_ACCESS_TOKEN does not exists'); } + return $token; } @@ -200,11 +253,10 @@ protected function getPersonalAccessToken(): string */ protected function getRequestToken($params) { - $body = $this->request('POST', + return $this->request('POST', Constants::get_authorization_endpoint_uri(), static::appendHash($params), $this->getAuthorizationHeader()); - return json_decode($body, false) ?? ''; } /** @@ -214,11 +266,11 @@ protected function getRequestToken($params) */ protected function requestPaymentDescription($params) { - $data = $this->request('POST', + return $this->request('POST', Constants::get_description_endpoint_uri(), static::appendHash($params), - $this->getAuthorizationHeader()); - return $data; + $this->getAuthorizationHeader(), + true); } /** Public Methods **/ @@ -236,44 +288,48 @@ public function ping(): bool } /** - * @param string $url + * @param string $url * @return TendoPayClient */ public function setRedirectURL(string $url): self { $this->redirectURL = $url; + return $this; } /** - * @param string $url + * @param string $url * @return TendoPayClient */ public function setErrorRedirectURL(string $url): self { $this->errorRedirectURL = $url; + return $this; } /** * Enable Sandbox mode * - * @param bool $bool + * @param bool $bool * @return TendoPayClient */ public function enableSandBox(bool $bool = true): self { $this->setSandBoxMode($bool); + return $this; } /** - * @param Payment $payment + * @param Payment $payment * @return TendoPayClient */ public function setPayment(Payment $payment): self { $this->payment = $payment; + return $this; } @@ -292,7 +348,6 @@ public function getAuthorizeLink(): string $requestToken = $this->getRequestToken($params); - $params = array_merge($params, [ Constants::AUTH_TOKEN_PARAM => $requestToken, ]); @@ -304,12 +359,12 @@ public function getAuthorizeLink(): string Constants::VENDOR_PARAM => $this->getMerchantId(), ]); - return Constants::get_redirect_uri() . '?' . http_build_query(static::appendHash($params)); + return Constants::get_redirect_uri().'?'.http_build_query(static::appendHash($params)); } /** * @param $orderId - * @param VerifyTransactionRequest $request + * @param VerifyTransactionRequest $request * @return VerifyTransactionResponse * @throws TendoPayConnectionException * @throws VerifyTransactionException @@ -332,9 +387,10 @@ public function verifyTransaction($orderId, VerifyTransactionRequest $request): $response = $this->request('GET', Constants::get_verification_endpoint_uri(), static::appendHash($params), - $this->getAuthorizationHeader()); + $this->getAuthorizationHeader(), true); $data = json_decode($response, true) ?? []; + return new VerifyTransactionResponse($data); } @@ -367,9 +423,10 @@ public function getTransactionDetail($transactionNumber): Transaction $response = $this->request('GET', Constants::getTransactionDetailEndpointURI($transactionNumber), $params, - $this->getAuthorizationHeader(true)); + $this->getAuthorizationHeader(), true); $transaction = json_decode($response, true); + return new Transaction($transaction); } @@ -385,11 +442,10 @@ public function cancelPayment($transactionNumber) Constants::TRANSACTION_NO_PARAM => $transactionNumber, ]; - $body = $this->request('POST', + return $this->request('POST', Constants::get_cancel_payment_endpoint_uri(), static::appendHash($params), $this->getAuthorizationHeader()); - return json_decode($body, false) ?? ''; } } From 66158fb3e5e3b16387111322afb29da6018d92c1 Mon Sep 17 00:00:00 2001 From: SangminLee Date: Thu, 17 Sep 2020 14:54:07 -0400 Subject: [PATCH 4/8] update README --- .env.sample | 10 ++-- README.md | 129 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 115 insertions(+), 24 deletions(-) diff --git a/.env.sample b/.env.sample index 13a80bb..2dfd993 100644 --- a/.env.sample +++ b/.env.sample @@ -6,15 +6,11 @@ MERCHANT_SECRET= CLIENT_ID= CLIENT_SECRET= +## Enable Sandbox mode, it must be false in production +TENDOPAY_SANDBOX_ENABLED=true + ## Redirect URI when the transaction succeed REDIRECT_URL=https:// ## Redirect URI when the transaction fails ERROR_REDIRECT_URL=https:// - -## Personal Access Token if you use $client->getTransactionDetail(), this token should be set. -## See https://app.tendopay.ph/merchants/api-settings -MERCHANT_PERSONAL_ACCESS_TOKEN= - -## If you have own sandbox -#SANDBOX_HOST_URL=https:// diff --git a/README.md b/README.md index daac752..7e80707 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,23 @@ You can install the sdk via [Composer](http://getcomposer.org/). Run the followi composer require tendopay/tendopay-sdk-php ``` -then imports +## Run SDK Tester -```php -require_once 'vendor/autoload.php'; +- Run a sample server +```bash +php -s localhost:8000 -t vendor/tendopay/tendopay-sdk-php/samples ``` -## Run Sample code - -- Copy sample page to in the local +- Open browser and goto ```bash -cp -av vendor/tendopay/tendopay-sdk-php/samples . +http://localhost:8000/ ``` -- Add some environment variables into .env +## Code Examples + +### Create TendoPayClient + +- Using .env > MERCHANT_ID,MERCHANT_SECRET for test can get them at [TendoPay Sandbox](https://sandbox.tendopay.ph) ```bash ## Merchant Credentials @@ -38,6 +41,9 @@ MERCHANT_SECRET= CLIENT_ID= CLIENT_SECRET= +## Enable Sandbox, it must be false in production +TENDOPAY_SANDBOX_ENABLED=false + ## Redirect URI when the transaction succeed REDIRECT_URL=https://localhost:8000/purhase.php @@ -45,15 +51,104 @@ REDIRECT_URL=https://localhost:8000/purhase.php ERROR_REDIRECT_URL=https://localhost:8000/purchase.php ``` -- Run a sample server -```bash -php -s localhost:8000 -t samples +```php +use TendoPay\SDK\TendoPayClient; + +$client = new TendoPayClient(); ``` -- Open browser and goto -```bash -http://localhost:8000/cart.html + +- Using $config variable +```php +use TendoPay\SDK\TendoPayClient; + +$config = [ + 'MERCHANT_ID' => '', + 'MERCHANT_SECRET' => '', + 'CLIENT_ID' => '', + 'CLIENT_SECRET' => '', + 'REDIRECT_URL' => '', + 'ERROR_REDIRECT_URL' => '', + 'TENDOPAY_SANDBOX_ENABLED' => false, +]; +$client = new TendoPayClient($config); +``` + + +### Make Payment + +```php +use TendoPay\SDK\Exception\TendoPayConnectionException; +use TendoPay\SDK\Models\Payment; +use TendoPay\SDK\TendoPayClient; + +### S:Merchant set proper values +$merchant_order_id = $_POST['tp_merchant_order_id']; +$request_order_amount = $_POST['tp_amount']; +$request_order_title = $_POST['tp_description']; +$_SESSION['merchant_order_id'] = $merchant_order_id; +### E:Merchant set proper values + +$client = new TendoPayClient(); + +try { + $payment = new Payment(); + $payment->setMerchantOrderId($merchant_order_id) + ->setDescription($request_order_title) + ->setRequestAmount($request_order_amount); + + $client->setPayment($payment); + + $redirectURL = $client->getAuthorizeLink(); + header('Location: '.$redirectURL); +} catch (TendoPayConnectionException $e) { + echo 'Connection Error:'.$e->getMessage(); +} catch (Exception $e) { + echo 'Runtime Error:'.$e->getMessage(); +} ``` -## Dependencies -- guzzle -- phpdotenv +### Callback (redirected page) +```php +use TendoPay\SDK\Exception\TendoPayConnectionException; +use TendoPay\SDK\Models\VerifyTransactionRequest; +use TendoPay\SDK\TendoPayClient; + +$client = new TendoPayClient(); + +try { + if (TendoPayClient::isCallBackRequest($_REQUEST)) { + $merchant_order_id = $_SESSION['merchant_order_id'] ?? null; + $transaction = $client->verifyTransaction($merchant_order_id, new VerifyTransactionRequest($_REQUEST)); + + if (!$transaction->isVerified()) { + throw new UnexpectedValueException('Invalid signature for the verification'); + } + + // Save $transactionNumber here + // Proceed merchant post order process + } +} catch (TendoPayConnectionException $e) { + echo 'Connection Error:'.$e->getMessage(); +} catch (Exception $e) { + echo 'Runtime Error:'.$e->getMessage(); +} +``` + +### Cancel Payment + +```php +use TendoPay\SDK\Exception\TendoPayConnectionException; +use TendoPay\SDK\TendoPayClient; + +$client = new TendoPayClient(); + +try { + $client->cancelPayment($transactionNumber); + // merchant process here + +} catch (TendoPayConnectionException $e) { + echo 'Connection Error:'.$e->getMessage(); +} catch (Exception $e) { + echo 'Runtime Error:'.$e->getMessage(); +} +``` From 09d52efd9a8aea1c9ba127c4e82fa8bdb52b6e1a Mon Sep 17 00:00:00 2001 From: SangminLee Date: Thu, 17 Sep 2020 14:54:30 -0400 Subject: [PATCH 5/8] Refactoring sample app --- samples/api.php | 60 +++++++++ samples/callback.php | 33 +++++ samples/cart.html | 56 -------- samples/common.php | 47 +++++++ samples/index.html.php | 113 ++++++++++++++++ samples/index.php | 6 + samples/js/components/TpCollapse.vue | 53 ++++++++ samples/js/components/TpPayment.vue | 72 ++++++++++ samples/js/components/TpSdkCredentials.vue | 86 ++++++++++++ samples/js/components/TpSdkTransactions.vue | 140 ++++++++++++++++++++ samples/payment.php | 33 +++++ samples/purchase.php | 62 --------- samples/start.sh | 4 + src/Models/Transaction.php | 20 +++ 14 files changed, 667 insertions(+), 118 deletions(-) create mode 100644 samples/api.php create mode 100644 samples/callback.php delete mode 100644 samples/cart.html create mode 100644 samples/common.php create mode 100644 samples/index.html.php create mode 100644 samples/index.php create mode 100644 samples/js/components/TpCollapse.vue create mode 100644 samples/js/components/TpPayment.vue create mode 100644 samples/js/components/TpSdkCredentials.vue create mode 100644 samples/js/components/TpSdkTransactions.vue create mode 100644 samples/payment.php delete mode 100644 samples/purchase.php create mode 100755 samples/start.sh diff --git a/samples/api.php b/samples/api.php new file mode 100644 index 0000000..933e957 --- /dev/null +++ b/samples/api.php @@ -0,0 +1,60 @@ +job ?? null; + +try { + switch ($job) { + case 'SAVE_CREDENTIALS': + $_SESSION['credentials'] = $request->credentials ?? null; + + return json(); + case 'GET_CREDENTIALS': + return json($_SESSION['credentials'] ?? null); + case 'GET_TRANSACTIONS': + return json($_SESSION['transactions'] ?? []); + case 'GET_TRANSACTION': + $client = new TendoPayClient($config); + $response = $client->getTransactionDetail($request->transactionNumber); + + return json($response->toArray()); + case 'CANCEL_TRANSACTION': + $transactionNumber = $request->transactionNumber; + $client = new TendoPayClient($config); + $client->cancelPayment($transactionNumber); + + $_SESSION['transactions'] = array_filter($_SESSION['transactions'] ?? [], + static function ($transaction) use ($transactionNumber) { + return $transaction['transactionNumber'] != $transactionNumber; + }); + + return json($_SESSION['transactions']); + default: + // do nothing + throw new InvalidArgumentException('Invalid parameters', 422); + } +} catch (\Exception $e) { + $code = $e->getCode() ?: 500; + + return json(['error' => $e->getMessage()], $code); +} + + + diff --git a/samples/callback.php b/samples/callback.php new file mode 100644 index 0000000..98ce8fa --- /dev/null +++ b/samples/callback.php @@ -0,0 +1,33 @@ +verifyTransaction($merchant_order_id, new VerifyTransactionRequest($_REQUEST)); + + if (!$transaction->isVerified()) { + throw new UnexpectedValueException('Invalid signature for the verification'); + } + +// dump('verificationResult:', $transaction->toArray()); + // @Note check request amount with approved amount. it can be different but must be enough to purchase + // Save $transactionNumber here + $transactions = $_SESSION['transactions'] ?? []; + $transactions[] = $transaction->toArray(); + $_SESSION['transactions'] = $transactions; + header('Location: /'); + } +} catch (TendoPayConnectionException $e) { + dump('Connection Error:'.$e->getMessage()); +} catch (Exception $e) { + dump('Runtime Error:'.$e->getMessage()); +} diff --git a/samples/cart.html b/samples/cart.html deleted file mode 100644 index 9207735..0000000 --- a/samples/cart.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - Title - - - -
-
-

Sample Cart

-
-
- -
-
- ... -
-
-
-
Product #1
-
-
Quantity
-
1
- -
Total
-
PHP 1,000
-
-
- -
-
-
-
- -
- -
-
-
- - - - - diff --git a/samples/common.php b/samples/common.php new file mode 100644 index 0000000..c48dcf2 --- /dev/null +++ b/samples/common.php @@ -0,0 +1,47 @@ +'; + array_map('print_r', func_get_args()); + echo ''; +} + +$credentials = $_SESSION['credentials']; +//putenv('MERCHANT_ID='.$credentials->merchant_id); +//putenv('MERCHANT_SECRET='.$credentials->merchant_secret); +//putenv('CLIENT_ID='.$credentials->client_id); +//putenv('CLIENT_SECRET='.$credentials->client_secret); +//putenv('REDIRECT_URL='.$credentials->redirect_url ?? ''); +//putenv('ERROR_REDIRECT_URL='.$credentials->error_redirect_url ?? ''); +//putenv('TENDOPAY_SANDBOX_ENABLED=true'); + +$config = [ + 'MERCHANT_ID' => $credentials->merchant_id, + 'MERCHANT_SECRET' => $credentials->merchant_secret, + 'CLIENT_ID' => $credentials->client_id, + 'CLIENT_SECRET' => $credentials->client_secret, + 'REDIRECT_URL' => $credentials->redirect_url ?? '', + 'ERROR_REDIRECT_URL' => $credentials->error_redirect_url ?? '', + 'TENDOPAY_SANDBOX_ENABLED' => true, + 'TENDOPAY_DEBUG' => true, +]; + diff --git a/samples/index.html.php b/samples/index.html.php new file mode 100644 index 0000000..5019ba4 --- /dev/null +++ b/samples/index.html.php @@ -0,0 +1,113 @@ + + + + + TendoPay PHP SDK + + + + + + +
+
+
+ +
+ TendoPay Logo +

TendoPay PHP SDK Tester

+
+ +
+

+ +

+

+ +

+
+ + + +
+
+
+ + + + + + + diff --git a/samples/index.php b/samples/index.php new file mode 100644 index 0000000..88c0f0f --- /dev/null +++ b/samples/index.php @@ -0,0 +1,6 @@ + +
+
+
+ +
+
+
+
+ +
+
+
+ + + + + diff --git a/samples/js/components/TpPayment.vue b/samples/js/components/TpPayment.vue new file mode 100644 index 0000000..b97b09d --- /dev/null +++ b/samples/js/components/TpPayment.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/samples/js/components/TpSdkCredentials.vue b/samples/js/components/TpSdkCredentials.vue new file mode 100644 index 0000000..1fb1017 --- /dev/null +++ b/samples/js/components/TpSdkCredentials.vue @@ -0,0 +1,86 @@ + + + + + diff --git a/samples/js/components/TpSdkTransactions.vue b/samples/js/components/TpSdkTransactions.vue new file mode 100644 index 0000000..40ed0b6 --- /dev/null +++ b/samples/js/components/TpSdkTransactions.vue @@ -0,0 +1,140 @@ + + + + + diff --git a/samples/payment.php b/samples/payment.php new file mode 100644 index 0000000..417f125 --- /dev/null +++ b/samples/payment.php @@ -0,0 +1,33 @@ +setMerchantOrderId($merchant_order_id) + ->setDescription($request_order_title) + ->setRequestAmount($request_order_amount); + + $client->setPayment($payment); + + $redirectURL = $client->getAuthorizeLink(); + header('Location: '.$redirectURL); +} catch (TendoPayConnectionException $e) { + dump('Connection Error:'.$e->getMessage()); +} catch (Exception $e) { + dump('Runtime Error:'.$e->getMessage()); +} diff --git a/samples/purchase.php b/samples/purchase.php deleted file mode 100644 index 734f2e3..0000000 --- a/samples/purchase.php +++ /dev/null @@ -1,62 +0,0 @@ -'; - array_map('print_r', func_get_args()); - echo ''; -} - -use TendoPay\SDK\Exception\TendoPayConnectionException; -use TendoPay\SDK\Models\Payment; -use TendoPay\SDK\Models\VerifyTransactionRequest; -use TendoPay\SDK\TendoPayClient; - -### Merchant Transaction Example Start -$merchant_order_id = 'TEST-OID-1234567890'; -$request_order_amount = 2000; -$request_order_title = 'Test Order #3'; -$item_price = $request_order_amount; -$item_title = 'Item #1'; -### Merchant Transaction Example End - - -$client = new TendoPayClient(); -$client->enableSandBox(); - -try { - - if (TendoPayClient::isCallBackRequest($_REQUEST)) { - - $transaction = $client->verifyTransaction($merchant_order_id, new VerifyTransactionRequest($_REQUEST)); - - if ($transaction->isVerified()) { - dump('verificationResult:', $transaction->toArray()); - // @Note check request amount with approved amount. it can be different but must be enough to purchase - // Save $transactionNumber here - } - - } else { - // Request authorization - $payment = new Payment(); - $payment->setMerchantOrderId($merchant_order_id) - ->setDescription($request_order_title) - ->setRequestAmount($request_order_amount); - - $client->setPayment($payment); - - $redirectURL = $client->getAuthorizeLink(); - header('Location: ' . $redirectURL); - } -} catch (TendoPayConnectionException $te) { - echo '
';
-    echo 'Connection Error:' . $te->getMessage() . PHP_EOL;
-    echo '
'; -} catch (Exception $e) { - echo '
';
-    echo 'Unknown Error:' . $e->getMessage() . PHP_EOL;
-    echo '
'; -} - - diff --git a/samples/start.sh b/samples/start.sh new file mode 100755 index 0000000..7566cb9 --- /dev/null +++ b/samples/start.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +DOC_ROOT=$(dirname $(realpath $0)) +php -S localhost:8000 -t $DOC_ROOT diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index 22d266b..bca0054 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -29,6 +29,11 @@ class Transaction protected $createdAt; protected $status; + /** + * Transaction constructor. + * @param array $response + * @throws TendoPayParameterException + */ public function __construct(array $response = []) { $this->merchantId = $response[Constants::MERCHANT_ID] ?? null; @@ -95,4 +100,19 @@ public function getStatus() return $this->status; } + /** + * @return null[] + */ + public function toArray(): array + { + return [ + 'tp_merchant_id' => $this->getMerchantId(), + 'tp_merchant_order_id' => $this->getMerchantOrderId(), + 'tp_amount' => $this->getAmount(), + 'tp_transaction_id' => $this->getTransactionNumber(), + 'tp_transaction_status' => $this->getStatus(), + 'tp_created_at' => $this->getCreatedAt(), + ]; + } + } From 3d318c8fea9fb61c3bedae5bbcda8db8dfc4a9b6 Mon Sep 17 00:00:00 2001 From: SangminLee Date: Thu, 17 Sep 2020 15:59:17 -0400 Subject: [PATCH 6/8] Add Show Transaction to README --- README.md | 31 +++++++++++++++++++++++++++++++ samples/common.php | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e80707..65b4d28 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ http://localhost:8000/ - Using .env > MERCHANT_ID,MERCHANT_SECRET for test can get them at [TendoPay Sandbox](https://sandbox.tendopay.ph) + ```bash ## Merchant Credentials MERCHANT_ID= @@ -58,6 +59,7 @@ $client = new TendoPayClient(); ``` - Using $config variable + ```php use TendoPay\SDK\TendoPayClient; @@ -108,6 +110,7 @@ try { ``` ### Callback (redirected page) + ```php use TendoPay\SDK\Exception\TendoPayConnectionException; use TendoPay\SDK\Models\VerifyTransactionRequest; @@ -152,3 +155,31 @@ try { echo 'Runtime Error:'.$e->getMessage(); } ``` + + +### Show Transaction Detail + +```php +use TendoPay\SDK\Exception\TendoPayConnectionException; +use TendoPay\SDK\TendoPayClient; + +$client = new TendoPayClient(); + +try { + + $transaction = $client->getTransactionDetail($transactionNumber); + + // merchant process here + // $transaction->getMerchantId(); + // $transaction->getMerchantOrderId(); + // $transaction->getAmount(); + // $transaction->getTransactionNumber(); + // $transaction->getCreatedAt(); + // $transaction->getStatus(); + +} catch (TendoPayConnectionException $e) { + echo 'Connection Error:'.$e->getMessage(); +} catch (Exception $e) { + echo 'Runtime Error:'.$e->getMessage(); +} +``` diff --git a/samples/common.php b/samples/common.php index c48dcf2..1149813 100644 --- a/samples/common.php +++ b/samples/common.php @@ -25,7 +25,7 @@ function dump() echo ''; } -$credentials = $_SESSION['credentials']; +$credentials = $_SESSION['credentials'] ?? null; //putenv('MERCHANT_ID='.$credentials->merchant_id); //putenv('MERCHANT_SECRET='.$credentials->merchant_secret); //putenv('CLIENT_ID='.$credentials->client_id); From d1ea81734da097e4cb801a59f8cbde34d3936588 Mon Sep 17 00:00:00 2001 From: SangminLee Date: Thu, 17 Sep 2020 16:43:24 -0400 Subject: [PATCH 7/8] Add compatible showTransaction --- src/TendoPayClient.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/TendoPayClient.php b/src/TendoPayClient.php index ce95c39..cbfde6a 100644 --- a/src/TendoPayClient.php +++ b/src/TendoPayClient.php @@ -419,11 +419,16 @@ public static function isCallbackRequest($request): bool */ public function getTransactionDetail($transactionNumber): Transaction { + $usePersonalAccessToken = false; + try { + $usePersonalAccessToken = (bool) $this->getPersonalAccessToken(); + } catch (\InvalidArgumentException $e) {} + $params = []; $response = $this->request('GET', Constants::getTransactionDetailEndpointURI($transactionNumber), $params, - $this->getAuthorizationHeader(), true); + $this->getAuthorizationHeader($usePersonalAccessToken), true); $transaction = json_decode($response, true); From 612d1bd6d880bf141159de9a5227f2949ad6be33 Mon Sep 17 00:00:00 2001 From: SangminLee Date: Fri, 18 Sep 2020 15:11:29 -0400 Subject: [PATCH 8/8] init credentials from env it exists --- samples/common.php | 8 ++++---- samples/index.php | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/samples/common.php b/samples/common.php index 1149813..6dabd8f 100644 --- a/samples/common.php +++ b/samples/common.php @@ -35,10 +35,10 @@ function dump() //putenv('TENDOPAY_SANDBOX_ENABLED=true'); $config = [ - 'MERCHANT_ID' => $credentials->merchant_id, - 'MERCHANT_SECRET' => $credentials->merchant_secret, - 'CLIENT_ID' => $credentials->client_id, - 'CLIENT_SECRET' => $credentials->client_secret, + 'MERCHANT_ID' => $credentials->merchant_id ?? '', + 'MERCHANT_SECRET' => $credentials->merchant_secret ?? '', + 'CLIENT_ID' => $credentials->client_id ?? '', + 'CLIENT_SECRET' => $credentials->client_secret ?? '', 'REDIRECT_URL' => $credentials->redirect_url ?? '', 'ERROR_REDIRECT_URL' => $credentials->error_redirect_url ?? '', 'TENDOPAY_SANDBOX_ENABLED' => true, diff --git a/samples/index.php b/samples/index.php index 88c0f0f..48d55f8 100644 --- a/samples/index.php +++ b/samples/index.php @@ -1,6 +1,22 @@