2011-09-27 12:48:11 +00:00
|
|
|
from regluit.core.models import Campaign, Wishlist
|
2011-12-14 13:30:37 +00:00
|
|
|
from regluit.payment.models import Transaction, Receiver, PaymentResponse
|
2011-09-27 12:48:11 +00:00
|
|
|
from django.contrib.auth.models import User
|
2012-01-10 20:16:04 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
|
2011-09-27 12:48:11 +00:00
|
|
|
from regluit.payment.parameters import *
|
2012-01-10 23:26:04 +00:00
|
|
|
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, IPN_PAY_STATUS_NONE
|
2011-12-21 01:36:27 +00:00
|
|
|
from regluit.payment.paypal import Preapproval, IPN_PAY_STATUS_COMPLETED, CancelPreapproval, PaymentDetails, PreapprovalDetails, IPN_SENDER_STATUS_COMPLETED, IPN_TXN_STATUS_COMPLETED
|
2012-01-05 06:42:05 +00:00
|
|
|
from regluit.payment.paypal import RefundPayment
|
2011-09-27 12:48:11 +00:00
|
|
|
import uuid
|
|
|
|
import traceback
|
2011-10-27 08:05:21 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from dateutil.relativedelta import relativedelta
|
2011-10-06 00:56:20 +00:00
|
|
|
import logging
|
|
|
|
from decimal import Decimal as D
|
2011-10-27 08:05:21 +00:00
|
|
|
from xml.dom import minidom
|
2012-01-10 20:16:04 +00:00
|
|
|
import urllib, urlparse
|
2011-10-06 00:56:20 +00:00
|
|
|
|
2011-12-19 23:34:30 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
2012-01-10 20:16:04 +00:00
|
|
|
|
2011-10-06 00:56:20 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-10-27 08:05:21 +00:00
|
|
|
def append_element(doc, parent, name, text):
|
|
|
|
|
|
|
|
element = doc.createElement(name)
|
|
|
|
parent.appendChild(element)
|
|
|
|
text_node = doc.createTextNode(text)
|
|
|
|
element.appendChild(text_node)
|
|
|
|
|
|
|
|
return element
|
|
|
|
|
2011-10-13 17:28:23 +00:00
|
|
|
# at this point, there is no internal context and therefore, the methods of PaymentManager can be recast into static methods
|
2011-09-27 12:48:11 +00:00
|
|
|
class PaymentManager( object ):
|
2011-11-22 11:14:58 +00:00
|
|
|
|
|
|
|
def __init__( self, embedded=False):
|
|
|
|
self.embedded = embedded
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2012-01-11 19:12:12 +00:00
|
|
|
def update_preapproval(self, transaction):
|
|
|
|
t = transaction
|
|
|
|
p = PreapprovalDetails(t)
|
|
|
|
|
|
|
|
preapproval_status = {'id':t.id, 'key':t.preapproval_key}
|
|
|
|
|
|
|
|
if p.error() or not p.success():
|
|
|
|
logger.info("Error retrieving preapproval details for transaction %d" % t.id)
|
|
|
|
preapproval_status["error"] = "An error occurred while verifying this transaction, see server logs for details"
|
|
|
|
else:
|
|
|
|
|
|
|
|
# Check the transaction status
|
|
|
|
if t.status != p.status:
|
|
|
|
preapproval_status["status"] = {'ours':t.status, 'theirs':p.status}
|
|
|
|
t.status = p.status
|
|
|
|
t.save()
|
|
|
|
|
|
|
|
# check the currency code
|
|
|
|
if t.currency != p.currency:
|
|
|
|
preapproval_status["currency"] = {'ours':t.currency, 'theirs':p.currency}
|
|
|
|
t.currency = p.currency
|
|
|
|
t.save()
|
|
|
|
|
|
|
|
# Check the amount
|
|
|
|
if t.max_amount != D(p.amount):
|
|
|
|
preapproval_status["amount"] = {'ours':t.max_amount, 'theirs':p.amount}
|
|
|
|
t.max_amount = p.amount
|
|
|
|
t.save()
|
2012-01-11 21:47:56 +00:00
|
|
|
|
|
|
|
# Check approved
|
|
|
|
if t.approved != p.approved:
|
|
|
|
preapproval_status["approved"] = {'ours':t.approved, 'theirs':p.approved}
|
|
|
|
t.approved = p.approved
|
|
|
|
t.save()
|
|
|
|
|
2012-01-11 19:12:12 +00:00
|
|
|
|
|
|
|
return preapproval_status
|
|
|
|
|
|
|
|
def update_payment(self, transaction):
|
|
|
|
|
|
|
|
t = transaction
|
|
|
|
payment_status = {'id':t.id}
|
|
|
|
|
|
|
|
p = PaymentDetails(t)
|
|
|
|
|
|
|
|
if p.error() or not p.success():
|
|
|
|
logger.info("Error retrieving payment details for transaction %d" % t.id)
|
|
|
|
payment_status['error'] = "An error occurred while verifying this transaction, see server logs for details"
|
|
|
|
else:
|
|
|
|
|
|
|
|
# Check the transaction status
|
|
|
|
if t.status != p.status:
|
|
|
|
payment_status['status'] = {'ours': t.status, 'theirs': p.status}
|
|
|
|
|
|
|
|
t.status = p.status
|
|
|
|
t.save()
|
|
|
|
|
|
|
|
receivers_status = []
|
|
|
|
|
|
|
|
for r in p.transactions:
|
|
|
|
|
|
|
|
try:
|
|
|
|
receiver = Receiver.objects.get(transaction=t, email=r['email'])
|
|
|
|
|
|
|
|
receiver_status = {'email':r['email']}
|
|
|
|
|
|
|
|
logger.info(r)
|
|
|
|
logger.info(receiver)
|
|
|
|
|
|
|
|
# Check for updates on each receiver's status. Note that unprocessed delayed chained payments
|
|
|
|
# will not have a status code or txn id code
|
|
|
|
if receiver.status != r['status']:
|
|
|
|
receiver_status['status'] = {'ours': receiver.status, 'theirs': r['status']}
|
|
|
|
receiver.status = r['status']
|
|
|
|
receiver.save()
|
|
|
|
|
|
|
|
if receiver.txn_id != r['txn_id']:
|
|
|
|
receiver_status['txn_id'] = {'ours':receiver.txn_id, 'theirs':r['txn_id']}
|
|
|
|
|
|
|
|
receiver.txn_id = r['txn_id']
|
|
|
|
receiver.save()
|
|
|
|
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
if not set(["status","txn_id"]).isdisjoint(receiver_status.keys()):
|
|
|
|
receivers_status.append(receiver_status)
|
|
|
|
|
|
|
|
if len(receivers_status):
|
|
|
|
payment_status["receivers"] = receivers_status
|
|
|
|
|
|
|
|
return payment_status
|
|
|
|
|
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
def checkStatus(self, past_days=None, transactions=None):
|
2011-10-27 08:05:21 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
Run through all pay transactions and verify that their current status is as we think.
|
2012-01-11 19:50:08 +00:00
|
|
|
|
|
|
|
Allow for a list of transactions to be passed in or for the method to check on all transactions within the
|
|
|
|
given past_days
|
|
|
|
|
2011-10-27 08:05:21 +00:00
|
|
|
'''
|
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
DEFAULT_DAYS_TO_CHECK = 3
|
|
|
|
|
2011-12-23 01:34:24 +00:00
|
|
|
status = {'payments':[], 'preapprovals':[]}
|
|
|
|
|
|
|
|
# look at all PAY transactions for stated number of past days; if past_days is not int, get all Transaction
|
|
|
|
# only PAY transactions have date_payment not None
|
2012-01-11 19:50:08 +00:00
|
|
|
|
|
|
|
if transactions is None:
|
2011-12-08 17:13:23 +00:00
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
if past_days is None:
|
|
|
|
past_days = DEFAULT_DAYS_TO_CHECK
|
2011-10-27 08:05:21 +00:00
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
try:
|
|
|
|
ref_date = datetime.utcnow() - relativedelta(days=int(past_days))
|
|
|
|
payment_transactions = Transaction.objects.filter(date_payment__gte=ref_date)
|
|
|
|
except:
|
|
|
|
ref_date = datetime.utcnow()
|
|
|
|
payment_transactions = Transaction.objects.filter(date_payment__isnull=False)
|
|
|
|
|
|
|
|
logger.info(payment_transactions)
|
2011-10-27 08:05:21 +00:00
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
# Now look for preapprovals that have not been paid and check on their status
|
|
|
|
preapproval_transactions = Transaction.objects.filter(date_authorized__gte=ref_date, date_payment=None, type=PAYMENT_TYPE_AUTHORIZATION)
|
|
|
|
|
|
|
|
logger.info(preapproval_transactions)
|
2011-12-23 01:34:24 +00:00
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
transactions = payment_transactions | preapproval_transactions
|
|
|
|
|
2011-12-06 14:36:18 +00:00
|
|
|
|
|
|
|
for t in transactions:
|
|
|
|
|
2012-01-11 19:50:08 +00:00
|
|
|
if t.date_payment is None:
|
|
|
|
preapproval_status = self.update_preapproval(t)
|
2012-01-11 21:47:56 +00:00
|
|
|
if not set(['status', 'currency', 'amount', 'approved']).isdisjoint(set(preapproval_status.keys())):
|
2012-01-11 19:50:08 +00:00
|
|
|
status["preapprovals"].append(preapproval_status)
|
|
|
|
else:
|
|
|
|
payment_status = self.update_payment(t)
|
|
|
|
if not set(["status", "receivers"]).isdisjoint(payment_status.keys()):
|
|
|
|
status["payments"].append(payment_status)
|
|
|
|
|
2011-12-23 01:34:24 +00:00
|
|
|
return status
|
2011-10-27 08:05:21 +00:00
|
|
|
|
|
|
|
|
2011-09-27 12:48:11 +00:00
|
|
|
def processIPN(self, request):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
processIPN
|
|
|
|
|
|
|
|
Turns a request from Paypal into an IPN, and extracts info. We support 2 types of IPNs:
|
|
|
|
|
|
|
|
1) Payment - Used for instant payments and to execute pre-approved payments
|
|
|
|
2) Preapproval - Used for comfirmation of a preapproval
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
2011-09-27 12:48:11 +00:00
|
|
|
try:
|
|
|
|
ipn = IPN(request)
|
|
|
|
|
|
|
|
if ipn.success():
|
2011-10-06 00:56:20 +00:00
|
|
|
logger.info("Valid IPN")
|
2011-10-27 06:35:46 +00:00
|
|
|
logger.info("IPN Transaction Type: %s" % ipn.transaction_type)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
|
|
|
if ipn.transaction_type == IPN_TYPE_PAYMENT:
|
2011-10-27 06:35:46 +00:00
|
|
|
# payment IPN. we use our unique reference for the transaction as the key
|
|
|
|
# is only valid for 3 hours
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-10-27 06:35:46 +00:00
|
|
|
uniqueID = ipn.uniqueID()
|
|
|
|
t = Transaction.objects.get(secret=uniqueID)
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
# The status is always one of the IPN_PAY_STATUS codes defined in paypal.py
|
2011-09-27 12:48:11 +00:00
|
|
|
t.status = ipn.status
|
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2011-09-27 12:48:11 +00:00
|
|
|
for item in ipn.transactions:
|
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
try:
|
|
|
|
r = Receiver.objects.get(transaction=t, email=item['receiver'])
|
2011-10-06 00:56:20 +00:00
|
|
|
logger.info(item)
|
2011-12-14 13:30:37 +00:00
|
|
|
# one of the IPN_SENDER_STATUS codes defined in paypal.py, If we are doing delayed chained
|
|
|
|
# payments, then there is no status or id for non-primary receivers. Leave their status alone
|
2011-10-01 12:01:40 +00:00
|
|
|
r.status = item['status_for_sender_txn']
|
|
|
|
r.txn_id = item['id_for_sender_txn']
|
|
|
|
r.save()
|
|
|
|
except:
|
2011-12-14 13:30:37 +00:00
|
|
|
# Log an exception if we have a receiver that is not found. This will be hit
|
|
|
|
# for delayed chained payments as there is no status or id for the non-primary receivers yet
|
2011-10-01 12:01:40 +00:00
|
|
|
traceback.print_exc()
|
2011-10-27 08:05:21 +00:00
|
|
|
|
2011-09-29 07:50:07 +00:00
|
|
|
t.save()
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2011-10-27 06:35:46 +00:00
|
|
|
logger.info("Final transaction status: %s" % t.status)
|
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
elif ipn.transaction_type == IPN_TYPE_ADJUSTMENT:
|
|
|
|
# a chargeback, reversal or refund for an existng payment
|
2012-01-05 06:42:05 +00:00
|
|
|
|
2011-10-27 06:35:46 +00:00
|
|
|
uniqueID = ipn.uniqueID()
|
|
|
|
if uniqueID:
|
|
|
|
t = Transaction.objects.get(secret=uniqueID)
|
|
|
|
else:
|
2011-12-14 13:30:37 +00:00
|
|
|
key = ipn.pay_key
|
|
|
|
t = Transaction.objects.get(pay_key=key)
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
# The status is always one of the IPN_PAY_STATUS codes defined in paypal.py
|
|
|
|
t.status = ipn.status
|
|
|
|
|
|
|
|
# Reason code indicates more details of the adjustment type
|
|
|
|
t.reason = ipn.reason_code
|
2012-01-05 06:42:05 +00:00
|
|
|
|
|
|
|
# Update the receiver status codes
|
|
|
|
for item in ipn.transactions:
|
|
|
|
|
|
|
|
try:
|
|
|
|
r = Receiver.objects.get(transaction=t, email=item['receiver'])
|
|
|
|
logger.info(item)
|
|
|
|
# one of the IPN_SENDER_STATUS codes defined in paypal.py, If we are doing delayed chained
|
|
|
|
# payments, then there is no status or id for non-primary receivers. Leave their status alone
|
|
|
|
r.status = item['status_for_sender_txn']
|
|
|
|
r.save()
|
|
|
|
except:
|
|
|
|
# Log an exception if we have a receiver that is not found. This will be hit
|
|
|
|
# for delayed chained payments as there is no status or id for the non-primary receivers yet
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
t.save()
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2011-09-29 07:50:07 +00:00
|
|
|
|
|
|
|
elif ipn.transaction_type == IPN_TYPE_PREAPPROVAL:
|
|
|
|
|
2011-10-27 06:35:46 +00:00
|
|
|
# IPN for preapproval always uses the key to ref the transaction as this is always valid
|
2011-12-14 13:30:37 +00:00
|
|
|
key = ipn.preapproval_key
|
|
|
|
t = Transaction.objects.get(preapproval_key=key)
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
# The status is always one of the IPN_PREAPPROVAL_STATUS codes defined in paypal.py
|
2011-09-29 07:50:07 +00:00
|
|
|
t.status = ipn.status
|
|
|
|
t.save()
|
2011-10-06 00:56:20 +00:00
|
|
|
logger.info("IPN: Preapproval transaction: " + str(t.id) + " Status: " + ipn.status)
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-09-27 12:48:11 +00:00
|
|
|
else:
|
2011-10-06 00:56:20 +00:00
|
|
|
logger.info("IPN: Unknown Transaction Type: " + ipn.transaction_type)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-09-27 12:48:11 +00:00
|
|
|
else:
|
2011-10-06 00:56:20 +00:00
|
|
|
logger.info("ERROR: INVALID IPN")
|
|
|
|
logger.info(ipn.error)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2012-01-03 19:49:37 +00:00
|
|
|
def run_query(self, transaction_list, summary, pledged, authorized, incomplete, completed):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
Generic query handler for returning summary and transaction info, see query_user, query_list and query_campaign
|
|
|
|
'''
|
|
|
|
|
2011-09-27 12:48:11 +00:00
|
|
|
if pledged:
|
2011-10-01 12:01:40 +00:00
|
|
|
pledged_list = transaction_list.filter(type=PAYMENT_TYPE_INSTANT,
|
2012-01-03 19:49:37 +00:00
|
|
|
status=IPN_PAY_STATUS_COMPLETED)
|
2011-09-27 12:48:11 +00:00
|
|
|
else:
|
|
|
|
pledged_list = []
|
|
|
|
|
|
|
|
if authorized:
|
2012-01-02 15:47:36 +00:00
|
|
|
authorized_list = transaction_list.filter(type=PAYMENT_TYPE_AUTHORIZATION,
|
2012-01-03 19:49:37 +00:00
|
|
|
status=IPN_PAY_STATUS_ACTIVE)
|
2011-09-27 12:48:11 +00:00
|
|
|
else:
|
2012-01-03 19:49:37 +00:00
|
|
|
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 = []
|
2011-09-27 12:48:11 +00:00
|
|
|
|
|
|
|
if summary:
|
2011-10-08 03:11:57 +00:00
|
|
|
pledged_amount = D('0.00')
|
|
|
|
authorized_amount = D('0.00')
|
2012-01-03 19:49:37 +00:00
|
|
|
incomplete_amount = D('0.00')
|
|
|
|
completed_amount = D('0.00')
|
2011-09-27 12:48:11 +00:00
|
|
|
|
|
|
|
for t in pledged_list:
|
2011-10-01 12:01:40 +00:00
|
|
|
for r in t.receiver_set.all():
|
2011-10-13 22:12:11 +00:00
|
|
|
if r.status == IPN_TXN_STATUS_COMPLETED:
|
|
|
|
# or IPN_SENDER_STATUS_COMPLETED
|
2011-10-01 12:01:40 +00:00
|
|
|
# individual senders may not have been paid due to errors, and disputes/chargebacks only appear here
|
|
|
|
pledged_amount += r.amount
|
2011-09-27 12:48:11 +00:00
|
|
|
|
|
|
|
for t in authorized_list:
|
|
|
|
authorized_amount += t.amount
|
|
|
|
|
2012-01-03 19:49:37 +00:00
|
|
|
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
|
2011-09-27 12:48:11 +00:00
|
|
|
return amount
|
|
|
|
|
|
|
|
else:
|
2012-01-03 19:49:37 +00:00
|
|
|
return pledged_list | authorized_list | incomplete_list | completed_list
|
2011-10-13 17:28:23 +00:00
|
|
|
|
2012-01-03 19:49:37 +00:00
|
|
|
def query_user(self, user, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
query_user
|
|
|
|
|
|
|
|
Returns either an amount or list of transactions for a user
|
|
|
|
|
|
|
|
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
|
2012-01-03 19:49:37 +00:00
|
|
|
incomplete: include amounts for transactions with INCOMPLETE status
|
|
|
|
completed: include amounts for transactions that are COMPLETED
|
2011-10-13 17:28:23 +00:00
|
|
|
|
|
|
|
return value: either a float summary or a list of transactions
|
|
|
|
|
|
|
|
'''
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
transactions = Transaction.objects.filter(user=user)
|
2012-01-03 19:49:37 +00:00
|
|
|
return self.run_query(transactions, summary, pledged, authorized, incomplete=True, completed=True)
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2012-01-03 19:49:37 +00:00
|
|
|
def query_campaign(self, campaign, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
query_campaign
|
|
|
|
|
|
|
|
Returns either an amount or list of transactions for a campaign
|
|
|
|
|
|
|
|
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
|
2012-01-03 19:49:37 +00:00
|
|
|
incomplete: include amounts for transactions with INCOMPLETE status
|
|
|
|
completed: includes payments that have been completed
|
2011-10-13 17:28:23 +00:00
|
|
|
|
|
|
|
return value: either a float summary or a list of transactions
|
|
|
|
|
|
|
|
'''
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
transactions = Transaction.objects.filter(campaign=campaign)
|
2012-01-03 19:49:37 +00:00
|
|
|
return self.run_query(transactions, summary, pledged, authorized, incomplete, completed)
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2011-10-13 17:28:23 +00:00
|
|
|
|
2012-01-03 19:49:37 +00:00
|
|
|
def query_list(self, list, summary=False, pledged=True, authorized=True, incomplete=True, completed=True):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
query_list
|
|
|
|
|
|
|
|
Returns either an amount or list of transactions for a list
|
|
|
|
|
|
|
|
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
|
2012-01-03 19:49:37 +00:00
|
|
|
incomplete: include amounts for transactions with INCOMPLETE status
|
|
|
|
completed: includes payments that have been completed
|
2011-10-13 17:28:23 +00:00
|
|
|
|
|
|
|
return value: either a float summary or a list of transactions
|
|
|
|
|
|
|
|
'''
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
transactions = Transaction.objects.filter(list=list)
|
2012-01-03 19:49:37 +00:00
|
|
|
return self.run_query(transactions, summary, pledged, authorized, incomplete, completed)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-09-29 07:50:07 +00:00
|
|
|
def execute_campaign(self, campaign):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
execute_campaign
|
|
|
|
|
|
|
|
attempts to execute all pending transactions for a campaign.
|
|
|
|
|
|
|
|
return value: returns a list of transactions with the status of each receiver/transaction updated
|
|
|
|
|
|
|
|
'''
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
# only allow active transactions to go through again, if there is an error, intervention is needed
|
2011-12-21 01:36:27 +00:00
|
|
|
transactions = Transaction.objects.filter(campaign=campaign, status=IPN_PAY_STATUS_ACTIVE)
|
2011-09-29 07:50:07 +00:00
|
|
|
|
|
|
|
for t in transactions:
|
|
|
|
|
2011-12-19 23:34:30 +00:00
|
|
|
receiver_list = [{'email':settings.PAYPAL_GLUEJAR_EMAIL, 'amount':t.amount},
|
|
|
|
{'email':campaign.paypal_receiver, 'amount':D(t.amount) * (D('1.00') - D(str(settings.GLUEJAR_COMMISSION)))}]
|
2011-09-29 07:50:07 +00:00
|
|
|
|
|
|
|
self.execute_transaction(t, receiver_list)
|
|
|
|
|
|
|
|
return transactions
|
2011-12-21 17:31:58 +00:00
|
|
|
|
|
|
|
def finish_campaign(self, campaign):
|
|
|
|
'''
|
|
|
|
finish_campaign
|
|
|
|
|
|
|
|
attempts to execute all remaining payment to non-primary receivers
|
|
|
|
|
|
|
|
|
|
|
|
return value: returns a list of transactions with the status of each receiver/transaction updated
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
# QUESTION: to figure out which transactions are in a state in which the payment to the primary recipient is done but not to secondary recipient
|
|
|
|
# Consider two possibilities: status=IPN_PAY_STATUS_INCOMPLETE or execution = EXECUTE_TYPE_CHAINED_DELAYED
|
|
|
|
# which one? Let's try the second one
|
|
|
|
# only allow incomplete transactions to go through again, if there is an error, intervention is needed
|
|
|
|
transactions = Transaction.objects.filter(campaign=campaign, execution=EXECUTE_TYPE_CHAINED_DELAYED)
|
|
|
|
|
|
|
|
for t in transactions:
|
|
|
|
result = self.finish_transaction(t)
|
|
|
|
|
|
|
|
return transactions
|
2011-12-21 22:32:08 +00:00
|
|
|
|
|
|
|
def cancel_campaign(self, campaign):
|
|
|
|
'''
|
|
|
|
cancel_campaign
|
|
|
|
|
|
|
|
attempts to cancel active preapprovals related to the campaign
|
|
|
|
|
|
|
|
|
|
|
|
return value: returns a list of transactions with the status of each receiver/transaction updated
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
transactions = Transaction.objects.filter(campaign=campaign, status=IPN_PAY_STATUS_ACTIVE)
|
|
|
|
|
|
|
|
for t in transactions:
|
|
|
|
result = self.cancel_transaction(t)
|
|
|
|
|
|
|
|
return transactions
|
2011-12-21 17:31:58 +00:00
|
|
|
|
2011-10-13 17:28:23 +00:00
|
|
|
|
2011-12-14 13:30:37 +00:00
|
|
|
def finish_transaction(self, transaction):
|
|
|
|
'''
|
|
|
|
finish_transaction
|
|
|
|
|
2011-12-19 23:34:30 +00:00
|
|
|
calls the paypal API to execute payment to non-primary receivers
|
2011-12-14 13:30:37 +00:00
|
|
|
|
|
|
|
transaction: the transaction we want to complete
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
if transaction.execution != EXECUTE_TYPE_CHAINED_DELAYED:
|
|
|
|
logger.error("FinishTransaction called with invalid execution type")
|
|
|
|
return False
|
|
|
|
|
|
|
|
# mark this transaction as executed
|
2011-12-23 01:34:24 +00:00
|
|
|
transaction.date_executed = datetime.utcnow()
|
2011-12-14 13:30:37 +00:00
|
|
|
transaction.save()
|
|
|
|
|
|
|
|
p = Execute(transaction)
|
|
|
|
|
|
|
|
# Create a response for this
|
|
|
|
envelope = p.envelope()
|
|
|
|
|
|
|
|
if envelope:
|
|
|
|
correlation = p.correlation_id()
|
|
|
|
timestamp = p.timestamp()
|
|
|
|
|
|
|
|
r = PaymentResponse.objects.create(api=p.url,
|
|
|
|
correlation_id = correlation,
|
|
|
|
timestamp = timestamp,
|
|
|
|
info = p.raw_response,
|
|
|
|
transaction=transaction)
|
|
|
|
|
|
|
|
if p.success() and not p.error():
|
|
|
|
logger.info("finish_transaction Success")
|
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
|
|
|
transaction.error = p.error_string()
|
|
|
|
transaction.save()
|
|
|
|
logger.info("finish_transaction error " + p.error_string())
|
|
|
|
return False
|
|
|
|
|
2011-09-29 07:50:07 +00:00
|
|
|
def execute_transaction(self, transaction, receiver_list):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
execute_transaction
|
|
|
|
|
|
|
|
executes a single pending transaction.
|
|
|
|
|
|
|
|
transaction: the transaction object to execute
|
|
|
|
receiver_list: a list of receivers for the transaction, in this format:
|
|
|
|
|
|
|
|
[
|
|
|
|
{'email':'email-1', 'amount':amount1},
|
|
|
|
{'email':'email-2', 'amount':amount2}
|
|
|
|
]
|
|
|
|
|
|
|
|
return value: a bool indicating the success or failure of the process. Please check the transaction status
|
|
|
|
after the IPN has completed for full information
|
|
|
|
|
|
|
|
'''
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
if len(transaction.receiver_set.all()) > 0:
|
|
|
|
# we are re-submitting a transaction, wipe the old receiver list
|
|
|
|
transaction.receiver_set.all().delete()
|
|
|
|
|
|
|
|
transaction.create_receivers(receiver_list)
|
2011-10-27 08:05:21 +00:00
|
|
|
|
|
|
|
# Mark as payment attempted so we will poll this periodically for status changes
|
2011-12-23 01:34:24 +00:00
|
|
|
transaction.date_payment = datetime.utcnow()
|
2011-10-27 08:05:21 +00:00
|
|
|
transaction.save()
|
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
p = Pay(transaction)
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-12-14 13:30:37 +00:00
|
|
|
# Create a response for this
|
|
|
|
envelope = p.envelope()
|
|
|
|
|
|
|
|
if envelope:
|
|
|
|
|
|
|
|
correlation = p.correlation_id()
|
|
|
|
timestamp = p.timestamp()
|
|
|
|
|
|
|
|
r = PaymentResponse.objects.create(api=p.api(),
|
|
|
|
correlation_id = correlation,
|
|
|
|
timestamp = timestamp,
|
|
|
|
info = p.raw_response,
|
|
|
|
transaction=transaction)
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-12-14 13:30:37 +00:00
|
|
|
# We will update our transaction status when we receive the IPN
|
|
|
|
if p.success() and not p.error():
|
|
|
|
transaction.pay_key = p.key()
|
|
|
|
transaction.save()
|
|
|
|
logger.info("execute_transaction Success")
|
2011-09-29 07:50:07 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
2011-12-14 13:30:37 +00:00
|
|
|
transaction.error = p.error_string()
|
|
|
|
transaction.save()
|
|
|
|
logger.info("execute_transaction Error: " + p.error_string())
|
2011-09-29 07:50:07 +00:00
|
|
|
return False
|
2011-10-01 12:01:40 +00:00
|
|
|
|
2011-12-21 22:32:08 +00:00
|
|
|
def cancel_transaction(self, transaction):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
cancel
|
|
|
|
|
|
|
|
cancels a pre-approved transaction
|
|
|
|
|
|
|
|
return value: True if successful, false otherwise
|
|
|
|
'''
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
p = CancelPreapproval(transaction)
|
|
|
|
|
2011-12-14 13:30:37 +00:00
|
|
|
# Create a response for this
|
|
|
|
envelope = p.envelope()
|
|
|
|
|
|
|
|
if envelope:
|
|
|
|
|
|
|
|
correlation = p.correlation_id()
|
|
|
|
timestamp = p.timestamp()
|
|
|
|
|
|
|
|
r = PaymentResponse.objects.create(api=p.url,
|
|
|
|
correlation_id = correlation,
|
|
|
|
timestamp = timestamp,
|
|
|
|
info = p.raw_response,
|
|
|
|
transaction=transaction)
|
|
|
|
|
|
|
|
if p.success() and not p.error():
|
2011-10-06 00:56:20 +00:00
|
|
|
logger.info("Cancel Transaction " + str(transaction.id) + " Completed")
|
2011-10-01 12:01:40 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
2011-12-14 13:30:37 +00:00
|
|
|
transaction.error = p.error_string()
|
|
|
|
transaction.save()
|
|
|
|
logger.info("Cancel Transaction " + str(transaction.id) + " Failed with error: " + p.error_string())
|
2011-10-01 12:01:40 +00:00
|
|
|
return False
|
|
|
|
|
2011-12-20 19:56:01 +00:00
|
|
|
def authorize(self, currency, target, amount, expiry=None, campaign=None, list=None, user=None, return_url=None, cancel_url=None, anonymous=False):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
authorize
|
|
|
|
|
|
|
|
authorizes a set amount of money to be collected at a later date
|
|
|
|
|
|
|
|
currency: a 3-letter paypal currency code, i.e. USD
|
|
|
|
target: a defined target type, i.e. TARGET_TYPE_CAMPAIGN, TARGET_TYPE_LIST, TARGET_TYPE_NONE
|
|
|
|
amount: the amount to authorize
|
|
|
|
campaign: optional campaign object(to be set with TARGET_TYPE_CAMPAIGN)
|
|
|
|
list: optional list object(to be set with TARGET_TYPE_LIST)
|
|
|
|
user: optional user object
|
|
|
|
|
|
|
|
return value: a tuple of the new transaction object and a re-direct url. If the process fails,
|
|
|
|
the redirect url will be None
|
|
|
|
|
|
|
|
'''
|
2011-09-29 07:50:07 +00:00
|
|
|
|
|
|
|
t = Transaction.objects.create(amount=amount,
|
2012-01-05 06:42:05 +00:00
|
|
|
max_amount=amount,
|
2011-12-14 13:30:37 +00:00
|
|
|
type=PAYMENT_TYPE_AUTHORIZATION,
|
|
|
|
execution = EXECUTE_TYPE_CHAINED_DELAYED,
|
2011-09-29 07:50:07 +00:00
|
|
|
target=target,
|
|
|
|
currency=currency,
|
|
|
|
status='NONE',
|
|
|
|
campaign=campaign,
|
|
|
|
list=list,
|
2011-11-01 21:08:09 +00:00
|
|
|
user=user,
|
|
|
|
anonymous=anonymous
|
2011-09-29 07:50:07 +00:00
|
|
|
)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2012-01-10 20:16:04 +00:00
|
|
|
# we might want to not allow for a return_url or cancel_url to be passed in but calculated
|
|
|
|
# here because we have immediate access to the Transaction object.
|
|
|
|
|
|
|
|
if cancel_url is None:
|
|
|
|
cancel_path = "{0}?{1}".format(reverse('pledge_cancel'),
|
2012-01-10 23:26:04 +00:00
|
|
|
urllib.urlencode({'tid':t.id}))
|
2012-01-10 20:16:04 +00:00
|
|
|
cancel_url = urlparse.urljoin(settings.BASE_URL, cancel_path)
|
2012-01-11 01:15:39 +00:00
|
|
|
|
|
|
|
if return_url is None:
|
|
|
|
return_path = "{0}?{1}".format(reverse('pledge_complete'),
|
|
|
|
urllib.urlencode({'tid':t.id}))
|
|
|
|
return_url = urlparse.urljoin(settings.BASE_URL, return_path)
|
2012-01-10 20:16:04 +00:00
|
|
|
|
2011-12-20 19:56:01 +00:00
|
|
|
p = Preapproval(t, amount, expiry, return_url=return_url, cancel_url=cancel_url)
|
2011-09-29 07:50:07 +00:00
|
|
|
|
2011-12-14 13:30:37 +00:00
|
|
|
# Create a response for this
|
|
|
|
envelope = p.envelope()
|
|
|
|
|
|
|
|
if envelope:
|
|
|
|
r = PaymentResponse.objects.create(api=p.url,
|
|
|
|
correlation_id = p.correlation_id(),
|
|
|
|
timestamp = p.timestamp(),
|
|
|
|
info = p.raw_response,
|
|
|
|
transaction=t)
|
|
|
|
|
|
|
|
if p.success() and not p.error():
|
|
|
|
t.preapproval_key = p.key()
|
2011-09-29 07:50:07 +00:00
|
|
|
t.save()
|
2011-11-22 11:14:58 +00:00
|
|
|
|
|
|
|
url = p.next_url()
|
|
|
|
|
|
|
|
logger.info("Authorize Success: " + url)
|
|
|
|
return t, url
|
|
|
|
|
2011-09-29 07:50:07 +00:00
|
|
|
|
|
|
|
else:
|
2011-12-14 13:30:37 +00:00
|
|
|
t.error = p.error_string()
|
2011-09-29 07:50:07 +00:00
|
|
|
t.save()
|
2011-12-14 13:30:37 +00:00
|
|
|
logger.info("Authorize Error: " + p.error_string())
|
2011-09-29 07:50:07 +00:00
|
|
|
return t, None
|
|
|
|
|
2012-01-05 06:42:05 +00:00
|
|
|
def modify_transaction(self, transaction, amount=None, expiry=None, return_url=None, cancel_url=None):
|
|
|
|
'''
|
|
|
|
modify
|
|
|
|
|
|
|
|
Modifies a transaction. The only type of modification allowed is to the amount and expiration date
|
|
|
|
|
|
|
|
amount: the new amount
|
|
|
|
expiry: the new expiration date, or if none the current expiration date will be used
|
|
|
|
return_url: the return URL after the preapproval(if needed)
|
|
|
|
cancel_url: the cancel url after the preapproval(if needed)
|
|
|
|
|
|
|
|
return value: True if successful, false otherwise. An optional second parameter for the forward URL if a new authorhization is needed
|
|
|
|
'''
|
|
|
|
|
|
|
|
if not amount:
|
|
|
|
logger.info("Error, no amount speicified")
|
|
|
|
return False
|
|
|
|
|
|
|
|
if transaction.type != PAYMENT_TYPE_AUTHORIZATION:
|
|
|
|
# Can only modify the amount of a preapproval for now
|
|
|
|
logger.info("Error, attempt to modify an invalid transaction type")
|
|
|
|
return False, None
|
|
|
|
|
|
|
|
if transaction.status != IPN_PAY_STATUS_ACTIVE:
|
|
|
|
# Can only modify an active, pending transaction. If it is completed, we need to do a refund. If it is incomplete,
|
|
|
|
# then an IPN may be pending and we cannot touch it
|
|
|
|
logger.info("Error, attempt to modify a transaction that is not active")
|
|
|
|
return False, None
|
|
|
|
|
|
|
|
if not expiry:
|
|
|
|
# Use the old expiration date
|
|
|
|
expiry = transaction.date_expired
|
|
|
|
|
|
|
|
if amount > transaction.max_amount or expiry != transaction.date_expired:
|
|
|
|
|
|
|
|
# Increase or expiuration change, cancel and start again
|
|
|
|
self.cancel_transaction(transaction)
|
|
|
|
|
|
|
|
# Start a new authorization for the new amount
|
|
|
|
|
|
|
|
t, url = self.authorize(transaction.currency,
|
|
|
|
transaction.target,
|
|
|
|
amount,
|
|
|
|
expiry,
|
|
|
|
transaction.campaign,
|
|
|
|
transaction.list,
|
|
|
|
transaction.user,
|
|
|
|
return_url,
|
|
|
|
cancel_url,
|
|
|
|
transaction.anonymous)
|
|
|
|
|
|
|
|
if t and url:
|
|
|
|
# Need to re-direct to approve the transaction
|
|
|
|
logger.info("New authorization needed, redirectiont to url %s" % url)
|
|
|
|
return True, url
|
|
|
|
else:
|
|
|
|
# No amount change necessary
|
|
|
|
logger.info("Error, unable to start a new authorization")
|
|
|
|
return False, None
|
|
|
|
|
2012-01-06 15:32:52 +00:00
|
|
|
elif amount <= transaction.max_amount:
|
2012-01-05 06:42:05 +00:00
|
|
|
# Change the amount but leave the preapproval alone
|
|
|
|
transaction.amount = amount
|
|
|
|
transaction.save()
|
|
|
|
logger.info("Updated amount of transaction to %f" % amount)
|
|
|
|
return True, None
|
|
|
|
|
|
|
|
else:
|
|
|
|
# No changes
|
|
|
|
logger.info("Error, no modifications requested")
|
|
|
|
return False, None
|
|
|
|
|
|
|
|
|
|
|
|
def refund_transaction(self, transaction):
|
|
|
|
'''
|
|
|
|
refund
|
|
|
|
|
|
|
|
Refunds a transaction. The money for the transaction may have gone to a number of places. We can only
|
|
|
|
refund money that is in our account
|
|
|
|
|
|
|
|
return value: True if successful, false otherwise
|
|
|
|
'''
|
|
|
|
|
|
|
|
# First check if a payment has been made. It is possible that some of the receivers may be incomplete
|
|
|
|
# We need to verify that the refund API will cancel these
|
|
|
|
if transaction.status != IPN_PAY_STATUS_COMPLETED:
|
|
|
|
logger.info("Refund Transaction failed, invalid transaction status")
|
|
|
|
return False
|
|
|
|
|
|
|
|
p = RefundPayment(transaction)
|
|
|
|
|
|
|
|
# Create a response for this
|
|
|
|
envelope = p.envelope()
|
|
|
|
|
|
|
|
if envelope:
|
|
|
|
|
|
|
|
correlation = p.correlation_id()
|
|
|
|
timestamp = p.timestamp()
|
|
|
|
|
|
|
|
r = PaymentResponse.objects.create(api=p.url,
|
|
|
|
correlation_id = correlation,
|
|
|
|
timestamp = timestamp,
|
|
|
|
info = p.raw_response,
|
|
|
|
transaction=transaction)
|
|
|
|
|
|
|
|
if p.success() and not p.error():
|
|
|
|
logger.info("Refund Transaction " + str(transaction.id) + " Completed")
|
|
|
|
return True
|
|
|
|
|
|
|
|
else:
|
|
|
|
transaction.error = p.error_string()
|
|
|
|
transaction.save()
|
|
|
|
logger.info("Refund Transaction " + str(transaction.id) + " Failed with error: " + p.error_string())
|
|
|
|
return False
|
|
|
|
|
2011-11-01 21:08:09 +00:00
|
|
|
def pledge(self, currency, target, receiver_list, campaign=None, list=None, user=None, return_url=None, cancel_url=None, anonymous=False):
|
2011-10-13 17:28:23 +00:00
|
|
|
'''
|
|
|
|
pledge
|
|
|
|
|
|
|
|
Performs an instant payment
|
|
|
|
|
|
|
|
currency: a 3-letter paypal currency code, i.e. USD
|
|
|
|
target: a defined target type, i.e. TARGET_TYPE_CAMPAIGN, TARGET_TYPE_LIST, TARGET_TYPE_NONE
|
|
|
|
receiver_list: a list of receivers for the transaction, in this format:
|
|
|
|
|
|
|
|
[
|
|
|
|
{'email':'email-1', 'amount':amount1},
|
|
|
|
{'email':'email-2', 'amount':amount2}
|
|
|
|
]
|
|
|
|
|
|
|
|
campaign: optional campaign object(to be set with TARGET_TYPE_CAMPAIGN)
|
|
|
|
list: optional list object(to be set with TARGET_TYPE_LIST)
|
|
|
|
user: optional user object
|
|
|
|
|
|
|
|
return value: a tuple of the new transaction object and a re-direct url. If the process fails,
|
|
|
|
the redirect url will be None
|
|
|
|
|
|
|
|
'''
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-10-06 00:56:20 +00:00
|
|
|
amount = D('0.00')
|
2011-10-01 12:01:40 +00:00
|
|
|
|
|
|
|
# for chained payments, first amount is the total amount
|
2011-10-06 00:56:20 +00:00
|
|
|
amount = D(receiver_list[0]['amount'])
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2012-01-05 06:42:05 +00:00
|
|
|
t = Transaction.objects.create(amount=amount,
|
|
|
|
max_amount=amount,
|
2011-12-14 13:30:37 +00:00
|
|
|
type=PAYMENT_TYPE_INSTANT,
|
|
|
|
execution=EXECUTE_TYPE_CHAINED_INSTANT,
|
2011-09-27 12:48:11 +00:00
|
|
|
target=target,
|
2011-09-29 07:50:07 +00:00
|
|
|
currency=currency,
|
2011-09-27 12:48:11 +00:00
|
|
|
status='NONE',
|
|
|
|
campaign=campaign,
|
|
|
|
list=list,
|
2011-10-27 08:05:21 +00:00
|
|
|
user=user,
|
2011-12-23 01:34:24 +00:00
|
|
|
date_payment=datetime.utcnow(),
|
2011-11-01 21:08:09 +00:00
|
|
|
anonymous=anonymous
|
2011-09-27 12:48:11 +00:00
|
|
|
)
|
|
|
|
|
2011-10-01 12:01:40 +00:00
|
|
|
t.create_receivers(receiver_list)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-10-13 21:13:37 +00:00
|
|
|
p = Pay(t,return_url=return_url, cancel_url=cancel_url)
|
2011-09-27 12:48:11 +00:00
|
|
|
|
2011-12-14 13:30:37 +00:00
|
|
|
# Create a response for this
|
|
|
|
envelope = p.envelope()
|
2011-12-19 23:34:30 +00:00
|
|
|
logger.info(envelope)
|
2011-12-14 13:30:37 +00:00
|
|
|
|
|
|
|
if envelope:
|
|
|
|
r = PaymentResponse.objects.create(api=p.api(),
|
|
|
|
correlation_id = p.correlation_id(),
|
|
|
|
timestamp = p.timestamp(),
|
|
|
|
info = p.raw_response,
|
|
|
|
transaction=t)
|
|
|
|
|
|
|
|
if p.success() and not p.error():
|
|
|
|
t.pay_key = p.key()
|
2011-10-14 17:52:17 +00:00
|
|
|
t.status = 'CREATED'
|
2011-09-27 12:48:11 +00:00
|
|
|
t.save()
|
2011-11-22 11:14:58 +00:00
|
|
|
|
|
|
|
if self.embedded:
|
|
|
|
url = p.embedded_url()
|
2011-12-19 23:34:30 +00:00
|
|
|
logger.info(url)
|
2011-11-22 11:14:58 +00:00
|
|
|
else:
|
|
|
|
url = p.next_url()
|
|
|
|
|
|
|
|
logger.info("Pledge Success: " + url)
|
|
|
|
return t, url
|
2011-09-27 12:48:11 +00:00
|
|
|
|
|
|
|
else:
|
2011-12-14 13:30:37 +00:00
|
|
|
t.error = p.error_string()
|
2011-09-27 12:48:11 +00:00
|
|
|
t.save()
|
2011-12-14 13:30:37 +00:00
|
|
|
logger.info("Pledge Error: " + p.error_string())
|
2011-09-27 12:48:11 +00:00
|
|
|
return t, None
|
|
|
|
|
|
|
|
|