Merge branch 'master' of github.com:Gluejar/regluit
commit
a3fbf5d7b7
8
admin.py
8
admin.py
|
@ -57,6 +57,12 @@ class UserProfileAdmin(ModelAdmin):
|
|||
class TransactionAdmin(ModelAdmin):
|
||||
date_hierarchy = 'date_created'
|
||||
|
||||
class PaymentResponseAdmin(ModelAdmin):
|
||||
pass
|
||||
|
||||
class ReceiverAdmin(ModelAdmin):
|
||||
ordering = ('email',)
|
||||
|
||||
admin_site = RegluitAdmin("Admin")
|
||||
|
||||
admin_site.register(models.User, UserAdmin)
|
||||
|
@ -72,3 +78,5 @@ admin_site.register(models.Ebook, EbookAdmin)
|
|||
admin_site.register(models.Wishlist, WishlistAdmin)
|
||||
admin_site.register(models.UserProfile, UserProfileAdmin)
|
||||
admin_site.register(payment.models.Transaction, TransactionAdmin)
|
||||
admin_site.register(payment.models.PaymentResponse, PaymentResponseAdmin)
|
||||
admin_site.register(payment.models.Receiver, ReceiverAdmin)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from regluit.core import models
|
||||
from regluit.payment.models import Transaction
|
||||
from regluit.payment.models import Transaction, PaymentResponse, Receiver
|
||||
from regluit.payment.manager import PaymentManager
|
||||
from regluit.payment.paypal import IPN_PAY_STATUS_ACTIVE, IPN_PAY_STATUS_INCOMPLETE, IPN_PAY_STATUS_COMPLETED
|
||||
|
||||
|
@ -31,7 +31,10 @@ def finish_campaigns(clist):
|
|||
return [pm.finish_campaign(c) for c in clist]
|
||||
|
||||
def drop_all_transactions():
|
||||
PaymentResponse.objects.all().delete()
|
||||
Receiver.objects.all().delete()
|
||||
Transaction.objects.all().delete()
|
||||
|
||||
# go through all Campaigns and set the self.left = self.target
|
||||
for c in models.Campaign.objects.all():
|
||||
c.left = c.target
|
||||
|
|
|
@ -92,6 +92,7 @@ class Campaign(models.Model):
|
|||
amazon_receiver = models.CharField(max_length=100, blank=True)
|
||||
work = models.ForeignKey("Work", related_name="campaigns", null=False)
|
||||
managers = models.ManyToManyField(User, related_name="campaigns", null=False)
|
||||
# status: INITIALIZED, ACTIVE, SUSPENDED, WITHDRAWN, SUCCESSFUL, UNSUCCESSFUL
|
||||
status = models.CharField(max_length=15, null=True, blank=False, default="INITIALIZED")
|
||||
problems = []
|
||||
|
||||
|
@ -149,9 +150,10 @@ class Campaign(models.Model):
|
|||
else:
|
||||
return 0
|
||||
|
||||
def transactions(self, pledged=True, authorized=True):
|
||||
def transactions(self, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
||||
p = PaymentManager()
|
||||
return p.query_campaign(campaign=self, summary=False, pledged=pledged, authorized=authorized)
|
||||
return p.query_campaign(campaign=self, summary=summary, pledged=pledged, authorized=authorized, incomplete=incomplete,
|
||||
completed=completed)
|
||||
|
||||
def activate(self):
|
||||
status = self.status
|
||||
|
|
|
@ -2,7 +2,7 @@ from regluit.core.models import Campaign, Wishlist
|
|||
from regluit.payment.models import Transaction, Receiver, PaymentResponse
|
||||
from django.contrib.auth.models import User
|
||||
from regluit.payment.parameters import *
|
||||
from regluit.payment.paypal import Pay, Execute, IPN, IPN_TYPE_PAYMENT, IPN_TYPE_PREAPPROVAL, IPN_TYPE_ADJUSTMENT, IPN_PAY_STATUS_ACTIVE
|
||||
from regluit.payment.paypal import Pay, Execute, IPN, IPN_TYPE_PAYMENT, IPN_TYPE_PREAPPROVAL, IPN_TYPE_ADJUSTMENT, IPN_PAY_STATUS_ACTIVE, IPN_PAY_STATUS_INCOMPLETE
|
||||
from regluit.payment.paypal import Preapproval, IPN_PAY_STATUS_COMPLETED, CancelPreapproval, PaymentDetails, PreapprovalDetails, IPN_SENDER_STATUS_COMPLETED, IPN_TXN_STATUS_COMPLETED
|
||||
import uuid
|
||||
import traceback
|
||||
|
@ -257,26 +257,40 @@ class PaymentManager( object ):
|
|||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
def run_query(self, transaction_list, summary, pledged, authorized):
|
||||
def run_query(self, transaction_list, summary, pledged, authorized, incomplete, completed):
|
||||
'''
|
||||
Generic query handler for returning summary and transaction info, see query_user, query_list and query_campaign
|
||||
'''
|
||||
|
||||
if pledged:
|
||||
pledged_list = transaction_list.filter(type=PAYMENT_TYPE_INSTANT,
|
||||
status="COMPLETED")
|
||||
status=IPN_PAY_STATUS_COMPLETED)
|
||||
else:
|
||||
pledged_list = []
|
||||
|
||||
if authorized:
|
||||
authorized_list = transaction_list.filter(type=PAYMENT_TYPE_AUTHORIZATION,
|
||||
status="ACTIVE")
|
||||
status=IPN_PAY_STATUS_ACTIVE)
|
||||
else:
|
||||
authorized_list = []
|
||||
|
||||
if incomplete:
|
||||
incomplete_list = transaction_list.filter(type=PAYMENT_TYPE_AUTHORIZATION,
|
||||
status=IPN_PAY_STATUS_INCOMPLETE)
|
||||
else:
|
||||
incomplete_list = []
|
||||
|
||||
if completed:
|
||||
completed_list = transaction_list.filter(type=PAYMENT_TYPE_AUTHORIZATION,
|
||||
status=IPN_PAY_STATUS_COMPLETED)
|
||||
else:
|
||||
completed_list = []
|
||||
|
||||
if summary:
|
||||
pledged_amount = D('0.00')
|
||||
authorized_amount = D('0.00')
|
||||
incomplete_amount = D('0.00')
|
||||
completed_amount = D('0.00')
|
||||
|
||||
for t in pledged_list:
|
||||
for r in t.receiver_set.all():
|
||||
|
@ -288,15 +302,19 @@ class PaymentManager( object ):
|
|||
for t in authorized_list:
|
||||
authorized_amount += t.amount
|
||||
|
||||
amount = pledged_amount + authorized_amount
|
||||
for t in incomplete_list:
|
||||
incomplete_amount += t.amount
|
||||
|
||||
for t in completed_list:
|
||||
completed_amount += t.amount
|
||||
|
||||
amount = pledged_amount + authorized_amount + incomplete_amount + completed_amount
|
||||
return amount
|
||||
|
||||
else:
|
||||
return pledged_list | authorized_list
|
||||
return pledged_list | authorized_list | incomplete_list | completed_list
|
||||
|
||||
|
||||
|
||||
def query_user(self, user, summary=False, pledged=True, authorized=True):
|
||||
def query_user(self, user, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
||||
'''
|
||||
query_user
|
||||
|
||||
|
@ -305,15 +323,17 @@ class PaymentManager( object ):
|
|||
summary: if true, return a float of the total, if false, return a list of transactions
|
||||
pledged: include amounts pledged
|
||||
authorized: include amounts pre-authorized
|
||||
incomplete: include amounts for transactions with INCOMPLETE status
|
||||
completed: include amounts for transactions that are COMPLETED
|
||||
|
||||
return value: either a float summary or a list of transactions
|
||||
|
||||
'''
|
||||
|
||||
transactions = Transaction.objects.filter(user=user)
|
||||
return self.run_query(transactions, summary, pledged, authorized)
|
||||
return self.run_query(transactions, summary, pledged, authorized, incomplete=True, completed=True)
|
||||
|
||||
def query_campaign(self, campaign, summary=False, pledged=True, authorized=True):
|
||||
def query_campaign(self, campaign, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
||||
'''
|
||||
query_campaign
|
||||
|
||||
|
@ -322,16 +342,18 @@ class PaymentManager( object ):
|
|||
summary: if true, return a float of the total, if false, return a list of transactions
|
||||
pledged: include amounts pledged
|
||||
authorized: include amounts pre-authorized
|
||||
incomplete: include amounts for transactions with INCOMPLETE status
|
||||
completed: includes payments that have been completed
|
||||
|
||||
return value: either a float summary or a list of transactions
|
||||
|
||||
'''
|
||||
|
||||
transactions = Transaction.objects.filter(campaign=campaign)
|
||||
return self.run_query(transactions, summary, pledged, authorized)
|
||||
return self.run_query(transactions, summary, pledged, authorized, incomplete, completed)
|
||||
|
||||
|
||||
def query_list(self, list, summary=False, pledged=True, authorized=True):
|
||||
def query_list(self, list, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
||||
'''
|
||||
query_list
|
||||
|
||||
|
@ -340,13 +362,15 @@ class PaymentManager( object ):
|
|||
summary: if true, return a float of the total, if false, return a list of transactions
|
||||
pledged: include amounts pledged
|
||||
authorized: include amounts pre-authorized
|
||||
incomplete: include amounts for transactions with INCOMPLETE status
|
||||
completed: includes payments that have been completed
|
||||
|
||||
return value: either a float summary or a list of transactions
|
||||
|
||||
'''
|
||||
|
||||
transactions = Transaction.objects.filter(list=list)
|
||||
return self.run_query(transactions, summary, pledged, authorized)
|
||||
return self.run_query(transactions, summary, pledged, authorized, incomplete, completed)
|
||||
|
||||
def execute_campaign(self, campaign):
|
||||
'''
|
||||
|
|
|
@ -96,6 +96,9 @@ class PaymentResponse(models.Model):
|
|||
|
||||
transaction = models.ForeignKey(Transaction, null=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"PaymentResponse -- api: {0} correlation_id: {1} transaction: {2}".format(self.api, self.correlation_id, unicode(self.transaction))
|
||||
|
||||
|
||||
class Receiver(models.Model):
|
||||
|
||||
|
@ -110,6 +113,9 @@ class Receiver(models.Model):
|
|||
txn_id = models.CharField(max_length=64)
|
||||
transaction = models.ForeignKey(Transaction)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"Receiver -- email: {0} status: {1} transaction: {2}".format(self.email, self.status, unicode(self.transaction))
|
||||
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
import regluit.payment.manager
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@ EXECUTE_TYPE_CHAINED_INSTANT = 1
|
|||
EXECUTE_TYPE_CHAINED_DELAYED = 2
|
||||
EXECUTE_TYPE_PARALLEL = 3
|
||||
|
||||
|
||||
TARGET_TYPE_NONE = 0
|
||||
TARGET_TYPE_CAMPAIGN = 1
|
||||
TARGET_TYPE_LIST = 2
|
||||
TARGET_TYPE_DONATION = 3
|
||||
|
||||
# these two following parameters are probably extraneous since I think we will compute dynamically where to return each time.
|
||||
COMPLETE_URL = '/paymentcomplete'
|
||||
CANCEL_URL = '/paymentcancel'
|
||||
|
|
|
@ -35,11 +35,20 @@ IPN_TYPE_ADJUSTMENT = 'Adjustment'
|
|||
IPN_TYPE_PREAPPROVAL = 'Adaptive Payment PREAPPROVAL'
|
||||
|
||||
#pay API status constants
|
||||
# I think 'NONE' is not something the API produces but is particular to our implementation
|
||||
# couldn't we use the Python None?
|
||||
# NONE' is not something the API produces but is particular to our implementation
|
||||
IPN_PAY_STATUS_NONE = 'NONE'
|
||||
|
||||
# The following apply to INSTANT PAYMENTS
|
||||
|
||||
#The following apply to INSTANT PAYMENTS
|
||||
#https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APPayAPI
|
||||
#CREATED - The payment request was received; funds will be transferred once the payment is approved
|
||||
#COMPLETED - The payment was successful
|
||||
#INCOMPLETE - Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
|
||||
#ERROR - The payment failed and all attempted transfers failed or all completed transfers were successfully reversed
|
||||
#REVERSALERROR - One or more transfers failed when attempting to reverse a payment
|
||||
#PROCESSING - The payment is in progress
|
||||
#PENDING - The payment is awaiting processing
|
||||
|
||||
IPN_PAY_STATUS_CREATED = 'CREATED'
|
||||
IPN_PAY_STATUS_COMPLETED = 'COMPLETED'
|
||||
IPN_PAY_STATUS_INCOMPLETE = 'INCOMPLETE'
|
||||
|
@ -49,10 +58,26 @@ IPN_PAY_STATUS_PROCESSING = 'PROCESSING'
|
|||
IPN_PAY_STATUS_PENDING = 'PENDING'
|
||||
|
||||
# particular to preapprovals -- may want to rename these constants to IPN_PREAPPROVAL_STATUS_*
|
||||
# https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APPreapprovalDetails
|
||||
#ACTIVE - The preapproval is active
|
||||
#CANCELED - The preapproval was explicitly canceled by the sender or by PayPal
|
||||
#DEACTIVED - The preapproval is not active; you can be reactivate it by resetting the personal identification number (PIN) or by contacting PayPal
|
||||
|
||||
IPN_PAY_STATUS_ACTIVE = "ACTIVE"
|
||||
IPN_PAY_STATUS_CANCELED = "CANCELED"
|
||||
IPN_PAY_STATUS_DEACTIVED = "DEACTIVED"
|
||||
|
||||
# https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIPN
|
||||
#COMPLETED - The sender's transaction has completed
|
||||
#PENDING - The transaction is awaiting further processing
|
||||
#CREATED - The payment request was received; funds will be transferred once approval is received
|
||||
#PARTIALLY_REFUNDED - Transaction was partially refunded
|
||||
#DENIED - The transaction was rejected by the receiver
|
||||
#PROCESSING - The transaction is in progress
|
||||
#REVERSED - The payment was returned to the sender
|
||||
#REFUNDED - The payment was refunded
|
||||
#FAILED - The payment failed
|
||||
|
||||
IPN_SENDER_STATUS_COMPLETED = 'COMPLETED'
|
||||
IPN_SENDER_STATUS_PENDING = 'PENDING'
|
||||
IPN_SENDER_STATUS_CREATED = 'CREATED'
|
||||
|
@ -67,7 +92,7 @@ IPN_SENDER_STATUS_FAILED = 'FAILED'
|
|||
IPN_ACTION_TYPE_PAY = 'PAY'
|
||||
IPN_ACTION_TYPE_CREATE = 'CREATE'
|
||||
|
||||
# individual sender transaction constants
|
||||
# individual sender transaction constants (???)
|
||||
IPN_TXN_STATUS_COMPLETED = 'Completed'
|
||||
IPN_TXN_STATUS_PENDING = 'Pending'
|
||||
IPN_TXN_STATUS_REFUNDED = 'Refunded'
|
||||
|
|
|
@ -249,7 +249,6 @@ def suite():
|
|||
#testcases = [PledgeTest, AuthorizeTest]
|
||||
testcases = [TransactionTest]
|
||||
suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases])
|
||||
|
||||
return suites
|
||||
|
||||
|
Loading…
Reference in New Issue