Last active
August 29, 2015 14:14
-
-
Save chris-jamieson/dd6047be45bcaaccc718 to your computer and use it in GitHub Desktop.
GoCardless bad request error
This file contains hidden or 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
| # when get_gc_partner_authorization_url() is called, returns a URL | |
| # when that URL is visited in the browser, error occurs | |
| # error is: "invalid client_id or redirect_uri for sandbox environment" | |
| gocardless.environment = settings.GOCARDLESS_ENVIRONMENT | |
| gocardless.set_details( | |
| app_id=settings.GOCARDLESS_MERCHANT_APP_ID, # taken from https://dashboard-sandbox.gocardless.com/developer/api-keys | |
| app_secret=settings.GOCARDLESS_MERCHANT_APP_SECRET, # taken from https://dashboard-sandbox.gocardless.com/developer/api-keys | |
| access_token=settings.GOCARDLESS_MERCHANT_ACCESS_TOKEN, # taken from https://dashboard-sandbox.gocardless.com/developer/api-keys | |
| merchant_id=settings.GOCARDLESS_MERCHANT_ID # taken from https://dashboard-sandbox.gocardless.com/developer/api-keys | |
| ) | |
| def get_gc_partner_authorization_url(prefill_merchant_details): | |
| """ | |
| passes merchant details to GoCardless and returns a URL, where a merchant can authorise with GoCardless | |
| info: https://developer.gocardless.com/python/#merchant-account-authorization | |
| """ | |
| client = gocardless.Client( | |
| settings.GOCARDLESS_PARTNER_APP_ID, # taken from https://partner-sandbox.gocardless.com/developer/api-keys | |
| settings.GOCARDLESS_PARTNER_APP_SECRET # taken from https://partner-sandbox.gocardless.com/developer/api-keys | |
| ) | |
| merchant_details = { | |
| "user": { | |
| # some processing happens here to set up merchant_details var from prefill_merchant_details... | |
| } | |
| } | |
| redirect_uri = settings.BASE_URL + '/api/v1/gocardless/authorize-merchant' | |
| url = client.new_merchant_url( | |
| redirect_uri=redirect_uri, | |
| merchant=merchant_details | |
| ) | |
| return url |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out error was caused by not setting the redirect_uri in GC sandbox settings.