Ejemplo n.º 1
0
def dashboard(request):
    club, club_entity = get_club_and_club_entity(request)
    stripe_controller = get_stripe_recipient_controller_for_club(club)
    if not stripe_controller:
        if EventController.PopEvent(request, EventController.CLUB_REGISTERED):
            messages.success(
                request,
                "You are almost finished registering %s, just one more step to go." % club_entity.name)
        return redirect('/club/dashboard/stripe-connect')
    template_data = {
        'stripe': stripe_controller,
        'club_entity': club_entity}
    return render(request, 'spudderspuds/clubs/pages/dashboard.html', template_data)
Ejemplo n.º 2
0
def stripe(request):
    error = get_oauth_request_error(request)
    if error and error == StripeOAuthError.ACCESS_DENIED:
        return redirect('/club/dashboard')

    exception_occurred = False
    club, club_entity = get_club_and_club_entity(request)
    message = None
    json_data = None
    try:
        code = request.GET.get('code', '')
        params = urllib.urlencode({
            'client_secret': settings.STRIPE_SECRET_KEY,
            'code': code,
            'grant_type': 'authorization_code'})
        url = '/oauth/token?%s' % params
        connection = httplib.HTTPSConnection('connect.stripe.com')
        connection.connect()
        connection.request('POST', url)
        resp = connection.getresponse()
        resp_data = resp.read()
        json_data = json.loads(resp_data)
        stripe_user = StripeUser(
            club=club,
            code=code,
            access_token=json_data['access_token'],
            refresh_token=json_data['refresh_token'],
            publishable_key=json_data['stripe_publishable_key'],
            user_id=json_data['stripe_user_id'],
            scope=json_data['scope'],
            token_type=json_data['token_type'])
        stripe_user.save()
        stripe_controller = StripeController(stripe_user)
        account_details = stripe_controller.get_account_details()
        if not account_details or not account_details.get('display_name'):
            message = 'It looks like you registered with Stripe but did not provide a valid business name for your ' \
                      'organization. Please contact [email protected] quoting "NO STRIPE NAME".'
            raise Exception
        club_display_name = account_details['display_name']
        club.name = club_display_name
        club.name_is_fixed = True
        club.save()
        messages.success(
            request,
            "Congratulations, you have successfully connected with Stripe and can now start fundraising on Spudder. "
            "Your organizations name has been changed to match the IRS records you provided to Stripe and is now set "
            "to '%s'." % club_display_name)
    except httplib.HTTPException:
        exception_occurred = True
        logging.error('Http connection exception while trying to contact Stripe API server')
    except KeyError:
        exception_occurred = True
        logging.error('Access token missing in JSON object. Probably Stripe keys are configured improperly')
        logging.error(json_data)
    except Exception as e:
        exception_occurred = True

    if exception_occurred:
        logging.error(traceback.format_exc())
        try:
            StripeUser.objects.get(club=club).delete()
        except StripeUser.DoesNotExist:
            pass
        if not message:
            message = "Sorry, there was an error connecting your stripe account. Please try again and contact " \
                      "[email protected] if the problem continues."
        messages.error(
            request,
            message)
    return redirect('/club/dashboard')
Ejemplo n.º 3
0
def dashboard_stripe_connect(request):
    club, club_entity = get_club_and_club_entity(request)
    template_data = {'club_entity': club_entity}
    return render(request, 'spudderspuds/clubs/pages/dashboard_stripe_connect.html', template_data)