-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade GoCardless API and use gocardless_pro
GoCardless updated their API and deprecated the older one. These changes keep the same donation flow with the new API. Note that there's a slightly ugly relationship between the GoCardlessHelper and the session. This is because we need to hand the user off to GC to create a "customer" object (that contains the bank details), and that object is accessible after being redirected. It would be nice to find a neater way to do this, as right now the logic is split between the helper class, the middleware and the views.
- Loading branch information
Showing
10 changed files
with
149 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import vcr | ||
|
||
|
||
@vcr.use_cassette( | ||
'fixtures/vcr_cassettes/test_donation_redirect_url.yaml', | ||
filter_headers=['Authorization', 'Idempotency-Key']) | ||
def test_donation_middleware_form_valid(db, client): | ||
form_data = { | ||
'donation_form-amount': 10, | ||
'donation_form-payment_type': 'subscription', | ||
} | ||
req = client.post('/donate/', form_data) | ||
assert req.url == "https://pay-sandbox.gocardless.com/flow/RE0000PV77M4SN1QWF1F30SP8PXQHAWC" # noqa | ||
assert req.status_code == 302 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from django.conf.urls import url | ||
|
||
from .views import DonateFormView, DonateThanksView | ||
from .views import DonateFormView, DonateThanksView, ProcessDonationView | ||
|
||
urlpatterns = [ | ||
url(r'thanks', DonateThanksView.as_view(), name="donate_thanks"), | ||
url(r'process', ProcessDonationView.as_view(), name="donate_process"), | ||
url(r'', DonateFormView.as_view(), name="donate"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
interactions: | ||
- request: | ||
body: '{"redirect_flows": {"success_redirect_url": "http://localhost:8000/donate/process/", | ||
"session_token": "l73u2qofrcu2xnfwks8ha5tv6pohqkpu", "description": "Helping | ||
Democracy Club increase the quality of information on elections & the democratic | ||
processes"}}' | ||
headers: | ||
Accept: [application/json] | ||
Accept-Encoding: ['gzip, deflate'] | ||
Connection: [keep-alive] | ||
Content-Length: ['255'] | ||
Content-Type: [application/json] | ||
GoCardless-Client-Library: [gocardless-pro-python] | ||
GoCardless-Client-Version: [1.1.0] | ||
GoCardless-Version: ['2015-07-06'] | ||
User-Agent: [gocardless-pro-python/1.1.0 python/3.4 CPython/3.4.3-final0 Darwin/15.2.0 | ||
requests/2.17.3] | ||
method: POST | ||
uri: https://api-sandbox.gocardless.com/redirect_flows | ||
response: | ||
body: {string: '{"redirect_flows":{"id":"RE0000PV77M4SN1QWF1F30SP8PXQHAWC","description":"Helping | ||
Democracy Club increase the quality of information on elections & the democratic | ||
processes","session_token":"l73u2qofrcu2xnfwks8ha5tv6pohqkpu","scheme":null,"success_redirect_url":"http://localhost:8000/donate/process/","created_at":"2017-12-01T11:47:43.447Z","links":{"creditor":"CR00005378BCBE"},"redirect_url":"https://pay-sandbox.gocardless.com/flow/RE0000PV77M4SN1QWF1F30SP8PXQHAWC"}}'} | ||
headers: | ||
CF-RAY: [3c65d0342bc806e2-LHR] | ||
Cache-Control: [no-store] | ||
Connection: [keep-alive] | ||
Content-Type: [application/json] | ||
Date: ['Fri, 01 Dec 2017 11:47:43 GMT'] | ||
ETag: [W/"1a147b8d7b39ae13c43a721886ca3a35"] | ||
Location: ['https://api-sandbox.gocardless.com/redirect_flows/RE0000PV77M4SN1QWF1F30SP8PXQHAWC'] | ||
Pragma: [no-cache] | ||
RateLimit-Limit: ['1000'] | ||
RateLimit-Remaining: ['999'] | ||
RateLimit-Reset: ['Fri, 01 Dec 2017 11:48:00 GMT'] | ||
Server: [cloudflare-nginx] | ||
Set-Cookie: ['__cfduid=d357016786b54d22d85e275fccf3800ff1512128863; expires=Sat, | ||
01-Dec-18 11:47:43 GMT; path=/; domain=.gocardless.com; HttpOnly'] | ||
Strict-Transport-Security: [max-age=31556926; includeSubDomains; preload] | ||
Vary: [Origin] | ||
X-Content-Type-Options: [nosniff] | ||
X-Request-Id: [02274725-9552-4874-9023-af56b99a5651] | ||
X-XSS-Protection: [1; mode=block] | ||
status: {code: 201, message: Created} | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters