[#40140123] Working out logic for expiring CC in iPython notebook

pull/1/head
Raymond Yee 2012-11-30 15:09:28 -08:00
parent 0993d393d2
commit 98d6b7b971
1 changed files with 167 additions and 0 deletions

167
expiring_stripe_cc.ipynb Normal file
View File

@ -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": {}
}
]
}