Skip to content

Commit

Permalink
Hooked up fundraising to Stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez authored and timgraham committed Jan 20, 2015
1 parent 6a352bd commit 3f73c44
Show file tree
Hide file tree
Showing 40 changed files with 2,496 additions and 132 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dependencies": {
"jquery": "<2.0",
"jquery.inview": "1.0.0",
"webfontloader": "~1.5.10"
"webfontloader": "~1.5.10",
"jquery.payment": "~1.1.4"
}
}
8 changes: 7 additions & 1 deletion djangoproject/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'releases',
'svntogit',
'tracdb',
'fundraising'
'fundraising',
]

LANGUAGE_CODE = 'en-us'
Expand Down Expand Up @@ -224,3 +224,9 @@

# SUPERFEEDR_CREDS is a 2 element list in the form of [email,secretkey]
SUPERFEEDR_CREDS = SECRETS.get('superfeedr_creds')

# Stripe settings

# only testing keys as fallback values here please!
STRIPE_SECRET_KEY = SECRETS.get('STRIPE_SECRET_KEY', 'sk_test_x6zP4wd7Z5jcvDOJbbHZlHHt')
STRIPE_PUBLISHABLE_KEY = SECRETS.get('STRIPE_PUBLISHABLE_KEY', 'pk_test_TyB5jcROwK8mlCNrn3dCwW7l')
19 changes: 19 additions & 0 deletions djangoproject/static/js/lib/jquery.payment/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "jquery.payment",
"version": "1.1.4",
"main": "lib/jquery.payment.js",
"dependencies": {
"jquery": ">=1.5"
},
"homepage": "https://github.com/stripe/jquery.payment",
"_release": "1.1.4",
"_resolution": {
"type": "version",
"tag": "v1.1.4",
"commit": "1fc33e1cf9e35ec4cd7b81eb7a6d8065c66cc0e7"
},
"_source": "git://github.com/stripe/jquery.payment.git",
"_target": "~1.1.4",
"_originalSource": "jquery.payment",
"_direct": true
}
1 change: 1 addition & 0 deletions djangoproject/static/js/lib/jquery.payment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions djangoproject/static/js/lib/jquery.payment/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"
18 changes: 18 additions & 0 deletions djangoproject/static/js/lib/jquery.payment/Cakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{spawn} = require 'child_process'
path = require 'path'

binPath = (bin) -> path.resolve(__dirname, "./node_modules/.bin/#{bin}")

runExternal = (cmd, args) ->
child = spawn(binPath(cmd), args, stdio: 'inherit')
child.on('error', console.error)
child.on('close', process.exit)

task 'build', 'Build lib/ from src/', ->
runExternal 'coffee', ['-c', '-o', 'lib', 'src']

task 'watch', 'Watch src/ for changes', ->
runExternal 'coffee', ['-w', '-c', '-o', 'lib', 'src']

task 'test', 'Run tests', ->
runExternal 'mocha', ['--compilers', 'coffee:coffee-script/register']
20 changes: 20 additions & 0 deletions djangoproject/static/js/lib/jquery.payment/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 Stripe

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
214 changes: 214 additions & 0 deletions djangoproject/static/js/lib/jquery.payment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# jQuery.payment [![Build Status](https://travis-ci.org/stripe/jquery.payment.svg?branch=master)](https://travis-ci.org/stripe/jquery.payment)

A general purpose library for building credit card forms, validating inputs and formatting numbers.

For example, you can make a input act like a credit card field (with number formatting and length restriction):

``` javascript
$('input.cc-num').payment('formatCardNumber');
```

Then, when the payment form is submitted, you can validate the card number on the client-side:

``` javascript
var valid = $.payment.validateCardNumber($('input.cc-num').val());

if (!valid) {
alert('Your card is not valid!');
return false;
}
```

