Skip to main content

Library to handle Refund requests using Google Sheets integrations in Django

Project description

mitol-django-google-sheets-refunds

This is the Open Learning Django Google Sheets library for handling refund requests over Google Sheets

Setup

Before you begin setting up this library make sure you set up mitol-django-google-sheets first. Follow the instructions here.

Once you have mitol-django-google-sheets installed, then:

pip install mitol-django-google-sheets-refunds

In settings.py

INSTALLED_APPS = [
    ...
    "mitol.google_sheets_refunds.apps.GoogleSheetsRefundsApp",
]
MITOL_GOOGLE_SHEETS_REFUNDS_PLUGINS = [
    "ecommerce.plugins.RefundPlugin"
]

In ecommerce/plugins.py

from mitol.google_sheets_refunds.hooks import hookimpl

class RefundPlugin:
    @hookimpl
    def refunds_process_request(refund_request: RefundRequestRow) -> RefundResult:
        # TODO: look up the user/order
        # TODO: mark the order as refunded
        # TODO: unenroll the user

Create your google sheets folder

The structure of the folder should look as the following:

  1. Spreadsheet that contains sheets with 'Refund Form Responses' and the 'Refunds' sheets, that is being processed.
  2. Request Form

Ask a developer for a template folder to copy this structure.

Add settings to your app

Set MITOL_GOOGLE_SHEETS_REFUNDS_REQUEST_WORKSHEET_ID in your .env file. It is required.

Some settings have default values, which you might need to update, if your sheet is different.

Description of settings (in addition to the ones described in mitol-django-google-sheets):

  • MITOL_GOOGLE_SHEETS_REFUNDS_REQUEST_WORKSHEET_ID

    The IDs of the refund and deferral sheets in the change of enrollment spreadsheet. These can be found by opening the spreadsheet, selecting the "Refunds" or "Deferrals" worksheets, and copying down the gid value in the URL.

    Example: https://docs.google.com/spreadsheets/d/<MITOL_GOOGLE_SHEETS_ENROLLMENT_CHANGE_SHEET_ID>/edit#gid=<MITOL_GOOGLE_SHEETS_REFUNDS_REQUEST_WORKSHEET_ID>

  • MITOL_GOOGLE_SHEETS_REFUNDS_PROCESSOR_COL

    The zero-based index of the refund change sheet column that contains the user that processed the row

  • MITOL_GOOGLE_SHEETS_REFUNDS_COMPLETED_DATE_COL

    The zero-based index of the refund change sheet column that contains the row completion date

  • MITOL_GOOGLE_SHEETS_REFUNDS_ERROR_COL

    The zero-based index of the refund change sheet column that contains row processing error messages

  • MITOL_GOOGLE_SHEETS_REFUNDS_SKIP_ROW_COL

    The zero-based index of the refund change sheet column that indicates whether the row should be skipped

  • MITOL_GOOGLE_SHEETS_REFUNDS_FIRST_ROW

    The first row (as it appears in the spreadsheet) of data that our scripts should consider processing in the refund request spreadsheet

Usage

To processing your google sheet with refund requests simply add:

refund_request_handler = RefundRequestHandler()
results = refund_request_handler.process_sheet()

Here are two main ways that we are currently getting our Google Sheets Refunds processed:

  1. Run a management command. For example: ./manage.py process_refund_requests -i "<spreadsheet id>"
  2. Set up a scheduled celery task. For example:
from mitol.google_sheets_refunds.api import RefundRequestHandler
from main.celery import app

@app.task
def process_refund_requests():
    """
    Task to process refund requests from Google sheets
    """
    refund_request_handler = RefundRequestHandler()
    if not refund_request_handler.is_configured():
        log.warning("MITOL_GOOGLE_SHEETS_* are not set")
        return
    refund_request_handler.process_sheet()

Develper setup

For local development setup and testing please follow the instructions Developer Setup here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file mitol_django_google_sheets_refunds-2025.6.13.tar.gz.

File metadata

File hashes

Hashes for mitol_django_google_sheets_refunds-2025.6.13.tar.gz
Algorithm Hash digest
SHA256 77192dbcf9663bc4295679f0092058cc1ea3630a0244234f59e2075f1c6da078
MD5 2c47d192743976d6ead3ef177a90aa09
BLAKE2b-256 31672c1d2b5860dcf8f23e72dcffb9d451b34f3bd75654f3885c9d4a660ce53c

See more details on using hashes here.

File details

Details for the file mitol_django_google_sheets_refunds-2025.6.13-py3-none-any.whl.

File metadata

File hashes

Hashes for mitol_django_google_sheets_refunds-2025.6.13-py3-none-any.whl
Algorithm Hash digest
SHA256 28a504396a681d10b03d9f58f142dd93a96c9cb987240faff333b318c4dd43fe
MD5 c024be0967f972c31c6e507baad64647
BLAKE2b-256 0c96f2a9f651f9055e5104a12e91e4bc01982be57b8116d054bb2c771b39b45b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page