diff --git a/expiring_stripe_cc.ipynb b/expiring_stripe_cc.ipynb new file mode 100644 index 00000000..55215873 --- /dev/null +++ b/expiring_stripe_cc.ipynb @@ -0,0 +1,167 @@ +{ + "metadata": { + "name": "expiring_stripe_cc" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# working out logic around expiring credit cards" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from regluit.payment.stripelib import StripeClient\n", + "from regluit.payment.models import Account\n", + "\n", + "from django.db.models import Q, F\n" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from regluit.payment.models import Account\n", + "from django.db.models import Q\n", + "\n", + "month = 7\n", + "year = 2013\n", + "\n", + "# look only at active accounts\n", + "\n", + "active_accounts = Account.objects.filter(Q(date_deactivated__isnull=True))\n", + "\n", + "# calculate expired cards\n", + "accounts_expired = active_accounts.filter((Q(card_exp_year__lt=year) | Q(card_exp_year=year, card_exp_month__lt = month)))\n", + "\n", + "# expiring on a given month\n", + "\n", + "accounts_expiring = active_accounts.filter(card_exp_year=year, card_exp_month = month)\n", + "\n", + "# yet to expire\n", + "\n", + "accounts_expiring_later = active_accounts.filter((Q(card_exp_year__gt=year) | Q(card_exp_year=year, card_exp_month__gt = month)))\n", + "\n", + "print active_accounts.count()\n", + "print accounts_expired.count(), accounts_expiring.count(), accounts_expiring_later.count()\n", + "\n", + "[(account.card_exp_month, account.card_exp_year) for account in accounts_expired]" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# validity of accounts" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from regluit.payment.stripelib import StripeClient\n", + "from django.db.models import Q\n", + "\n", + "sc = StripeClient()\n", + "customers = list(sc._all_objs('Customer'))\n", + "\n", + "[(customer.active_card[\"address_line1_check\"], \n", + "customer.active_card[\"address_zip_check\"], \n", + "customer.active_card[\"cvc_check\"]) for customer in customers]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "[(customer.active_card[\"address_line1_check\"], \n", + "customer.active_card[\"address_zip_check\"], \n", + "customer.active_card[\"cvc_check\"]) for customer in customers]" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# look at only customers that are attached to active Account" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from regluit.payment.stripelib import StripeClient\n", + "from regluit.payment.models import Account\n", + "\n", + "sc = StripeClient()\n", + "customers = sc._all_objs('Customer')\n", + "\n", + "active_accounts = Account.objects.filter(Q(date_deactivated__isnull=True))\n", + "\n", + "active_customer_ids = set([account.account_id for account in active_accounts])\n" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "[(customer.active_card[\"address_line1_check\"], \n", + "customer.active_card[\"address_zip_check\"], \n", + "customer.active_card[\"cvc_check\"]) for customer in customers if customer.id in active_customer_ids]" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# should we delete stripe accounts associated with deactivated accounts -- I think yes" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "len(active_customer_ids)" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file