Documentation on accepting Yandex.Money does not contain a specific example in PHP, so that you can fasten everything as quickly as possible without understanding all the details of how Yandex.Money reception in PHP works. Having made an automatic reception of Yandex.Money in
itsoft.ru , our company, I would like to give step-by-step instructions with PHP code examples in order to significantly save time for other developers.
Initially, the automatic reception Yandex. Money seemed to me very difficult. But as it turned out, everything is easier than WebMoney.
Step 1: Create an HTML form for receiving payments
The form code itself can be generated here
money.yandex.ru/embed/quickpay/shop.xml But since our goal is to accept payments automatically, in the HTML form we need to add the id of the account that the client pays us. And most likely, we want to receive the full amount of the bill, i.e. we want the Yandex commission to pay 0.05% for the client, therefore as a result the HTML form
in our php script it will be generated like this:
$sum = 1.005*$i->itsum; print <<<HTML <p> . 0.5%. , , , /1.005. , , . </p> <p> <b> online, .</b> </p> <iframe allowtransparency="true" src="https://money.yandex.ru/embed/shop.xml?uid=4100138353971&writer=seller&targets=i$i->id&default-sum=$sum&button-text=01&hint=" frameborder="0" height="163" scrolling="no" width="450"></iframe> HTML;
')
Notice the two variables $ sum and $ i-> id
We also added a warning that payments with a protection code cannot be credited automatically, since our system, the protection code cannot guess at all
By implementing this form on your website, you can already receive money on your Yandex.Walker and see by what account number the payment was made. To automatically credit a payment, follow the steps below.
Step 2: Download the PHP library for working with the Yandex.Money API
You can get the library here
github.com/melnikovdv/PHP-Yandex.Money-API-SDKNext, you need to unzip it and copy it to your site, for example, to the / invoice / ym / directory
In your / invoice / ym / directory, the lib and sample folders should appear, respectively.
Step 3: Register the application for working with the Yandex.Money API
This can be done here
sp-money.yandex.ru/myservices/new.xmlFor example, we have the following values:
Name of your application:
(users will see it, giving the application rights) ITSoft
Your website address:
itsoft.ruRedirect uri:
itsoft.ru/invoice/ym/sample/index.php(the address to which the Yandex.Money server will redirect after the user allows or denies access; corresponds to the redirect_uri parameter in the documentation)
Use application authentication Yes
- After registering the application, you will see the “Application ID” and “OAuth2 client_secret:”
If you lose them all of a sudden, you can always get them in the settings of your Yandex.Money account in the My Applications section
sp-money.yandex.ru/tunes.xml?from=bal , on the right is the "Configure" button.
The application identifier and “OAuth2 client_secret” must be copied to the file /invoice/ym/sample/consts.php
In the same place, initialize REDIRECT_URI to
yourdomain.ru/invoice/ym/sample/index.phpStep 4: Get the token to work with your Yandex.Koshelk using the PHP library
In the script
yourdomain.ru/invoice/ym/sample/index.php you need to comment out
following lines:
//cm. lines 10-16 and comment as shown below, we will not need these operations, so we will not request permission for them
$scope = "account-info " . "operation-history " . "operation-details " ; $authUri = YandexMoneyNew::authorizeUri(CLIENT_ID, REDIRECT_URI, $scope);
And comment on the lines from 82nd to 131y.
Now you need to call yourdomain.ru/invoice/ym/sample/index.php script in the browser, log in and save the received token. Be careful, copy the token in its entirety, it is very long.
We are already close to victory.
Step 5: Setting up a callback script that Yandex.Money will call upon receipt of payment to your wallet
On this page
sp-money.yandex.ru/myservices/online.xml you must enter the address of the script, for example:
itsoft.ru/invoice/ym/payment.phpYou can press the test button, however, you do not yet have a handler script, and you have to test by paying 1 ruble from a wallet on your website.
Check the “Send notifications” box and click Save.
You will need the secret key from this page. Save it.
Step 6: Processing and crediting payments
The script
itsoft.ru/invoice/ym/payment.php here looks like this, I removed a number of details that relate exclusively to the processing of customer orders.
<? require_once($_SERVER["DOCUMENT_ROOT"]."/conf/config_db_ro_without_auth1.php"); require_once(dirname(__FILE__) . '/lib/YandexMoney.php'); require_once(dirname(__FILE__) . '/sample/consts.php'); main(); function main() { ob_start(); print_r($_POST); $message = ob_get_contents(); ob_end_clean();
Well, that's all. There will be questions, ask here, I will try to answer all. If you like it, you can send me money for a beer on my Yandex.Walker. :)
PS
This article is devoted to how quickly to fasten the Yandex.Money reception. PHP script code everyone can rewrite depending on their tasks and needs.