-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prabhakar Bhat
committed
Apr 28, 2016
0 parents
commit da1a127
Showing
10 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
__MACOSX__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: psr2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Prabhakar Bhat <[email protected]> | ||
|
||
> 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]", | ||
"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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayUBiz; | ||
|
||
use Omnipay\Common\AbstractGateway; | ||
|
||
class Gateway extends AbstractGateway | ||
{ | ||
/** | ||
* Get gateway display name | ||
* | ||
* This can be used by carts to get the display name for each gateway. | ||
*/ | ||
public function getName() | ||
{ | ||
return 'PayUBiz'; | ||
} | ||
|
||
public function setKey($key) | ||
{ | ||
$this->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' => '' | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayUBiz; | ||
|
||
use Omnipay\Common\Message\AbstractRequest; | ||
use Omnipay\Common\Message\ResponseInterface; | ||
|
||
class PurchaseRequest extends AbstractRequest | ||
{ | ||
protected $liveEndpoint = 'https://secure.payu.in/_payment'; | ||
protected $testEndpoint = 'https://test.payu.in/_payment'; | ||
|
||
/** | ||
* Get the raw data array for this message. The format of this varies from gateway to | ||
* gateway, but will usually be either an associative array, or a SimpleXMLElement. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
$data = []; | ||
$data['key'] = $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayUBiz; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RedirectResponseInterface; | ||
|
||
class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface | ||
{ | ||
public function __construct(PurchaseRequest $request, $data) | ||
{ | ||
parent::__construct($request, $data); | ||
} | ||
/** | ||
* Is the response successful? | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
return false; | ||
} | ||
|
||
public function isRedirect(){ | ||
return true; | ||
} | ||
|
||
/** | ||
* Gets the redirect target url. | ||
*/ | ||
public function getRedirectUrl() | ||
{ | ||
return $this->getRequest()->getEndPoint(); | ||
} | ||
|
||
public function getRedirectMethod() | ||
{ | ||
return 'POST'; | ||
} | ||
|
||
public function getRedirectData() | ||
{ | ||
return $this->data; | ||
} | ||
} |