Flask-PaycomUz
Only for Uzbekistan
Paycom.uz integration for Flask
Links
How it Works
Install
pip install Flask-PaycomUz
Add your credentials from PaycomUz to config file
PAYCOM_ID = "your merchant ID"
PAYCOM_KEY = "your sercet key"
Create Flask App With Flask-PaycomUz
from flask_paycomuz import Paycom
from flask import *
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
paycom = Paycom(db)
def CheckAllowment(account): # Before creating transaction Flask-PaycomUz send account data which will have key whick you gave to Register_Account_data to validate it. Return True/False and detail object
order_id = account.get('order_id')
res = Order.query.filter(Order.id == order_id).first()
detail = {
"discount": { # скидка, необязательное поле
"title": "Скидка 5%",
"price": 10000
},
"shipping": { # доставка, необязательное поле
"title": "Доставка до ттз-4 28/23",
"price": 500000
},
"items": [ # товарная позиция, обязательное поле для фискализации
{
"title": "Помидоры", # нааименование товара или услуги
"price": 505000, # цена за единицу товара или услуги, сумма указана в тийинах
"count": 2, # кол-во товаров или услуг
"code": "00702001001000001", # код *ИКПУ обязательное поле
"units": 241092, # значение изменится в зависимости от вида товара
"vat_percent": 15, # обязательное поле, процент уплачиваемого НДС для данного товара или услуги
"package_code": "123456" # Код упаковки для конкретного товара или услуги, содержится на сайте в деталях найденного ИКПУ.
}
]
}
if res:
return True, detail
return False, {
}
def CallbackPayme(transaction): # After Creating and Performing transaction from Payme this function will call with Payme_Transaction as argument
if transaction.state == 1: # Successful creating transaction in Payme
pass
if transaction.state == 2: # Successful performing transaction in Payme
pass
def create_app():
app = Flask(__name__)
app.config.from_pyfile('config.py')
paycom.Register_Account_Data(['order_id']) # Register Paycom payment details, requires to set before init app
paycom.Register_Validators(CheckAllowment) # Register your Validator for payment, requires to set before init app
paycom.Register_Callback(CallbackPayme) # Register your Callback function which will be called after Creating and Performing transaction
paycom.init_app(app, url_prefix='/payme') # Init Paycom to your application, url_prefix to add view to app, defualt /payme, in that case Flask-PaycomUz register JSON-RPC route to recieve requests from PaycomUz as https://example.uz/payme
@app.get("/")
def index():
return "Hello World"
@app.get('/create_transaction')
def create_transaction():
amount = 10000
order_id = 45 # Order ID to create Transaction in Paycom
return_url = "https://example.uz/return_url" # return Url after successful or error payment
url = paycom.Generate(amount=amount, return_url=return_url, order_id = order_id)
with app.app_context():
db.create_all() # Don't forget to create db, flask_paycomuz adds 2 table to db, Payme_Transaction and Payme_Account
return app
app = create_app()
if __name__ == "__main__":
app.run(debug=True)
Flask-PaycomUz models schema
# Flask-PaycomUz uses Flask-SQLAlchemy models to save data in database, it prefers to use Postgresql
class Payme_Transaction(db.Model):
__tablename__ = 'payme_transaction'
id = db.Column(db.Integer, primary_key = True)
payme_id = db.Column(db.Integer, unique=True)
transaction_id = db.Column(db.String, unique=True)
time = db.Column(db.BigInteger, nullable=True)
amount = db.Column(db.Integer, nullable=True)
state = db.Column(db.Integer, default=1)
created_at = db.Column(db.BigInteger, nullable=False)
account = db.relationship('Payme_Account', backref='payme_transaction')
def result(self):
return {"result" : {
"create_time" : self.created_at,
"transaction" : self.transaction_id,
"state" : self.state}
}
class Payme_Account(db.Model):
__tablename__ = 'payme_account'
id = db.Column(db.Integer, primary_key = True)
transaction_id = db.Column(db.ForeignKey("payme_transaction.transaction_id"))
key = db.Column(db.String, nullable=True)
value = db.Column(db.String, nullable=True)
Accessing Models
Select data from models
paycom.models # it contains 2 models in list, [Payme_Transaction,Payme_Account ]
Payme_Transaction, Payme_Account = paycom.models
transaction = Payme_Transaction.query.all() # You can select or filter data
Add model view to Flask-Admin
from flask_admin.contrib.sqla import ModelView
admin.add_view(ModelView(paycom.models[0], db.session))
admin.add_view(ModelView(paycom.models[1], db.session))
Task List
Merchant API methods
- CheckPerformTransaction
- CreateTransaction
- CheckTransaction
- PerformTransaction
- CancelTransaction
Licence
This project is licensed under the MIT License (see the LICENSE file for details).
Metadata
Release files for Flask-PaycomUz 1.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-PaycomUz-1.2.5.tar.gz | 9.2 kB | Without provenance | Details for Flask-PaycomUz-1.2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_PaycomUz-1.2.5-py3-none-any.whl | Python 3 | none | any | Details for Flask_PaycomUz-1.2.5-py3-none-any.whl |
Total release size: 17.8 kB
Release files / Flask-PaycomUz-1.2.5.tar.gz
| Download URL | Flask-PaycomUz-1.2.5.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0eee897bb87f41ec5aa01e5f0dcaaa9afe134961972f6e95eb8c6c90708f4c8
|
|
BLAKE2b-256 checksum How to use checksums |
c4513f6737cbedead2ba374d1f0081802fdb9d5d947f8240e71333a54468bd73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Release files / Flask_PaycomUz-1.2.5-py3-none-any.whl
| Download URL | Flask_PaycomUz-1.2.5-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a60f855b3a463d24ea40c35bdd268d1c15cd4435a047b3d2fe2171ff62f58a05
|
|
BLAKE2b-256 checksum How to use checksums |
8adbcfe536e5e8706f32eeaeec6c6b10f3ef9d4c4eb45ebd3ba400d88e06182e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Security for Flask-PaycomUz 1.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.