YooKassa Payout API SDK Python Library
Project description
YooKassa Payout API Python Client Library
Russian | English
Client to work on Mass Payment Protocol
Opportunities
You can with this SDK:
- Generate a certificateп»ї for interaction with YooKassa.
- 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 payments (balance).
- Receive notifications the unsuccessful status of transfers to a Bank account, card, or mobile phone (errorDepositionNotification).
Requirements
- Python 3.5 (и выше)
- 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://github.com/yoomoney/yookassa-payout-sdk-python/archive/master.zip
tar zxf yookassa-payout-sdk-python-master.tar.gz
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 payments 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 payments
Example of payment 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 payment
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.2.0.tar.gz
.
File metadata
- Download URL: yookassa-payout-2.2.0.tar.gz
- Upload date:
- Size: 42.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44822ed84726a4fe9357c7bb8f3a1a8ca6dbf51fd6f24fabc926fe2919a8c062 |
|
MD5 | 614f2e34a30e935d2cded295c28f4e98 |
|
BLAKE2b-256 | edd4aea70f226445bc2e227a500ac1c344a0462f06d39fb56fd3629abe9ffb25 |