Django integration for API "https://bw.gitbooks.io/api-oc/content/pay.html".
Project description
Simple django integration for API “Оплата Частями в Интернете”: Схема взаимодействия №1 (Создание платежа по сервису Оплата частями/Мгновенная рассрочка).
Installation
Install with pip:
$ pip install django-ok-payparts
Update INSTALLED_APPS:
INSTALLED_APPS = [ ... 'payparts', ... ]
Add payparts.urls to your project urlpatterns:
urlpatterns = [ ... path('', include('payparts.urls')), ... ]
Make migrations:
$ python manage.py migrate
Available settings
PAYPARTS_API_PASSWORD - Password of your store.
PAYPARTS_API_STORE_ID - Your store’s ID.
PAYPARTS_API_URL - Url for creation of a payment. By default: https://payparts2.privatbank.ua/ipp/v2/.
PAYPARTS_API_REDIRECT_URL - Url to redirect after a success payment. By default: https://payparts2.privatbank.ua/ipp/v2/payment.
Usage
How to create a payment
- Prepare your order’s data:
data = { "order_id": f"order-123", "amount": 400.00, "parts_count": 2, # optional, default value is '2' "merchant_type": "II", # optional, default value is 'II' "products": [ { "name": "Телевизор", "count": 2, "price": 100.00 }, { "name": "Микроволновка", "count": 1, "price": 200.00 } ], # also optional fields (can be set in your cabinet): "response_url": "http://shop.com/response", "redirect_url": "http://shop.com/redirect", }
- Get your redirect url:
from payparts.use_cases import GetRedirectUrlUseCase redirect_url = GetRedirectUrlUseCase().execute(data)
- Redirect a user to the url.
How to process a callback
Whenever a callback is processed a signal will be sent with the result of the transaction.
There are two signals (payparts.signals):
- pay_parts_success_callback - if signature is valid.
- pay_parts_invalid_callback - if signature is not valid.
Connect the signals to actions to perform the needed operations when a successful payment is received:
from payparts.signals import pay_parts_success_callback, pay_parts_invalid_callback from orders.models import Order def success_callback(sender, log, request, **kwargs): # ensure success state if log.is_success: order = Order.objects.get(pk=log.order_id) order.set_success_payment_state() pay_parts_success_callback.connect(success_callback)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size django_ok_payparts-0.4-py3-none-any.whl (19.4 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size django-ok-payparts-0.4.tar.gz (13.9 kB) | File type Source | Python version None | Upload date | Hashes View |
Hashes for django_ok_payparts-0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 589e99175e4220bb3a3b4425d869298f298a74d9cce8287d2ea932cdd4c33e35 |
|
MD5 | 1aa9e971c20939da31a5f3d7c270e762 |
|
BLAKE2-256 | 12d2b941fa45e6cb4dbe1e7b42f566f631c7655b6114bfa55c147f26f862d928 |