You can find a full [demo here](http://stripe.github.io/jquery.payment/example).

Supported card types are:

* Visa
* MasterCard
* American Express
* Diners Club
* Discover
* UnionPay
* JCB
* Visa Electron
* Maestro
* Forbrugsforeningen
* Dankort

## API

### $.fn.payment('formatCardNumber')

Formats card numbers:

* Includes a space between every 4 digits
* Restricts input to numbers
* Limits to 16 numbers
* Supports American Express formatting
* Adds a class of the card type (e.g. 'visa') to the input

Example:

``` javascript
$('input.cc-num').payment('formatCardNumber');
```

### $.fn.payment('formatCardExpiry')

Formats card expiry:

* Includes a `/` between the month and year
* Restricts input to numbers
* Restricts length

Example:

``` javascript
$('input.cc-exp').payment('formatCardExpiry');
```

### $.fn.payment('formatCardCVC')

Formats card CVC:

* Restricts length to 4 numbers
* Restricts input to numbers

Example:

``` javascript
$('input.cc-cvc').payment('formatCardCVC');
```

### $.fn.payment('restrictNumeric')

General numeric input restriction.

Example:

``` javascript
$('[data-numeric]').payment('restrictNumeric');
```

### $.payment.validateCardNumber(number)

Validates a card number:

* Validates numbers
* Validates Luhn algorithm
* Validates length

Example:

``` javascript
$.payment.validateCardNumber('4242 4242 4242 4242'); //=> true
```

### $.payment.validateCardExpiry(month, year)

Validates a card expiry:

* Validates numbers
* Validates in the future
* Supports year shorthand

Example:

``` javascript
$.payment.validateCardExpiry('05', '20'); //=> true
$.payment.validateCardExpiry('05', '2015'); //=> true
$.payment.validateCardExpiry('05', '05'); //=> false
```

### $.payment.validateCardCVC(cvc, type)

Validates a card CVC:

* Validates number
* Validates length to 4

Example:

``` javascript
$.payment.validateCardCVC('123'); //=> true
$.payment.validateCardCVC('123', 'amex'); //=> true
$.payment.validateCardCVC('1234', 'amex'); //=> true
$.payment.validateCardCVC('12344'); //=> false
```

### $.payment.cardType(number)

Returns a card type. Either:

* `visa`
* `mastercard`
* `amex`
* `dinersclub`
* `discover`
* `unionpay`
* `jcb`
* `visaelectron`
* `maestro`
* `forbrugsforeningen`
* `dankort`

The function will return `null` if the card type can't be determined.

Example:

``` javascript
$.payment.cardType('4242 4242 4242 4242'); //=> 'visa'
```

### $.payment.cardExpiryVal(string) and $.fn.payment('cardExpiryVal')

Parses a credit card expiry in the form of MM/YYYY, returning an object containing the `month` and `year`. Shorthand years, such as `13` are also supported (and converted into the longhand, e.g. `2013`).

``` javascript
$.payment.cardExpiryVal('03 / 2025'); //=> {month: 3: year: 2025}
$.payment.cardExpiryVal('05 / 04'); //=> {month: 5, year: 2004}
$('input.cc-exp').payment('cardExpiryVal') //=> {month: 4, year: 2020}
```

This function doesn't perform any validation of the month or year; use `$.payment.validateCardExpiry(month, year)` for that.

## Example

Look in [`./example/index.html`](example/index.html)

## Building

Run `cake build`

## Running tests

Run `cake test`

## Autocomplete recommendations

We recommend you turn autocomplete on for credit card forms, except for the CVC field (which should never be stored). You can do this by setting the `autocomplete` attribute:

``` html
<form autocomplete="on">
<input class="cc-number">
<input class="cc-cvc" autocomplete="off">
</form>
```

You should also mark up your fields using the [Autocomplete Types spec](http://wiki.whatwg.org/wiki/Autocomplete_Types). These are respected by a number of browsers, including Chrome.

``` html
<input type="text" class="cc-number" pattern="\d*" autocomplete="cc-number" placeholder="Card number" required>
```

Set `autocomplete` to `cc-number` for credit card numbers and `cc-exp` for credit card expiry.

## Mobile recommendations

We recommend you set the `pattern` attribute which will cause the numeric keyboard to be displayed on mobiles:

``` html
<input class="cc-number" pattern="\d*">
```

You may have to turn off HTML5 validation (using the `novalidate` form attribute) when using this `pattern`, as it won't match space formatting.
8 changes: 8 additions & 0 deletions djangoproject/static/js/lib/jquery.payment/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "jquery.payment",
"version": "1.1.4",
"main": "lib/jquery.payment.js",
"dependencies": {
"jquery": ">=1.5"
}
}
Loading

0 comments on commit 3f73c44

Please sign in to comment.