YooKassa Payout API SDK Python Library
Project description
YooMoney Payout API Python Client Library
Russian | English
Client to work on the Protocol for mass payouts
Opportunities
You can with this SDK:
- Generate a certificate for interaction with YooMoney.
- Transfer money to individuals for wallets in YooMoney, mobile phone numbers, Bank cards and accounts (makeDeposition).
- To test the possibility of transfer of remittances to wallets in YooMoney (testDeposition).
- Keep track of the balance of payouts (balance).
- Receive notifications the unsuccessful status of transfers to a Bank account, card, or mobile phone (errorDepositionNotification).
Requirements
- Python 3.5 (or later version)
- pip
Installation
Under console using pip
- Install pip.
- In the console, run the following command:
pip install yookassa-payout
Under console using easy_install
- Install easy_install.
- In the console, run the following command:
easy_install --upgrade yookassa-payout
Manually
- In the console, run the following command:
wget https://git.yoomoney.ru/rest/api/latest/projects/SDK/repos/yookassa-payout-sdk-python/archive?format=zip -O yookassa-payout-sdk-python-master.zip
unzip yookassa-payout-sdk-python-master.zip -d yookassa-payout-sdk-python-master
cd yookassa-payout-sdk-python-master
python setup.py install
Getting a certificate for authenticating requests
To interact with YooMoney.The cashier must obtain a certificate. For this:
- Create a private key and a certificate request (CSR).
- Fill out the certificate application form.
- Exchange data with YooMoney.
Step 1. Creating a private key and CSR
Using the SDK method
- Import classes to create CSR
from yookassa_payout.domain.models.organization import Organization
from yookassa_payout.payout import Payout
- Create an instance of the
Organization
class with data for creating the request. All data must be entered in Latin.
org = Organization({
"org_name": "YooMoney", # Organization Name (Latin)
"common_name": "/business/yoomoney", # Common Name, for example the name of your organization; must start with В«/business/В»
"email": "cms@yoomoney.ru" # Email
})
- Create a CSR and a private key.
# Specify the location where the files should be saved and the password for the private key (if necessary)
Payout.get_csr(org, './files/output', '12345')
As a result, the SDK will generate a private key, CSR, and a text file with an electronic signature (necessary for further steps).
Via the console
- In the console, go to your project folder.
cd '<your project folder>'
- Execute the command:
yookassa-payout -getcsr
- Enter data for the certificate, following the instructions on the screen. The text must be entered in Latin letters. As a result, the SDK will generate a private key, CSR, and a text file with an electronic signature (necessary for further steps).
Step 2. Filling out the certificate application
Download the application to the certificate, fill it out and print it out. Sign and seal the document. Scan.
Parameter | Description |
---|---|
CN | Must match the value of the Common Name parameter (eg, YOUR name). For example, /business/predpriyatie. |
Electronic signature of the certificate request | The text view obtained in the previous step. |
Organization name in Latin letters | Must match the value of the Organization Name parameter (eg, company) Internet Widgits Pty Ltd. |
The reason for the request | Possible options:
|
Contact person (full name, phone number, e-mail) | Contact a specialist to contact you if you have any questions about the issued certificate. |
Step 3. Data exchange with YooMoney
Send the certificate request file (request.csr) and a scan of the request by email to your YooMoney Manager.Box office. In response to the request, the Manager will send a file with the certificate within 2 business days. The certificate is valid for 1 year. Place the received certificate on your server
Start of work
- Determine what types of payouts you need and whether you want to check your balance.
- Import required classes
from yookassa_payout.domain.common.keychain import KeyChain
from yookassa_payout.configuration import Configuration
from yookassa_payout.payout import Payout
- Import the classes you need to solve your problems.
- Create an instance of the
KeyChain
class by passing the path to the public key, the path to the private key, and, if necessary, the password for the private key.
keychain = KeyChain('publicCert.cer', 'privateCert.pem', 'password')
- Create an instance of the
Client
class and pass the gateway ID from the merchant profile YooMoney and instance of theKeyChain
class.
Configuration.configure('000000', keychain)
- Call the appropriate method. More information about making payouts
Example of payout to a Bank account
# Importing classes
from yookassa_payout.configuration import Configuration
from yookassa_payout.payout import Payout
from yookassa_payout.domain.common.keychain import KeyChain
from yookassa_payout.domain.models.recipients.bank_account_recipient import BankAccountRecipient
from yookassa_payout.domain.request.make_deposition_request import MakeDepositionRequest
# Creating a housekeeper and saving settings
keychain = KeyChain('./files/250000.cer', './files/privateKey.pem', '12345')
Configuration.configure(250000, keychain)
# Getting the current balance
balance = Payout.get_balance()
# The compilation of data on the beneficiary
recipient = BankAccountRecipient()
recipient.pof_offer_accepted = True
recipient.bank_name = 'Barclays'
recipient.bank_city = 'London'
recipient.bank_cor_account = '30101810400000000225'
recipient.customer_account = '40817810255030943620'
recipient.bank_bik = '042809679'
recipient.payment_purpose = 'Refund under the agreement 25-001, without VAT'
recipient.pdr_first_name = 'John'
recipient.pdr_last_name = 'Watson'
recipient.pdr_doc_number = '4002109067'
recipient.pdr_doc_issue_date = '1999-07-30'
recipient.pdr_address = 'Baker street, 221'
recipient.pdr_birth_date = '1987-05-24'
recipient.sms_phone_number = '79653457676'
# Preparing a request to create a payout
request = MakeDepositionRequest()
request.agent_id = 250000
request.client_order_id = '215d8da0-000f-50be-b000-0003308c89be'
request.request_dt = '2020-03-04T15:39:45.456+03:00'
request.payment_params = recipient
# The carrying out of the payout
result = Payout.create_deposition(request)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file yookassa-payout-2.5.2.tar.gz
.
File metadata
- Download URL: yookassa-payout-2.5.2.tar.gz
- Upload date:
- Size: 39.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0370f23f92aab587ef4e4bb34221466a50e5a3ca5ce80634f08c9677e95dbdd |
|
MD5 | 4a6b9a35c2eed5dc55ef8bbc39352339 |
|
BLAKE2b-256 | 6b09cae432bf25e21554e2769e7bc3260d4514d20bf633d220850038e3ad7c20 |