Package: djangorave
Django RaveProject DescriptionThis project provides Django integration forFlutterwaveRave Card payments and subscriptions.Current functionality:Allow users to make payments (once off and subscription)Create payment buttons which launch Rave payment modalsMaintain a transaction history linked to usersRequirementsPython >= 3.6Django >= 2.0InstallationpipinstalldjangoraveSetupAdd"djangorave"to yourINSTALLED_APPSRun Django migrations:manage.pymigrateAdd the following to yoursettings.py:RAVE_PRODUCTION_PUBLIC_KEY="your key"RAVE_PRODUCTION_SECRET_KEY="your key"RAVE_SANDBOX_PUBLIC_KEY="your key"RAVE_SANDBOX_SECRET_KEY="your key"RAVE_SANDBOX=TrueThe above config will ensuredjangoraveuses your Rave sandbox. Once you are
ready to go live, setRAVE_SANDBOX = FalseAdddjangoraveto yoururls.py:path("djangorave/",include("djangorave.urls",namespace="djangorave"))Add the following url as a webhook in your Rave dashboard. This will be used by
Rave toPOSTpayment transactions to your site:http://yoursite.com/djangorave/transaction/Note:while in development, a tool like ngrok (or similar) may prove useful.Usagedjangoraveprovides two models, namely:TheDRPaymentTypeModelallows you to createonce offorrecurringpayment types. When creating arecurringpayment type, ensure thepayment_planfield
corresponds to the RavePlan ID.TheDRTransactionModelcreates transactions when Rave POSTS to the above mentioned webhook url. This provides a history of all transactions (once off or recurring), linked to the relevantDRPaymentTypeModelanduser.A payment button can be created as follows:Create a newPaymentTypeusing the django admin.In the view where you wish the button to appear, add the above createdPaymentTypeto your context, eg:fromdjangorave.modelsimportDRPaymentTypeModelclassSignUpView(TemplateView):"""Sign Up view"""template_name="my_payment_template.html"defget_context_data(self,**kwargs):"""Add payment type to context data"""kwargs=super().get_context_data(**kwargs)kwargs["pro_plan"]=DRPaymentTypeModel.objects.filter(description="Pro Plan").first()returnkwargsIn your template, add your button wherever you wish for it to appear as follows:{%include'djangorave/pay_button.html'withpayment_model=pro_plan%}Note:You can add multiple buttons to a single template by simply adding multiple
plans to your context data and then including each of them with their ownincludetag as above.Add the following script to your django base template (or anywhere in your template heirarchy that ensures it is loaded before your payment buttons):<scriptsrc="{% static 'djangorave/js/payment.js' %}"></script>Button StylingThe following css classes are available for styling your payment buttons:rave-pay-btnwill apply to all buttons.rave-subscription-btnwill apply to recurring payment types (ie: those with apayment_plan).rave-onceoff-btnwill apply to once off payment types (ie: those without apayment_plan).Transaction Detail PageFollowing a user payment, they will be redirected to the transaction detail page
located at/djangorave/<str:reference>/A default transaction detail template is already available, however if you want
to override it, you may do so by creating a new template in your root
templates directory, ie:/templates/djangorave/transaction.htmlYou will have access to{{ transaction }}within that template.DevelopmentIf you wish to contribute to the project, there is an example app that demonstrates
general usage.Running the example:gitclonehttps://github.com/bdelate/django-rave.gitcddjango-rave
makebuild
makemigrate
makeimport
makedupThere is a section at the bottom ofdjango-rave/example/example/settings.py. Ensure the values are set accordingly:RAVE_PRODUCTION_PUBLIC_KEY="your key"RAVE_PRODUCTION_SECRET_KEY="your key"RAVE_SANDBOX_PUBLIC_KEY="your key"RAVE_SANDBOX_SECRET_KEY="your key"RAVE_SANDBOX=TrueFlutterwave Rave requires payments to be associated with users who have an email address.
Therefore, create and login with a new django user or use the existing user already
generated following the above import command:username: testuser
password: secretNavigate tohttp://localhost:8000/