Exemple #1
0
def _state_engine_process_pay(request, challenge, engine, state,
                              template_data):
    template = challenge.template
    beneficiary = EntityController.GetWrappedEntityByTypeAndId(
        challenge.recipient_entity_type, challenge.recipient_entity_id,
        EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type))
    participation = get_object_or_404(
        ChallengeParticipation,
        challenge=challenge,
        participating_entity_id=request.current_role.entity.id,
        participating_entity_type=request.current_role.entity_type)
    if beneficiary.entity_type != EntityController.ENTITY_CLUB or not beneficiary.entity.is_fully_activated(
    ):
        participation.state_engine_state = _StateEngineStates.PLEDGE_THANKS
        participation.state_engine = engine
        participation.save()
        response = redirect(
            '/challenges/%s/%s/%s' %
            (challenge.id, engine, _StateEngineStates.PLEDGE_THANKS))
        return response, state

    if request.method == "POST":
        token = request.POST.get('stripeToken', None)
        if token is None:
            logging.error('Missing stripeToken in payment processing')
            return None, _StateEngineStates.PAY_FAILED

        stripe_controller = get_stripe_recipient_controller_for_club(
            beneficiary.entity)
        if stripe_controller is None:
            return None, _StateEngineStates.PAY_FAILED

        donation = int(participation.donation_amount) * 100
        payment_status = stripe_controller.accept_payment(
            "Donation of $%s by %s to %s for %s" %
            (int(participation.donation_amount), request.user.email,
             beneficiary.name, challenge.name), token, donation)
        if not payment_status['success']:
            return None, _StateEngineStates.PAY_FAILED

        participation.state_engine_state = _StateEngineStates.PAY_THANKS
        participation.charge_id = payment_status['charge_id']
        participation.save()

        response = redirect('/challenges/%s/%s' % (challenge.id, engine))

        return response, state

    template_data = {
        'challenge': challenge,
        'participation': participation,
        'template': template,
        'beneficiary': beneficiary,
        'errors': request.method == 'POST'
    }
    response = render(
        request,
        'spudderspuds/challenges/pages_ajax/challenge_accept_pay.html',
        template_data)
    return response, state
