diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cd8eb86 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc90948 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +__MACOSX__ + diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..247a09c --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: psr2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4683553 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +We accept contributions via Pull Requests on [Github](https://github.com/jaysson/omnipay-payubiz). + +**Happy coding**! diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a1832df --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) 2016 Prabhakar Bhat + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f1b0ea9 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# OmniPay PayUBiz + +Integrates PayUBiz payment gateway with Omnipay. + +## Install + +Via Composer + +``` bash +$ composer require jaysson/omnipay-payubiz +``` + +## Usage + +### Configuration +``` php +$gateway = OmniAuth::create('PayUBiz'); +$gateway->setKey(MERCHANT_ID); +$gateway->setSalt(PAYU_SALT); +$params = [ + 'name' => $user->name, + 'email' => $user->email, + 'amount' => $product->amount, + 'product' => $product->name, + 'transactionId' => uniqid(), + 'failureUrl' => url('api/v1/checkout/failed'), + 'returnUrl' => url('api/v1/checkout/thank-you') +]; + +$gateway->purchase($params)->send()->redirect(); +``` +Check official omniauth documentation for more + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. + +## Security + +If you discover any security related issues, please email prabhakarbhat@live.com instead of using the issue tracker. + +## Credits +- [Prabhakar Bhat][link-author] + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + +[ico-version]: https://img.shields.io/packagist/v/jaysson/omnipay-payubiz.svg?style=flat-square +[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square +[ico-downloads]: https://img.shields.io/packagist/dt/jaysson/omnipay-payubiz.svg?style=flat-square + +[link-packagist]: https://packagist.org/packages/jaysson/omnipay-payubiz +[link-downloads]: https://packagist.org/packages/jaysson/omnipay-payubiz +[link-author]: https://github.com/jaysson diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8bc6a76 --- /dev/null +++ b/composer.json @@ -0,0 +1,34 @@ +{ + "name": "jaysson/omnipay-payubiz", + "type": "library", + "description": "Integrates PayUBiz payment gateway with omnipay", + "keywords": [ + "jaysson", + "omnipay", + "payubiz", + "payu" + ], + "homepage": "https://github.com/jaysson/omnipay-payubiz", + "license": "MIT", + "authors": [ + { + "name": "Prabhakar Bhat", + "email": "prabhakarbhat@live.com", + "homepage": "http://prabhakarbhat.com", + "role": "Developer" + } + ], + "require": { + "php": "~5.5|~7.0" + }, + "autoload": { + "psr-4": { + "Omnipay\\PayUBiz\\": "src" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + } +} diff --git a/src/Gateway.php b/src/Gateway.php new file mode 100644 index 0000000..e51de7a --- /dev/null +++ b/src/Gateway.php @@ -0,0 +1,41 @@ +setParameter('key', $key); + } + + public function setSalt($salt) + { + $this->setParameter('salt', $salt); + } + + public function purchase(array $parameters = []) + { + return $this->createRequest('\Omnipay\PayUBiz\PurchaseRequest', $parameters); + } + + public function getDefaultParameters() + { + return [ + 'salt' => '', + 'key' => '' + ]; + } +} \ No newline at end of file diff --git a/src/PurchaseRequest.php b/src/PurchaseRequest.php new file mode 100644 index 0000000..65b8bc7 --- /dev/null +++ b/src/PurchaseRequest.php @@ -0,0 +1,130 @@ +getParameter('key'); + $data['txnid'] = $this->getTransactionId(); + $data['amount'] = $this->getAmount(); + $data['productinfo'] = $this->getParameter('product'); + $data['firstname'] = $this->getParameter('firstName') ?: $this->getParameter('name'); + $data['hash'] = $this->getHash(); + $data['lastname'] = $this->getParameter('lastName'); + $data['email'] = $this->getParameter('email'); + $data['curl'] = $this->getCancelUrl(); + $data['furl'] = $this->getParameter('failureUrl'); + $data['surl'] = $this->getReturnUrl(); + return $data; + } + + public function setSalt($salt) + { + $this->setParameter('salt', $salt); + } + + public function setKey($merchantId) + { + $this->setParameter('key', $merchantId); + } + + public function setName($name) + { + $this->setParameter('name', $name); + } + + public function setProduct($productInfo) + { + $this->setParameter('product', $productInfo); + } + + public function setFirstName($name) + { + $this->setParameter('first_name', $name); + } + + public function setLastName($name) + { + $this->setParameter('last_name', $name); + } + + public function setEmail($email) + { + $this->setParameter('email', $email); + } + + public function setFailureUrl($furl) + { + $this->setParameter('failureUrl', $furl); + } + + public function setUdf($index, $value) + { + if ($index <= 10 && $index > 0) { + $this->setParameter('udf' . $index, $value); + } + } + + public function getUdf() + { + return array_map(function ($index) { + return $this->getParameter('udf' . $index); + }, range(1, 10)); + } + + /** + * Send the request with specified data + * + * @param mixed $data The data to send + * @return ResponseInterface + */ + public function sendData($data) + { + return $this->response = new PurchaseResponse($this, $data); + } + + public function getEndPoint() + { + return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; + } + + private function getHash() + { + $values = $this->gatewayParams(); + $string = join('|', $values); + return strtolower(hash('sha512', $string)); + } + + /** + * @return array + */ + private function gatewayParams() + { + $payUParams = array_map(function ($item) { + return $this->getParameter($item); + }, ['key', 'transactionId', 'amount', 'product']); + $additional = [ + $this->getParameter('firstName') ?: $this->getParameter('name'), + $this->getParameter('email') + ]; + $udf = $this->getUdf(); + $values = array_merge($payUParams, $additional, $udf); + $values[] = $this->getParameter('salt'); + return $values; + } +} \ No newline at end of file diff --git a/src/PurchaseResponse.php b/src/PurchaseResponse.php new file mode 100644 index 0000000..3e8053e --- /dev/null +++ b/src/PurchaseResponse.php @@ -0,0 +1,45 @@ +getRequest()->getEndPoint(); + } + + public function getRedirectMethod() + { + return 'POST'; + } + + public function getRedirectData() + { + return $this->data; + } +} \ No newline at end of file