Package: django-omise
django-omise Django + OmiseDjango models for Omise. Currently, we support the following features:Creating a customerAllowing customer to add/delete credit/debit cardsCollect payments with new card with the option to keep the cardCollect payments with saved cardsCollect payments withInternet BankingCollect payments withTrueMoney WalletCollect payments withPromptpayCollect payments withRabbit LINE PayWebhook handler, saving raw data as an Event object and update related objects, currently supportingCustomerCardChargeSourceRefundScheduleScheduled ChargeSchedule Occurrence3DS pending charges handlingSee theroadmapfor the plan of this project. Contributions are welcome!Quick startAdd "django_omise" to your INSTALLED_APPS setting like this:INSTALLED_APPS = [
        ...
        "django_omise",
    ]Include the django_omise URLconf in your project urls.py like this:path("payments/", include("django_omise.urls")),Add Omise keys and operating mode in settings.py:OMISE_PUBLIC_KEY=xxxxOMISE_SECRET_KEY=xxxxOMISE_LIVE_MODE=True|FalseOMISE_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]Runpython manage.py migrateto create the Omise models.Add Omise endpoint webhook urlhttps://www.your-own-domain.com/payments/webhook/Basic usageCreate an Omise customer from User:fromdjango.contrib.authimportget_user_modelfromdjango_omise.models.coreimportCustomerUser=get_user_model()user=User.objects.first()customer=Customer.get_or_create(user=user)Add card to Customer2.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 Manuallyfromdjango_omise.models.coreimportCustomerfromdjango_omise.omiseimportomiseomise_token=omise.Token.retrieve(token_id)Customer.objects.live().first().add_card(token=omise_token)Charge a customer (Currently supporting new/saved cards,Internet Banking,TrueMoney Wallet,Promptpay)3.1 With the build-in mixinThis 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 seeExample 1:fromdjango.contrib.auth.mixinsimportLoginRequiredMixinfromdjango_omise.mixinsimportCheckoutMixinfromdjango_omise.models.choicesimportCurrency# Your own class-based-viewclassCheckoutView(LoginRequiredMixin,CheckoutMixin):template_name="yourapp/template.html"success_url=...defget_charge_details(self):return{"amount":100000,"currency":Currency.THB,}defprocess_charge_and_form(self,charge,form):ifcharge.statusin[ChargeStatus.SUCCESSFUL,ChargeStatus.PENDING]:# Create new order and attach a charge object# And handle form datahandle_form_data(form.cleaned_data)3.2 Manuallyfromdjango_omise.models.choicesimportCurrency,ChargeStatusfromdjango_omise.models.coreimportCustomercustomer=Customer.objects.first()card=customer.cards.live().first()charge=customer.charge_with_card(amount=100000,currency=Currency.THB,card=card,)ifcharge.status==ChargeStatus.SUCCESSFUL:# Do somethingelifcharge.status==ChargeStatus.FAILED:# Do something elseCreate 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:importdatetimefromdjango_omise.models.choicesimportCurrencyfromdjango_omise.models.coreimportCustomercustomer=Customer.objects.first()card=customer.default_cardcustomer.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 contributionsHere 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 atsiwatjames@gmail.com.Omise FeaturesHandle refunds APIHandle webhook events and update related objectsCreate charge with SourcesInternet bankingTrueMoney WalletPromptpayRabbit LINE PayInstallmentScheduleScheduled ChargesScheduled TransferOthersImplement testsAdd documentationsDevelopmentYou can run tests with either coverage or pytest.To run with pytestpipinstallpytest-django
python-mpytest[path_to_file][--verbose-s--cov-report=html--cov=.]To run with coveragepipinstallcoverage
coveragerunrun_tests.py
coveragereport
coveragehtml