Exemple #2
0
def _state_engine_process_pay(request, challenge, engine, state, template_data):
    template = challenge.template
    beneficiary = EntityController.GetWrappedEntityByTypeAndId(
        challenge.recipient_entity_type,
        challenge.recipient_entity_id,
        EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type))
    participation = get_object_or_404(
        ChallengeParticipation,
        challenge=challenge,
        participating_entity_id=request.current_role.entity.id,
        participating_entity_type=request.current_role.entity_type)
    if beneficiary.entity_type != EntityController.ENTITY_CLUB or not beneficiary.entity.is_fully_activated():
        participation.state_engine_state = _StateEngineStates.PLEDGE_THANKS
        participation.state_engine = engine
        participation.save()
        response = redirect('/challenges/%s/%s/%s' % (
            challenge.id,
            engine,
            _StateEngineStates.PLEDGE_THANKS))
        return response, state

    if request.method == "POST":
        token = request.POST.get('stripeToken', None)
        if token is None:
            logging.error('Missing stripeToken in payment processing')
            return None, _StateEngineStates.PAY_FAILED

        stripe_controller = get_stripe_recipient_controller_for_club(beneficiary.entity)
        if stripe_controller is None:
            return None, _StateEngineStates.PAY_FAILED

        donation = int(participation.donation_amount) * 100
        payment_status = stripe_controller.accept_payment(
            "Donation of $%s by %s to %s for %s" % (
                int(participation.donation_amount),
                request.user.email,
                beneficiary.name,
                challenge.name),
            token,
            donation)
        if not payment_status['success']:
            return None, _StateEngineStates.PAY_FAILED

        participation.state_engine_state = _StateEngineStates.PAY_THANKS
        participation.charge_id = payment_status['charge_id']
        participation.save()

        response = redirect('/challenges/%s/%s' % (challenge.id, engine))

        return response, state

    template_data = {
        'challenge': challenge,
        'participation': participation,
        'template': template,
        'beneficiary': beneficiary,
        'errors': request.method == 'POST'}
    response = render(request, 'spudderspuds/challenges/pages_ajax/challenge_accept_pay.html', template_data)
    return response, state
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)
def challenge_accept_pay(request, challenge_id):
    if not request.current_role:
        return redirect('/challenges/create/register?next=%s' % request.path)
    challenge = get_object_or_404(Challenge, id=challenge_id)
    template = challenge.template
    beneficiary = EntityController.GetWrappedEntityByTypeAndId(
        challenge.recipient_entity_type, challenge.recipient_entity_id,
        EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type))
    challenge_participation = get_object_or_404(
        ChallengeParticipation,
        challenge=challenge,
        participating_entity_id=request.current_role.entity.id,
        participating_entity_type=request.current_role.entity_type)
    if not beneficiary.entity_type == EntityController.ENTITY_CLUB or not beneficiary.entity.is_fully_activated(
    ):
        return redirect('/challenges/%s/accept/notice?just_pledged=True' %
                        challenge.id)
    if request.method == "POST":
        token = request.POST.get('stripeToken', None)
        if token is not None:

            stripe_controller = get_stripe_recipient_controller_for_club(
                beneficiary.entity)
            if stripe_controller is not None:

                payment_status = stripe_controller.accept_payment(
                    "Donation by %s to %s for %s" %
                    (request.user.email, beneficiary.name, challenge.name),
                    token,
                    int(challenge_participation.donation_amount) * 100)

                if payment_status['success']:
                    challenge_participation.charge_id = payment_status[
                        'charge_id']
                    challenge_participation.save()

                    return redirect(
                        '/challenges/%s/accept/notice?just_donated=True' %
                        challenge.id)

    template_data = {
        'challenge': challenge,
        'challenge_participation': challenge_participation,
        'template': template,
        'beneficiary': beneficiary,
        'errors': request.method == 'POST'
    }
    return render(request,
                  'spudderspuds/challenges/pages/challenge_accept_pay.html',
                  template_data)
Exemple #5
0
def challenge_accept_pay(request, challenge_id):
    if not request.current_role:
        return redirect('/challenges/create/register?next=%s' % request.path)
    challenge = get_object_or_404(Challenge, id=challenge_id)
    template = challenge.template
    beneficiary = EntityController.GetWrappedEntityByTypeAndId(
        challenge.recipient_entity_type,
        challenge.recipient_entity_id,
        EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type))
    challenge_participation = get_object_or_404(
        ChallengeParticipation,
        challenge=challenge,
        participating_entity_id=request.current_role.entity.id,
        participating_entity_type=request.current_role.entity_type)
    if not beneficiary.entity_type == EntityController.ENTITY_CLUB or not beneficiary.entity.is_fully_activated():
        return redirect('/challenges/%s/accept/notice?just_pledged=True' % challenge.id)
    if request.method == "POST":
        token = request.POST.get('stripeToken', None)
        if token is not None:

            stripe_controller = get_stripe_recipient_controller_for_club(beneficiary.entity)
            if stripe_controller is not None:

                payment_status = stripe_controller.accept_payment(
                    "Donation by %s to %s for %s" % (request.user.email, beneficiary.name, challenge.name),
                    token,
                    int(challenge_participation.donation_amount) * 100)

                if payment_status['success']:
                    challenge_participation.charge_id = payment_status['charge_id']
                    challenge_participation.save()

                    return redirect('/challenges/%s/accept/notice?just_donated=True' % challenge.id)

    template_data = {
        'challenge': challenge,
        'challenge_participation': challenge_participation,
        'template': template,
        'beneficiary': beneficiary,
        'errors': request.method == 'POST'}
    return render(request, 'spudderspuds/challenges/pages/challenge_accept_pay.html', template_data)