Django RestFramework PaycomUz

Django RestFramework PaycomUz

Assalom alaykum. Ushbu maqolada Payme to'lov tizimi orqali to'lov qiladigan API xizmat yaratamiz.

✈️ Ishni boshlash

pip install django 
pip install djangorestframework 
pip install PaycomUz 
pip install request

settings.py

INSTALLED_APPS = [ 
    'rest_framework',
    'PaycomUz' 
]

python manage.py migrate

⚙️ To'lovlarni sozlash

To'lovlarni amalga oshirish uchun sizda Paycom classi bo'lishi kerak. U qanday yoziladi va nega kerak! Paycom classi buyurtma bor yoki yo'qligi yoki narxini tekshirib, javob qaytarish uchun kerak! Mana pastda qanday yozilishi ko'rsatilgan. Paycom classni ichida check_order funksiyasi bo'lishi kerak. U buyurtma bor yoki yo'qligini tekshirb beradi va return qilib javob yuboradi.

from PaycomUz.status import ORDER_FOUND,ORDER_NOT_FOUND,INVALID_AMOUNT 
class Paycom: 
    def __init__(self,order_id=None,order_type=None,amount=None):
         self.order_id = None #buyurtmaning raqami 
         self.order_type = None #buyurtmaning turi yozilmasayam bo'ladi 
         self.amount = None #buyurtmaning narxi 
    def check_order(self): 
        if self.order == True: #ma'lumotlari omborida huddi shunday buyurtma bor narxi ham to'g'ri keladi 
            return ORDER_FOUND 
        else: #agar bunday buyurtma bo'lmasa 
            return ORDER_NOT_FOUND #yoki INVALID_AMOUNT #narxi to'g'ri kelmadi

settings.py

PAYCOM_SETTINGS = { 
    "HOST":"<a href="https://checkout.test.paycom.uz/api">https://checkout.test.paycom.uz/api</a>", #test host 
    "ID":"qwertt12345", #token 
    "SECRET_KEY":"wertyu234567", #password 
    "PATH_CLASS":"apps.order.views", #Paycom classini qayerga yozgan bo'lsangiz o'sha joyni ko'rsating 
    "ACCOUNTS":{ 
            "KEY1":"order_id", 
            "KEY2":None #or "type" } 
}

urls.py

from django.contrib import admin from django.urls import path, include 
urlpatterns = [ 
     path('admin/', admin.site.urls),
     path('api/payment/', include('PaycomUz.urls')) 
]

💲 To'lovlarni amalga oshirish

from PaycomUz.methods_subscribe_api import Subcribe 
token = 'token' 
data = Subcribe(token=token,order_id=1,amount=5000.00,order_type='order').receipts_create() print(data) 
>>> {'_id': '5c42fb5ae3331dc358f3afef', 'paid': True, 'status': 'success', 'error': None}
>>> {'_id': 'error_response14', 'paid': False, 'status': 'failed', 'error': {'jsonrpc': '2.0', 'id': 123, 'error': {'code': -31700, 'id': 138, 'message': 'Заказ не найден', 'origin': 'merchants.checkPerformTransaction'}}}

Github : https://github.com/begyy/PaycomUz

Ushbu videoda qanday qilib Paymeni ulash haqida ko'rishingiz mumkin!

YouTubeda

Moverda


Sadullayev Bekhzod Bohodir og'li - Texnoman foydalanuvchisi

Muallif haqida

Sadullayev Bekhzod Bohodir og'li Python Django Backend Developer


Blogdagi so‘nggi maqolalar:


Birinchi bo‘ling!

Iltimos, fikr bildirish uchun saytga kiring yoki ro‘yxatdan o‘ting!