Merge branch 'relaunch_ry' of github.com:Gluejar/regluit into pledge_pretty_stick
Conflicts: requirements_versioned.pippull/1/head
commit
b07c49a87e
|
@ -84,6 +84,19 @@ class Claim(models.Model):
|
|||
user = models.ForeignKey(User, related_name="claim", null=False )
|
||||
status = models.CharField(max_length=7, choices= STATUSES, default='pending')
|
||||
|
||||
@property
|
||||
def can_open_new(self):
|
||||
# whether a campaign can be opened for this claim
|
||||
|
||||
#must be an active claim
|
||||
if self.status != 'active':
|
||||
return False
|
||||
#can't already be a campaign
|
||||
for campaign in self.campaigns:
|
||||
if campaign.status in ['ACTIVE','INITIALIZED', 'SUCCESSFUL']:
|
||||
return False
|
||||
return True
|
||||
|
||||
class RightsHolder(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
email = models.CharField(max_length=100, blank=True)
|
||||
|
|
|
@ -1139,10 +1139,8 @@ def rh_tools(request):
|
|||
claim.campaigns = claim.work.campaigns.all()
|
||||
else:
|
||||
claim.campaigns = []
|
||||
claim.can_open_new=False if claim.work.last_campaign_status in ['ACTIVE','INITIALIZED'] else True
|
||||
for campaign in claim.campaigns:
|
||||
if campaign.status in ['ACTIVE','INITIALIZED']:
|
||||
claim.can_open_new=False
|
||||
if request.method == 'POST' and request.POST.has_key('edit_managers_%s'% campaign.id) :
|
||||
campaign.edit_managers_form=EditManagersForm( instance=campaign, data=request.POST, prefix=campaign.id)
|
||||
if campaign.edit_managers_form.is_valid():
|
||||
|
@ -1150,7 +1148,7 @@ def rh_tools(request):
|
|||
campaign.edit_managers_form = EditManagersForm(instance=campaign, prefix=campaign.id)
|
||||
else:
|
||||
campaign.edit_managers_form=EditManagersForm(instance=campaign, prefix=campaign.id)
|
||||
if claim.status == 'active' and claim.can_open_new:
|
||||
if claim.can_open_new:
|
||||
if request.method == 'POST' and request.POST.has_key('work') and int(request.POST['work']) == claim.work.id :
|
||||
claim.campaign_form = OpenCampaignForm(request.POST)
|
||||
if claim.campaign_form.is_valid():
|
||||
|
@ -1159,11 +1157,8 @@ def rh_tools(request):
|
|||
new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET)
|
||||
new_campaign.save()
|
||||
claim.campaign_form.save_m2m()
|
||||
claim.can_open_new=False
|
||||
else:
|
||||
claim.campaign_form = OpenCampaignForm(data={'work': claim.work, 'name': claim.work.title, 'userid': request.user.id, 'managers_1': request.user.id})
|
||||
else:
|
||||
claim.can_open_new=False
|
||||
campaigns = request.user.campaigns.all()
|
||||
new_campaign = None
|
||||
for campaign in campaigns:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from regluit.payment.models import Transaction, PaymentResponse
|
||||
from regluit.payment.models import PaymentResponse
|
||||
|
||||
from django.http import HttpResponseForbidden
|
||||
from datetime import timedelta
|
||||
|
@ -8,18 +8,6 @@ import datetime
|
|||
import time
|
||||
|
||||
|
||||
def requires_explicit_preapprovals():
|
||||
"""a function that returns for the given payment processor"""
|
||||
return False
|
||||
|
||||
def make_account(user, token):
|
||||
"""template function for return a payment.Account corresponding to the payment system"""
|
||||
return None
|
||||
|
||||
def ProcessIPN(request):
|
||||
return HttpResponseForbidden()
|
||||
|
||||
|
||||
class BasePaymentRequest:
|
||||
'''
|
||||
Handles common information incident to payment processing
|
||||
|
@ -71,120 +59,131 @@ class BasePaymentRequest:
|
|||
def timestamp(self):
|
||||
return str(datetime.datetime.now())
|
||||
|
||||
class Processor:
|
||||
"""a function that returns for the given payment processor"""
|
||||
requires_explicit_preapprovals=False
|
||||
|
||||
class Pay( BasePaymentRequest ):
|
||||
|
||||
'''
|
||||
The pay function generates a redirect URL to approve the transaction
|
||||
'''
|
||||
def make_account(self, user, token):
|
||||
"""template function for return a payment.Account corresponding to the payment system"""
|
||||
return None
|
||||
|
||||
def __init__( self, transaction, return_url=None, amount=None, paymentReason=""):
|
||||
self.transaction=transaction
|
||||
|
||||
def api(self):
|
||||
return "null api"
|
||||
|
||||
def exec_status( self ):
|
||||
return None
|
||||
|
||||
def amount( self ):
|
||||
return None
|
||||
|
||||
def key( self ):
|
||||
return None
|
||||
|
||||
def next_url( self ):
|
||||
return self.url
|
||||
|
||||
class Preapproval(Pay):
|
||||
|
||||
def __init__( self, transaction, amount, expiry=None, return_url=None, paymentReason=""):
|
||||
|
||||
# set the expiration date for the preapproval if not passed in. This is what the paypal library does
|
||||
now_val = now()
|
||||
if expiry is None:
|
||||
expiry = now_val + timedelta( days=settings.PREAPPROVAL_PERIOD )
|
||||
transaction.date_authorized = now_val
|
||||
transaction.date_expired = expiry
|
||||
transaction.save()
|
||||
|
||||
# Call into our parent class
|
||||
Pay.__init__(self, transaction, return_url=return_url, amount=amount, paymentReason=paymentReason)
|
||||
|
||||
|
||||
class Execute(BasePaymentRequest):
|
||||
|
||||
'''
|
||||
The Execute function sends an existing token(generated via the URL from the pay operation), and collects
|
||||
the money.
|
||||
'''
|
||||
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
def api(self):
|
||||
return "Base Pay"
|
||||
|
||||
def key(self):
|
||||
# IN paypal land, our key is updated from a preapproval to a pay key here, just return the existing key
|
||||
return self.transaction.pay_key
|
||||
|
||||
|
||||
|
||||
class Finish(BasePaymentRequest):
|
||||
'''
|
||||
The Finish function handles the secondary receiver in a chained payment.
|
||||
'''
|
||||
def __init__(self, transaction):
|
||||
def ProcessIPN(self, request):
|
||||
return HttpResponseForbidden()
|
||||
|
||||
print "Finish"
|
||||
|
||||
|
||||
class PaymentDetails(BasePaymentRequest):
|
||||
'''
|
||||
Get details about executed PAY operation
|
||||
|
||||
This api must set the following class variables to work with the code in manager.py
|
||||
|
||||
status - one of the global transaction status codes
|
||||
transactions -- Not supported for amazon, used by paypal
|
||||
|
||||
'''
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
class Pay( BasePaymentRequest ):
|
||||
|
||||
'''
|
||||
The pay function generates a redirect URL to approve the transaction
|
||||
'''
|
||||
|
||||
def __init__( self, transaction, return_url=None, amount=None, paymentReason=""):
|
||||
self.transaction=transaction
|
||||
|
||||
|
||||
|
||||
class CancelPreapproval(BasePaymentRequest):
|
||||
'''
|
||||
Cancels an exisiting token.
|
||||
'''
|
||||
def api(self):
|
||||
return "null api"
|
||||
|
||||
def exec_status( self ):
|
||||
return None
|
||||
|
||||
def amount( self ):
|
||||
return None
|
||||
|
||||
def key( self ):
|
||||
return None
|
||||
|
||||
def __init__(self, transaction):
|
||||
self.transaction = transaction
|
||||
|
||||
|
||||
class RefundPayment(BasePaymentRequest):
|
||||
def next_url( self ):
|
||||
return self.url
|
||||
|
||||
class Preapproval(Pay):
|
||||
|
||||
def __init__( self, transaction, amount, expiry=None, return_url=None, paymentReason=""):
|
||||
|
||||
# set the expiration date for the preapproval if not passed in. This is what the paypal library does
|
||||
now_val = now()
|
||||
if expiry is None:
|
||||
expiry = now_val + timedelta( days=settings.PREAPPROVAL_PERIOD )
|
||||
transaction.date_authorized = now_val
|
||||
transaction.date_expired = expiry
|
||||
transaction.save()
|
||||
|
||||
# Call into our parent class
|
||||
Pay.__init__(self, transaction, return_url=return_url, amount=amount, paymentReason=paymentReason)
|
||||
|
||||
|
||||
class Execute(BasePaymentRequest):
|
||||
|
||||
'''
|
||||
The Execute function sends an existing token(generated via the URL from the pay operation), and collects
|
||||
the money.
|
||||
'''
|
||||
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
def api(self):
|
||||
return "Base Pay"
|
||||
|
||||
def key(self):
|
||||
# IN paypal land, our key is updated from a preapproval to a pay key here, just return the existing key
|
||||
return self.transaction.pay_key
|
||||
|
||||
|
||||
|
||||
def __init__(self, transaction):
|
||||
self.transaction = transaction
|
||||
class Finish(BasePaymentRequest):
|
||||
'''
|
||||
The Finish function handles the secondary receiver in a chained payment.
|
||||
'''
|
||||
def __init__(self, transaction):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class PreapprovalDetails(BasePaymentRequest):
|
||||
'''
|
||||
Get details about an authorized token
|
||||
|
||||
This api must set 4 different class variables to work with the code in manager.py
|
||||
|
||||
status - one of the global transaction status codes
|
||||
approved - boolean value
|
||||
currency - not used in this API, but we can get some more info via other APIs - TODO
|
||||
amount - not used in this API, but we can get some more info via other APIs - TODO
|
||||
|
||||
'''
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
print "Finish"
|
||||
|
||||
|
||||
class PaymentDetails(BasePaymentRequest):
|
||||
'''
|
||||
Get details about executed PAY operation
|
||||
|
||||
This api must set the following class variables to work with the code in manager.py
|
||||
|
||||
status - one of the global transaction status codes
|
||||
transactions -- Not supported for amazon, used by paypal
|
||||
|
||||
'''
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
|
||||
|
||||
class CancelPreapproval(BasePaymentRequest):
|
||||
'''
|
||||
Cancels an exisiting token.
|
||||
'''
|
||||
|
||||
def __init__(self, transaction):
|
||||
self.transaction = transaction
|
||||
|
||||
|
||||
class RefundPayment(BasePaymentRequest):
|
||||
|
||||
def __init__(self, transaction):
|
||||
self.transaction = transaction
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class PreapprovalDetails(BasePaymentRequest):
|
||||
'''
|
||||
Get details about an authorized token
|
||||
|
||||
This api must set 4 different class variables to work with the code in manager.py
|
||||
|
||||
status - one of the global transaction status codes
|
||||
approved - boolean value
|
||||
currency - not used in this API, but we can get some more info via other APIs - TODO
|
||||
amount - not used in this API, but we can get some more info via other APIs - TODO
|
||||
|
||||
'''
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
|
@ -4,6 +4,7 @@ from django.contrib.auth.models import User
|
|||
from django.conf import settings
|
||||
|
||||
from regluit.payment.parameters import *
|
||||
from regluit.payment import baseprocessor
|
||||
from regluit.payment.baseprocessor import BasePaymentRequest
|
||||
|
||||
|
||||
|
@ -28,28 +29,29 @@ def credit_transaction(t,user,amount):
|
|||
user.credit.add_to_pledged(pledge_amount)
|
||||
t.set_credit_approved(pledge_amount)
|
||||
|
||||
class CancelPreapproval(BasePaymentRequest):
|
||||
'''
|
||||
Cancels an exisiting token.
|
||||
'''
|
||||
class Processor(baseprocessor.Processor):
|
||||
class CancelPreapproval(BasePaymentRequest):
|
||||
'''
|
||||
Cancels an exisiting token.
|
||||
'''
|
||||
|
||||
def __init__(self, transaction):
|
||||
self.transaction = transaction
|
||||
if transaction.user.credit.add_to_pledged(-transaction.amount):
|
||||
#success
|
||||
transaction.status=TRANSACTION_STATUS_CANCELED
|
||||
transaction.save()
|
||||
else:
|
||||
self.errorMessage="couldn't cancel the transaction"
|
||||
self.status = 'Credit Cancel Failure'
|
||||
|
||||
def __init__(self, transaction):
|
||||
self.transaction = transaction
|
||||
if transaction.user.credit.add_to_pledged(-transaction.amount):
|
||||
#success
|
||||
transaction.status=TRANSACTION_STATUS_CANCELED
|
||||
transaction.save()
|
||||
else:
|
||||
self.errorMessage="couldn't cancel the transaction"
|
||||
self.status = 'Credit Cancel Failure'
|
||||
|
||||
class PreapprovalDetails(BasePaymentRequest):
|
||||
status = None
|
||||
approved = None
|
||||
currency = None
|
||||
amount = None
|
||||
def __init__(self, transaction):
|
||||
self.status = transaction.status
|
||||
self.approved = transaction.approved
|
||||
self.currency = transaction.currency
|
||||
self.amount = transaction.amount
|
||||
class PreapprovalDetails(BasePaymentRequest):
|
||||
status = None
|
||||
approved = None
|
||||
currency = None
|
||||
amount = None
|
||||
def __init__(self, transaction):
|
||||
self.status = transaction.status
|
||||
self.approved = transaction.approved
|
||||
self.currency = transaction.currency
|
||||
self.amount = transaction.amount
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from regluit.payment import stripelib
|
||||
from decimal import Decimal as D
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "create a credit card record and charge it -- for testing"
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
# test card
|
||||
sc = stripelib.StripeClient()
|
||||
card = stripelib.card(number="4242424242424242", exp_month="01", exp_year="2013", cvc="123")
|
||||
cust = sc.create_customer(card=card, description="William Shakespeare XIV (via test_stripe_charge)", email="bill.shakespeare@gmail.com")
|
||||
print cust
|
||||
# let's charge RY $1.00
|
||||
charge = sc.create_charge(D('1.00'), customer=cust.id, description="$1 TEST CHARGE for Will S. XIV")
|
||||
print charge
|
|
@ -1,4 +1,3 @@
|
|||
from regluit.core.models import Campaign, Wishlist
|
||||
from regluit.payment.models import Transaction, Receiver, PaymentResponse
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
|
@ -7,8 +6,6 @@ from regluit.payment.parameters import *
|
|||
from regluit.payment.signals import transaction_charged, pledge_modified, pledge_created
|
||||
from regluit.payment import credit
|
||||
|
||||
from regluit.payment.baseprocessor import Pay, Finish, Preapproval, ProcessIPN, CancelPreapproval, PaymentDetails, PreapprovalDetails, RefundPayment
|
||||
|
||||
import uuid
|
||||
import traceback
|
||||
from regluit.utils.localdatetime import now
|
||||
|
@ -40,14 +37,12 @@ class PaymentManager( object ):
|
|||
|
||||
# Forward to our payment processor
|
||||
mod = __import__("regluit.payment." + module, fromlist=[str(module)])
|
||||
method = getattr(mod, "ProcessIPN")
|
||||
return method(request)
|
||||
return = mod.Processor().ProcessIPN(request)
|
||||
|
||||
def update_preapproval(self, transaction):
|
||||
"""Update a transaction to hold the data from a PreapprovalDetails on that transaction"""
|
||||
t = transaction
|
||||
method = getattr(transaction.get_payment_class(), "PreapprovalDetails")
|
||||
p = method(t)
|
||||
p = transaction.get_payment_class().PreapprovalDetails(t)
|
||||
|
||||
preapproval_status = {'id':t.id, 'key':t.preapproval_key}
|
||||
|
||||
|
@ -99,8 +94,7 @@ class PaymentManager( object ):
|
|||
t = transaction
|
||||
payment_status = {'id':t.id}
|
||||
|
||||
method = getattr(transaction.get_payment_class(), "PaymentDetails")
|
||||
p = method(t)
|
||||
p = transaction.get_payment_class().PaymentDetails(t)
|
||||
|
||||
if p.error() or not p.success():
|
||||
logger.info("Error retrieving payment details for transaction %d" % t.id)
|
||||
|
@ -414,8 +408,7 @@ class PaymentManager( object ):
|
|||
transaction.date_executed = now()
|
||||
transaction.save()
|
||||
|
||||
method = getattr(transaction.get_payment_class(), "Finish")
|
||||
p = method(transaction)
|
||||
p = transaction.get_payment_class().Finish(transaction)
|
||||
|
||||
# Create a response for this
|
||||
envelope = p.envelope()
|
||||
|
@ -469,8 +462,7 @@ class PaymentManager( object ):
|
|||
transaction.date_payment = now()
|
||||
transaction.save()
|
||||
|
||||
method = getattr(transaction.get_payment_class(), "Execute")
|
||||
p = method(transaction)
|
||||
p = transaction.get_payment_class().Execute(transaction)
|
||||
|
||||
# Create a response for this
|
||||
envelope = p.envelope()
|
||||
|
@ -510,12 +502,11 @@ class PaymentManager( object ):
|
|||
'''
|
||||
|
||||
# does this transaction explicity require preapprovals?
|
||||
requires_explicit_preapprovals = getattr(transaction.get_payment_class(), "requires_explicit_preapprovals")
|
||||
requires_explicit_preapprovals = transaction.get_payment_class().requires_explicit_preapprovals
|
||||
|
||||
if requires_explicit_preapprovals():
|
||||
if requires_explicit_preapprovals:
|
||||
|
||||
method = getattr(transaction.get_payment_class(), "CancelPreapproval")
|
||||
p = method(transaction)
|
||||
p = transaction.get_payment_class().CancelPreapproval(transaction)
|
||||
|
||||
# Create a response for this
|
||||
envelope = p.envelope()
|
||||
|
@ -576,8 +567,7 @@ class PaymentManager( object ):
|
|||
urllib.urlencode({'tid':transaction.id}))
|
||||
return_url = urlparse.urljoin(settings.BASE_URL, return_path)
|
||||
|
||||
method = getattr(transaction.get_payment_class(), "Preapproval")
|
||||
p = method(transaction, transaction.amount, expiry, return_url=return_url, paymentReason=paymentReason)
|
||||
p = transaction.get_payment_class().Preapproval(transaction, transaction.amount, expiry, return_url=return_url, paymentReason=paymentReason)
|
||||
|
||||
# Create a response for this
|
||||
envelope = p.envelope()
|
||||
|
@ -745,7 +735,7 @@ class PaymentManager( object ):
|
|||
|
||||
# does this transaction explicity require preapprovals?
|
||||
|
||||
requires_explicit_preapprovals = getattr(transaction.get_payment_class(), "requires_explicit_preapprovals")
|
||||
requires_explicit_preapprovals = transaction.get_payment_class().requires_explicit_preapprovals
|
||||
|
||||
if transaction.type != PAYMENT_TYPE_AUTHORIZATION:
|
||||
logger.info("Error, attempt to modify an invalid transaction type")
|
||||
|
@ -786,7 +776,7 @@ class PaymentManager( object ):
|
|||
credit.CancelPreapproval(transaction)
|
||||
return t, reverse('fund_pledge', args=[t.id])
|
||||
|
||||
elif requires_explicit_preapprovals() and (amount > transaction.max_amount or expiry != transaction.date_expired):
|
||||
elif requires_explicit_preapprovals and (amount > transaction.max_amount or expiry != transaction.date_expired):
|
||||
|
||||
# set the expiry date based on the campaign deadline
|
||||
expiry = transaction.campaign.deadline + timedelta( days=settings.PREAPPROVAL_PERIOD_AFTER_CAMPAIGN )
|
||||
|
@ -829,7 +819,7 @@ class PaymentManager( object ):
|
|||
# corresponding notification to the user? that would go here.
|
||||
return False, None
|
||||
|
||||
elif (requires_explicit_preapprovals() and amount <= transaction.max_amount) or (not requires_explicit_preapprovals()):
|
||||
elif (requires_explicit_preapprovals and amount <= transaction.max_amount) or (not requires_explicit_preapprovals):
|
||||
# Update transaction but leave the preapproval alone
|
||||
transaction.amount = amount
|
||||
transaction.set_pledge_extra(pledge_extra)
|
||||
|
@ -862,8 +852,7 @@ class PaymentManager( object ):
|
|||
logger.info("Refund Transaction failed, invalid transaction status")
|
||||
return False
|
||||
|
||||
method = getattr(transaction.get_payment_class(), "RefundPayment")
|
||||
p = method(transaction)
|
||||
p = transaction.get_payment_class().RefundPayment(transaction)
|
||||
|
||||
# Create a response for this
|
||||
envelope = p.envelope()
|
||||
|
@ -921,8 +910,7 @@ class PaymentManager( object ):
|
|||
t.date_payment=now()
|
||||
t.execution=EXECUTE_TYPE_CHAINED_INSTANT
|
||||
t.type=PAYMENT_TYPE_INSTANT
|
||||
method = getattr(t.get_payment_class(), "Pay")
|
||||
p = method(t,return_url=return_url, nevermind_url=nevermind_url)
|
||||
p = t.get_payment_class().Pay(t,return_url=return_url, nevermind_url=nevermind_url)
|
||||
|
||||
# Create a response for this
|
||||
envelope = p.envelope()
|
||||
|
@ -955,8 +943,7 @@ class PaymentManager( object ):
|
|||
|
||||
"""delegate to a specific payment module the task of creating a payment account"""
|
||||
mod = __import__("regluit.payment." + host, fromlist=[host])
|
||||
method = getattr(mod, "make_account")
|
||||
return method(user, token)
|
||||
return mod.Processor().make_account(user, token)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from regluit.core.models import Campaign, Wishlist, Premium, PledgeExtra
|
||||
|
||||
from regluit.payment.parameters import *
|
||||
from regluit.payment.signals import credit_balance_added, pledge_created
|
||||
from regluit.utils.localdatetime import now
|
||||
|
@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
|
|||
# c.card.fingerprint, c.card.type, c.card.last4, c.card.exp_month, c.card.exp_year
|
||||
|
||||
# promising fields
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
|
||||
# type e.g., PAYMENT_TYPE_INSTANT or PAYMENT_TYPE_AUTHORIZATION -- defined in parameters.py
|
||||
|
@ -78,8 +78,8 @@ class Transaction(models.Model):
|
|||
|
||||
# associated User, Campaign, and Premium for this Transaction
|
||||
user = models.ForeignKey(User, null=True)
|
||||
campaign = models.ForeignKey(Campaign, null=True)
|
||||
premium = models.ForeignKey(Premium, null=True)
|
||||
campaign = models.ForeignKey('core.Campaign', null=True)
|
||||
premium = models.ForeignKey('core.Premium', null=True)
|
||||
|
||||
# how to acknowledge the user on the supporter page of the campaign ebook
|
||||
ack_name = models.CharField(max_length=64, null=True)
|
||||
|
@ -109,13 +109,13 @@ class Transaction(models.Model):
|
|||
|
||||
def get_payment_class(self):
|
||||
'''
|
||||
Returns the specific payment module that implements this transaction
|
||||
Returns the specific payment processor that implements this transaction
|
||||
'''
|
||||
if self.host == PAYMENT_HOST_NONE:
|
||||
return None
|
||||
else:
|
||||
mod = __import__("regluit.payment." + self.host, fromlist=[str(self.host)])
|
||||
return mod
|
||||
return mod.Processor()
|
||||
|
||||
def set_credit_approved(self, amount):
|
||||
self.amount=amount
|
||||
|
@ -137,10 +137,12 @@ class Transaction(models.Model):
|
|||
self.ack_dedication = pledge_extra.ack_dedication
|
||||
|
||||
def get_pledge_extra(self, pledge_extra):
|
||||
return PledgeExtra(anonymous=self.anonymous,
|
||||
premium=self.premium,
|
||||
ack_name=self.ack_name,
|
||||
ack_dedication=self.ack_dedication)
|
||||
class pe:
|
||||
premium=self.premium
|
||||
anonymous=self.anonymous
|
||||
ack_name=self.ack_name
|
||||
ack_dedication=self.ack_dedication
|
||||
return pe
|
||||
|
||||
@classmethod
|
||||
def create(cls,amount=0.00, host=PAYMENT_HOST_NONE, max_amount=0.00, currency='USD',
|
||||
|
|
|
@ -7,15 +7,16 @@ from pytz import utc
|
|||
|
||||
from django.conf import settings
|
||||
|
||||
from regluit.payment.models import Account
|
||||
from regluit.payment.parameters import PAYMENT_HOST_STRIPE
|
||||
from regluit.payment.parameters import TRANSACTION_STATUS_ACTIVE, TRANSACTION_STATUS_COMPLETE, PAYMENT_TYPE_AUTHORIZATION, TRANSACTION_STATUS_CANCELED
|
||||
from regluit.payment import baseprocessor
|
||||
from regluit.utils.localdatetime import now, zuluformat
|
||||
|
||||
import stripe
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StripeError(Exception):
|
||||
pass
|
||||
|
||||
|
@ -260,230 +261,157 @@ class PledgeScenarioTest(TestCase):
|
|||
print "list of events", cls._sc.event.all()
|
||||
print [(i, e.id, e.type, e.created, e.pending_webhooks, e.data) for (i,e) in enumerate(cls._sc.event.all()['data'])]
|
||||
|
||||
class StripePaymentRequest(object):
|
||||
'''
|
||||
Handles common information incident to payment processing
|
||||
|
||||
'''
|
||||
class StripePaymentRequest(baseprocessor.BasePaymentRequest):
|
||||
"""so far there is no need to have a separate class here"""
|
||||
pass
|
||||
|
||||
class Processor(baseprocessor.Processor):
|
||||
|
||||
# Global values for the class
|
||||
response = None
|
||||
raw_response = None
|
||||
errorMessage = None
|
||||
status = None
|
||||
url = None
|
||||
def make_account(self, user, token):
|
||||
"""returns a payment.models.Account based on stripe token and user"""
|
||||
|
||||
sc = StripeClient()
|
||||
|
||||
# create customer and charge id and then charge the customer
|
||||
customer = sc.create_customer(card=token, description=user.username,
|
||||
email=user.email)
|
||||
|
||||
def ack( self ):
|
||||
return None
|
||||
|
||||
def success(self):
|
||||
|
||||
if self.errorMessage:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def error(self):
|
||||
if self.errorMessage:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def error_data(self):
|
||||
return None
|
||||
account = Account(host = PAYMENT_HOST_STRIPE,
|
||||
account_id = customer.id,
|
||||
card_last4 = customer.active_card.last4,
|
||||
card_type = customer.active_card.type,
|
||||
card_exp_month = customer.active_card.exp_month,
|
||||
card_exp_year = customer.active_card.exp_year,
|
||||
card_fingerprint = customer.active_card.fingerprint,
|
||||
card_country = customer.active_card.country,
|
||||
user = user
|
||||
)
|
||||
|
||||
def error_id(self):
|
||||
return None
|
||||
account.save()
|
||||
|
||||
return account
|
||||
|
||||
def error_string(self):
|
||||
return self.errorMessage
|
||||
class Pay(StripePaymentRequest, baseprocessor.Processor.Pay):
|
||||
pass
|
||||
|
||||
class Preapproval(StripePaymentRequest, baseprocessor.Processor.Preapproval):
|
||||
|
||||
def __init__( self, transaction, amount, expiry=None, return_url=None, paymentReason=""):
|
||||
|
||||
# set the expiration date for the preapproval if not passed in. This is what the paypal library does
|
||||
|
||||
self.transaction = transaction
|
||||
|
||||
now_val = now()
|
||||
if expiry is None:
|
||||
expiry = now_val + timedelta( days=settings.PREAPPROVAL_PERIOD )
|
||||
transaction.date_authorized = now_val
|
||||
transaction.date_expired = expiry
|
||||
|
||||
sc = StripeClient()
|
||||
|
||||
# let's figure out what part of transaction can be used to store info
|
||||
# try placing charge id in transaction.pay_key
|
||||
# need to set amount
|
||||
# how does transaction.max_amount get set? -- coming from /pledge/xxx/ -> manager.process_transaction
|
||||
# max_amount is set -- but I don't think we need it for stripe
|
||||
|
||||
def envelope(self):
|
||||
# The envelope is used to store info about this request
|
||||
if self.response:
|
||||
return str(self.response)
|
||||
else:
|
||||
# ASSUMPTION: a user has any given moment one and only one active payment Account
|
||||
|
||||
if transaction.user.account_set.filter(date_deactivated__isnull=True).count() > 1:
|
||||
logger.warning("user {0} has more than one active payment account".format(transaction.user))
|
||||
elif transaction.user.account_set.filter(date_deactivated__isnull=True).count() == 0:
|
||||
logger.warning("user {0} has no active payment account".format(transaction.user))
|
||||
raise StripeError("user {0} has no active payment account".format(transaction.user))
|
||||
|
||||
account = transaction.user.account_set.filter(date_deactivated__isnull=True)[0]
|
||||
logger.info("user: {0} customer.id is {1}".format(transaction.user, account.account_id))
|
||||
|
||||
# settings to apply to transaction for TRANSACTION_STATUS_ACTIVE
|
||||
# should approved be set to False and wait for a webhook?
|
||||
transaction.approved = True
|
||||
transaction.type = PAYMENT_TYPE_AUTHORIZATION
|
||||
transaction.host = PAYMENT_HOST_STRIPE
|
||||
transaction.status = TRANSACTION_STATUS_ACTIVE
|
||||
|
||||
transaction.preapproval_key = account.account_id
|
||||
|
||||
transaction.currency = 'USD'
|
||||
transaction.amount = amount
|
||||
|
||||
transaction.save()
|
||||
|
||||
def key(self):
|
||||
return self.transaction.preapproval_key
|
||||
|
||||
def next_url(self):
|
||||
"""return None because no redirection to stripe is required"""
|
||||
return None
|
||||
|
||||
def correlation_id(self):
|
||||
return None
|
||||
|
||||
def timestamp(self):
|
||||
return str(datetime.datetime.now())
|
||||
|
||||
def requires_explicit_preapprovals():
|
||||
"""a function that returns for the given payment processor"""
|
||||
return False
|
||||
|
||||
def make_account(user, token):
|
||||
"""returns a payment.models.Account based on stripe token and user"""
|
||||
|
||||
sc = StripeClient()
|
||||
|
||||
# create customer and charge id and then charge the customer
|
||||
customer = sc.create_customer(card=token, description=user.username,
|
||||
email=user.email)
|
||||
|
||||
|
||||
from regluit.payment.models import Account
|
||||
|
||||
account = Account(host = PAYMENT_HOST_STRIPE,
|
||||
account_id = customer.id,
|
||||
card_last4 = customer.active_card.last4,
|
||||
card_type = customer.active_card.type,
|
||||
card_exp_month = customer.active_card.exp_month,
|
||||
card_exp_year = customer.active_card.exp_year,
|
||||
card_fingerprint = customer.active_card.fingerprint,
|
||||
card_country = customer.active_card.country,
|
||||
user = user
|
||||
)
|
||||
|
||||
account.save()
|
||||
|
||||
return account
|
||||
|
||||
class Pay(StripePaymentRequest):
|
||||
|
||||
'''
|
||||
The pay function generates a redirect URL to approve the transaction
|
||||
'''
|
||||
|
||||
def __init__( self, transaction, return_url=None, amount=None, paymentReason=""):
|
||||
self.transaction=transaction
|
||||
|
||||
def api(self):
|
||||
return "null api"
|
||||
|
||||
def exec_status( self ):
|
||||
return None
|
||||
|
||||
def amount( self ):
|
||||
return None
|
||||
|
||||
def key( self ):
|
||||
return None
|
||||
|
||||
def next_url( self ):
|
||||
return self.url
|
||||
|
||||
class Preapproval(StripePaymentRequest):
|
||||
|
||||
def __init__( self, transaction, amount, expiry=None, return_url=None, paymentReason=""):
|
||||
|
||||
# set the expiration date for the preapproval if not passed in. This is what the paypal library does
|
||||
class Execute(StripePaymentRequest):
|
||||
|
||||
self.transaction = transaction
|
||||
'''
|
||||
The Execute function sends an existing token(generated via the URL from the pay operation), and collects
|
||||
the money.
|
||||
'''
|
||||
|
||||
now_val = now()
|
||||
if expiry is None:
|
||||
expiry = now_val + timedelta( days=settings.PREAPPROVAL_PERIOD )
|
||||
transaction.date_authorized = now_val
|
||||
transaction.date_expired = expiry
|
||||
|
||||
sc = StripeClient()
|
||||
|
||||
# let's figure out what part of transaction can be used to store info
|
||||
# try placing charge id in transaction.pay_key
|
||||
# need to set amount
|
||||
# how does transaction.max_amount get set? -- coming from /pledge/xxx/ -> manager.process_transaction
|
||||
# max_amount is set -- but I don't think we need it for stripe
|
||||
|
||||
# ASSUMPTION: a user has any given moment one and only one active payment Account
|
||||
|
||||
if transaction.user.account_set.filter(date_deactivated__isnull=True).count() > 1:
|
||||
logger.warning("user {0} has more than one active payment account".format(transaction.user))
|
||||
elif transaction.user.account_set.filter(date_deactivated__isnull=True).count() == 0:
|
||||
logger.warning("user {0} has no active payment account".format(transaction.user))
|
||||
raise StripeError("user {0} has no active payment account".format(transaction.user))
|
||||
|
||||
account = transaction.user.account_set.filter(date_deactivated__isnull=True)[0]
|
||||
logger.info("user: {0} customer.id is {1}".format(transaction.user, account.account_id))
|
||||
|
||||
# settings to apply to transaction for TRANSACTION_STATUS_ACTIVE
|
||||
# should approved be set to False and wait for a webhook?
|
||||
transaction.approved = True
|
||||
transaction.type = PAYMENT_TYPE_AUTHORIZATION
|
||||
transaction.host = PAYMENT_HOST_STRIPE
|
||||
transaction.status = TRANSACTION_STATUS_ACTIVE
|
||||
|
||||
transaction.preapproval_key = account.account_id
|
||||
|
||||
transaction.currency = 'USD'
|
||||
transaction.amount = amount
|
||||
|
||||
transaction.save()
|
||||
|
||||
def key(self):
|
||||
return self.transaction.preapproval_key
|
||||
|
||||
def next_url(self):
|
||||
"""return None because no redirection to stripe is required"""
|
||||
return None
|
||||
|
||||
|
||||
class Execute(StripePaymentRequest):
|
||||
|
||||
'''
|
||||
The Execute function sends an existing token(generated via the URL from the pay operation), and collects
|
||||
the money.
|
||||
'''
|
||||
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
# execute transaction
|
||||
assert transaction.host == PAYMENT_HOST_STRIPE
|
||||
|
||||
sc = StripeClient()
|
||||
|
||||
# look at transaction.preapproval_key
|
||||
# is it a customer or a token?
|
||||
|
||||
# BUGBUG: replace description with somethin more useful
|
||||
if transaction.preapproval_key.startswith('cus_'):
|
||||
charge = sc.create_charge(transaction.amount, customer=transaction.preapproval_key, description="${0} for test / retain cc".format(transaction.amount))
|
||||
elif transaction.preapproval_key.startswith('tok_'):
|
||||
charge = sc.create_charge(transaction.amount, card=transaction.preapproval_key, description="${0} for test / cc not retained".format(transaction.amount))
|
||||
|
||||
transaction.status = TRANSACTION_STATUS_COMPLETE
|
||||
transaction.pay_key = charge.id
|
||||
transaction.date_payment = now()
|
||||
transaction.save()
|
||||
def __init__(self, transaction=None):
|
||||
self.transaction = transaction
|
||||
|
||||
self.charge = charge
|
||||
|
||||
def api(self):
|
||||
return "Base Pay"
|
||||
# execute transaction
|
||||
assert transaction.host == PAYMENT_HOST_STRIPE
|
||||
|
||||
sc = StripeClient()
|
||||
|
||||
# look at transaction.preapproval_key
|
||||
# is it a customer or a token?
|
||||
|
||||
# BUGBUG: replace description with somethin more useful
|
||||
if transaction.preapproval_key.startswith('cus_'):
|
||||
charge = sc.create_charge(transaction.amount, customer=transaction.preapproval_key, description="${0} for test / retain cc".format(transaction.amount))
|
||||
elif transaction.preapproval_key.startswith('tok_'):
|
||||
charge = sc.create_charge(transaction.amount, card=transaction.preapproval_key, description="${0} for test / cc not retained".format(transaction.amount))
|
||||
|
||||
def key(self):
|
||||
# IN paypal land, our key is updated from a preapproval to a pay key here, just return the existing key
|
||||
return self.transaction.pay_key
|
||||
transaction.status = TRANSACTION_STATUS_COMPLETE
|
||||
transaction.pay_key = charge.id
|
||||
transaction.date_payment = now()
|
||||
transaction.save()
|
||||
|
||||
self.charge = charge
|
||||
|
||||
def api(self):
|
||||
return "Base Pay"
|
||||
|
||||
def key(self):
|
||||
# IN paypal land, our key is updated from a preapproval to a pay key here, just return the existing key
|
||||
return self.transaction.pay_key
|
||||
|
||||
|
||||
class PreapprovalDetails(StripePaymentRequest):
|
||||
'''
|
||||
Get details about an authorized token
|
||||
|
||||
This api must set 4 different class variables to work with the code in manager.py
|
||||
|
||||
status - one of the global transaction status codes
|
||||
approved - boolean value
|
||||
currency - not used in this API, but we can get some more info via other APIs - TODO
|
||||
amount - not used in this API, but we can get some more info via other APIs - TODO
|
||||
|
||||
'''
|
||||
def __init__(self, transaction):
|
||||
|
||||
self.transaction = transaction
|
||||
self.status = self.transaction.status
|
||||
if self.status == TRANSACTION_STATUS_CANCELED:
|
||||
self.approved = False
|
||||
else:
|
||||
self.approved = True
|
||||
|
||||
class PreapprovalDetails(StripePaymentRequest):
|
||||
'''
|
||||
Get details about an authorized token
|
||||
|
||||
This api must set 4 different class variables to work with the code in manager.py
|
||||
|
||||
status - one of the global transaction status codes
|
||||
approved - boolean value
|
||||
currency - not used in this API, but we can get some more info via other APIs - TODO
|
||||
amount - not used in this API, but we can get some more info via other APIs - TODO
|
||||
|
||||
'''
|
||||
def __init__(self, transaction):
|
||||
|
||||
self.transaction = transaction
|
||||
self.status = self.transaction.status
|
||||
if self.status == TRANSACTION_STATUS_CANCELED:
|
||||
self.approved = False
|
||||
else:
|
||||
self.approved = True
|
||||
|
||||
# Set the other fields that are expected. We don't have values for these now, so just copy the transaction
|
||||
self.currency = transaction.currency
|
||||
self.amount = transaction.amount
|
||||
# Set the other fields that are expected. We don't have values for these now, so just copy the transaction
|
||||
self.currency = transaction.currency
|
||||
self.amount = transaction.amount
|
||||
|
||||
def suite():
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ from regluit.payment.models import Transaction
|
|||
from regluit.core.models import Campaign, Wishlist, Work
|
||||
from regluit.core.signals import handle_transaction_charged
|
||||
from regluit.payment.parameters import *
|
||||
from regluit.payment.paypal import *
|
||||
import traceback
|
||||
from django.core.validators import URLValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from regluit.payment.manager import PaymentManager
|
||||
from regluit.payment.paypal import IPN
|
||||
from regluit.payment.models import Transaction
|
||||
from regluit.core.models import Campaign, Wishlist
|
||||
|
||||
|
|
|
@ -49,6 +49,5 @@ ssh==1.7.14
|
|||
stevedore==0.4
|
||||
stripe==1.7.4
|
||||
virtualenv==1.4.9
|
||||
virtualenv-clone==0.2.4
|
||||
virtualenvwrapper==3.6
|
||||
wsgiref==0.1.2
|
||||
|
|
|
@ -21,7 +21,8 @@ DATABASES = {
|
|||
'PASSWORD': 'forgetn0t',
|
||||
'HOST': 'justdb.cboagmr25pjs.us-east-1.rds.amazonaws.com',
|
||||
'PORT': '',
|
||||
'TEST_CHARSET': 'utf8'
|
||||
'TEST_CHARSET': 'utf8',
|
||||
'TEST_COLLATION': 'utf8_bin'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from regluit.core import models
|
||||
from regluit.payment.models import Transaction, PaymentResponse, Receiver
|
||||
from regluit.payment.manager import PaymentManager
|
||||
from regluit.payment.paypal import IPN_PREAPPROVAL_STATUS_ACTIVE, IPN_PAY_STATUS_INCOMPLETE, IPN_PAY_STATUS_COMPLETED
|
||||
|
||||
import django
|
||||
from django.conf import settings
|
||||
|
@ -14,9 +13,6 @@ import unittest, time, re
|
|||
import logging
|
||||
import os
|
||||
|
||||
# PayPal developer sandbox
|
||||
from regluit.payment.tests import loginSandbox, paySandbox, payAmazonSandbox
|
||||
|
||||
def setup_selenium():
|
||||
# Set the display window for our xvfb
|
||||
os.environ['DISPLAY'] = ':99'
|
||||
|
@ -305,195 +301,7 @@ def test_relaunch(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=True,
|
|||
yield sel
|
||||
|
||||
|
||||
def support_campaign(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=True, backend='amazon', browser='firefox'):
|
||||
"""
|
||||
programatically fire up selenium to make a Pledge
|
||||
do_local should be True only if you are running support_campaign on db tied to LIVE_SERVER_TEST_URL
|
||||
"""
|
||||
|
||||
django.db.transaction.enter_transaction_management()
|
||||
|
||||
UNGLUE_IT_URL = unglue_it_url
|
||||
USER = settings.UNGLUEIT_TEST_USER
|
||||
PASSWORD = settings.UNGLUEIT_TEST_PASSWORD
|
||||
|
||||
setup_selenium()
|
||||
|
||||
if browser == 'firefox':
|
||||
sel = webdriver.Firefox()
|
||||
elif browser == 'chrome':
|
||||
sel = webdriver.Chrome(executable_path='/Users/raymondyee/C/src/Gluejar/regluit/test/chromedriver')
|
||||
elif browser == 'htmlunit':
|
||||
# HTMLUNIT with JS -- not successful
|
||||
sel = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS)
|
||||
else:
|
||||
sel = webdriver.Firefox()
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
# find a campaign to pledge to
|
||||
if backend == 'paypal':
|
||||
loginSandbox(sel)
|
||||
time.sleep(2)
|
||||
|
||||
print "now opening unglue.it"
|
||||
|
||||
#sel.get("http://www.google.com")
|
||||
sel.get(UNGLUE_IT_URL)
|
||||
|
||||
# long wait because sel is slow after PayPal
|
||||
sign_in_link = WebDriverWait(sel, 100).until(lambda d : d.find_element_by_xpath("//span[contains(text(),'Sign In')]/.."))
|
||||
sign_in_link.click()
|
||||
|
||||
# enter unglue.it login info
|
||||
input_username = WebDriverWait(sel,20).until(lambda d : d.find_element_by_css_selector("input#id_username"))
|
||||
input_username.send_keys(USER)
|
||||
sel.find_element_by_css_selector("input#id_password").send_keys(PASSWORD)
|
||||
sel.find_element_by_css_selector("input[value*='sign in']").click()
|
||||
|
||||
# click on biggest campaign list
|
||||
# I have no idea why selenium thinks a is not displayed....so that's why I'm going up one element.
|
||||
# http://stackoverflow.com/a/6141678/7782
|
||||
biggest_campaign_link = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("li > a[href*='/campaigns/ending']"))
|
||||
biggest_campaign_link.click()
|
||||
time.sleep(1)
|
||||
|
||||
# pull up one of the campaigns to pledge to
|
||||
# for now, take the first book and click on the link to get to the work page
|
||||
work_links = WebDriverWait(sel,10).until(lambda d: d.find_elements_by_css_selector("div.book-list div.title a"))
|
||||
work_links[0].click()
|
||||
|
||||
support_button = WebDriverWait(sel,10).until(lambda d: d.find_element_by_css_selector("input[value*='Support']"))
|
||||
support_button.click()
|
||||
|
||||
# just click Pledge button without filling out amount -- should have the form validation spot the error
|
||||
pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Pledge']"))
|
||||
pledge_button.click()
|
||||
# check to see whether there is an error
|
||||
error_messages = WebDriverWait(sel,20).until(lambda d: d.find_elements_by_css_selector("ul.errorlist"))
|
||||
if len(error_messages):
|
||||
print "yes: Error in just hitting pledge button as expected"
|
||||
else:
|
||||
print "ooops: there should be an error message when pledge button hit"
|
||||
|
||||
# fill out a premium -- the first one for now
|
||||
premium_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector('input[type="radio"][value="1"]'))
|
||||
premium_button.click()
|
||||
|
||||
print "making $10 pledge"
|
||||
|
||||
# now we have to replace the current preapproval amount with 10
|
||||
sel.execute_script("""document.getElementById("id_preapproval_amount").value="10";""")
|
||||
# must also pick a premium level -- otherwise there will not be a pledge_button -- let's pick the first premium ($1)
|
||||
premium_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector('input[type="radio"][value="1"]'))
|
||||
premium_button.click()
|
||||
|
||||
pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Pledge']"))
|
||||
pledge_button.click()
|
||||
|
||||
# grab the URL where sel is now?
|
||||
|
||||
if backend == 'paypal':
|
||||
print "Now trying to pay PayPal", sel.current_url
|
||||
paySandbox(None, sel, sel.current_url, authorize=True, already_at_url=True, sleep_time=5)
|
||||
elif backend == 'amazon':
|
||||
payAmazonSandbox(sel)
|
||||
|
||||
# should be back on a pledge complete page
|
||||
print sel.current_url, re.search(r"/pledge/complete",sel.current_url)
|
||||
|
||||
time.sleep(2)
|
||||
django.db.transaction.commit()
|
||||
|
||||
# time out to simulate an IPN -- update all the transactions
|
||||
if do_local:
|
||||
django.db.transaction.enter_transaction_management()
|
||||
pm = PaymentManager()
|
||||
print pm.checkStatus()
|
||||
transaction0 = Transaction.objects.all()[0]
|
||||
print "transaction amount:{0}, transaction premium:{1}".format(transaction0.amount, transaction0.premium.id)
|
||||
django.db.transaction.commit()
|
||||
|
||||
|
||||
django.db.transaction.enter_transaction_management()
|
||||
|
||||
# I have no idea what the a[href*="/work/"] is not displayed....so that's why I'm going up one element.
|
||||
work_url = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector('p > a[href*="/work/"]'))
|
||||
work_url.click()
|
||||
|
||||
# change_pledge
|
||||
print "clicking Modify Pledge button"
|
||||
change_pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
|
||||
change_pledge_button.click()
|
||||
|
||||
# enter a new pledge, which is less than the previous amount and therefore doesn't require a new PayPal transaction
|
||||
print "changing pledge to $5 -- should not need to go to PayPal"
|
||||
preapproval_amount_input = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#id_preapproval_amount"))
|
||||
preapproval_amount_input.clear() # get rid of existing pledge
|
||||
preapproval_amount_input.send_keys("5")
|
||||
pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
|
||||
pledge_button.click()
|
||||
|
||||
# return to the Work page again
|
||||
work_url = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector('p > a[href*="/work/"]'))
|
||||
work_url.click()
|
||||
change_pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
|
||||
change_pledge_button.click()
|
||||
|
||||
# enter a new pledge, which is more than the previous amount and therefore requires a new PayPal transaction
|
||||
preapproval_amount_input = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#id_preapproval_amount"))
|
||||
preapproval_amount_input.clear() # get rid of existing pledge
|
||||
preapproval_amount_input.send_keys("25")
|
||||
pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
|
||||
pledge_button.click()
|
||||
if backend == 'paypal':
|
||||
paySandbox(None, sel, sel.current_url, authorize=True, already_at_url=True, sleep_time=5)
|
||||
elif backend == 'amazon':
|
||||
payAmazonSandbox(sel)
|
||||
|
||||
# wait a bit to allow PayPal sandbox to be update the status of the Transaction
|
||||
time.sleep(10)
|
||||
django.db.transaction.commit()
|
||||
|
||||
# time out to simulate an IPN -- update all the transactions
|
||||
if do_local:
|
||||
django.db.transaction.enter_transaction_management()
|
||||
pm = PaymentManager()
|
||||
print pm.checkStatus()
|
||||
django.db.transaction.commit()
|
||||
|
||||
django.db.transaction.enter_transaction_management()
|
||||
|
||||
# now go back to the work page, hit modify pledge, and then the cancel link
|
||||
work_url = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector('p > a[href*="/work/"]'))
|
||||
work_url.click()
|
||||
change_pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
|
||||
change_pledge_button.click()
|
||||
cancel_url = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector('a[href*="/pledge/cancel"]'))
|
||||
cancel_url.click()
|
||||
|
||||
# hit the confirm cancellation button
|
||||
cancel_pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Confirm Pledge Cancellation']"))
|
||||
cancel_pledge_button.click()
|
||||
|
||||
django.db.transaction.commit()
|
||||
|
||||
# Why is the status of the new transaction not being updated?
|
||||
|
||||
# force a db lookup -- see whether there are 1 or 2 transactions
|
||||
# they should both be cancelled
|
||||
if do_local:
|
||||
transactions = list(Transaction.objects.all())
|
||||
print "number of transactions", Transaction.objects.count()
|
||||
|
||||
print "transactions before pm.checkStatus"
|
||||
print [(t.id, t.type, t.preapproval_key, t.status, t.premium, t.amount) for t in Transaction.objects.all()]
|
||||
|
||||
print "checkStatus:", pm.checkStatus(transactions=transactions)
|
||||
|
||||
|
||||
yield sel
|
||||
#sel.quit()
|
||||
|
||||
def successful_campaign_signal():
|
||||
"""fire off a success_campaign signal and send notifications"""
|
||||
|
|
Loading…
Reference in New Issue