django-memberpress-client


Namedjango-memberpress-client JSON
Version 1.0.5 PyPI version JSON
download
home_pagehttps://github.com/lpm0073/django-memberpress-client
SummaryA Django plugin to add Memberpress REST API and Webhook integrations.
upload_time2024-04-26 19:17:19
maintainerNone
docs_urlNone
authorLawrence McDaniel
requires_python>=3.8
licenseNone
keywords python django wordpress memberpress rest api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Plugin For memberpress REST API Client

[![pypi django-memberpress-client](https://img.shields.io/static/v1?label=pypi&style=flat-square&color=0475b6&message=django-memberpress-client)](https://pypi.org/project/django-memberpress-client/) [![memberpress](https://img.shields.io/static/v1?label=memberpress&style=flat-square&color=04d4e4&message=REST%20API)](https://memberpress.com/addons/developer-tools/) [![hack.d Lawrence McDaniel](https://img.shields.io/badge/hack.d-Lawrence%20McDaniel-orange.svg)](https://lawrencemcdaniel.com)

![memberpress](https://memberpress.com/wp-content/uploads/2022/01/memberpress-logo-color.svg)

A lightweight, performant Django plugin that implements REST api and Webhook integrations for the [Wordpress](https://wordpress.org/) [memberpress](https://memberpress.com/blog/memberpress-developer-tools/) Pro plugin.

## Installation

```bash
pip install django-memberpress-client
```

```python
from django.conf import settings

# required settings
settings.MEMBERPRESS_API_KEY = 'set-me-please'
settings.MEMBERPRESS_API_BASE_URL = 'https://set-me-please.com/'

# optional settings
settings.MEMBERPRESS_API_KEY_NAME = "MEMBERPRESS-API-KEY"
settings.MEMBERPRESS_CACHE_EXPIRATION = 60*60*24
settings.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:

```shell
# required settings
MEMBERPRESS_API_KEY=set-me-please
MEMBERPRESS_API_BASE_URL=https://set-me-please.com

# optional settings
MEMBERPRESS_CACHE_EXPIRATION=3600
MEMBERPRESS_API_KEY_NAME=MEMBERPRESS-API-KEY
MEMBERPRESS_SENSITIVE_KEYS=password,token,client_id,client_secret,Authorization,secret
```


You'll find the memberpress API Key in the Wordpress admin site.
![memberpress API Key](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-api-key.png "memberpress API Key")

## Usage

### REST API

```python
# from a Python module inside your existing Django project.
from memberpress_client.member import Member

member = Member(username="jsmith")

if member.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)
```

### Webhooks

This plugin listens for events from memberpress' webhooks framework, a Pro 'developer tools' premium option of memberpress. Add a url of the form https://yourdomain.com/mp/api/v1/webhook to the Developer "Webhooks" page.
![memberpress webhooks](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-api-webhook.png "memberpress webhooks")

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/

![Django admin console](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-django-admin2.png "Django admin console")

## Developers

### quick start

Keep 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/.env
- install all service-level dependencies on your local dev machine. This includes MySQL and Redis.
- clone this repo
- create and activate a Python virtual environment
- run make quickstart

Other 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 hierarchy

Use 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.



```python
class Memberpress:

    class MemberpressEvent(Memberpress):

    class MemberpressAPIClient(Memberpress):
        class Member(MemberpressAPIClient):
        class Membership(MemberpressAPIClient):
        class Subscriber(MemberpressAPIClient):
        class Transaction(MemberpressAPIClient):
```

### constants

Use 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_types

```python
from memberpress_client.constants import MemberpressEvents

print(MemberpressEvents.AFTER_CC_EXPIRES_REMINDER)
after-cc-expires-reminder

print(MemberpressEvents.AFTER_MEMBER_SIGNUP_REMINDER)
after-member-signup-reminder

print(MemberpressEvents.LOGIN)
login

print(MemberpressEvents.MEMBER_ACCOUNT_UPDATED)
member-account-updated

print(MemberpressEvents.SUBSCRIPTION_EXPIRED)
subscription-expired
# ...
# ectetera, etcetera, etcetera ...
# ...
print(MemberpressEvents.TRANSACTION_COMPLETED)
transaction-completed
```

Additionally, note that many of the constants include helper functions.
![memberpress_client constants](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-constants.png "memberpress_client constants")

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lpm0073/django-memberpress-client",
    "name": "django-memberpress-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "Python, Django, Wordpress, MemberPress, REST API",
    "author": "Lawrence McDaniel",
    "author_email": "Lawrence McDaniel <lpm0073@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/0c/9c/e9d0a908e37864ff140f31f3306605ccb0a245f7947620a0da226d1be9c7/django_memberpress_client-1.0.5.tar.gz",
    "platform": null,
    "description": "# Django Plugin For memberpress REST API Client\n\n[![pypi django-memberpress-client](https://img.shields.io/static/v1?label=pypi&style=flat-square&color=0475b6&message=django-memberpress-client)](https://pypi.org/project/django-memberpress-client/) [![memberpress](https://img.shields.io/static/v1?label=memberpress&style=flat-square&color=04d4e4&message=REST%20API)](https://memberpress.com/addons/developer-tools/) [![hack.d Lawrence McDaniel](https://img.shields.io/badge/hack.d-Lawrence%20McDaniel-orange.svg)](https://lawrencemcdaniel.com)\n\n![memberpress](https://memberpress.com/wp-content/uploads/2022/01/memberpress-logo-color.svg)\n\nA lightweight, performant Django plugin that implements REST api and Webhook integrations for the [Wordpress](https://wordpress.org/) [memberpress](https://memberpress.com/blog/memberpress-developer-tools/) Pro plugin.\n\n## Installation\n\n```bash\npip install django-memberpress-client\n```\n\n```python\nfrom django.conf import settings\n\n# required settings\nsettings.MEMBERPRESS_API_KEY = 'set-me-please'\nsettings.MEMBERPRESS_API_BASE_URL = 'https://set-me-please.com/'\n\n# optional settings\nsettings.MEMBERPRESS_API_KEY_NAME = \"MEMBERPRESS-API-KEY\"\nsettings.MEMBERPRESS_CACHE_EXPIRATION = 60*60*24\nsettings.MEMBERPRESS_SENSITIVE_KEYS = [\n    \"password\",\n    \"token\",\n    \"client_id\",\n    \"client_secret\",\n    \"Authorization\",\n    \"secret\",\n]\n```\n\nAlternatively, you can rename .env-sample, located in the same folder location\nas this README.md, to .env:\n\n```shell\n# required settings\nMEMBERPRESS_API_KEY=set-me-please\nMEMBERPRESS_API_BASE_URL=https://set-me-please.com\n\n# optional settings\nMEMBERPRESS_CACHE_EXPIRATION=3600\nMEMBERPRESS_API_KEY_NAME=MEMBERPRESS-API-KEY\nMEMBERPRESS_SENSITIVE_KEYS=password,token,client_id,client_secret,Authorization,secret\n```\n\n\nYou'll find the memberpress API Key in the Wordpress admin site.\n![memberpress API Key](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-api-key.png \"memberpress API Key\")\n\n## Usage\n\n### REST API\n\n```python\n# from a Python module inside your existing Django project.\nfrom memberpress_client.member import Member\n\nmember = Member(username=\"jsmith\")\n\nif member.should_raise_paywall:\n    # not a member, free trial has expired, subscription expired,\n    # subscription renewal payment transaction declined, etc.\n    your_custom_paywall_code()\n\n# and, there is lots more detailed information about the member,\n# their subscription status, their recent transactions history,\n# and so on...\nprint(member.is_active_subscription)\nprint(member.is_trial_subscription)\nprint(member.latest_transaction.amount)\nprint(member.recent_subscriptions[0].created_at)\nprint(member.active_memberships[0].pricing_title)\n```\n\n### Webhooks\n\nThis plugin listens for events from memberpress' webhooks framework, a Pro 'developer tools' premium option of memberpress. Add a url of the form https://yourdomain.com/mp/api/v1/webhook to the Developer \"Webhooks\" page.\n![memberpress webhooks](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-api-webhook.png \"memberpress webhooks\")\n\nurls:\n\n- receive http POST requests: https://your-django-project.com/mp/api/v1/events/\n- view the event log: https://your-django-project.com/admin/memberpress_client/memberpressevents/\n\n![Django admin console](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-django-admin2.png \"Django admin console\")\n\n## Developers\n\n### quick start\n\nKeep in mind that this code package is intended to install as an add-on to your existing Django project. Therefore,\nthe 'production' settings and requirements intentionally ommit all Django and Django support packages\nother 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'.\n\nYou should be able to follow the normal workflow for setting up a Django project for local development. This substantially\nconsists of the following:\n\n- rename ./memberpress_client/settings/.env-sample to ./memberpress_client/settings/.env\n- install all service-level dependencies on your local dev machine. This includes MySQL and Redis.\n- clone this repo\n- create and activate a Python virtual environment\n- run make quickstart\n\nOther 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.\n\n\n### class hierarchy\n\nUse these class objects rather than working directly with the memberpress\njson dicts returned by the api. These class objects include structural and type-checking validations,\nplus they handle dict value data type conversations for you.\n\n\n\n```python\nclass Memberpress:\n\n    class MemberpressEvent(Memberpress):\n\n    class MemberpressAPIClient(Memberpress):\n        class Member(MemberpressAPIClient):\n        class Membership(MemberpressAPIClient):\n        class Subscriber(MemberpressAPIClient):\n        class Transaction(MemberpressAPIClient):\n```\n\n### constants\n\nUse these built-in constants rather than working directly with memberpress' dict key string values:\n\n- MemberpressEvents: discrete list of memberpress event types. The str value exactly matches the event dict key \"event\".\n- MemberpressEventTypes: discrete list of memberpress event_types\n\n```python\nfrom memberpress_client.constants import MemberpressEvents\n\nprint(MemberpressEvents.AFTER_CC_EXPIRES_REMINDER)\nafter-cc-expires-reminder\n\nprint(MemberpressEvents.AFTER_MEMBER_SIGNUP_REMINDER)\nafter-member-signup-reminder\n\nprint(MemberpressEvents.LOGIN)\nlogin\n\nprint(MemberpressEvents.MEMBER_ACCOUNT_UPDATED)\nmember-account-updated\n\nprint(MemberpressEvents.SUBSCRIPTION_EXPIRED)\nsubscription-expired\n# ...\n# ectetera, etcetera, etcetera ...\n# ...\nprint(MemberpressEvents.TRANSACTION_COMPLETED)\ntransaction-completed\n```\n\nAdditionally, note that many of the constants include helper functions.\n![memberpress_client constants](https://raw.githubusercontent.com/lpm0073/django-memberpress-client/main/doc/memberpress-constants.png \"memberpress_client constants\")\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Django plugin to add Memberpress REST API and Webhook integrations.",
    "version": "1.0.5",
    "project_urls": {
        "Bug Tracker": "https://github.com/lpm0073/django-memberpress-client/issues",
        "Homepage": "https://github.com/lpm0073/django-memberpress-client",
        "Repository": "https://github.com/lpm0073/django-memberpress-client"
    },
    "split_keywords": [
        "python",
        " django",
        " wordpress",
        " memberpress",
        " rest api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5091bf74ef32c11a8fc55fea838f1507d49028a7751aa4f41ca0160d03709f57",
                "md5": "054f2f3fee58b99a506a716671c157cd",
                "sha256": "b6d9d12675b1d041ae955c44c4fc8ae7942648e9f98a0311f1175d6d0291a400"
            },
            "downloads": -1,
            "filename": "django_memberpress_client-1.0.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "054f2f3fee58b99a506a716671c157cd",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 46880,
            "upload_time": "2024-04-26T19:17:17",
            "upload_time_iso_8601": "2024-04-26T19:17:17.878270Z",
            "url": "https://files.pythonhosted.org/packages/50/91/bf74ef32c11a8fc55fea838f1507d49028a7751aa4f41ca0160d03709f57/django_memberpress_client-1.0.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c9ce9d0a908e37864ff140f31f3306605ccb0a245f7947620a0da226d1be9c7",
                "md5": "86edaf88b48d5927e10e5b16f18a5c20",
                "sha256": "500d6c70db8b74f2652ad507b5410f8bf36e50e20d24e13eb116826ccb7644f5"
            },
            "downloads": -1,
            "filename": "django_memberpress_client-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "86edaf88b48d5927e10e5b16f18a5c20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 36121,
            "upload_time": "2024-04-26T19:17:19",
            "upload_time_iso_8601": "2024-04-26T19:17:19.771323Z",
            "url": "https://files.pythonhosted.org/packages/0c/9c/e9d0a908e37864ff140f31f3306605ccb0a245f7947620a0da226d1be9c7/django_memberpress_client-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-26 19:17:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lpm0073",
    "github_project": "django-memberpress-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-memberpress-client"
}
        
Elapsed time: 2.18855s