|
1 | | -omnipay-ym |
2 | | -========== |
| 1 | +# Omnipay: Yandex.Money |
3 | 2 |
|
4 | | -Yandex.Money payments provider for Omnipay |
| 3 | +**Yandex.Money driver for the Omnipay PHP payment processing library** |
| 4 | + |
| 5 | +[](https://travis-ci.org/lazychaser/omnipay-ym) |
| 6 | +[](https://packagist.org/packages/omnipay/ym) |
| 7 | +[](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. |
0 commit comments