Skip to main content

No project description provided

Project description

Garpix CloudPayments

Прием платажей с CloudPayments.

Быстрый старт

Установите через pipenv:

pipenv install garpix_cloudpayments

Добавьте garpix_cloudpayments в INSTALLED_APPS и укажите адрес для миграций:

# settings.py

INSTALLED_APPS += [
    'garpix_cloudpayments',
]
MIGRATION_MODULES = {
    # ...
}
MIGRATION_MODULES['garpix_cloudpayments'] = 'app.migrations.garpix_cloudpayments'

Создайте директории и файлы:

backend/app/migrations/garpix_cloudpayments/
backend/app/migrations/garpix_cloudpayments/__init__.py

Сделайте миграции и мигрируйте:

python3 backend/manage.py makemigrations
python3 backend/manage.py migrate

Добавьте пути в urls.py:

from django.urls import path, include

urlpatterns = [
    path('cloudpayments/', include('garpix_cloudpayments.urls')),
    # ...
]

Также, добавьте в личном кабинете CloudPayments ссылки на эти коллбеки:

  • Pay уведомление => https://example.com/cloudpayments/pay/

  • Fail уведомление => https://example.com/cloudpayments/fail/

После этого необходимо зайти в административную панель и добавить публичный ключ из личного кабинета CloudPayments.

При изменении статуса платежа, дергается функция, указанная в app/settings.py (вы можете поменять на свою функцию и указать путь до нее):

# app/settings.py

GARPIX_PAYMENT_STATUS_CHANGED_CALLBACK = 'garpix_payment.callbacks.empty_callback'

Пример функции:

from garpix_cloudpayments.models.choices import PAYMENT_STATUS_COMPLETED, PAYMENT_STATUS_CANCELLED, PAYMENT_STATUS_DECLINED


def my_callback(payment):
    if payment.status == PAYMENT_STATUS_COMPLETED:
        print('Меняем статус заказа на успешный')
    elif payment.status in (PAYMENT_STATUS_CANCELLED, PAYMENT_STATUS_DECLINED):
        print('Заказ провален')
    else:
        print('Можем тоже использовать')

Ниже пример работы на фронтенде (до вызова точки /cloudpayments/payment_data/ необходимо создать объект модели Payment):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Garpix CloudPayments</title>
    <script src="https://widget.cloudpayments.ru/bundles/cloudpayments"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>

<label>Номер заказа (payment_uuid):<input type="text" value="1" name="payment_uuid" class="jsPaymentUUID"></label>
<button onclick="getDataAndPay(); return false;">Оплатить</button>

<script>
    function getDataAndPay() {
        var paymentUUID = document.querySelector('.jsPaymentUUID').value;
        axios.get('/cloudpayments/payment_data/?payment_uuid=' + paymentUUID)
            .then(function (paymentData) {
                console.log(paymentData);
                pay(paymentData);
            })
    }


    function pay(paymentData) {
        var widget = new cp.CloudPayments();
        widget.pay('auth', // или 'charge'
            paymentData,
            {
                onSuccess: function (options) { // success
                    //действие при успешной оплате
                    alert('success');
                },
                onFail: function (reason, options) { // fail
                    //действие при неуспешной оплате
                    alert('fail');
                },
                onComplete: function (paymentResult, options) { //Вызывается как только виджет получает от api.cloudpayments ответ с результатом транзакции.
                    //например вызов вашей аналитики Facebook Pixel
                    alert('complete')
                }
            }
        )
    };
</script>
</body>
</html>

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

License

MIT


Developed by Garpix / https://garpix.com

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

garpix_cloudpayments-1.2.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

garpix_cloudpayments-1.2.0-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file garpix_cloudpayments-1.2.0.tar.gz.

File metadata

  • Download URL: garpix_cloudpayments-1.2.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.15

File hashes

Hashes for garpix_cloudpayments-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5f20946ef98692830be0479c539c81001895149a2a09e9feea4494e0d9d9cc20
MD5 942cab64f53d2fd435da2f780f8e02bf
BLAKE2b-256 5cd160666bba08a5592de16b5ddeda6cbb9c800e96fa810d3e4aae67e7259556

See more details on using hashes here.

File details

Details for the file garpix_cloudpayments-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: garpix_cloudpayments-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.15

File hashes

Hashes for garpix_cloudpayments-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ce2c20724b2165f3db3a539f9205bda0c1b3b9c384b237d711db4fdb80a77fb
MD5 562fe54c0f8bad98499ededad834c268
BLAKE2b-256 976bae12caf5c24758988683e042c8f0d99d6de4ed59274c7ebffe9622de00c4

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