first pass at stripelib.Processor.Pay

pull/1/head
Raymond Yee 2013-06-26 18:46:30 -07:00
parent d3166d3aef
commit 3ff53dd5bc
2 changed files with 45 additions and 4 deletions

View File

@ -656,6 +656,7 @@ class PaymentManager( object ):
# urllib.urlencode({'tid':transaction.id})) # urllib.urlencode({'tid':transaction.id}))
# return_url = urlparse.urljoin(settings.BASE_URL_SECURE, return_path) # return_url = urlparse.urljoin(settings.BASE_URL_SECURE, return_path)
# Question: do I need to set transaction.amount = transaction.max_amount ?
p = transaction.get_payment_class().Pay(transaction, amount=transaction.max_amount, return_url=return_url, paymentReason=paymentReason) p = transaction.get_payment_class().Pay(transaction, amount=transaction.max_amount, return_url=return_url, paymentReason=paymentReason)
# Create a response for this # Create a response for this

View File

@ -646,12 +646,53 @@ class Processor(baseprocessor.Processor):
def __init__( self, transaction, return_url=None, amount=None, paymentReason=""): def __init__( self, transaction, return_url=None, amount=None, paymentReason=""):
self.transaction=transaction self.transaction=transaction
self.url = return_url
now_val = now()
transaction.date_authorized = now_val
# ASSUMPTION: a user has any given moment one and only one active payment Account
account = transaction.user.profile.account
if not account:
logger.warning("user {0} has no active payment account".format(transaction.user))
raise StripelibError("user {0} has no active payment account".format(transaction.user))
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_INSTANT
transaction.host = PAYMENT_HOST_STRIPE
transaction.preapproval_key = account.account_id
transaction.currency = 'USD'
transaction.amount = amount
transaction.save()
# execute the transaction
p = transaction.get_payment_class().Execute(transaction)
if p.success() and not p.error():
transaction.pay_key = p.key()
transaction.save()
return True
else:
transaction.error = p.error_string()
transaction.save()
logger.info("execute_transaction Error: " + p.error_string())
return False
def amount( self ): def amount( self ):
return self.transaction.amount return self.transaction.amount
def key( self ): def key( self ):
return None return self.transaction.pay_key
def next_url( self ): def next_url( self ):
return self.url return self.url
@ -732,7 +773,6 @@ class Processor(baseprocessor.Processor):
# IN paypal land, our key is updated from a preapproval to a pay key here, just return the existing key # 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 return self.transaction.pay_key
class PreapprovalDetails(StripePaymentRequest): class PreapprovalDetails(StripePaymentRequest):
''' '''
Get details about an authorized token Get details about an authorized token