From 29831a586c1cd915611bf33dc928f6ce3447ef5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Sj=C3=B6berg?= Date: Mon, 7 Jan 2019 09:31:50 +0600 Subject: [PATCH] Mondido PHP SDK 2.0 --- .gitignore | 3 + README.md | 49 +- composer.json | 27 + composer.lock | 968 ++++++++++++++++++ examples/index.php | 10 +- examples/sample_transaction.php | 66 +- phpunit.php | 28 + phpunit.xml | 26 + src/Api/ApiBase.php | 77 ++ src/Api/Customer.php | 69 ++ src/Api/Plan.php | 29 + src/Api/Refund.php | 25 + src/Api/StoredCard.php | 40 + src/Api/Subscription.php | 67 ++ src/Api/Transaction.php | 57 ++ src/HttpHelper.php | 95 ++ src/Models/BaseModel.php | 36 + src/Models/CreditCard.php | 118 +++ src/Models/Customer.php | 33 + src/Models/Plan.php | 23 + src/Models/Subscription.php | 23 + src/Models/Transaction.php | 287 ++++++ src/Mondido.php | 187 ++++ .../webhook.php => Request/Webhook.php} | 14 +- src/Settings/Configuration.php | 25 + src/api/api_base.php | 23 - src/api/refund.php | 22 - src/api/stored_card.php | 37 - src/api/transaction.php | 54 - src/helpers.php | 13 + src/http_helper.php | 60 -- src/models/base_model.php | 9 - src/models/credit_card.php | 65 -- src/models/transaction.php | 188 ---- src/mondido_sdk.php | 51 - src/settings/configuration.php | 23 - test/test_base.php | 24 - test/webhook_Test.php | 30 - .../ApiBaseTest.php | 12 +- .../ApiRefundTest.php | 47 +- .../ApiStoredCardTest.php | 40 +- .../ApiTransactionTest.php | 58 +- tests/TestBase.php | 33 + tests/WebhookTest.php | 42 + wh.json | 1 - 45 files changed, 2503 insertions(+), 711 deletions(-) create mode 100644 composer.json create mode 100644 composer.lock create mode 100755 phpunit.php create mode 100755 phpunit.xml create mode 100644 src/Api/ApiBase.php create mode 100644 src/Api/Customer.php create mode 100644 src/Api/Plan.php create mode 100644 src/Api/Refund.php create mode 100644 src/Api/StoredCard.php create mode 100644 src/Api/Subscription.php create mode 100644 src/Api/Transaction.php create mode 100644 src/HttpHelper.php create mode 100644 src/Models/BaseModel.php create mode 100644 src/Models/CreditCard.php create mode 100644 src/Models/Customer.php create mode 100644 src/Models/Plan.php create mode 100644 src/Models/Subscription.php create mode 100644 src/Models/Transaction.php create mode 100644 src/Mondido.php rename src/{request/webhook.php => Request/Webhook.php} (59%) create mode 100644 src/Settings/Configuration.php delete mode 100644 src/api/api_base.php delete mode 100644 src/api/refund.php delete mode 100644 src/api/stored_card.php delete mode 100644 src/api/transaction.php create mode 100644 src/helpers.php delete mode 100644 src/http_helper.php delete mode 100644 src/models/base_model.php delete mode 100644 src/models/credit_card.php delete mode 100644 src/models/transaction.php delete mode 100644 src/mondido_sdk.php delete mode 100644 src/settings/configuration.php delete mode 100644 test/test_base.php delete mode 100644 test/webhook_Test.php rename test/api_base_Test.php => tests/ApiBaseTest.php (70%) rename test/api_refund_Test.php => tests/ApiRefundTest.php (53%) rename test/api_stored_card_Test.php => tests/ApiStoredCardTest.php (62%) rename test/api_transaction_Test.php => tests/ApiTransactionTest.php (51%) create mode 100644 tests/TestBase.php create mode 100644 tests/WebhookTest.php delete mode 100644 wh.json diff --git a/.gitignore b/.gitignore index c6ef218..de02b52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .idea + +/vendor/ +wh.json diff --git a/README.md b/README.md index e060ac3..77440dd 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,48 @@ -php_sdk 1.2 +#Mondido PHP SDK 2.0 by Snowfire ======= -The PHP SDK for Mondido Payments +To get started with the SDK, simply run `composer require snowfire/mondido-php-sdk` and include the composer-generated `autoload.php`. +Every time you wish to use the api through the SDK, you must first instantiate the `Mondido\Mondido` class with your merchant id, password and secret. If you plan to use this in more than one place, it is recommended to place this instantiation in a constructor, trait or similar. -```php +You can then access the different api features through your main instance. + +## Example + +``` api = new Mondido\Mondido($merchantId, $password, $secret); + } + + public function recordPayment($data) + { + $transaction = $this->api->transaction()->create($data); + } + } ``` +For complete API documentation, please visit [Mondido](https://doc.mondido.com/api). + + The unit tests require PHPUnit to be installed and run `phpunit test/` *Changelog* +- 2.0, Transitioned to non-static api +- 2.0, Refactored all code for PSR-0 +- 2.0, Fixed tests +- 2.0, Bug and syntax fixes - 1.2, Updated Hash recipe, refactor models, etc. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..296addc --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "snowfire/mondido-php-sdk", + "description": "A fork of the Mondido PHP SDK available on composer", + "authors": [ + { + "name": "Leo Sjöberg", + "email": "leo@snowfire.net" + } + ], + "require": {}, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "autoload": { + "psr-4": { + "Mondido\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "autoload-dev": { + "classmap": [ + "tests/TestBase.php" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..4a09669 --- /dev/null +++ b/composer.lock @@ -0,0 +1,968 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "a52ff9053f55fa7be248f6035cdce2e7", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "phpDocumentor": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "mike.vanriel@naenius.com" + } + ], + "time": "2015-02-03 12:10:50" + }, + { + "name": "phpspec/prophecy", + "version": "v1.4.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "phpdocumentor/reflection-docblock": "~2.0", + "sebastian/comparator": "~1.1" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2015-04-27 22:15:08" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.1.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "6044546998c7627ab997501a3d0db972b3db9790" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6044546998c7627ab997501a3d0db972b3db9790", + "reference": "6044546998c7627ab997501a3d0db972b3db9790", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2015-07-13 11:25:58" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", + "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2015-04-02 05:19:05" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21 13:50:34" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", + "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2015-06-13 07:35:30" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2015-06-19 03:43:16" + }, + { + "name": "phpunit/phpunit", + "version": "4.7.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "9b97f9d807b862c2de2a36e86690000801c85724" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9b97f9d807b862c2de2a36e86690000801c85724", + "reference": "9b97f9d807b862c2de2a36e86690000801c85724", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "~1.3,>=1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": ">=1.0.6", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.2", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.7.x-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": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-07-13 11:28:34" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "1c330b1b6e1ea8fd15f2fbea46770576e366855c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/1c330b1b6e1ea8fd15f2fbea46770576e366855c", + "reference": "1c330b1b6e1ea8fd15f2fbea46770576e366855c", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-07-04 05:41:32" + }, + { + "name": "sebastian/comparator", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e", + "reference": "1dd8869519a225f7f2b9eb663e225298fade819e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2015-01-29 16:28:08" + }, + { + "name": "sebastian/diff", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", + "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-02-22 15:13:53" + }, + { + "name": "sebastian/environment", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e", + "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2015-01-01 10:01:08" + }, + { + "name": "sebastian/exporter", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "84839970d05254c73cde183a721c7af13aede943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", + "reference": "84839970d05254c73cde183a721c7af13aede943", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "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" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2015-01-27 07:23:06" + }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2014-10-06 09:23:50" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" + }, + { + "name": "sebastian/version", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-06-21 13:59:46" + }, + { + "name": "symfony/yaml", + "version": "v2.7.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "4bfbe0ed3909bfddd75b70c094391ec1f142f860" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/4bfbe0ed3909bfddd75b70c094391ec1f142f860", + "reference": "4bfbe0ed3909bfddd75b70c094391ec1f142f860", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "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": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-07-01 11:25:50" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/examples/index.php b/examples/index.php index 6cdd037..4da401a 100644 --- a/examples/index.php +++ b/examples/index.php @@ -3,18 +3,18 @@ require_once(dirname(__FILE__) . '/../src/mondido_sdk.php'); //get the transaction id from the POST -$transaction = mondido\request\webhook::get(); +$transaction = \Mondido\Request\webhook::get(); //get the id $transaction_id = $transaction['id']; //log to file -mondido\mondido_sdk::logToFile('log.txt',$transaction); +Mondido\mondido_sdk::logToFile('log.txt',$transaction); -$transaction = mondido\api\transaction::get(1986); +$transaction = \Mondido\Api\Transaction::get(1986); print_r($transaction); -$transactions = mondido\api\transaction::index(10,0); +$transactions = \Mondido\Api\Transaction::index(10,0); print_r($transactions); -$refund = mondido\api\refund::create($transaction['id'],'wrong payment',$transaction['amount']); +$refund = \Mondido\Api\Refund::create($transaction['id'],'wrong payment',$transaction['amount']); print_r($refund); \ No newline at end of file diff --git a/examples/sample_transaction.php b/examples/sample_transaction.php index ef17566..e7fda5e 100644 --- a/examples/sample_transaction.php +++ b/examples/sample_transaction.php @@ -1,34 +1,34 @@ - "", - "Amount" => 10, - "PaymentRef" => "MyOrderId", - "Payment" => new credit_card(array( - "Holder" => "PHPSDKTest", - "Cvv" => "200", - "Expiry" => "0116", - "Number" => "4111111111111111", - "Type" => "VISA" - )), - "Test" => true, - #"Metadata" => json_encode(array("name" => "Anderson")), - "Currency" => "usd", - "StoreCard" => true, - "PlanId" => 100, - #"CustomerRef" => "", - #"Hash" => "", - #"Webhook" => json_encode(array("trigger" => "payment_success", "email" => "myname@domain.com")), - "Encrypted" => "", - #"Process" => true, - "SuccessUrl" => "", - "ErrorUrl" => "" -)); - -$response = mondido\api\transaction::create($transaction); + "", + "Amount" => 10, + "PaymentRef" => "MyOrderId", + "Payment" => new CreditCard(array( + "Holder" => "PHPSDKTest", + "Cvv" => "200", + "Expiry" => "0116", + "Number" => "4111111111111111", + "Type" => "VISA" + )), + "Test" => true, + #"Metadata" => json_encode(array("name" => "Anderson")), + "Currency" => "usd", + "StoreCard" => true, + "PlanId" => 100, + #"CustomerRef" => "", + #"Hash" => "", + #"Webhook" => json_encode(array("trigger" => "payment_success", "email" => "myname@domain.com")), + "Encrypted" => "", + #"Process" => true, + "SuccessUrl" => "", + "ErrorUrl" => "" +)); + +$response = \Mondido\Api\Transaction::create($transaction); print_r($response); \ No newline at end of file diff --git a/phpunit.php b/phpunit.php new file mode 100755 index 0000000..25c90c8 --- /dev/null +++ b/phpunit.php @@ -0,0 +1,28 @@ + + + + + ./tests + /tests/TestBase.php + + + + + ./src + + + diff --git a/src/Api/ApiBase.php b/src/Api/ApiBase.php new file mode 100644 index 0000000..3a7145c --- /dev/null +++ b/src/Api/ApiBase.php @@ -0,0 +1,77 @@ +username = $username; + $this->password = $password; + $this->secret = $secret; + $this->apiUrl = $apiUrl; + } + + public function endpoint($url) + { + return $this->apiUrl . $url; + } + + public function request($method, $endpoint, array $data = array(), $endpointIsUrl = false) + { + if ( ! $endpointIsUrl) { + $endpoint = $this->endpoint($endpoint); + } + + $request = array('\Mondido\HttpHelper', $method); + + $arguments = array( + $this->username, + $this->password, + $endpoint, + $data, + ); + + return call_user_func_array($request, $arguments); + } +// public static function getApiUrl() +// { +// return Configuration::$app_settings['api_url']; +// } +// +// public static function getUsername() +// { +// return Configuration::$app_settings['username']; +// } +// +// public static function getPassword() +// { +// return Configuration::$app_settings['password']; +// } +} diff --git a/src/Api/Customer.php b/src/Api/Customer.php new file mode 100644 index 0000000..6d242b9 --- /dev/null +++ b/src/Api/Customer.php @@ -0,0 +1,69 @@ +endpoint('customers/' . $id); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function index() + { + $remote_url = $this->endpoint('customers'); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function create($customer) + { + if (!($customer instanceof \Mondido\Models\Customer)) { + $customer = new \Mondido\Models\Customer($customer); + } + + $params = $customer->getAllAttributes(); + + foreach ($params as $attr => $value) { + if ($value == null) { + unset($params[$attr]); + } else { + if (is_bool($params[$attr])) { + if ($params[$attr]) { + $params[$attr] = 'true'; + } else { + $params[$attr] = 'false'; + } + } + } + } + + $remote_url = $this->endpoint('customers'); + return HttpHelper::post($this->username, $this->password, $remote_url, $params); + } + + public function update($customer) + { + if (!($customer instanceof \Mondido\Models\Customer)) { + $customer = new \Mondido\Models\Customer($customer); + } + + $remote_url = $this->endpoint('customers/' . $customer->id); + return HttpHelper::put($this->username, $this->password, $remote_url, $customer->getAllAttributes()); + } + + public function delete($id) + { + $remote_url = $this->endpoint('customers/' . $id); + return HttpHelper::delete($this->username, $this->password, $remote_url); + } +} \ No newline at end of file diff --git a/src/Api/Plan.php b/src/Api/Plan.php new file mode 100644 index 0000000..7ddf281 --- /dev/null +++ b/src/Api/Plan.php @@ -0,0 +1,29 @@ + $value) { + if (substr($filter, 0, 6) != 'filter') { + // The user probably wants to filter the request + // but didn't format it correctly, so we do it. + $options["filter[{$filter}]"] = $value; + unset ($options[$filter]); + } + } + $remote_url = $this->endpoint('plans') . '?' . http_build_query($options); + + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function get($id) + { + return $this->request('get', 'plans/'.$id); + } +} \ No newline at end of file diff --git a/src/Api/Refund.php b/src/Api/Refund.php new file mode 100644 index 0000000..a0154cb --- /dev/null +++ b/src/Api/Refund.php @@ -0,0 +1,25 @@ +endpoint('refunds/' . $id); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function create($data) + { + $remote_url = $this->endpoint('refunds'); + return HttpHelper::post($this->username, $this->password, $remote_url, $data); + } +} \ No newline at end of file diff --git a/src/Api/StoredCard.php b/src/Api/StoredCard.php new file mode 100644 index 0000000..73e1f96 --- /dev/null +++ b/src/Api/StoredCard.php @@ -0,0 +1,40 @@ +endpoint('stored_cards/' . $id); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function index($limit, $offset) + { + $remote_url = $this->endpoint('stored_cards/?limit=' . $limit . '&offset=' . $offset); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function create($card) + { + $remote_url = $this->endpoint('stored_cards'); + return HttpHelper::post($this->username, $this->password, $remote_url, $card); + } + + public function delete($id) + { + $remote_url = $this->endpoint('stored_cards/' . $id); + return HttpHelper::delete($this->username, $this->password, $remote_url); + } + +} \ No newline at end of file diff --git a/src/Api/Subscription.php b/src/Api/Subscription.php new file mode 100644 index 0000000..aca67e1 --- /dev/null +++ b/src/Api/Subscription.php @@ -0,0 +1,67 @@ +request('get', 'subscriptions', $options); + } + + /** + * Update a given subscription. + * + * @param int $id + * @param array $params + * @return array + */ + public function update($id, array $params) + { + return $this->request('put', 'subscriptions/'.$id, $params); + } + + /** + * Fetch a given subscription. + * + * @param int $id + * @return array + */ + public function get($id) + { + return $this->request('get', 'subscriptions/'.$id); + } + + /** + * Create a new subscription. + * + * @param string $planId + * @param int|string $identifier + * @param string $identifierType + * @return array + */ + public function create($planId, $identifier, $identifierType = 'ref') + { + $types = array( + 'card' => 'stored_card_id', + 'ref' => 'customer_ref', + 'customer' => 'customer_id', + ); + + $type = isset($types[$identifierType]) ? $types[$identifierType] : $identifierType; + + return $this->request('post', 'subscriptions', array( + 'plan_id' => $planId, + $type => $identifier, + 'quantity' => 1, + )); + } +} \ No newline at end of file diff --git a/src/Api/Transaction.php b/src/Api/Transaction.php new file mode 100644 index 0000000..be0c0af --- /dev/null +++ b/src/Api/Transaction.php @@ -0,0 +1,57 @@ +endpoint('transactions/' . $id); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + /* + * list transactions with a offset and a limit + */ + public function index($limit, $offset) + { + $remote_url = $this->endpoint('transactions/?limit=' . $limit . '&offset=' . $offset); + return HttpHelper::get($this->username, $this->password, $remote_url); + } + + public function create($transaction) + { + // Make a check to see if we passed in an actual transaction, or just values for the transaction + if (!($transaction instanceof \Mondido\Models\Transaction)) { + $transaction = new \Mondido\Models\Transaction($this->username, $this->secret, $transaction); + } + + $transaction_fields = $transaction->getAllAttributes(); + $card_fields = $transaction->getPayment()->getAllAttributes(); + + unset($transaction_fields["payment"]); + $params = array_merge($transaction_fields, $card_fields); + $params["amount"] = (string)number_format((float)$params["amount"], 2, '.', ''); + + // Remove Null and Update Booleans + foreach ($params as $attr => $value) { + if ($value == null) { + unset($params[$attr]); + } else { + if (is_bool($params[$attr])) { + if ($params[$attr]) { + $params[$attr] = 'true'; + } else { + $params[$attr] = 'false'; + } + } + } + } + + $remote_url = $this->endpoint('transactions'); + return HttpHelper::post($this->username, $this->password, $remote_url, $params); + } + +} \ No newline at end of file diff --git a/src/HttpHelper.php b/src/HttpHelper.php new file mode 100644 index 0000000..79b6129 --- /dev/null +++ b/src/HttpHelper.php @@ -0,0 +1,95 @@ + array( + 'method' => "GET", + 'header' => "Authorization: Basic " . base64_encode("$uname:$pass") + ) + ); + $context = stream_context_create($opts); + $file = file_get_contents($url, false, $context); + return json_decode($file, true); + } + + public static function delete($uname, $pass, $url, array $data = null) + { + if ($data) { + $url = $url . '?' . http_build_query($data); + } + + $opts = array( + 'http' => array( + 'method' => "DELETE", + 'header' => "Authorization: Basic " . base64_encode("$uname:$pass") + ) + ); + $context = stream_context_create($opts); + $file = file_get_contents($url, false, $context); + return json_decode($file, true); + } + + public static function post($uname, $pass, $url, $data) + { + $body = http_build_query($data); + $opts = array( + 'http' => array( + 'method' => "POST", + 'header' => array( + "Authorization: Basic " . base64_encode("$uname:$pass"), + "Content-type: application/x-www-form-urlencoded", + "Content-Length: " . strlen($body) + ), + 'content' => $body + ) + ); + +// $context = stream_context_create($opts); +// $result = file_get_contents($url, false, $context); +// return json_decode($result, true); + + + $ch = curl_init(); + + //set the url, number of POST vars, POST data + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, count($body)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + curl_setopt($ch, CURLOPT_USERPWD, "$uname:$pass"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + //execute post + $result = curl_exec($ch); + + return json_decode($result, true); + } + + public static function put($uname, $pass, $url, $data) + { + $body = http_build_query($data); + + $ch = curl_init(); + + //set the url, number of POST vars, POST data + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + curl_setopt($ch, CURLOPT_USERPWD, "$uname:$pass"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + //execute post + $result = curl_exec($ch); + + return json_decode($result, true); + } + +} \ No newline at end of file diff --git a/src/Models/BaseModel.php b/src/Models/BaseModel.php new file mode 100644 index 0000000..867c3d5 --- /dev/null +++ b/src/Models/BaseModel.php @@ -0,0 +1,36 @@ + $value) { + if (in_array($attribute, $this->allowedAttributes)) { + $this->attributes[$attribute] = $value; + } else { + $this->attributes['metadata'][$attribute] = $value; + } + } + + $this->attributes = $attributes; + } + + public function getAllAttributes() + { + return $this->attributes; + } + + public function __get($attribute) + { + if (isset($this->attributes[$attribute])) { + return $this->attributes[$attribute]; + } + + return null; + } + +} diff --git a/src/Models/CreditCard.php b/src/Models/CreditCard.php new file mode 100644 index 0000000..773e7ed --- /dev/null +++ b/src/Models/CreditCard.php @@ -0,0 +1,118 @@ + $value) { + $attribute = snakify($attribute); + + $aliasedAttributes = array_combine($this->aliases, $this->allowedAttributes); + + if (in_array($attribute, $this->aliases)) { + // The user passed an alias instead of the fully qualified attribute name, so we'll convert it + $attribute = $aliasedAttributes[$attribute]; + } + + if (in_array($attribute, $this->allowedAttributes)) { + $this->attributes[$attribute] = $value; + } + } + } + + /** + * is utilized for reading data from inaccessible members. + * + * @param $name string + * @return mixed + * @link http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members + */ + public function __get($name) + { + return $this->attributes[snakify($name)]; + } + + + public function getCvv() + { + return $this->card_cvv; + } + + public function setCvv($cvv) + { + $this->card_cvv = $cvv; + } + + public function getNumber() + { + return $this->card_number; + } + + public function setNumber($number) + { + $this->card_number = $number; + } + + public function getExpiry() + { + return $this->card_expiry; + } + + public function setExpiry($expiry) + { + $this->card_expiry = $expiry; + } + + public function getHolder() + { + return $this->card_holder; + } + + public function setHolder($holder) + { + $this->card_holder = $holder; + } + + public function getType() + { + return $this->card_type; + } + + public function setType($type) + { + $this->card_type = $type; + } + + public function getAllAttributes() + { + return $this->attributes; + } +} \ No newline at end of file diff --git a/src/Models/Customer.php b/src/Models/Customer.php new file mode 100644 index 0000000..faf70f3 --- /dev/null +++ b/src/Models/Customer.php @@ -0,0 +1,33 @@ + $value) { + if (in_array($attribute, $this->allowedAttributes)) { + $this->attributes[$attribute] = $value; + } else { + $this->attributes['metadata'][$attribute] = $value; + } + } + + $this->attributes = $attributes; + } + + +} \ No newline at end of file diff --git a/src/Models/Plan.php b/src/Models/Plan.php new file mode 100644 index 0000000..1306770 --- /dev/null +++ b/src/Models/Plan.php @@ -0,0 +1,23 @@ +attributes['merchant_id'] = $merchantId; + $this->attributes['payment_ref'] = $paymentRef; + $this->attributes['customer_ref'] = $customerRef; + $this->attributes['secret'] = $secret; + + $payment = array(); + + foreach ($arguments as $attribute => $value) { +// $methodName = "set" . $attribute; +// $this->$methodName($value); + $attribute = snakify($attribute); + if(in_array($attribute, $this->cardAttributes)) { + $payment[$attribute] = $value; + } + + if(in_array($attribute, $this->allowedAttributes)) { + $this->attributes[$attribute] = $value; + } + } + + if (! ($this->paymentRef && $this->customerRef)) { + throw new \Exception("You must provide both a payment reference and a customer reference to make a transaction"); + } + + if (!empty($payment) && is_array($payment)) { + $this->attributes['payment'] = new CreditCard($payment); + } + +// if (!isset($arguments["MerchantId"])) { +// $this->setMerchantId(Configuration::$app_settings['username']); +// } + + if (!isset($arguments["hash"])) { + $this->setHash($secret); + } + } + + /** + * is utilized for reading data from inaccessible members. + * + * @param $name string + * @return mixed + * @link http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members + */ + public function __get($name) + { + return $this->attributes[snakify($name)]; + } + + + public function getMerchantId() + { + return $this->merchant_id; + } + + public function setMerchantId($merchantId) + { + $this->merchant_id = $merchantId; + } + + public function getAmount() + { + return $this->amount; + } + + public function setAmount($amount) + { + $this->amount = $amount; + } + + public function getPaymentRef() + { + return $this->payment_ref; + } + + public function setPaymentRef($paymentRef) + { + $this->payment_ref = $paymentRef; + } + + public function getPayment() + { + return $this->payment; + } + + public function setPayment($payment) + { + $this->payment = $payment; + } + + public function getTest() + { + return $this->test; + } + + public function setTest($test) + { + $this->test = $test; + } + + public function getMetadata() + { + return $this->metadata; + } + + public function setMetadata($metadata) + { + $this->metadata = $metadata; + } + + public function getCurrency() + { + return $this->currency; + } + + public function setCurrency($currency) + { + $this->currency = $currency; + } + + public function getStoreCard() + { + return $this->store_card; + } + + public function setStoreCard($storeCard) + { + $this->store_card = $storeCard; + } + + public function getPlanId() + { + return $this->plan_id; + } + + public function setPlanId($planId) + { + $this->plan_id = $planId; + } + + public function getCustomerRef() + { + return $this->customer_ref; + } + + public function setCustomerRef($customerRef) + { + $this->customer_ref = $customerRef; + } + + public function getHash() + { + return $this->hash; + } + + public function setHash($secret, $algorithm = null) + { + if (!$secret) { + $secret = Configuration::$app_settings['secret']; + } + if (!$algorithm) { + $algorithm = Configuration::$app_settings['algorithm']; + } + $this->attributes['hash'] = $this->calculateHash($secret, $algorithm); + } + + public function getWebhook() + { + return $this->webhook; + } + + public function setWebhook($webhook) + { + $this->webhook = $webhook; + } + + public function getEncrypted() + { + return $this->encrypted; + } + + public function setEncrypted($encrypted) + { + $this->encrypted = $encrypted; + } + + public function getProcess() + { + return $this->process; + } + + public function setProcess($process) + { + $this->process = $process; + } + + public function getSuccessUrl() + { + return $this->success_url; + } + + public function setSuccessUrl($successUrl) + { + $this->success_url = $successUrl; + } + + public function getErrorUrl() + { + return $this->error_url; + } + + public function setErrorUrl($errorUrl) + { + $this->error_url = $errorUrl; + } + + # Custom + + private function calculateHash($secret, $algorithm) + { + $recipe = (string)$this->getMerchantId(); + $recipe .= (string )$this->getPaymentRef(); + $recipe .= (string)$this->getCustomerRef(); + $recipe .= (string)number_format((float)$this->getAmount(), 2, '.', ''); + $recipe .= (string)$this->getCurrency(); + $recipe .= ($this->getTest()) ? "test" : ""; + $recipe .= $secret; + + return $algorithm($recipe); + } + +} \ No newline at end of file diff --git a/src/Mondido.php b/src/Mondido.php new file mode 100644 index 0000000..79238a1 --- /dev/null +++ b/src/Mondido.php @@ -0,0 +1,187 @@ +setIfExists('username', $username); + $this->setIfExists('password', $password); + $this->setIfExists('secret', $secret); + $this->setIfExists('apiUrl', $apiUrl); + $this->setIfExists('algorithm', $algorithm); + + $this->refund = new Refund($this->username, $this->password, $this->secret, $this->apiUrl); + $this->storedCard = new storedCard($this->username, $this->password, $this->secret, $this->apiUrl); + $this->transaction = new Transaction($this->username, $this->password, $this->secret, $this->apiUrl); + $this->customer = new Customer($this->username, $this->password, $this->secret, $this->apiUrl); + $this->subscription = new Subscription($this->username, $this->password, $this->secret, $this->apiUrl); + $this->plan = new Plan($this->username, $this->password, $this->secret, $this->apiUrl); + } + + public function refund() + { + return new Refund($this->username, $this->password, $this->secret, $this->apiUrl); + } + + public function storedCard() + { + return new storedCard($this->username, $this->password, $this->secret, $this->apiUrl); + } + + public function transaction() + { + return new Transaction($this->username, $this->password, $this->secret, $this->apiUrl); + } + + private function setIfExists($attribute, $value) + { + if ($value) { + $this->$attribute = $value; + } else { + $this->$attribute = Configuration::$app_settings[snakify($attribute)]; + } + } + + public function generateHash($paymentRef, $customerRef, $amount, $currency, $test = null) + { + $recipe = (string) $this->username; + $recipe .= (string )$paymentRef; + $recipe .= (string)$customerRef; + $recipe .= (string)number_format((float)$amount, 2, '.', ''); + $recipe .= (string)$currency; + $recipe .= $test ? "test" : ""; + $recipe .= $this->secret; + + $algorithm = $this->algorithm; + + return $algorithm($recipe); + } + + public function generatePostForm($payload) + { + if (!isset ($payload['amount'])) { + throw new \Exception('You need to specify an amount'); + } + + $payload['amount'] = number_format((float)$payload['amount'], 2, '.', ''); + + if (!isset($payload['hash'])) { + $test = null; + if (isset($payload['test'])) { + $test = $payload['test']; + } + + $paymentRef = $payload['payment_ref']; + $customerRef = $payload['customer_ref']; + $amount = $payload['amount']; + $currency = $payload['currency']; + + if (! ( + isset ($paymentRef) && + isset ($customerRef) && + isset ($amount) && + isset ($currency) + )) { + throw new \Exception('You need to define payment and customer reference, amount and currency to generate a correct hash'); + } + + $payload['hash'] = $this->generateHash($paymentRef, $customerRef, $amount, $currency, $test); + } + + $form = '
'; + $form .= ''; + + empty($payload['test']) ? $payload['test'] = "false" : "true"; + + foreach ($payload as $dataType => $data) { + if (is_array($data)) { + $data = json_encode($data); + } + $form .= ''; + } + + $form .= ''; + $form .= '
'; + + // The JS to make this work + $form .= + ''; + + return $form; + } + + + public function getApiUrl() + { + return $this->apiUrl; + } + + public function getPassword() + { + return $this->password; + } + + public function getUsername() + { + return $this->username; + } + + public function getSecret() + { + return $this->secret; + } + + /* + *Log data to file + */ + public static function logToFile($path, $transaction) + { + + $log = 'id: ' . $transaction['id'] . PHP_EOL; + $log .= 'created_at: ' . $transaction['created_at'] . PHP_EOL; + $log .= 'amount: ' . $transaction['amount'] . PHP_EOL; + $log .= 'payment_ref: ' . $transaction['payment_ref'] . PHP_EOL; + $log .= 'card_holder: ' . $transaction['card_holder'] . PHP_EOL; + $log .= 'card_number: ' . $transaction['card_number'] . PHP_EOL; + $log .= 'metadata: ' . $transaction['metadata'] . PHP_EOL; + $log .= 'currency: ' . $transaction['currency'] . PHP_EOL; + $log .= 'status: ' . $transaction['status'] . PHP_EOL; + $log .= 'card_type: ' . $transaction['card_type'] . PHP_EOL; + $log .= 'error: ' . $transaction['error'] . PHP_EOL; + $log .= 'cost: ' . $transaction['cost'] . PHP_EOL; + $log .= 'stored_card: ' . $transaction['stored_card'] . PHP_EOL; + $log .= 'customer: ' . $transaction['customer'] . PHP_EOL; + $log .= 'transaction_type: ' . $transaction['transaction_type'] . PHP_EOL; + $log .= 'subscription: ' . $transaction['subscription'] . PHP_EOL; + $log .= 'webhooks: ' . $transaction['webhooks'] . PHP_EOL; + file_put_contents($path, $log); + } +} diff --git a/src/request/webhook.php b/src/Request/Webhook.php similarity index 59% rename from src/request/webhook.php rename to src/Request/Webhook.php index 0ab6430..489aaf3 100644 --- a/src/request/webhook.php +++ b/src/Request/Webhook.php @@ -7,17 +7,19 @@ * To change this template use File | Settings | File Templates. */ -namespace mondido\request; +namespace Mondido\Request; -class webhook { - public static function get($data=null){ - if($data==null){ +class Webhook +{ + public static function get($data = null) + { + if ($data == null) { $data = 'php://input'; } $raw_data = file_get_contents($data); - if($raw_data != null){ - return json_decode($raw_data, TRUE); + if ($raw_data != null) { + return json_decode($raw_data, true); } return null; } diff --git a/src/Settings/Configuration.php b/src/Settings/Configuration.php new file mode 100644 index 0000000..3ede84e --- /dev/null +++ b/src/Settings/Configuration.php @@ -0,0 +1,25 @@ + 'https://api.mondido.com/v1/', + "username" => '148', + "password" => '', + "secret" => '', + "algorithm" => 'md5' + ); + +} \ No newline at end of file diff --git a/src/api/api_base.php b/src/api/api_base.php deleted file mode 100644 index a5208e5..0000000 --- a/src/api/api_base.php +++ /dev/null @@ -1,23 +0,0 @@ -getAllAttributes(); - $card_fields = $transaction->getPayment()->getAllAttributes(); - - unset($transaction_fields["payment"]); - $params = array_merge($transaction_fields, $card_fields); - $params["amount"] = (string) number_format( (float) $params["amount"], 2, '.', ''); - - // Remove Null and Update Booleans - foreach( $params as $attr => $value ){ - if($value == null) - unset($params[$attr]); - else if(is_bool($params[$attr])){ - if($params[$attr]) - $params[$attr] = 'true'; - else - $params[$attr] = 'false'; - } - } - - $remote_url = self::getApiUrl().'transactions'; - return http_helper::post(self::getUsername(),self::getPassword(),$remote_url,$params); - } - -} \ No newline at end of file diff --git a/src/helpers.php b/src/helpers.php new file mode 100644 index 0000000..41d5a0e --- /dev/null +++ b/src/helpers.php @@ -0,0 +1,13 @@ +array( - 'method'=>"GET", - 'header' => "Authorization: Basic " . base64_encode("$uname:$pass") - ) - ); - $context = stream_context_create($opts); - $file = file_get_contents($url, false, $context); - return json_decode($file, TRUE); - } - - public static function delete($uname,$pass,$url){ - $opts = array( - 'http'=>array( - 'method'=>"DELETE", - 'header' => "Authorization: Basic " . base64_encode("$uname:$pass") - ) - ); - $context = stream_context_create($opts); - $file = file_get_contents($url, false, $context); - return json_decode($file, TRUE); - } - - public static function post($uname,$pass,$url,$data){ - $body = http_build_query($data); - $opts = array( - 'http'=>array( - 'method'=>"POST", - 'header' => array( - "Authorization: Basic " . base64_encode("$uname:$pass"), - "Content-type: application/x-www-form-urlencoded", - "Content-Length: " . strlen($body) - ), - 'content' => $body - ) - ); - - - $ch = curl_init(); - - //set the url, number of POST vars, POST data - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, count($body)); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - curl_setopt($ch, CURLOPT_USERPWD, "$uname:$pass"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - //execute post - $result = curl_exec($ch); - - return json_decode($result, TRUE); - } - -} \ No newline at end of file diff --git a/src/models/base_model.php b/src/models/base_model.php deleted file mode 100644 index 3f26392..0000000 --- a/src/models/base_model.php +++ /dev/null @@ -1,9 +0,0 @@ - $value) - { - $methodName = "set" . $attribute; - $this->$methodName($value); - } - } - - public function getCvv(){ - return $this->card_cvv; - } - - public function setCvv($cvv){ - $this->card_cvv = $cvv; - } - - public function getNumber(){ - return $this->card_number; - } - - public function setNumber($number){ - $this->card_number = $number; - } - - public function getExpiry(){ - return $this->card_expiry; - } - - public function setExpiry($expiry){ - $this->card_expiry = $expiry; - } - - public function getHolder(){ - return $this->card_holder; - } - - public function setHolder($holder){ - $this->card_holder = $holder; - } - - public function getType(){ - return $this->card_type; - } - - public function setType($type){ - $this->card_type = $type; - } - - public function getAllAttributes(){ - return get_object_vars($this); - } -} \ No newline at end of file diff --git a/src/models/transaction.php b/src/models/transaction.php deleted file mode 100644 index 417838b..0000000 --- a/src/models/transaction.php +++ /dev/null @@ -1,188 +0,0 @@ - $value) - { - $methodName = "set" . $attribute; - $this->$methodName($value); - } - - if(!isset($arguments["MerchantId"])) - $this->setMerchantId( configuration::$app_settings['username'] ); - - if(!isset($arguments["Hash"])) - $this->setHash(); - } - - public function getMerchantId(){ - return $this->merchant_id; - } - - public function setMerchantId($merchantId){ - $this->merchant_id = $merchantId; - } - - public function getAmount(){ - return $this->amount; - } - - public function setAmount($amount){ - $this->amount = $amount; - } - - public function getPaymentRef(){ - return $this->payment_ref; - } - - public function setPaymentRef($paymentRef){ - $this->payment_ref = $paymentRef; - } - - - public function getPayment(){ - return $this->payment; - } - - public function setPayment($payment){ - $this->payment = $payment; - } - - public function getTest(){ - return $this->test; - } - - public function setTest($test){ - $this->test = $test; - } - - public function getMetadata(){ - return $this->metadata; - } - - public function setMetadata($metadata){ - $this->metadata = $metadata; - } - - public function getCurrency(){ - return $this->currency; - } - - public function setCurrency($currency){ - $this->currency = $currency; - } - - public function getStoreCard(){ - return $this->store_card; - } - - public function setStoreCard($storeCard){ - $this->store_card = $storeCard; - } - - public function getPlanId(){ - return $this->plan_id; - } - - public function setPlanId($planId){ - $this->plan_id = $planId; - } - - public function getCustomerRef(){ - return $this->customer_ref; - } - - public function setCustomerRef($customerRef){ - $this->customer_ref = $customerRef; - } - - public function getHash(){ - return $this->hash; - } - - public function setHash($options=array("secret" => null, "algorithm" => null)){ - if(!$options["secret"]) $secret = configuration::$app_settings['secret']; - if(!$options["algorithm"]) $algorithm = configuration::$app_settings['algorithm']; - $this->hash = $this->calculateHash($secret, $algorithm); - } - - public function getWebhook(){ - return $this->webhook; - } - - public function setWebhook($webhook){ - $this->webhook = $webhook; - } - - public function getEncrypted(){ - return $this->encrypted; - } - - public function setEncrypted($encrypted){ - $this->encrypted = $encrypted; - } - - public function getProcess(){ - return $this->process; - } - - public function setProcess($process){ - $this->process = $process; - } - - public function getSuccessUrl(){ - return $this->success_url; - } - - public function setSuccessUrl($successUrl){ - $this->success_url = $successUrl; - } - - public function getErrorUrl(){ - return $this->error_url; - } - - public function setErrorUrl($errorUrl){ - $this->error_url = $errorUrl; - } - - # Custom - - private function calculateHash($secret, $algorithm){ - $recipe = (string) $this->getMerchantId(); - $recipe .= (string )$this->getPaymentRef(); - $recipe .= (string) $this->getCustomerRef(); - $recipe .= (string) number_format( (float) $this->getAmount(), 2, '.', ''); - $recipe .= (string) $this->getCurrency(); - $recipe .= ($this->getTest()) ? "test" : ""; - $recipe .= $secret; - - return $algorithm($recipe); - } - - public function getAllAttributes(){ - return get_object_vars($this); - } - -} \ No newline at end of file diff --git a/src/mondido_sdk.php b/src/mondido_sdk.php deleted file mode 100644 index 60f8037..0000000 --- a/src/mondido_sdk.php +++ /dev/null @@ -1,51 +0,0 @@ - 'https://api.mondido.com/v1/', - "username" => '148', - "password" => '', - "secret" => '', - "algorithm" => 'md5' - ); - -} \ No newline at end of file diff --git a/test/test_base.php b/test/test_base.php deleted file mode 100644 index 0f6a4ab..0000000 --- a/test/test_base.php +++ /dev/null @@ -1,24 +0,0 @@ -assertEquals($transaction['id'], $transaction2['id']); - } -} diff --git a/test/api_base_Test.php b/tests/ApiBaseTest.php similarity index 70% rename from test/api_base_Test.php rename to tests/ApiBaseTest.php index 0967440..ad9ac79 100644 --- a/test/api_base_Test.php +++ b/tests/ApiBaseTest.php @@ -1,4 +1,5 @@ api->getApiUrl(); $this->assertEquals('https://api.mondido.com/v1/', $url); } public function testPassword() { echo "Testing api_base::getPassword()\n"; - $val = mondido\api\api_base::getPassword(); + $val = $this->api->getPassword(); $this->assertEquals('custom00', $val); } public function testUsername() { echo "Testing api_base::getUsername()\n"; - $val = mondido\api\api_base::getUsername(); + $val = $this->api->getUsername(); $this->assertEquals('3', $val); } diff --git a/test/api_refund_Test.php b/tests/ApiRefundTest.php similarity index 53% rename from test/api_refund_Test.php rename to tests/ApiRefundTest.php index 1b549f9..93d888b 100644 --- a/test/api_refund_Test.php +++ b/tests/ApiRefundTest.php @@ -1,8 +1,8 @@ "4111111111111111", @@ -28,42 +27,44 @@ public static function setUpBeforeClass() "card_expiry" => "0116", "card_cvv" => "200", "card_type" => "VISA", - "amount" => "10.00", + "amount" => "20.00", + "customer_ref" => 1, "payment_ref" => $ref, "currency" => "eur", "test" => "true", - "hash" => md5(configuration::$app_settings['username'].$ref."10.00".configuration::$app_settings['secret']) +// "hash" => md5($this->api->getUsername() . $ref . "10.00" . $this->api->getSecret()) ); echo "Testing refund, setting up a transaction\n"; - self::$trans = transaction::create($payment); + $this->trans = $this->api->transaction()->create($payment); $data = array( - "transaction_id" => self::$trans['id'], + "transaction_id" => $this->trans['id'], "amount" => "10.00", "reason" => "oops" ); echo "Testing refund, setting up a refund\n"; - self::$refund = refund::create($data); + $this->refund = $this->api->refund()->create($data); } - public function testGetRefund(){ + public function testGetRefund() + { echo "Testing refund::get\n"; - $res = refund::get(self::$refund['id']); - $this->assertEquals($res['id'], self::$refund['id']); + $res = $this->api->refund()->get($this->refund['id']); + $this->assertEquals($res['id'], $this->refund['id']); } - public function testCreateRefund(){ + public function testCreateRefund() + { echo "Testing refund::create\n"; $ref = rand(10, 100000); $data = array( - "transaction_id" => self::$trans['id'], + "transaction_id" => $this->trans['id'], "amount" => "10.00", "reason" => $ref ); - $res = refund::create($data); - + $res = $this->api->refund()->create($data); $this->assertEquals($res['reason'], $ref); } diff --git a/test/api_stored_card_Test.php b/tests/ApiStoredCardTest.php similarity index 62% rename from test/api_stored_card_Test.php rename to tests/ApiStoredCardTest.php index c84ab86..aea7cc5 100644 --- a/test/api_stored_card_Test.php +++ b/tests/ApiStoredCardTest.php @@ -1,6 +1,6 @@ "4111111111111111", "card_holder" => "php sdk", @@ -27,34 +26,37 @@ public static function setUpBeforeClass() "currency" => "eur", "test" => "true" ); - echo "Testing stored_card, setting up a stored_card\n"; - self::$card = stored_card::create($data); + $this->card = $this->api->storedCard()->create($data); } - public function testGetStoredcard(){ + public function testGetStoredcard() + { echo "Testing stored_card::get\n"; - $res = stored_card::get(self::$card['id']); + $res = $this->api->storedCard()->get($this->card['id']); print_r($res); - $this->assertEquals($res['id'], self::$card['id']); + $this->assertEquals($res['id'], $this->card['id']); } - public function testGetStoredcardsLimitOffset(){ + public function testGetStoredcardsLimitOffset() + { echo "Testing stored_card::index\n"; - $res = stored_card::index(2,0); + $res = $this->api->storedCard()->index(2, 0); print_r($res); $this->assertEquals(2, count($res)); } - public function testDeleteStoredcards(){ + public function testDeleteStoredcards() + { echo "Testing stored_card::delete\n"; - $res = stored_card::delete(self::$card['id']); + $res = $this->api->storedCard()->delete($this->card['id']); print_r($res); $this->assertEquals('deleted', $res['status']); } - public function testCreateStoredCard(){ + public function testCreateStoredCard() + { echo "Testing stored_card::create\n"; $ref = rand(10, 100000); @@ -68,7 +70,7 @@ public function testCreateStoredCard(){ "test" => "true" ); - $res = stored_card::create($data); + $res = $this->api->storedCard()->create($data); print_r($res); $this->assertEquals($res['card_holder'], $ref); diff --git a/test/api_transaction_Test.php b/tests/ApiTransactionTest.php similarity index 51% rename from test/api_transaction_Test.php rename to tests/ApiTransactionTest.php index 397be9b..6ed8d96 100644 --- a/test/api_transaction_Test.php +++ b/tests/ApiTransactionTest.php @@ -7,41 +7,57 @@ * To change this template use File | Settings | File Templates. */ -namespace mondido\test; -use mondido\api\transaction; -use mondido\settings\configuration; -use mondido\models\transaction as transaction_model; -use mondido\models\credit_card; +use Mondido\Api\Transaction; +use Mondido\Settings\Configuration; +use Mondido\Models\Transaction as transaction_model; +use Mondido\Models\CreditCard; -require_once(dirname(__FILE__) . '/test_base.php'); -class api_transaction_Test extends test_base { +class ApiTransactionTest extends TestBase +{ - public function testGetTransaction(){ + public function testGetTransaction() + { echo "Testing transaction::get\n"; - $tid = 29621; + $ref = rand(10, 100000); + $testTransaction = $this->api->transaction()->create(array( + "card_number" => "4111111111111111", + "card_holder" => "php sdk", + "card_expiry" => "0116", + "card_cvv" => "200", + "card_type" => "VISA", + "amount" => "20.00", + "customer_ref" => 1, + "payment_ref" => $ref, + "currency" => "eur", + "test" => "true", + )); + $tid = $testTransaction['id']; - $transaction = transaction::get($tid); + $transaction = $this->api->transaction()->get($tid); print_r($transaction); $this->assertEquals($tid, $transaction['id']); + $this->assertEquals($testTransaction, $transaction); } - public function testGetTransactionsLimitOffset(){ + public function testGetTransactionsLimitOffset() + { echo "Testing transaction::index\n"; - $transactions = transaction::index(10,0); + $transactions = $this->api->transaction()->index(10, 0); print_r($transactions); $this->assertEquals(10, count($transactions)); } - public function testCreateTransaction(){ + public function testCreateTransaction() + { echo "Testing transaction::create\n"; - $ref = "MyOrderId" . (string) rand(10, 100000); + $ref = "MyOrderId" . (string)rand(10, 100000); - $transaction = new transaction_model(array( - #"MerchantId" => "", + $transaction = array( "Amount" => 10, "PaymentRef" => $ref, - "Payment" => new credit_card(array( + "customerRef" => 1, + "Payment" => new CreditCard(array( "Holder" => "PHP SDK Test", "Cvv" => "200", "Expiry" => "0116", @@ -55,8 +71,6 @@ public function testCreateTransaction(){ "Currency" => "usd", "StoreCard" => true, "PlanId" => '', - #"CustomerRef" => "", - #"Hash" => "", "Webhook" => json_encode(array( "trigger" => "payment_success", "email" => "myname@domain.com" @@ -65,11 +79,13 @@ public function testCreateTransaction(){ "Process" => true, "SuccessUrl" => "", "ErrorUrl" => "" - )); + ); - $response = transaction::create($transaction); + $response = $this->api->transaction()->create($transaction); print_r($response); + + $this->assertEquals($ref, $response['payment_ref']); } diff --git a/tests/TestBase.php b/tests/TestBase.php new file mode 100644 index 0000000..0dc345f --- /dev/null +++ b/tests/TestBase.php @@ -0,0 +1,33 @@ +api = new \Mondido\Mondido($merchantId, $password, $secret); + } +} \ No newline at end of file diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php new file mode 100644 index 0000000..ee9e7a9 --- /dev/null +++ b/tests/WebhookTest.php @@ -0,0 +1,42 @@ +api->transaction()->create(array( + "card_number" => "4111111111111111", + "card_holder" => "php sdk", + "card_expiry" => "0116", + "card_cvv" => "200", + "card_type" => "VISA", + "amount" => "20.00", + "customer_ref" => 1, + "payment_ref" => $ref, + "currency" => "eur", + "test" => "true", + )); + $path = 'wh.json'; + file_put_contents($path, json_encode($transaction)); + + $transaction2 = webhook::get($path); + $this->assertEquals($transaction['id'], $transaction2['id']); + } +} diff --git a/wh.json b/wh.json deleted file mode 100644 index 77b8523..0000000 --- a/wh.json +++ /dev/null @@ -1 +0,0 @@ -{"id":443,"created_at":"2013-12-17T13:41:07Z","merchant_id":3,"amount":"480.0","payment_ref":null,"ref":null,"card_holder":"Annika Manns","card_number":"*****************1111","test":false,"metadata":{"user":{"email":"justmyemail@mondido.com"},"products":["awesomeness","coolness"]},"currency":"SEK","status":"approved","card_type":"VISA","transaction_type":null,"template_id":10,"error":null,"cost":{"percentual_fee":0,"fixed_fee":0,"percentual_exchange_fee":0,"total":"0.0"},"success_url":"https:\/\/mondido.com\/payment-ok?status=A","error_url":"https:\/\/mondido.com\/payment-error","stored_card":null,"customer":null,"subscription":null,"refunds":[],"webhooks":[]} \ No newline at end of file