django-omise


Namedjango-omise JSON
Version 0.2.11 PyPI version JSON
download
home_pagehttps://github.com/jamesx00/django-omise
SummaryDjango models for Omise
upload_time2022-05-28 00:21:06
maintainer
docs_urlNone
authorJames Tansiri
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            > :warning: The latest pypi package for Omise has a metadata error. Please reinstall omise from this command:

```
pip uninstall omise
pip install git+https://github.com/omise/omise-python@bfcf283378a823139b9f19f10e84d42a98c5b1ac
```

# django-omise Django + Omise

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



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jamesx00/django-omise",
    "name": "django-omise",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "James Tansiri",
    "author_email": "tansirijames@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/28/53/2b7400f6e470d1ff2b9c2a7f21f3e460380998ea61688b8733c4f4f23aea/django-omise-0.2.11.tar.gz",
    "platform": null,
    "description": "> :warning: The latest pypi package for Omise has a metadata error. Please reinstall omise from this command:\n\n```\npip uninstall omise\npip install git+https://github.com/omise/omise-python@bfcf283378a823139b9f19f10e84d42a98c5b1ac\n```\n\n# django-omise Django + Omise\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\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django models for Omise",
    "version": "0.2.11",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "3b422c0e1ff4d69f191daf9689a561b6",
                "sha256": "1705b6f4f007d49677fba1d0b9b3041ed8cd81991a02730265dd91b447bd7492"
            },
            "downloads": -1,
            "filename": "django_omise-0.2.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b422c0e1ff4d69f191daf9689a561b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 187609,
            "upload_time": "2022-05-28T00:21:04",
            "upload_time_iso_8601": "2022-05-28T00:21:04.220164Z",
            "url": "https://files.pythonhosted.org/packages/b6/35/1f53434ca820ed81e97e7f1a661fc57216d74229a73589373c592b5228c7/django_omise-0.2.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "065df080a42f4b0d9b30665edb2e04d9",
                "sha256": "6f527e8dfefe0b691c6c6a136e8c6513cc0da15d876d24d6f6172fc7824f4879"
            },
            "downloads": -1,
            "filename": "django-omise-0.2.11.tar.gz",
            "has_sig": false,
            "md5_digest": "065df080a42f4b0d9b30665edb2e04d9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 158656,
            "upload_time": "2022-05-28T00:21:06",
            "upload_time_iso_8601": "2022-05-28T00:21:06.803005Z",
            "url": "https://files.pythonhosted.org/packages/28/53/2b7400f6e470d1ff2b9c2a7f21f3e460380998ea61688b8733c4f4f23aea/django-omise-0.2.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-05-28 00:21:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "jamesx00",
    "github_project": "django-omise",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-omise"
}
        
Elapsed time: 0.41561s