Package: django-memberpress-client
Django Plugin For memberpress REST API ClientA lightweight, performant Django plugin that implements REST api and Webhook integrations for theWordpressmemberpressPro plugin.Installationpipinstalldjango-memberpress-clientfromdjango.confimportsettings# required settingssettings.MEMBERPRESS_API_KEY='set-me-please'settings.MEMBERPRESS_API_BASE_URL='https://set-me-please.com/'# optional settingssettings.MEMBERPRESS_API_KEY_NAME="MEMBERPRESS-API-KEY"settings.MEMBERPRESS_CACHE_EXPIRATION=60*60*24settings.MEMBERPRESS_SENSITIVE_KEYS=["password","token","client_id","client_secret","Authorization","secret",]Alternatively, you can rename .env-sample, located in the same folder location
as this README.md, to .env:# required settingsMEMBERPRESS_API_KEY=set-me-pleaseMEMBERPRESS_API_BASE_URL=https://set-me-please.com# optional settingsMEMBERPRESS_CACHE_EXPIRATION=3600MEMBERPRESS_API_KEY_NAME=MEMBERPRESS-API-KEYMEMBERPRESS_SENSITIVE_KEYS=password,token,client_id,client_secret,Authorization,secretYou'll find the memberpress API Key in the Wordpress admin site.UsageREST API# from a Python module inside your existing Django project.frommemberpress_client.memberimportMembermember=Member(username="jsmith")ifmember.should_raise_paywall:# not a member, free trial has expired, subscription expired,# subscription renewal payment transaction declined, etc.your_custom_paywall_code()# and, there is lots more detailed information about the member,# their subscription status, their recent transactions history,# and so on...print(member.is_active_subscription)print(member.is_trial_subscription)print(member.latest_transaction.amount)print(member.recent_subscriptions[0].created_at)print(member.active_memberships[0].pricing_title)WebhooksThis plugin listens for events from memberpress' webhooks framework, a Pro 'developer tools' premium option of memberpress. Add a url of the formhttps://yourdomain.com/mp/api/v1/webhookto the Developer "Webhooks" page.urls:receive http POST requests:https://your-django-project.com/mp/api/v1/events/view the event log:https://your-django-project.com/admin/memberpress_client/memberpressevents/Developersquick startKeep in mind that this code package is intended to install as an add-on to your existing Django project. Therefore,
the 'production' settings and requirements intentionally ommit all Django and Django support packages
other than those that are unique to this repo. The 'local' settings and requirements compensate for this by including all of the settings and requirements that you'd typically find in 'common' and/or 'production'.You should be able to follow the normal workflow for setting up a Django project for local development. This substantially
consists of the following:rename ./memberpress_client/settings/.env-sample to ./memberpress_client/settings/.envinstall all service-level dependencies on your local dev machine. This includes MySQL and Redis.clone this repocreate and activate a Python virtual environmentrun make quickstartOther common dev chores are automated in the Makefile, noting however that some syntax is specific to macOS environments (my sincerest apologies), plus, it assumes that you've installed mysql and redis using homebrew.class hierarchyUse these class objects rather than working directly with the memberpress
json dicts returned by the api. These class objects include structural and type-checking validations,
plus they handle dict value data type conversations for you.classMemberpress:classMemberpressEvent(Memberpress):classMemberpressAPIClient(Memberpress):classMember(MemberpressAPIClient):classMembership(MemberpressAPIClient):classSubscriber(MemberpressAPIClient):classTransaction(MemberpressAPIClient):constantsUse these built-in constants rather than working directly with memberpress' dict key string values:MemberpressEvents: discrete list of memberpress event types. The str value exactly matches the event dict key "event".MemberpressEventTypes: discrete list of memberpress event_typesfrommemberpress_client.constantsimportMemberpressEventsprint(MemberpressEvents.AFTER_CC_EXPIRES_REMINDER)after-cc-expires-reminderprint(MemberpressEvents.AFTER_MEMBER_SIGNUP_REMINDER)after-member-signup-reminderprint(MemberpressEvents.LOGIN)loginprint(MemberpressEvents.MEMBER_ACCOUNT_UPDATED)member-account-updatedprint(MemberpressEvents.SUBSCRIPTION_EXPIRED)subscription-expired# ...# ectetera, etcetera, etcetera ...# ...print(MemberpressEvents.TRANSACTION_COMPLETED)transaction-completedAdditionally, note that many of the constants include helper functions.