Exemple #1
0
def update_payment_info(request, recurring_payment_id,
                          template_name="recurring_payments/authnet/cim_update_payment_info2.html"):
    """
    Add or edit payment info.
    """
    rp = get_object_or_404(RecurringPayment, pk=recurring_payment_id)

    # only admin or user self can access this page
    if not request.user.profile.is_superuser and request.user.id <> rp.user.id:
        raise Http403

    rp.populate_payment_profile()

    payment_profiles = PaymentProfile.objects.filter(
                                        customer_profile_id=rp.customer_profile_id,
                                        status=True, status_detail='active')
    if payment_profiles:
        payment_profile = payment_profiles[0]
    else:
        payment_profile = None


    token, gateway_error = get_token(rp, CIMCustomerProfile, CIMHostedProfilePage,
                                     is_secure=request.is_secure())
    test_mode = get_test_mode()


    return render_to_response(template_name, {'rp': rp,
                                              'payment_profile': payment_profile,
                                              'token': token,
                                              'test_mode': test_mode,
                                              'gateway_error': gateway_error
                                              },
        context_instance=RequestContext(request))
Exemple #2
0
def view_account(request, recurring_payment_id, 
                          template_name="recurring_payments/index.html"):
    """View a recurring payment account.
    """
    rp = get_object_or_404(RecurringPayment, pk=recurring_payment_id)
    
    # only admin or user self can access this page
    if not request.user.profile.is_superuser and request.user.id <> rp.user.id:
        raise Http403
    
    paid_payment_transactions = PaymentTransaction.objects.filter(
                                                recurring_payment=rp,
                                                status=True
                                                                )
    if paid_payment_transactions:
        last_paid_payment_transaction = paid_payment_transactions[0]
    else:
        last_paid_payment_transaction = None
        
    failed_payment_transactions = PaymentTransaction.objects.filter(
                                                recurring_payment=rp,
                                                status=False
                                                                )
    if failed_payment_transactions:
        last_failed_payment_transaction = failed_payment_transactions[0]
    else:
        last_failed_payment_transaction = None
    
    display_failed_transaction = False    
    if last_failed_payment_transaction:
        if not last_paid_payment_transaction or \
            last_failed_payment_transaction.create_dt  \
            > last_paid_payment_transaction.create_dt:
            display_failed_transaction = True
            
    if not rp.trial_amount:
        rp.trial_amount = 0
        
    # rp_invoices
    rp_invoices = RecurringPaymentInvoice.objects.filter(
                                        recurring_payment=rp
                                        ).order_by('-billing_cycle_start_dt')
                                        
    # payment transactions
    payment_transactions = PaymentTransaction.objects.filter(
                                        recurring_payment=rp
                                        ).order_by('-create_dt')
                                        
    # get ready for the add/update payment method button
    test_mode = get_test_mode()
    is_active = (rp.status_detail == 'active')
    if is_active:
        rp.populate_payment_profile()
        payment_profiles = PaymentProfile.objects.filter(
                            customer_profile_id=rp.customer_profile_id, 
                            status=True, status_detail='active')
        if payment_profiles:
            payment_profile = payment_profiles[0]
        else:
            payment_profile = None
            
    else:
        payment_profile = None
    
    is_owner = False   
    if request.user.id == rp.user.id: is_owner = True
    
    num_accounts = RecurringPayment.objects.filter(user=rp.user).count()
    
    return render_to_response(template_name, {
                                              'rp': rp,
                                              'display_failed_transaction': display_failed_transaction,
                                              'last_paid_payment_transaction': last_paid_payment_transaction,
                                              'last_failed_payment_transaction': last_failed_payment_transaction,
                                              'rp_invoices': rp_invoices,
                                              'payment_transactions': payment_transactions,
                                              'payment_profile': payment_profile,
                                              'test_mode': test_mode,
                                              'is_active': is_active,
                                              'is_owner': is_owner,
                                              'num_accounts': num_accounts
                                              }, 
        context_instance=RequestContext(request))
Exemple #3
0
def view_account(request,
                 recurring_payment_id,
                 template_name="recurring_payments/index.html"):
    """View a recurring payment account.
    """
    rp = get_object_or_404(RecurringPayment, pk=recurring_payment_id)

    # only admin or user self can access this page
    if not request.user.profile.is_superuser and request.user.id <> rp.user.id:
        raise Http403

    paid_payment_transactions = PaymentTransaction.objects.filter(
        recurring_payment=rp, status=True)
    if paid_payment_transactions:
        last_paid_payment_transaction = paid_payment_transactions[0]
    else:
        last_paid_payment_transaction = None

    failed_payment_transactions = PaymentTransaction.objects.filter(
        recurring_payment=rp, status=False)
    if failed_payment_transactions:
        last_failed_payment_transaction = failed_payment_transactions[0]
    else:
        last_failed_payment_transaction = None

    display_failed_transaction = False
    if last_failed_payment_transaction:
        if not last_paid_payment_transaction or \
            last_failed_payment_transaction.create_dt  \
            > last_paid_payment_transaction.create_dt:
            display_failed_transaction = True

    if not rp.trial_amount:
        rp.trial_amount = 0

    # rp_invoices
    rp_invoices = RecurringPaymentInvoice.objects.filter(
        recurring_payment=rp).order_by('-billing_cycle_start_dt')

    # payment transactions
    payment_transactions = PaymentTransaction.objects.filter(
        recurring_payment=rp).order_by('-create_dt')

    # get ready for the add/update payment method button
    test_mode = get_test_mode()
    is_active = (rp.status_detail == 'active')
    if is_active:
        rp.populate_payment_profile()
        payment_profiles = PaymentProfile.objects.filter(
            customer_profile_id=rp.customer_profile_id,
            status=True,
            status_detail='active')
        if payment_profiles:
            payment_profile = payment_profiles[0]
        else:
            payment_profile = None

    else:
        payment_profile = None

    is_owner = False
    if request.user.id == rp.user.id: is_owner = True

    num_accounts = RecurringPayment.objects.filter(user=rp.user).count()

    return render_to_response(template_name, {
        'rp': rp,
        'display_failed_transaction': display_failed_transaction,
        'last_paid_payment_transaction': last_paid_payment_transaction,
        'last_failed_payment_transaction': last_failed_payment_transaction,
        'rp_invoices': rp_invoices,
        'payment_transactions': payment_transactions,
        'payment_profile': payment_profile,
        'test_mode': test_mode,
        'is_active': is_active,
        'is_owner': is_owner,
        'num_accounts': num_accounts
    },
                              context_instance=RequestContext(request))