django-omise


Namedjango-omise JSON
Version 0.2.20 PyPI version JSON
download
home_pagehttps://github.com/jamesx00/django-omise
SummaryDjango models for Omise
upload_time2024-06-08 14:37:28
maintainerNone
docs_urlNone
authorJames Tansiri
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # django-omise Django + Omise

![Test](https://github.com/jamesx00/django-omise/actions/workflows/tests.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/jamesx00/django-omise/badge.svg?branch=master)](https://coveralls.io/github/jamesx00/django-omise?branch=master)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/jamesx00/django-omise/issues)

Django models for Omise. Currently, we support the following features:

- Creating a customer
- Allowing customer to add/delete credit/debit cards
- Collect payments with new card with the option to keep the card
- Collect payments with saved cards
- Collect payments with [Internet Banking](https://www.omise.co/internet-banking)
- Collect payments with [TrueMoney Wallet](https://www.omise.co/truemoney-wallet)
- Collect payments with [Promptpay](https://www.omise.co/promptpay)
- Collect payments with [Rabbit LINE Pay](https://www.omise.co/rabbit-linepay)
- Webhook handler, saving raw data as an Event object and update related objects, currently supporting

  - Customer
  - Card
  - Charge
  - Source
  - Refund
  - Schedule
  - Scheduled Charge
  - Schedule Occurrence

- 3DS pending charges handling

See the [roadmap](#roadmap-and-contributions) for the plan of this project. Contributions are welcome!

### Quick start

---

1. Add "django_omise" to your INSTALLED_APPS setting like this:

```
    INSTALLED_APPS = [
        ...
        "django_omise",
    ]
```

2. Include the django_omise URLconf in your project urls.py like this:

```
    path("payments/", include("django_omise.urls")),
```

3. Add Omise keys and operating mode in settings.py:

```python
OMISE_PUBLIC_KEY = xxxx
OMISE_SECRET_KEY = xxxx
OMISE_LIVE_MODE = True | False
OMISE_CHARGE_RETURN_HOST = localhost:8000

# Optional. The default payment method is credit/debit card only.
# You must specify additional payment methods.
OMISE_PAYMENT_METHODS = [
    "card",
    "internet_banking", # Internet Banking
    "truemoney_wallet", # TrueMoney Wallet
    "promptpay", # Promptpay
    "rabbit_linepay", # Rabbit LINE Pay
]
```

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

5. Add Omise endpoint webhook url `https://www.your-own-domain.com/payments/webhook/`

### Basic usage

---

1. Create an Omise customer from User:

   ```python
   from django.contrib.auth import get_user_model
   from django_omise.models.core import Customer

   User = get_user_model()
   user = User.objects.first()
   customer = Customer.get_or_create(user=user)
   ```

2. Add card to Customer

   2.1 With the built-in view (Recommended)

   We have built a basic card collecting view where logged in users can add and remove their cards. Run Django server and visit _/payments/payment_methods/_ to see it in action. You could override the template used in the view by creating a new template in your project's directory _/templates/django_omise/manage_payment_methods.html_.

   2.2 Manually

   ```python
   from django_omise.models.core import Customer
   from django_omise.omise import omise

   omise_token = omise.Token.retrieve(token_id)
   Customer.objects.live().first().add_card(token=omise_token)
   ```

3. Charge a customer (Currently supporting new/saved cards, [Internet Banking](https://www.omise.co/internet-banking), [TrueMoney Wallet](https://www.omise.co/truemoney-wallet), [Promptpay](https://www.omise.co/promptpay))

   3.1 With the build-in mixin

   This package comes with a built-in mixin, with which you can create a class-based-view and write a few methods to charge a customer. See below for an example or see [Example 1](./examples/):

   ```python
   from django.contrib.auth.mixins import LoginRequiredMixin
   from django_omise.mixins import CheckoutMixin
   from django_omise.models.choices import Currency

   # Your own class-based-view
   class CheckoutView(LoginRequiredMixin, CheckoutMixin):

       template_name = "yourapp/template.html"
       success_url = ...

       def get_charge_details(self):
           return {
               "amount": 100000,
               "currency": Currency.THB,
           }

       def process_charge_and_form(self, charge, form):
           if charge.status in [ChargeStatus.SUCCESSFUL, ChargeStatus.PENDING]:
               # Create new order and attach a charge object
               # And handle form data
               handle_form_data(form.cleaned_data)
   ```

   3.2 Manually

   ```python
   from django_omise.models.choices import Currency, ChargeStatus
   from django_omise.models.core import Customer

   customer = Customer.objects.first()
   card = customer.cards.live().first()

   charge = customer.charge_with_card(
       amount=100000,
       currency=Currency.THB,
       card=card,
   )

   if charge.status == ChargeStatus.SUCCESSFUL:
       # Do something
   elif charge.status == ChargeStatus.FAILED:
       # Do something else
   ```

4. Create a charge schedule for a customer:

At the moment, you can create a new schedule for a customer manually by calling the method create_schedule from a Custoemr object. See below for an example:

```python
import datetime
from django_omise.models.choices import Currency
from django_omise.models.core import Customer

customer = Customer.objects.first()
card = customer.default_card

customer.create_schedule(
    amount=100000,
    currency=Currency.THB,
    card=card,
    every=1,
    period="month",
    start_date=datetime.date(year=2022, month=5, day=22),
    end_date=datetime.date(year=2032, month=5, day=22),
    on={
        'days_of_month': [22],
    },
    description="Monthly subscription",
)
```

### Roadmap and contributions

---

Here are our immediate plans for this package, and more will be added! All contributions are welcome. I am new to publishing a public package, so if you have any recommendations, please feel free to create an issue on this repository or feel free to send me an email at siwatjames@gmail.com.

Omise Features

- [x] Handle refunds API
- Handle webhook events and update related objects
- Create charge with Sources
  - [x] Internet banking
  - [x] TrueMoney Wallet
  - [x] Promptpay
  - [x] Rabbit LINE Pay
  - [ ] Installment
- Schedule
  - [x] Scheduled Charges
  - [ ] Scheduled Transfer

Others

- Implement tests
- Add documentations

### Development

---

You can run tests with either coverage or pytest.

To run with pytest

```shell
pip install pytest-django
python -m pytest [path_to_file] [--verbose -s --cov-report=html --cov=.]
```

To run with coverage

```shell
pip install coverage
coverage run run_tests.py
coverage report
coverage html
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jamesx00/django-omise",
    "name": "django-omise",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "James Tansiri",
    "author_email": "tansirijames@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ae/c9/907ed25df74d95fe5b10003787707876b1f6219410a0ea6c7f891265d846/django_omise-0.2.20.tar.gz",
    "platform": null,
    "description": "# django-omise Django + Omise\n\n![Test](https://github.com/jamesx00/django-omise/actions/workflows/tests.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/jamesx00/django-omise/badge.svg?branch=master)](https://coveralls.io/github/jamesx00/django-omise?branch=master)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/jamesx00/django-omise/issues)\n\nDjango models for Omise. Currently, we support the following features:\n\n- Creating a customer\n- Allowing customer to add/delete credit/debit cards\n- Collect payments with new card with the option to keep the card\n- Collect payments with saved cards\n- Collect payments with [Internet Banking](https://www.omise.co/internet-banking)\n- Collect payments with [TrueMoney Wallet](https://www.omise.co/truemoney-wallet)\n- Collect payments with [Promptpay](https://www.omise.co/promptpay)\n- Collect payments with [Rabbit LINE Pay](https://www.omise.co/rabbit-linepay)\n- Webhook handler, saving raw data as an Event object and update related objects, currently supporting\n\n  - Customer\n  - Card\n  - Charge\n  - Source\n  - Refund\n  - Schedule\n  - Scheduled Charge\n  - Schedule Occurrence\n\n- 3DS pending charges handling\n\nSee the [roadmap](#roadmap-and-contributions) for the plan of this project. Contributions are welcome!\n\n### Quick start\n\n---\n\n1. Add \"django_omise\" to your INSTALLED_APPS setting like this:\n\n```\n    INSTALLED_APPS = [\n        ...\n        \"django_omise\",\n    ]\n```\n\n2. Include the django_omise URLconf in your project urls.py like this:\n\n```\n    path(\"payments/\", include(\"django_omise.urls\")),\n```\n\n3. Add Omise keys and operating mode in settings.py:\n\n```python\nOMISE_PUBLIC_KEY = xxxx\nOMISE_SECRET_KEY = xxxx\nOMISE_LIVE_MODE = True | False\nOMISE_CHARGE_RETURN_HOST = localhost:8000\n\n# Optional. The default payment method is credit/debit card only.\n# You must specify additional payment methods.\nOMISE_PAYMENT_METHODS = [\n    \"card\",\n    \"internet_banking\", # Internet Banking\n    \"truemoney_wallet\", # TrueMoney Wallet\n    \"promptpay\", # Promptpay\n    \"rabbit_linepay\", # Rabbit LINE Pay\n]\n```\n\n4. Run `python manage.py migrate` to create the Omise models.\n\n5. Add Omise endpoint webhook url `https://www.your-own-domain.com/payments/webhook/`\n\n### Basic usage\n\n---\n\n1. Create an Omise customer from User:\n\n   ```python\n   from django.contrib.auth import get_user_model\n   from django_omise.models.core import Customer\n\n   User = get_user_model()\n   user = User.objects.first()\n   customer = Customer.get_or_create(user=user)\n   ```\n\n2. Add card to Customer\n\n   2.1 With the built-in view (Recommended)\n\n   We have built a basic card collecting view where logged in users can add and remove their cards. Run Django server and visit _/payments/payment_methods/_ to see it in action. You could override the template used in the view by creating a new template in your project's directory _/templates/django_omise/manage_payment_methods.html_.\n\n   2.2 Manually\n\n   ```python\n   from django_omise.models.core import Customer\n   from django_omise.omise import omise\n\n   omise_token = omise.Token.retrieve(token_id)\n   Customer.objects.live().first().add_card(token=omise_token)\n   ```\n\n3. Charge a customer (Currently supporting new/saved cards, [Internet Banking](https://www.omise.co/internet-banking), [TrueMoney Wallet](https://www.omise.co/truemoney-wallet), [Promptpay](https://www.omise.co/promptpay))\n\n   3.1 With the build-in mixin\n\n   This package comes with a built-in mixin, with which you can create a class-based-view and write a few methods to charge a customer. See below for an example or see [Example 1](./examples/):\n\n   ```python\n   from django.contrib.auth.mixins import LoginRequiredMixin\n   from django_omise.mixins import CheckoutMixin\n   from django_omise.models.choices import Currency\n\n   # Your own class-based-view\n   class CheckoutView(LoginRequiredMixin, CheckoutMixin):\n\n       template_name = \"yourapp/template.html\"\n       success_url = ...\n\n       def get_charge_details(self):\n           return {\n               \"amount\": 100000,\n               \"currency\": Currency.THB,\n           }\n\n       def process_charge_and_form(self, charge, form):\n           if charge.status in [ChargeStatus.SUCCESSFUL, ChargeStatus.PENDING]:\n               # Create new order and attach a charge object\n               # And handle form data\n               handle_form_data(form.cleaned_data)\n   ```\n\n   3.2 Manually\n\n   ```python\n   from django_omise.models.choices import Currency, ChargeStatus\n   from django_omise.models.core import Customer\n\n   customer = Customer.objects.first()\n   card = customer.cards.live().first()\n\n   charge = customer.charge_with_card(\n       amount=100000,\n       currency=Currency.THB,\n       card=card,\n   )\n\n   if charge.status == ChargeStatus.SUCCESSFUL:\n       # Do something\n   elif charge.status == ChargeStatus.FAILED:\n       # Do something else\n   ```\n\n4. Create a charge schedule for a customer:\n\nAt the moment, you can create a new schedule for a customer manually by calling the method create_schedule from a Custoemr object. See below for an example:\n\n```python\nimport datetime\nfrom django_omise.models.choices import Currency\nfrom django_omise.models.core import Customer\n\ncustomer = Customer.objects.first()\ncard = customer.default_card\n\ncustomer.create_schedule(\n    amount=100000,\n    currency=Currency.THB,\n    card=card,\n    every=1,\n    period=\"month\",\n    start_date=datetime.date(year=2022, month=5, day=22),\n    end_date=datetime.date(year=2032, month=5, day=22),\n    on={\n        'days_of_month': [22],\n    },\n    description=\"Monthly subscription\",\n)\n```\n\n### Roadmap and contributions\n\n---\n\nHere are our immediate plans for this package, and more will be added! All contributions are welcome. I am new to publishing a public package, so if you have any recommendations, please feel free to create an issue on this repository or feel free to send me an email at siwatjames@gmail.com.\n\nOmise Features\n\n- [x] Handle refunds API\n- Handle webhook events and update related objects\n- Create charge with Sources\n  - [x] Internet banking\n  - [x] TrueMoney Wallet\n  - [x] Promptpay\n  - [x] Rabbit LINE Pay\n  - [ ] Installment\n- Schedule\n  - [x] Scheduled Charges\n  - [ ] Scheduled Transfer\n\nOthers\n\n- Implement tests\n- Add documentations\n\n### Development\n\n---\n\nYou can run tests with either coverage or pytest.\n\nTo run with pytest\n\n```shell\npip install pytest-django\npython -m pytest [path_to_file] [--verbose -s --cov-report=html --cov=.]\n```\n\nTo run with coverage\n\n```shell\npip install coverage\ncoverage run run_tests.py\ncoverage report\ncoverage html\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django models for Omise",
    "version": "0.2.20",
    "project_urls": {
        "Homepage": "https://github.com/jamesx00/django-omise",
        "Repository": "https://github.com/jamesx00/django-omise"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f35ad89557646aff26f2111707b483a2b67dca236ad1e55099ca074ec4fca8e4",
                "md5": "70af1efa538eae9aae83fe2cf8bd0dd7",
                "sha256": "110a5840691770981404db21a17ca286c86f450ae6210d2b6006cfafe93455d3"
            },
            "downloads": -1,
            "filename": "django_omise-0.2.20-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "70af1efa538eae9aae83fe2cf8bd0dd7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 205771,
            "upload_time": "2024-06-08T14:37:26",
            "upload_time_iso_8601": "2024-06-08T14:37:26.821798Z",
            "url": "https://files.pythonhosted.org/packages/f3/5a/d89557646aff26f2111707b483a2b67dca236ad1e55099ca074ec4fca8e4/django_omise-0.2.20-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aec9907ed25df74d95fe5b10003787707876b1f6219410a0ea6c7f891265d846",
                "md5": "3f9d8fca748dfe9789c921be3fdadfba",
                "sha256": "d5ca1d3d9ee41b04cfc1cab87284d93d605ffb0b4945566065b74898aef81508"
            },
            "downloads": -1,
            "filename": "django_omise-0.2.20.tar.gz",
            "has_sig": false,
            "md5_digest": "3f9d8fca748dfe9789c921be3fdadfba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 166079,
            "upload_time": "2024-06-08T14:37:28",
            "upload_time_iso_8601": "2024-06-08T14:37:28.568415Z",
            "url": "https://files.pythonhosted.org/packages/ae/c9/907ed25df74d95fe5b10003787707876b1f6219410a0ea6c7f891265d846/django_omise-0.2.20.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-08 14:37:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jamesx00",
    "github_project": "django-omise",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "django-omise"
}
        
Elapsed time: 0.25555s