Skip to main content

YooKassa Payout API SDK Python Library

Project description

YooKassa Payout API Python Client Library

Build Status Latest Stable Version Total Downloads License

Russian | English

Client to work on Mass Payment Protocol

Opportunities

You can with this SDK:

  1. Generate a certificateп»ї for interaction with YooKassa.
  2. Transfer money to individuals for wallets in YooMoney, mobile phone numbers, Bank cards and accounts (makeDeposition).
  3. To test the possibility of transfer of remittances to wallets in YooMoney (testDeposition).
  4. Keep track of the balance of payments (balance).
  5. 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

  1. Install pip.
  2. In the console, run the following command:
pip install yookassa-payout

Under console using easy_install

  1. Install easy_install.
  2. In the console, run the following command:
easy_install --upgrade yookassa-payout

Manually

  1. 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:

  1. Create a private key and a certificate request (CSR).
  2. Fill out the certificate application form.
  3. Exchange data with YooMoney.

Step 1. Creating a private key and CSR

Using the SDK method

  1. Import classes to create CSR
from yookassa_payout.domain.models.organization import Organization
from yookassa_payout.payout import Payout
  1. 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
})
  1. 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

  1. In the console, go to your project folder.
cd '<your project folder>'
  1. Execute the command:
yookassa-payout -getcsr
  1. 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:
  • initial — to get the first certificate;
  • scheduled replacement — to replace a certificate that has expired;
  • replacement of a compromised — to replace a previously issued certificate in the event of a security breach;
  • adding a server — to use the new certificate on additional servers or services.
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

  1. Determine what types of payments you need and whether you want to check your balance.
  2. Import required classes
from yookassa_payout.domain.common.keychain import KeyChain
from yookassa_payout.configuration import Configuration
from yookassa_payout.payout import Payout
  1. Import the classes you need to solve your problems.
  2. 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')
  1. Create an instance of the Client class and pass the gateway ID from the merchant profile YooMoney and instance of the KeyChain class.
Configuration.configure('000000', keychain)
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yookassa-payout-2.3.1.tar.gz (44.8 kB view details)

Uploaded Source

File details

Details for the file yookassa-payout-2.3.1.tar.gz.

File metadata

  • Download URL: yookassa-payout-2.3.1.tar.gz
  • Upload date:
  • Size: 44.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for yookassa-payout-2.3.1.tar.gz
Algorithm Hash digest
SHA256 3b6b0197f0845fe237b95b9467b2068ec1445e64a370734a77a494d9d2708994
MD5 f9085165c8defec763b1eee82e393dcc
BLAKE2b-256 7c12f9b84a272454d421799b63494de09733778c6bad76dde058697d62edda6b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page