Skip to content

Commit f47b18a

Browse files
committed
First commit
1 parent aa9b805 commit f47b18a

25 files changed

+1185
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
/.idea/
3+
composer.lock

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- composer install -n --dev --prefer-source
12+
13+
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text

README.md

Lines changed: 171 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,172 @@
1-
omnipay-ym
2-
==========
1+
# Omnipay: Yandex.Money
32

4-
Yandex.Money payments provider for Omnipay
3+
**Yandex.Money driver for the Omnipay PHP payment processing library**
4+
5+
[![Build Status](https://travis-ci.org/lazychaser/omnipay-ym.png?branch=master)](https://travis-ci.org/lazychaser/omnipay-ym)
6+
[![Latest Stable Version](https://poser.pugx.org/omnipay/ym/version.png)](https://packagist.org/packages/omnipay/ym)
7+
[![Total Downloads](https://poser.pugx.org/omnipay/ym/d/total.png)](https://packagist.org/packages/omnipay/ym)
8+
9+
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
10+
processing library for PHP 5.3+. This package implements PayPal support for Omnipay.
11+
12+
## Installation
13+
14+
Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it
15+
to your `composer.json` file:
16+
17+
```json
18+
{
19+
"require": {
20+
"omnipay/ym": "~1.0"
21+
}
22+
}
23+
```
24+
25+
And run composer to update your dependencies:
26+
27+
$ curl -s http://getcomposer.org/installer | php
28+
$ php composer.phar update
29+
30+
## Basic Usage
31+
32+
The following gateways are provided by this package:
33+
34+
* YM_External
35+
36+
Since Yandex.Money API handles payments a little bit differently, there are now standard methods like `purchase` for
37+
this gateway. You can find usage samples below.
38+
39+
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
40+
repository. You can also visit [Yandex.Money API page](https://tech.yandex.ru/money/).
41+
42+
## Examples
43+
44+
### Setting up a gateway
45+
46+
```php
47+
$gateway = Omniplay::create('YM_External');
48+
49+
$gateway->setWalledId('my wallet id'); // The id of the wallet that will receive payments
50+
$gateway->setInstanceId('my instance id'); // A unique id, see below
51+
```
52+
53+
You can get your instance id from your client id:
54+
55+
```php
56+
$instanceId = $gateway->obtainInstanceId($clientId);
57+
58+
//store the instance id somewhere for further payments
59+
```
60+
61+
__IMPORTANT!__ You do not need to obtain instance id for each payment! It is retrieved only once per app.
62+
63+
### Creating a purchase
64+
65+
```php
66+
$response = $gateway->requestPayment(array( 'amount' => 10.0 ))->send();
67+
68+
if ( ! $response->isSuccessful())
69+
{
70+
// display error
71+
}
72+
73+
$transactionReference = $response->getTransactionReference();
74+
75+
// Save the transaction reference somewhere because we'll need one later to complete the purchase
76+
77+
$response = $gateway->processPayment(array(
78+
'transactionReference' => $transactionReference,
79+
'returnUrl' => '...',
80+
'cancelUrl' => '...',
81+
))->send();
82+
83+
if ($response->isRedirect()) $response->redirect();
84+
85+
// couldn't process the payment, show error
86+
```
87+
88+
### Completing the purchase
89+
90+
After customer fills required data, he'll be redirected to `returnUrl` where you need to complete the purchase:
91+
92+
```php
93+
// Retrieve previously stored transaction reference
94+
$transactionReference = ...;
95+
96+
// Same options here
97+
$response = $gateway->processPayment(...);
98+
99+
if ($response->isSuccessful())
100+
{
101+
// All done!
102+
// We can get internal invoice id of the payment
103+
$invoiceId = $response->getTransactionReference();
104+
}
105+
else
106+
{
107+
// Payment failed
108+
}
109+
```
110+
111+
### Saving customer's card
112+
113+
After successful payment it is possible to save the card for further payments. You just need transaction reference which
114+
you've got when created payment.
115+
116+
```php
117+
// Same options as for processPayment method
118+
$response = $gateway->createCard(...);
119+
120+
if ($response->isSuccessful() and ($cardReference = $response->getCardReference()))
121+
{
122+
// Store card reference somewhere
123+
124+
// You can also get extra info:
125+
$cardNumber = $response->getCardNumber();
126+
$cardType = $response->getCardType();
127+
}
128+
```
129+
130+
Note that response may be successful but have no info about card.
131+
132+
To make a purchase using a card, you need a card reference and `cvv` code:
133+
134+
```php
135+
$response = $gateway->requestPayment(array('amount' => 10.0))->send();
136+
137+
// Check status
138+
139+
$response = $gateway->processPayment(array(
140+
'transactionReference' => $response->getTransactionReference(),
141+
142+
..., // same options
143+
144+
'cardReference' => $cardReference,
145+
'cvv' => $cvv, // a user should enter this value
146+
));
147+
148+
if ($response->isSuccessful())
149+
{
150+
// Payment done!
151+
}
152+
elseif ($response->isRedirect())
153+
{
154+
// Confirmation required!
155+
$response->redirect();
156+
}
157+
158+
// Payment failed!
159+
```
160+
161+
## Support
162+
163+
If you are having general issues with Omnipay, we suggest posting on
164+
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
165+
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.
166+
167+
If you want to keep up to date with release anouncements, discuss ideas for the project,
168+
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
169+
you can subscribe to.
170+
171+
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/lazychaser/omnipay-ym/issues),
172+
or better yet, fork the library and submit a pull request.

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "omnipay/ym",
3+
"type": "library",
4+
"description": "Yandex.Money gateway for Omnipay payment processing library",
5+
6+
"license": "MIT",
7+
8+
"authors": [
9+
{
10+
"name": "Alexander Kalnoy",
11+
"email": "[email protected]"
12+
}
13+
],
14+
15+
"require": {
16+
"omnipay/common": "~2.0"
17+
},
18+
19+
"require-dev": {
20+
"omnipay/tests": "~2.0"
21+
},
22+
23+
"autoload": {
24+
"psr-4": { "Omnipay\\YM\\": "src/" }
25+
}
26+
27+
}

phpunit.xml.dist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="Omnipay Test Suite">
14+
<directory>./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<listeners>
18+
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" />
19+
</listeners>
20+
<filter>
21+
<whitelist>
22+
<directory>./src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/ExternalGateway.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace Omnipay\YM;
4+
5+
use Guzzle\Http\Message\Response;
6+
use Omnipay\Common\AbstractGateway;
7+
use Omnipay\Common\Exception\InvalidResponseException;
8+
use Omnipay\Common\Message\AbstractResponse;
9+
10+
class ExternalGateway extends AbstractGateway {
11+
12+
/**
13+
* Get gateway display name
14+
*
15+
* This can be used by carts to get the display name for each gateway.
16+
*/
17+
public function getName()
18+
{
19+
return 'Yandex.Money External';
20+
}
21+
22+
/**
23+
* @param $value
24+
*
25+
* @return $this
26+
*/
27+
public function setInstanceId($value)
28+
{
29+
return $this->setParameter('instanceId', $value);
30+
}
31+
32+
/**
33+
* @return mixed
34+
*/
35+
public function getInstanceId()
36+
{
37+
return $this->getParameter('instanceId');
38+
}
39+
40+
/**
41+
* @param $value
42+
*
43+
* @return $this
44+
*/
45+
public function setWalletId($value)
46+
{
47+
return $this->setParameter('walletId', $value);
48+
}
49+
50+
/**
51+
* @return mixed
52+
*/
53+
public function getWalletId()
54+
{
55+
return $this->getParameter('walletId');
56+
}
57+
58+
/**
59+
* Get instance id that is required for other operations.
60+
*
61+
* @param $clientId
62+
*
63+
* @return string
64+
*
65+
* @throws InvalidResponseException
66+
*/
67+
public function obtainInstanceId($clientId)
68+
{
69+
/** @var AbstractResponse $response */
70+
$response = $this->createRequest('Omnipay\YM\Message\InstanceIdRequest', compact('clientId'))->send();
71+
72+
if ( ! $response->isSuccessful())
73+
{
74+
throw new InvalidResponseException($response->getMessage());
75+
}
76+
77+
return $response->getTransactionReference();
78+
}
79+
80+
/**
81+
* @param array $parameters
82+
*
83+
* @return Message\RequestExternalPaymentRequest
84+
*/
85+
public function requestPayment(array $parameters = array())
86+
{
87+
return $this->createRequest('Omnipay\YM\Message\RequestExternalPaymentRequest', $parameters);
88+
}
89+
90+
/**
91+
* @param array $parameters
92+
*
93+
* @return Message\ProcessExternalPaymentRequest
94+
*/
95+
public function processPayment(array $parameters = array())
96+
{
97+
return $this->createRequest('Omnipay\YM\Message\ProcessExternalPaymentRequest', $parameters);
98+
}
99+
100+
/**
101+
* @param array $parameters
102+
*
103+
* @return Message\CreateCardRequest
104+
*/
105+
public function createCard(array $parameters = array())
106+
{
107+
return $this->createRequest('Omnipay\YM\Message\CreateCardRequest', $parameters);
108+
}
109+
110+
}

0 commit comments

Comments
 (0)