Skip to main content

A Django app for integrating Globee Payments

Project description

# django-globee

[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/lovvskillz/django-globee/master/LICENSE)
[![PyPI version](https://badge.fury.io/py/django-globee.svg)](https://badge.fury.io/py/django-globee)

django-globee is a Django app to integrate GloBee Payments.

Quick start
-----------

1. Add "globee" to your INSTALLED_APPS setting like this:
```python
INSTALLED_APPS = [
...
'globee',
]
```
2. Include the globee URLconf in your project urls.py like this:
```python
path('globee/', include('globee.urls')),
```

3. Include your globee key and test or live env in your project settings.py
```python
GLOBEE_AUTH_KEY = "YOUR GLOBEE X-AUTH-KEY"
GLOBEE_TEST_MODE = True # or False
```


4. Run `python manage.py migrate` to create the globee models.


## example

### create GloBee payment

```python
from random import randint
from django.http import HttpResponseRedirect
from django.urls.base import reverse
from globee.core import GlobeePayment

def my_payment_view(request):
custom_payment_id = 'Your-custom-payment-id-%s' % randint(1, 9999999)
payment_data = {
'total': 10.50,
'currency': 'USD',
'custom_payment_id': custom_payment_id,
'customer': {
'name': request.user.username,
'email': request.user.email
},
'success_url': request.build_absolute_uri(reverse('your-success-url')),
'cancel_url': request.build_absolute_uri(reverse('your-cancel-url')),
'ipn_url': request.build_absolute_uri(reverse('globee-ipn')),
}
payment = GlobeePayment(data=payment_data)
# check required fields for globee payments
if payment.check_required_fields():
# create payment request
if payment.create_request():
# redirect to globee payment page
return HttpResponseRedirect(payment.get_payment_url())
```

### get GloBee ipn signal

```python
from django.dispatch import receiver
from globee.models import PAYMENT_STATUS_GLOBEE_CONFIRMED
from globee.signals import globee_valid_ipn

@receiver(globee_valid_ipn)
def crypto_payment_ipn(sender, **kwargs):
payment = sender

# check if payment is confirmed or use any other payment status
if payment.payment_status == PAYMENT_STATUS_GLOBEE_CONFIRMED:
# get some payment infos
amount = payment.total # payment amount
currency = payment.currency # payment currency
payment_id = payment.payment_id # payment id from GloBee
custom_payment_id = payment.custom_payment_id # your custom payment id
customer_email = payment.customer_email # customer email

# Do more stuff
# ...

```

if you don't trust the ipn response, you can also get the payment data from GloBee

```python
from django.dispatch import receiver
from django.core.exceptions import ValidationError
from globee.models import PAYMENT_STATUS_GLOBEE_CONFIRMED
from globee.signals import globee_valid_ipn
from globee.core import GlobeePayment

@receiver(globee_valid_ipn)
def crypto_payment_ipn(sender, **kwargs):
payment = sender
globee_payment = GlobeePayment()

try:
# get the payment data from globee
payment_data = globee_payment.get_payment_by_id(payment.payment_id)

# check if payment is confirmed or use any other payment status
if payment_data['status'] == PAYMENT_STATUS_GLOBEE_CONFIRMED:
# get some payment infos
amount = float(payment_data['total']) # payment amount
currency = payment_data['currency'] # payment currency
payment_id = payment_data['payment_id'] # payment id from GloBee
custom_payment_id = payment_data['custom_payment_id'] # your custom payment id
customer_email = payment_data['customer']['email'] # customer email

# Do more stuff
# ...
except ValidationError as e:
# payment not found or other error
print(e)
```


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

django-globee-1.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

django_globee-1.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file django-globee-1.1.0.tar.gz.

File metadata

  • Download URL: django-globee-1.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for django-globee-1.1.0.tar.gz
Algorithm Hash digest
SHA256 910a9b6fbbf9383225b3b73a623720d22173b6fa1c4df5b1a25f52602adb7252
MD5 f7a891527106fc46dd43b1032b595aca
BLAKE2b-256 8de8b37cd73d6239a4a4c460f29ddee944e0d4eb91b974996da06b5e640f2e1d

See more details on using hashes here.

Provenance

File details

Details for the file django_globee-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_globee-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for django_globee-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c07577d27946d0af70294ac8a6ae45bedbdbfdebee46e94116343989aba1b129
MD5 9e568b93fb8f1270fdd0435c76cd81d2
BLAKE2b-256 c1b305ef424a40dcec5e838d197557aa516c24a6b75bd2eb33c9af0d155fc1f3

See more details on using hashes here.

Provenance

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