From 417f9e7ca1f7446ba3d7b6685896f294b05b5e03 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Mon, 9 Jul 2018 17:23:17 +0545 Subject: [PATCH 1/8] Added support for creating token (bank account, credit card). --- LICENSE | 2 +- README.md | 72 ++++- composer.lock | 291 ++++++++++++++---- src/Gateway.php | 24 +- src/Message/AbstractRequest.php | 10 + .../CreateSingleUseBankTokenRequest.php | 39 +++ .../CreateSingleUseCardTokenRequest.php | 41 +++ 7 files changed, 412 insertions(+), 67 deletions(-) create mode 100644 src/Message/CreateSingleUseBankTokenRequest.php create mode 100644 src/Message/CreateSingleUseCardTokenRequest.php diff --git a/LICENSE b/LICENSE index 8f6176d..d5f67df 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 Steve Dixon +Copyright (c) 2018 Steve Dixon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 55cb038..76a536a 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ processing library for PHP 5.3+. This package implements PayWay REST API support This module aims to implement a usable subset of the [PayWay REST API](https://www.payway.com.au/rest-docs/index.html) (a product of Westpac Bank). The API is extensive, so the initial aim is to implement the following features: -* create and maintain customers -* generate single-use tokens -* take payments using tokenised credit card details (aiding PCI compliance) -* schedule regular payments +* Create and maintain customers +* Create single-use tokens (Credit Card, Bank Account) +* Take payments using tokenised credit card details (aiding PCI compliance) +* Schedule regular payments These initial features have now been implemented. @@ -24,3 +24,67 @@ Install the module using composer. composer require rotassator/omnipay-payway-restapi ``` +## Usage + +### Take Payment + +To take a one-time credit card payment. + +```php + + setApiKeyPublic('REPLACE'); + $gateway->setApiKeySecret('REPLACE'); + $gateway->setMerchantId('REPLACE'); + $gateway->setTestMode('REPLACE'); + + try { + $response = $gateway->createSingleUseCardToken(array( + 'card' => new CreditCard(array( + 'firstName' => 'Sujip', + 'lastName' => 'Thapa', + 'number' => '4564710000000004', + 'expiryMonth' => '02', + 'expiryYear' => '2019', + 'cvv' => '847', + )), + ))->send(); + + $singleUseTokenId = $response->getData('singleUseTokenId'); + } catch (Exception $e) { + // handle error + } + + if (empty($singleUseTokenId)) { + // handle error + } + + try { + $request = $gateway->purchase(array( + 'singleUseTokenId' => $singleUseTokenId, + 'customerNumber' => 'AB1245', + 'principalAmount' => '10.00', + 'currency' => 'AUD', + 'orderNumber' => 12, + )); + + $response = $request->send(); + + if ($response->isSuccessful()) { + // update order + // showpayment success message + } + } catch (Exception $e) { + // handle error + } + +``` diff --git a/composer.lock b/composer.lock index 0c2b37c..9c2676b 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,9 @@ { "_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", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "bc73204db0cb00cdabfe96e13fbb7d5d", "content-hash": "2dac005e232ac784a018d6b4f63c3ae6", "packages": [ { @@ -101,20 +100,20 @@ "web service" ], "abandoned": "guzzlehttp/guzzle", - "time": "2015-03-18 18:23:50" + "time": "2015-03-18T18:23:50+00:00" }, { "name": "omnipay/common", - "version": "v2.5.1", + "version": "2.5.2", "source": { "type": "git", "url": "https://github.com/thephpleague/omnipay-common.git", - "reference": "731386e54688405a475d6dd43cd6397728cd709e" + "reference": "54910f2ece6b1be64f5e53e2111dd1254d50ee49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/omnipay-common/zipball/731386e54688405a475d6dd43cd6397728cd709e", - "reference": "731386e54688405a475d6dd43cd6397728cd709e", + "url": "https://api.github.com/repos/thephpleague/omnipay-common/zipball/54910f2ece6b1be64f5e53e2111dd1254d50ee49", + "reference": "54910f2ece6b1be64f5e53e2111dd1254d50ee49", "shasum": "" }, "require": { @@ -199,20 +198,69 @@ "payment", "purchase" ], - "time": "2016-07-07 09:52:09" + "time": "2016-11-07T06:10:23+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v2.0.17", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d", + "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "time": "2018-07-04T16:31:37+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v2.8.13", + "version": "v2.8.42", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "25c576abd4e0f212e678fe8b2bd9a9a98c7ea934" + "reference": "9b69aad7d4c086dc94ebade2d5eb9145da5dac8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/25c576abd4e0f212e678fe8b2bd9a9a98c7ea934", - "reference": "25c576abd4e0f212e678fe8b2bd9a9a98c7ea934", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9b69aad7d4c086dc94ebade2d5eb9145da5dac8c", + "reference": "9b69aad7d4c086dc94ebade2d5eb9145da5dac8c", "shasum": "" }, "require": { @@ -220,7 +268,7 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5|~3.0.0", + "symfony/config": "^2.0.5|~3.0.0", "symfony/dependency-injection": "~2.6|~3.0.0", "symfony/expression-language": "~2.6|~3.0.0", "symfony/stopwatch": "~2.3|~3.0.0" @@ -259,33 +307,34 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-10-13 01:43:15" + "time": "2018-04-06T07:35:03+00:00" }, { "name": "symfony/http-foundation", - "version": "v3.1.6", + "version": "v3.4.12", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "f21e5a8b88274b7720779aa88f9c02c6d6ec08d7" + "reference": "1c28679fcbb0d9b35e4fd49fbb74d2ca4ea17bce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/f21e5a8b88274b7720779aa88f9c02c6d6ec08d7", - "reference": "f21e5a8b88274b7720779aa88f9c02c6d6ec08d7", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/1c28679fcbb0d9b35e4fd49fbb74d2ca4ea17bce", + "reference": "1c28679fcbb0d9b35e4fd49fbb74d2ca4ea17bce", "shasum": "" }, "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.1" + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.1", + "symfony/polyfill-php70": "~1.6" }, "require-dev": { - "symfony/expression-language": "~2.8|~3.0" + "symfony/expression-language": "~2.8|~3.0|~4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "3.4-dev" } }, "autoload": { @@ -312,20 +361,20 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "https://symfony.com", - "time": "2016-10-24 15:52:44" + "time": "2018-06-21T11:10:19+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.2.0", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "dff51f72b0706335131b00a7f49606168c582594" + "reference": "3296adf6a6454a050679cde90f95350ad604b171" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594", - "reference": "dff51f72b0706335131b00a7f49606168c582594", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", + "reference": "3296adf6a6454a050679cde90f95350ad604b171", "shasum": "" }, "require": { @@ -337,7 +386,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -371,7 +420,66 @@ "portable", "shim" ], - "time": "2016-05-18 14:26:46" + "time": "2018-04-26T10:06:28+00:00" + }, + { + "name": "symfony/polyfill-php70", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "77454693d8f10dd23bb24955cffd2d82db1007a6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/77454693d8f10dd23bb24955cffd2d82db1007a6", + "reference": "77454693d8f10dd23bb24955cffd2d82db1007a6", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0|~2.0", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2018-04-26T10:06:28+00:00" } ], "packages-dev": [ @@ -418,20 +526,20 @@ "keywords": [ "test" ], - "time": "2015-05-11 14:41:42" + "time": "2015-05-11T14:41:42+00:00" }, { "name": "mockery/mockery", - "version": "0.9.5", + "version": "0.9.9", "source": { "type": "git", - "url": "https://github.com/padraic/mockery.git", - "reference": "4db079511a283e5aba1b3c2fb19037c645e70fc2" + "url": "https://github.com/mockery/mockery.git", + "reference": "6fdb61243844dc924071d3404bb23994ea0b6856" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/4db079511a283e5aba1b3c2fb19037c645e70fc2", - "reference": "4db079511a283e5aba1b3c2fb19037c645e70fc2", + "url": "https://api.github.com/repos/mockery/mockery/zipball/6fdb61243844dc924071d3404bb23994ea0b6856", + "reference": "6fdb61243844dc924071d3404bb23994ea0b6856", "shasum": "" }, "require": { @@ -483,7 +591,7 @@ "test double", "testing" ], - "time": "2016-05-22 21:52:33" + "time": "2017-02-28T12:52:32+00:00" }, { "name": "omnipay/tests", @@ -540,7 +648,7 @@ "payment", "purchase" ], - "time": "2016-07-07 09:35:23" + "time": "2016-07-07T09:35:23+00:00" }, { "name": "phpunit/php-code-coverage", @@ -601,20 +709,20 @@ "testing", "xunit" ], - "time": "2014-09-02 10:13:14" + "time": "2014-09-02T10:13:14+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.1", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -648,7 +756,7 @@ "filesystem", "iterator" ], - "time": "2015-06-21 13:08:43" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -689,29 +797,34 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", - "version": "1.0.8", + "version": "1.0.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", - "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4|~5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -733,7 +846,7 @@ "keywords": [ "timer" ], - "time": "2016-05-12 18:03:57" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", @@ -783,7 +896,7 @@ "keywords": [ "tokenizer" ], - "time": "2014-03-03 05:10:30" + "time": "2014-03-03T05:10:30+00:00" }, { "name": "phpunit/phpunit", @@ -856,7 +969,7 @@ "testing", "xunit" ], - "time": "2014-10-17 09:04:17" + "time": "2014-10-17T09:04:17+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -905,7 +1018,7 @@ "mock", "xunit" ], - "time": "2013-01-13 10:24:48" + "time": "2013-01-13T10:24:48+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -980,24 +1093,80 @@ "phpcs", "standards" ], - "time": "2014-12-04 22:32:15" + "time": "2014-12-04T22:32:15+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-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": "2018-04-30T19:57:29+00:00" }, { "name": "symfony/yaml", - "version": "v2.8.13", + "version": "v2.8.42", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "396784cd06b91f3db576f248f2402d547a077787" + "reference": "51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/396784cd06b91f3db576f248f2402d547a077787", - "reference": "396784cd06b91f3db576f248f2402d547a077787", + "url": "https://api.github.com/repos/symfony/yaml/zipball/51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff", + "reference": "51356b7a2ff7c9fd06b2f1681cc463bb62b5c1ff", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-ctype": "~1.8" }, "type": "library", "extra": { @@ -1029,7 +1198,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-10-21 20:59:10" + "time": "2018-05-01T22:52:40+00:00" } ], "aliases": [], diff --git a/src/Gateway.php b/src/Gateway.php index eac709f..77c9608 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -18,7 +18,7 @@ public function getDefaultParameters() return array( 'apiKeyPublic' => '', 'apiKeySecret' => '', - 'merchantId' => '', + 'merchantId' => '', 'useSecretKey' => false, ); } @@ -109,6 +109,28 @@ public function purchase(array $parameters = array()) return $this->createRequest('\Omnipay\PaywayRest\Message\PurchaseRequest', $parameters); } + /** + * Create singleUseTokenId with a CreditCard + * + * @param array $parameters + * @return \Omnipay\PaywayRest\Message\CreateCustomerRequest + */ + public function createSingleUseCardToken(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaywayRest\Message\CreateSingleUseCardTokenRequest', $parameters); + } + + /** + * Create singleUseTokenId with a Bank Account + * + * @param array $parameters + * @return \Omnipay\PaywayRest\Message\CreateCustomerRequest + */ + public function createSingleUseBankToken(array $parameters = array()) + { + return $this->createRequest('\Omnipay\PaywayRest\Message\CreateSingleUseBankTokenRequest', $parameters); + } + /** * Create Customer * diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 7600249..b6c90f1 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -202,6 +202,16 @@ public function setBankAccountId($value) return $this->setParameter('bankAccountId', $value); } + public function getBankAccountNumber() + { + return $this->getParameter('bankAccountNumber'); + } + + public function setBankAccountNumber($value) + { + return $this->getParameter('bankAccountNumber', $value); + } + public function getCustomerName() { return $this->getParameter('customerName'); diff --git a/src/Message/CreateSingleUseBankTokenRequest.php b/src/Message/CreateSingleUseBankTokenRequest.php new file mode 100644 index 0000000..e7fedb4 --- /dev/null +++ b/src/Message/CreateSingleUseBankTokenRequest.php @@ -0,0 +1,39 @@ +validate('bsb', 'accountNumber', 'accountName'); + + return array( + 'paymentMethod' => 'bankAccount', + 'bsb' => $this->getBankAccountId(), + 'accountNumber' => $this->getBankAccountNumber(), + 'accountName' => $this->getCustomerName(), + ); + } + + /** + * @return mixed + */ + public function getEndpoint() + { + return $this->endpoint . '/single-use-tokens'; + } + + public function getHttpMethod() + { + return 'POST'; + } +} diff --git a/src/Message/CreateSingleUseCardTokenRequest.php b/src/Message/CreateSingleUseCardTokenRequest.php new file mode 100644 index 0000000..a54d2a4 --- /dev/null +++ b/src/Message/CreateSingleUseCardTokenRequest.php @@ -0,0 +1,41 @@ +getCard()->validate(); + + return array( + 'paymentMethod' => 'creditCard', + 'cardNumber' => $this->getCard()->getNumber(), + 'cardholderName' => $this->getCard()->getName(), + 'cvn' => $this->getCard()->getCvv(), + 'expiryDateMonth' => $this->getCard()->getExpiryMonth(), + 'expiryDateYear' => $this->getCard()->getExpiryYear(), + ); + } + + /** + * @return mixed + */ + public function getEndpoint() + { + return $this->endpoint . '/single-use-tokens'; + } + + public function getHttpMethod() + { + return 'POST'; + } +} From b6319c149ee8c94fd84ad4bce1f4096a3dc0b2ad Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Mon, 9 Jul 2018 18:38:24 +0545 Subject: [PATCH 2/8] Adding fix for issue in create token with Bank Account --- README.md | 112 ++++++++++-------- src/Message/AbstractRequest.php | 22 +++- .../CreateSingleUseBankTokenRequest.php | 6 +- 3 files changed, 84 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 76a536a..d7649f8 100644 --- a/README.md +++ b/README.md @@ -31,60 +31,68 @@ composer require rotassator/omnipay-payway-restapi To take a one-time credit card payment. ```php - - setApiKeyPublic('REPLACE'); - $gateway->setApiKeySecret('REPLACE'); - $gateway->setMerchantId('REPLACE'); - $gateway->setTestMode('REPLACE'); - - try { - $response = $gateway->createSingleUseCardToken(array( - 'card' => new CreditCard(array( - 'firstName' => 'Sujip', - 'lastName' => 'Thapa', - 'number' => '4564710000000004', - 'expiryMonth' => '02', - 'expiryYear' => '2019', - 'cvv' => '847', - )), - ))->send(); - - $singleUseTokenId = $response->getData('singleUseTokenId'); - } catch (Exception $e) { - // handle error +setApiKeyPublic('REPLACE'); +$gateway->setApiKeySecret('REPLACE'); +$gateway->setMerchantId('REPLACE'); +$gateway->setTestMode(true); + +try { + $response = $gateway->createSingleUseCardToken([ + 'card' => new CreditCard([ + 'firstName' => 'Steve', + 'lastName' => 'Dixon', + 'number' => '4564710000000004', + 'expiryMonth' => '02', + 'expiryYear' => '2019', + 'cvv' => '847', + ]), + ])->send(); + + $singleUseTokenId = $response->getData('singleUseTokenId'); +} catch (Exception $e) { + // handle error +} + +if (empty($singleUseTokenId)) { + // handle error +} + +try { + $request = $gateway->purchase([ + 'singleUseTokenId' => $singleUseTokenId, + 'customerNumber' => 'AB1245', + 'principalAmount' => '10.00', + 'currency' => 'AUD', + 'orderNumber' => 12, + ]); + + $response = $request->send(); + + if ($response->isSuccessful()) { + // update order } +} catch (Exception $e) { + // handle error +} - if (empty($singleUseTokenId)) { - // handle error - } +// create Bank Account single-use token. - try { - $request = $gateway->purchase(array( - 'singleUseTokenId' => $singleUseTokenId, - 'customerNumber' => 'AB1245', - 'principalAmount' => '10.00', - 'currency' => 'AUD', - 'orderNumber' => 12, - )); - - $response = $request->send(); - - if ($response->isSuccessful()) { - // update order - // showpayment success message - } - } catch (Exception $e) { - // handle error - } +$response = $gateway->createSingleUseBankToken([ + 'bankAccountBsb' => '999999', + 'bankAccountNumber' => '999999999', + 'bankAccountName' => 'Steve Dixon', +])->send(); + +$singleUseTokenId = $response->getData('singleUseTokenId'); ``` diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index b6c90f1..6bd5e6f 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -202,6 +202,16 @@ public function setBankAccountId($value) return $this->setParameter('bankAccountId', $value); } + public function getBankAccountBsb() + { + return $this->getParameter('bankAccountBsb'); + } + + public function setBankAccountBsb($value) + { + return $this->setParameter('bankAccountBsb', $value); + } + public function getBankAccountNumber() { return $this->getParameter('bankAccountNumber'); @@ -209,7 +219,17 @@ public function getBankAccountNumber() public function setBankAccountNumber($value) { - return $this->getParameter('bankAccountNumber', $value); + return $this->setParameter('bankAccountNumber', $value); + } + + public function getBankAccountName() + { + return $this->getParameter('bankAccountName'); + } + + public function setBankAccountName($value) + { + return $this->setParameter('bankAccountName', $value); } public function getCustomerName() diff --git a/src/Message/CreateSingleUseBankTokenRequest.php b/src/Message/CreateSingleUseBankTokenRequest.php index e7fedb4..427d66f 100644 --- a/src/Message/CreateSingleUseBankTokenRequest.php +++ b/src/Message/CreateSingleUseBankTokenRequest.php @@ -14,13 +14,13 @@ class CreateSingleUseBankTokenRequest extends AbstractRequest { public function getData() { - $this->validate('bsb', 'accountNumber', 'accountName'); + $this->validate('bankAccountBsb', 'bankAccountNumber', 'bankAccountName'); return array( 'paymentMethod' => 'bankAccount', - 'bsb' => $this->getBankAccountId(), + 'bsb' => $this->getBankAccountBsb(), 'accountNumber' => $this->getBankAccountNumber(), - 'accountName' => $this->getCustomerName(), + 'accountName' => $this->getBankAccountName(), ); } From a4e95ccb711ec6446ba32b95f34b3d9f008d5d24 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Mon, 9 Jul 2018 18:40:24 +0545 Subject: [PATCH 3/8] Added fix for doc block --- src/Gateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 77c9608..b799aad 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -113,7 +113,7 @@ public function purchase(array $parameters = array()) * Create singleUseTokenId with a CreditCard * * @param array $parameters - * @return \Omnipay\PaywayRest\Message\CreateCustomerRequest + * @return \Omnipay\PaywayRest\Message\CreateSingleUseCardTokenRequest */ public function createSingleUseCardToken(array $parameters = array()) { @@ -124,7 +124,7 @@ public function createSingleUseCardToken(array $parameters = array()) * Create singleUseTokenId with a Bank Account * * @param array $parameters - * @return \Omnipay\PaywayRest\Message\CreateCustomerRequest + * @return \Omnipay\PaywayRest\Message\CreateSingleUseBankTokenRequest */ public function createSingleUseBankToken(array $parameters = array()) { From 3956ed99bb65e0ae8a64259bbac0a7580eb5a865 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Mon, 9 Jul 2018 18:48:43 +0545 Subject: [PATCH 4/8] Added fix for expiryDateMonth, it requires 2 digit month (02) --- src/Message/CreateSingleUseCardTokenRequest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Message/CreateSingleUseCardTokenRequest.php b/src/Message/CreateSingleUseCardTokenRequest.php index a54d2a4..207b8d7 100644 --- a/src/Message/CreateSingleUseCardTokenRequest.php +++ b/src/Message/CreateSingleUseCardTokenRequest.php @@ -16,12 +16,17 @@ public function getData() { $this->getCard()->validate(); + // PayWay requires two digit expiry month. + $expiryDateMonth = $this->getCard()->getExpiryMonth() > 9 + ? $this->getCard()->getExpiryMonth() + : '0'.$this->getCard()->getExpiryMonth(); + return array( 'paymentMethod' => 'creditCard', 'cardNumber' => $this->getCard()->getNumber(), 'cardholderName' => $this->getCard()->getName(), 'cvn' => $this->getCard()->getCvv(), - 'expiryDateMonth' => $this->getCard()->getExpiryMonth(), + 'expiryDateMonth' => $expiryDateMonth, 'expiryDateYear' => $this->getCard()->getExpiryYear(), ); } From 5d48ed9fa9476b71675fae471100b73406598bd0 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Mon, 9 Jul 2018 19:07:09 +0545 Subject: [PATCH 5/8] Added correct class doc block --- src/Message/CreateSingleUseBankTokenRequest.php | 2 +- src/Message/CreateSingleUseCardTokenRequest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/CreateSingleUseBankTokenRequest.php b/src/Message/CreateSingleUseBankTokenRequest.php index 427d66f..bbedbe2 100644 --- a/src/Message/CreateSingleUseBankTokenRequest.php +++ b/src/Message/CreateSingleUseBankTokenRequest.php @@ -1,7 +1,7 @@ Date: Mon, 9 Jul 2018 19:09:23 +0545 Subject: [PATCH 6/8] Added correct class doc block --- src/Message/CreateSingleUseBankTokenRequest.php | 2 +- src/Message/CreateSingleUseCardTokenRequest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/CreateSingleUseBankTokenRequest.php b/src/Message/CreateSingleUseBankTokenRequest.php index bbedbe2..55b13a0 100644 --- a/src/Message/CreateSingleUseBankTokenRequest.php +++ b/src/Message/CreateSingleUseBankTokenRequest.php @@ -6,7 +6,7 @@ namespace Omnipay\PaywayRest\Message; /** - * PaywayRest Create Customer Request + * PaywayRest Create Single Use Bank Account Token Request * * @link https://www.payway.com.au/docs/rest.html#tokenise-a-bank-account */ diff --git a/src/Message/CreateSingleUseCardTokenRequest.php b/src/Message/CreateSingleUseCardTokenRequest.php index e9d3794..20a15b5 100644 --- a/src/Message/CreateSingleUseCardTokenRequest.php +++ b/src/Message/CreateSingleUseCardTokenRequest.php @@ -6,7 +6,7 @@ namespace Omnipay\PaywayRest\Message; /** - * PaywayRest Create Customer Request + * PaywayRest Create Single Use Card Token Request * * @link https://www.payway.com.au/docs/rest.html#tokenise-a-credit-card */ From 0fcf728790289b84c02d95b689408995ffe0dab4 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Tue, 10 Jul 2018 09:08:19 +0545 Subject: [PATCH 7/8] Little clean up --- README.md | 20 +++++++------------ .../CreateSingleUseCardTokenRequest.php | 4 +--- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d7649f8..8f58fd5 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ $gateway->setTestMode(true); try { $response = $gateway->createSingleUseCardToken([ 'card' => new CreditCard([ - 'firstName' => 'Steve', - 'lastName' => 'Dixon', + 'firstName' => 'First Name', + 'lastName' => 'Last Name', 'number' => '4564710000000004', 'expiryMonth' => '02', 'expiryYear' => '2019', @@ -59,15 +59,11 @@ try { ])->send(); $singleUseTokenId = $response->getData('singleUseTokenId'); -} catch (Exception $e) { - // handle error -} -if (empty($singleUseTokenId)) { - // handle error -} + if (empty($singleUseTokenId)) { + // handle error + } -try { $request = $gateway->purchase([ 'singleUseTokenId' => $singleUseTokenId, 'customerNumber' => 'AB1245', @@ -85,14 +81,12 @@ try { // handle error } -// create Bank Account single-use token. - +// Example for creating single-use token with Bank Account $response = $gateway->createSingleUseBankToken([ 'bankAccountBsb' => '999999', 'bankAccountNumber' => '999999999', - 'bankAccountName' => 'Steve Dixon', + 'bankAccountName' => 'Your Name', ])->send(); $singleUseTokenId = $response->getData('singleUseTokenId'); - ``` diff --git a/src/Message/CreateSingleUseCardTokenRequest.php b/src/Message/CreateSingleUseCardTokenRequest.php index 20a15b5..4ff53d1 100644 --- a/src/Message/CreateSingleUseCardTokenRequest.php +++ b/src/Message/CreateSingleUseCardTokenRequest.php @@ -17,9 +17,7 @@ public function getData() $this->getCard()->validate(); // PayWay requires two digit expiry month. - $expiryDateMonth = $this->getCard()->getExpiryMonth() > 9 - ? $this->getCard()->getExpiryMonth() - : '0'.$this->getCard()->getExpiryMonth(); + $expiryDateMonth = str_pad($this->getCard()->getExpiryMonth(), 2, 0, STR_PAD_LEFT); return array( 'paymentMethod' => 'creditCard', From 38a4a0be78a0d60353f3680b5c3ec2632599af22 Mon Sep 17 00:00:00 2001 From: Sujip Thapa Date: Tue, 24 Jul 2018 08:36:05 +0545 Subject: [PATCH 8/8] Keeping the original stuff back --- LICENSE | 2 +- src/Gateway.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index d5f67df..8f6176d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Steve Dixon +Copyright (c) 2016 Steve Dixon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/Gateway.php b/src/Gateway.php index b799aad..bfd627d 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -18,7 +18,7 @@ public function getDefaultParameters() return array( 'apiKeyPublic' => '', 'apiKeySecret' => '', - 'merchantId' => '', + 'merchantId' => '', 'useSecretKey' => false, ); }