Payment providers API wrapper
Project description
PyPayment
Payment providers API wrapper.
Providers • Installation • Usage • Enums • Exceptions • Contributing • License
Providers:
Installation
Install the current version with PyPI
pip install -U pypayment
Usage
The module provides an interface Payment for the unification of each payment provider.
It has 3 properties:
url- Link to the created payment form.status- Current payment status.income- Income (profit) from the payment.
from pypayment import Payment
Qiwi
Authorization
Before using QiwiPayment class you must authorize with secret key from QIWI P2P.
from pypayment import QiwiPayment
QiwiPayment.authorize("my_secret_key")
You can set default parameters for every QiwiPayment instance.
theme_code- Code for displaying custom name and colors of the form. (Get it here)expiration_duration- Time that the invoice will be available for payment.payment_type- QiwiPaymentType enum.
from pypayment import QiwiPayment, QiwiPaymentType
from datetime import timedelta
QiwiPayment.authorize("my_secret_key",
theme_code="my_theme_code",
expiration_duration=timedelta(hours=1),
payment_type=QiwiPaymentType.CARD)
Creating invoice
To created new QIWI invoice, you need to instantiate QiwiPayment with 1 required parameter.
amount- The amount to be invoiced. (will be rounded to 2 decimal places)
from pypayment import Payment, QiwiPayment
payment: Payment = QiwiPayment(amount=123.45)
print(payment.url) # https://oplata.qiwi.com/form/?invoice_uid=payment_unique_id
And 4 optional parameters that will override default ones for specific instance.
description- Payment comment that will be displayed to user.theme_code- Code for displaying custom name and colors of the form. (Get it here)expiration_duration- Time that the invoice will be available for payment.payment_type- QiwiPaymentType enum.
from pypayment import Payment, QiwiPayment, QiwiPaymentType
from datetime import timedelta
different_payment: Payment = QiwiPayment(amount=987.65,
description="Flower pot",
theme_code="my_new_theme_code",
expiration_duration=timedelta(days=3),
payment_type=QiwiPaymentType.CARD)
print(different_payment.url) # https://oplata.qiwi.com/form/?invoice_uid=payment_unique_id_2
Recommended to put QiwiPayment into Payment variable to keep unification.
Getting status
To get payment status, you need to use status property.
from pypayment import Payment, QiwiPayment, PaymentStatus
payment: Payment = QiwiPayment(100)
if payment.status == PaymentStatus.PAID:
print("Got ur money!") # Got ur money!
Getting income
To get payment income (profit), you need to use income property.
from pypayment import Payment, QiwiPayment
payment: Payment = QiwiPayment(100) # E.x. commission is 10%
income = payment.income
if income:
print(income) # 90.0
Qiwi Payment Types
Enum QiwiPaymentType that represents every possible Qiwi payment type.
WALLET- Payment with Qiwi wallet.CARD- Payment with bank card.ALL- Payment with every type possible.
YooMoney
Getting access token
You need to get access_token to authorize.
client_id- Create new application and copy client_id (Do it here)redirect_uri- redirect_uri you specified when creating the application.instance_name- (Optional) ID of the authorization instance in the application.
from pypayment import YooMoneyPayment
YooMoneyPayment.get_access_token(client_id="my_client_id",
redirect_uri="my_redirect_uri",
instance_name="my_instance_name") # access_token = XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Authorization
Before using YooMoneyPayment class you must authorize with access_token.
from pypayment import YooMoneyPayment
YooMoneyPayment.authorize("my_access_token")
You can set default parameters for every YooMoneyPayment instance.
payment_type- YooMoney Payment Type enum.charge_commission- Charge Commission enum.success_url- User will be redirected to this url after paying.
from pypayment import YooMoneyPayment, YooMoneyPaymentType, ChargeCommission
YooMoneyPayment.authorize("my_access_token",
payment_type=YooMoneyPaymentType.CARD,
charge_commission=ChargeCommission.FROM_CUSTOMER,
success_url="my_success_url.com")
Creating invoice
To created new YooMoney invoice, you need to instantiate YooMoneyPayment with 1 required parameter.
amount- The amount to be invoiced. (will be rounded to 2 decimal places)
from pypayment import Payment, YooMoneyPayment
payment: Payment = YooMoneyPayment(amount=123.45)
print(payment.url) # https://yoomoney.ru/transfer/quickpay?requestId=XXXXXXXXXXXXXXXXXXXXXXXXXX
And 3 optional parameters that will override default ones for specific instance.
description- Payment comment that will be displayed to user.payment_type- YooMoney Payment Type enum.charge_commission- Charge Commission enum.success_url- User will be redirected to this url after paying.
from pypayment import Payment, YooMoneyPayment, YooMoneyPaymentType, ChargeCommission
different_payment: Payment = YooMoneyPayment(amount=987.65,
description="Flower pot",
payment_type=YooMoneyPaymentType.CARD,
charge_commission=ChargeCommission.FROM_CUSTOMER,
success_url="my_success_url.com")
print(different_payment.url) # https://yoomoney.ru/transfer/quickpay?requestId=XXXXXXXXXXXXXXXXXXXXXXXXXX
Recommended to put YooMoneyPayment into Payment variable to keep unification.
Getting status
To get payment status, you need to use status property.
from pypayment import Payment, YooMoneyPayment, PaymentStatus
payment: Payment = YooMoneyPayment(100)
if payment.status == PaymentStatus.PAID:
print("Got ur money!") # Got ur money!
Getting income
To get payment income (profit), you need to use income property.
from pypayment import Payment, YooMoneyPayment
payment: Payment = YooMoneyPayment(100) # E.x. commission is 10%
income = payment.income
if income:
print(income) # 90.0
YooMoney Payment Types
Enum YooMoneyPaymentType that represents every possible yoomoney payment type.
WALLET- Payment with YooMoney wallet.CARD- Payment with bank card.PHONE- Payment from phone balance.
PayOk
Authorization
Before using PayOkPayment class you must authorize with:
- API Key (
BalanceandTransactionspermissions are required) - API ID
- Shop ID
- Shop secret key
from pypayment import PayOkPayment
PayOkPayment.authorize("my_api_key", "my_api_id", "my_shop_id", "my_shop_secret_key")
You can set default parameters for every PayOkPayment instance.
payment_type- PayOkPaymentType enum.currency- PayOkCurrency enum.success_url- User will be redirected to this url after paying.
from pypayment import PayOkPayment, PayOkPaymentType, PayOkCurrency
PayOkPayment.authorize("my_api_key", "my_api_id", "my_shop_id", "my_shop_secret_key",
payment_type=PayOkPaymentType.CARD,
currency=PayOkCurrency.RUB,
success_url="my_success_url.com")
Creating invoice
To created new PayOk invoice, you need to instantiate PayOkPayment with 1 required parameter.
amount- The amount to be invoiced.
from pypayment import Payment, PayOkPayment
payment: Payment = PayOkPayment(amount=123)
print(payment.url) # https://payok.io/pay?amount=XXX&...
And 4 optional parameters that will override default ones for specific instance.
description- Payment comment that will be displayed to user.payment_type- PayOkPaymentType enum.currency- PayOkCurrency enum.success_url- User will be redirected to this url after paying.
from pypayment import Payment, PayOkPayment, PayOkPaymentType, PayOkCurrency
different_payment: Payment = PayOkPayment(amount=987.65,
description="Flower pot",
payment_type=PayOkPaymentType.CARD,
currency=PayOkCurrency.RUB,
success_url="my_success_url.com")
print(different_payment.url) # https://payok.io/pay?amount=XXX&...
Recommended to put PayOkPayment into Payment variable to keep unification.
Getting status
To get payment status, you need to use status property.
from pypayment import Payment, PayOkPayment, PaymentStatus
payment: Payment = PayOkPayment(100)
if payment.status == PaymentStatus.PAID:
print("Got ur money!") # Got ur money!
Getting income
To get payment income (profit), you need to use income property.
from pypayment import Payment, PayOkPayment
payment: Payment = PayOkPayment(100) # E.x. commission is 10%
income = payment.income
if income:
print(income) # 90.0
PayOk Payment Types
Enum PayOkPaymentType that represents every possible PayOk payment type.
CARD- Payment with bank card.QIWI- Payment with QIWI.YOOMONEY- Payment with YooMoney.WEBMONEY- Payment with WebMoney.PAYEER- Payment with Payeer.PERFECT_MONEY- Payment with Perfect Money.ADVCASH- Payment with Advcash.BEELINE- Payment with Beeline.MEGAFON- Payment with Megafon.TELE2- Payment with Tele2.MTS- Payment with MTS.QIWI_MOBILE- Payment with QIWI Mobile.BITCOIN- Payment with Bitcoin.LITECOIN- Payment with Litecoin.DOGECOIN- Payment with Dogecoin.DASH- Payment with Dash.ZCASH- Payment with Zcash.
PayOk Currency
Enum PayOkCurrency that represents every possible PayOk currency.
RUB- Russian ruble.UAH- Ukrainian hryvnia.USD- United States dollar.EUR- Euro.RUB2- Russian ruble. (Alternative Gateway)
Lava
Authorization
Before using LavaPayment class you must authorize with token and wallet number from Lava.
from pypayment import LavaPayment
LavaPayment.authorize("my_token", wallet_to="Rxxxxxxxxx")
You can set default parameters for every LavaPayment instance.
expiration_duration- Time that the invoice will be available for payment.charge_commission- Charge Commission enum.success_url- User will be redirected to this url after paying.fail_url- User will be redirected to this url if payment failed.
from pypayment import LavaPayment, ChargeCommission
from datetime import timedelta
LavaPayment.authorize("my_token",
wallet_to="Rxxxxxxxxx",
expiration_duration=timedelta(hours=1),
charge_commission=ChargeCommission.FROM_SELLER,
success_url="my_success_url.com",
fail_url="my_fail_url.com")
Creating invoice
To created new Lava invoice, you need to instantiate LavaPayment with 1 required parameter.
amount- The amount to be invoiced. (will be rounded to 2 decimal places)
from pypayment import Payment, LavaPayment
payment: Payment = LavaPayment(amount=123.45)
print(payment.url) # https://acquiring.lava.kz/invoice/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-xxxxxxxxx
And 4 optional parameters that will override default ones for specific instance.
expiration_duration- Time that the invoice will be available for payment.charge_commission- Charge Commission enum.success_url- User will be redirected to this url after paying.fail_url- User will be redirected to this url if payment failed.
from pypayment import Payment, LavaPayment, ChargeCommission
from datetime import timedelta
different_payment: Payment = LavaPayment(amount=987.65,
description="Flower pot",
expiration_duration=timedelta(hours=1),
charge_commission=ChargeCommission.FROM_SELLER,
success_url="my_success_url.com",
fail_url="my_fail_url.com")
print(different_payment.url) # https://acquiring.lava.kz/invoice/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-xxxxxxxxx
Recommended to put LavaPayment into Payment variable to keep unification.
Getting status
To get payment status, you need to use status property.
from pypayment import Payment, LavaPayment, PaymentStatus
payment: Payment = LavaPayment(100)
if payment.status == PaymentStatus.PAID:
print("Got ur money!") # Got ur money!
Getting income
To get payment income (profit), you need to use income property.
from pypayment import Payment, LavaPayment
payment: Payment = LavaPayment(100) # E.x. commission is 10%
income = payment.income
if income:
print(income) # 90.0
Enums
Charge Commission
Enum ChargeCommission that represents who will be charged the commission.
FROM_CUSTOMER- Charge commission from customer.FROM_SELLER- Charge commission from seller.
Payment Statuses
Enum that represents every possible status of the invoice.
WAITING- Payment has been created, but has not yet been paid.PAID- Payment was successfully paid.REJECTED- Payment was rejected.EXPIRED- Payment has expired.
Exceptions
NotAuthorized- Raised when payment provider class has not been authorized.AuthorizationError- Raised when authorization failed.PaymentCreationError- Raised when payment creation failed.PaymentGettingError- Raised when payment getting failed.
Contributing
Bug reports and/or pull requests are welcome
License
The module is available as open source under the terms of the Apache License, Version 2.0
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypayment-1.4.3.tar.gz.
File metadata
- Download URL: pypayment-1.4.3.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
678188f08a015e6dc29324c8bd1218d21488ab8f49d9d00e38f46ddd69ff4378
|
|
| MD5 |
d2dcf617aacf6a2a907e93d7b13c5b11
|
|
| BLAKE2b-256 |
95ba6d10ed119eb934cc28dc61722f6c11ef71a07153a4377371ffadb8c905c7
|
File details
Details for the file pypayment-1.4.3-py3-none-any.whl.
File metadata
- Download URL: pypayment-1.4.3-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e840fabf95f54873a710f6569bd74d8690735727424b4cac3ac0b58e00d423f
|
|
| MD5 |
51a24e9187459fd3d4d097905e3bc5ba
|
|
| BLAKE2b-256 |
2289b92f43d4f7ac01b77c507fdae05d9b3f07adea7e44a2520c9e169bd04fa0
|