本文整理汇总了Python中models.Transaction.put方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.put方法的具体用法?Python Transaction.put怎么用?Python Transaction.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Transaction
的用法示例。
在下文中一共展示了Transaction.put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def post(self):
data = flatten_arguments(self.request.arguments)
from models import Transaction, Invoice
from pprint import pformat
invoice_id = data.get('invoice')
if invoice_id:
invoice = Invoice.get_by_id(int(invoice_id, 10))
txn = Transaction(invoice=invoice)
txn.identifier = data.get('txn_id')
txn.subscription_id = data.get("subscr_id")
txn.transaction_type = data.get('txn_type')
txn.currency = data.get('mc_currency')
txn.amount = data.get('mc_gross', data.get('mc_amount3'))
txn.data = pformat(data)
txn.put()
if self.verify(data):
r = self.process(data, txn=txn, invoice=invoice)
else:
r = self.process_invalid(data, txn=txn, invoice=invoice)
if r:
self.write(r)
else:
self.write('Nothing to see here.')
else:
# error. invoice id was not found.
pass
示例2: make_guess
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def make_guess(self, request):
"""Guess a letter. Returns a game state with message"""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if game.game_over:
raise endpoints.BadRequestException(
'Game already over!')
if game.game_cancelled:
raise endpoints.BadRequestException(
'Game has been cancelled!')
if len(request.guess) > 1:
raise endpoints.BadRequestException(
'You can only guess one letter!')
if not request.guess.isalpha():
raise endpoints.BadRequestException(
'The guess must be a letter!')
# Determine if guess is correct. If so, update score
score = Score.query(ancestor=game.key).get()
if request.guess in game.game_word:
msg = 'You guessed right. The game word does contain the letter '\
+ request.guess + '.'
# find all correctly guess letters in the game word and
# set those letters in the guess string
for index, char in enumerate(game.game_word):
if char == request.guess:
game.correct_guesses[index] = char
score.points += 1
else:
msg = 'Sorry, the game word does not contain the letter '\
+ request.guess + '.'
game.hangman.append(STICK_MAN_PARTS[game.attempts_remaining-1])
game.attempts_remaining -= 1
game.incorrect_guesses.append(request.guess)
if ''.join(game.correct_guesses) == game.game_word:
game.game_over = True
score.points += 30
score.won = True
msg = 'You win!'
elif game.attempts_remaining < 1:
game.game_over = True
msg = msg + 'Sorry, Game over!'
game.put()
score.put()
# Record the transaction
trans = Transaction(date=datetime.today(),
game=game.key,
guess=request.guess,
result=msg)
trans.put()
return game.to_form(msg)
示例3: get
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def get(self, client):
# Get the transaction id, tx=blahblahblah
trans_id = self.request.get("tx")
# Confgure POST args
args = {}
# Specify the paypal command
args["cmd"] ="_notify-synch"
args["tx"] = trans_id
args["at"] = settings.PAYPAL_PDT_KEY
args = urllib.urlencode(args)
try:
# Do a post back to validate
# the transaction data
status = urlfetch.fetch(url = settings.PAYPAL_URL,
method = urlfetch.POST,
payload = args).content
except:
self.response.out.write("POST Failed")
# Check for SUCCESS at the start of the response
lines = status.split(' ')
if lines[0] == 'SUCCESS':
lines = line[1:]
props = {}
for line in lines:
(key, value) = line.split('=')
props[key] = value
# Check other transaction details here like
# payment_status etc..
# TODO Update donation transaction in streetcodes
client = Client.all().filter('shortCode =', props['item_number']).get()
donor = Donor.all().filter('email =', props['email']).get()
if donor is None:
donor = Donor()
donor.name = "%s %s" % (props['first'], props['last'])
donor.email = props['email']
donor.put()
tx = Transaction(method='PayPal',
donor=donor,
client=client,
amount=props['amount'])
tx.put()
# redirect user to thank you screen "/client_short_code#thanks"
self.response.out.write('<script> window.location = "/'+ client + '#thanks"; </script>')
# DEBUG code
# self.response.out.write("OK<br>")
# self.response.out.write(urllib.unquote(status))
else:
self.response.out.write("Failed")
示例4: post
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def post(self):
trans = Transaction(id=self.request.get("trans_code"))
trans.trans_code = self.request.get("trans_code")
sender = User.get_by_id(self.request.get("sender_code"))
trans.sender = sender.key.urlsafe()
receiver = User.get_by_id(self.request.get("receiver_code"))
trans.receiver = receiver.key.urlsafe()
trans.description = self.request.get("description")
logging.critical(self.request.get("eda"))
date = datetime.datetime.strptime(self.request.get("eda"), '%m/%d/%Y')
logging.critical(date)
trans.eda = date
p_code = ""
r_code = ""
while True:
p_code = parser_code()
parcel = P.get_by_id(p_code)
if not parcel:
break;
while True:
r_code = receiver_code()
receiver = R.get_by_id(r_code)
if not receiver:
break;
logging.critical(p_code)
logging.critical(r_code)
trans.parser_code = hash_code(p_code, "PARSER")
trans.receiver_code = hash_code(r_code, "RECEIVER")
trans.put()
""" save transaction for PARSEL code """
p = P(id=p_code)
p.codes = p_code
p.trans_key = trans.key.urlsafe()
p.put()
""" ---------------------------------- """
""" save transaction for RECEIVER code """
r = R(id=r_code)
r.codes = r_code
r.trans_key = trans.key.urlsafe()
r.put()
""" ---------------------------------- """
self.redirect(self.uri_for('www-login', success="Added!."))
示例5: createTransaction
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def createTransaction(self, props):
tx = Transaction( method = 'PayPal',
donor = props['donor'],
client = props['client'],
txID = props['txn_id'],
paymentDate = urllib.unquote(props['payment_date']).replace('+', ' '),
amount = float(props['mc_gross']),
fee = float(props['mc_fee']) ,
paymentStatus = props['payment_status'],
note = urllib.unquote(props['item_name']).replace('+', ' '),
fulfilled = False
)
tx.put()
return tx
示例6: post
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def post(self):
action = self.request.get('action', 'list')
if action == 'list':
self.sendTransactionList()
elif action == 'update':
# add a new or update a transaction
tkey = self.request.get('transaction', 'None')
if tkey == 'None':
transaction = Transaction()
transaction.project = self.project
else:
transaction = Transaction.get(tkey)
if transaction.project.key() != self.project.key():
raise Exception("Project/Transaction mismatch")
# update / set fields
transaction.date = datetime.strptime(self.request.get('date', transaction.date.isoformat()), "%Y-%m-%d")
transaction.source = Account.get(self.request.get('source', transaction.source and transaction.source.key()))
transaction.dest = Account.get(self.request.get('dest', transaction.dest and transaction.dest.key()))
transaction.ammount = float(self.request.get('ammount', str(transaction.ammount)).replace(',', '.'))
transaction.check = self.request.get('check', 'False') == 'True'
transaction.text = self.request.get('text', transaction.text)
transaction.user = self.user
# a None currency means we use the base currency!
c = self.request.get('currency', transaction.currency and transaction.currency.key())
transaction.currency = Currency.get(c) if c != "None" else None
# exchange source and dest, if the amount is negative
if transaction.ammount < 0:
tmp_src = transaction.source
transaction.source = transaction.dest
transaction.dest = tmp_src
transaction.ammount = -transaction.ammount
# put back into data store
transaction.put()
# retransmit all transactions
self.sendTransactionList()
elif action == 'delete':
# add a new or update a transaction
transaction = Transaction.get(self.request.get('transaction', 'None'))
if transaction.project.key() != self.project.key():
raise Exception("Project/Transaction mismatch")
transaction.delete()
# retransmit all transactions
self.sendTransactionList()
else:
raise Exception("Unknown action '%(action)s'!" % {'action':action})
示例7: get
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def get(self):
if not self.jerry_profile.can("accept_payment"):
webapp2.abort(403, "App can't accept payments")
if not self.app_access.payment_provider:
webapp2.abort(501, "No payment provider configured")
user_id = self.request.GET["uuid"]
user = ndb.Key(urlsafe=user_id).get()
if not user:
webapp2.abort(403, "No uuid given")
try:
compiler = getattr(self, "_compile_{}".format(self.app_access.payment_provider))
except:
webapp2.abort(403, "Unknown payment provider: {}".format(compiler))
transaction = Transaction(target=user.key)
transaction.put()
return webapp2.redirect(compiler(transaction.key.id()))
示例8: post
# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import put [as 别名]
def post(self, mode =""):
# Nothing to do here, content script will pick up accesstoken from here
if mode == "ipn":
logging.info(self.request.body)
result = urlfetch.fetch(
ipn_sandbox_url,
payload = "cmd=_notify-validate&" + self.request.body,
method=urlfetch.POST,
validate_certificate=True
)
logging.info(result.content)
if result.status_code == 200 and result.content == 'VERIFIED': # OK
ipn_values = cgi.parse_qs(self.request.body)
debug_msg = '\n'.join(["%s=%s" % (k,'&'.join(v)) for (k,v) in ipn_values.items()])
#logging.info("from tung with love")
item_number = cgi.escape(self.request.get('item_number'))
# get stuff
transaction_id = str(cgi.escape(self.request.get('txn_id')))
payer_email = str(cgi.escape(self.request.get('payer_email')))
receiver_email = str(cgi.escape(self.request.get('receiver_email')))
item_amount = str(cgi.escape(self.request.get('payment_gross')))
sales_tax = str(cgi.escape(self.request.get('tax')))
shipping = str(cgi.escape(self.request.get('shipping')))
handling = str(cgi.escape(self.request.get('mc_fee')))
quantity = str(cgi.escape(self.request.get('quantity')))
item_name = str(cgi.escape(self.request.get('item_name')))
date = str(cgi.escape(self.request.get('payment_date')))
status = str(cgi.escape(self.request.get('payment_status')))
payment_type = str(cgi.escape(self.request.get('payment_type')))
### Change Request to done
post = RequestPost.query(RequestPost.reference == item_number).get() #that post
if post:
post.payment_is_done = True
## Notify tutee
notifymsg = NotifiedMessage()
notifymsg.read = False
notifymsg.person_reference = post.requester
notifymsg.object_reference = item_number
notifymsg.content = " paid " + item_amount + ", click to give feedback"
notifymsg.price = item_amount
notifymsg.initiator = post.requester
notifymsg.put()
#
## Notify tutor
notifymsg2 = NotifiedMessage()
notifymsg2.read = False
notifymsg2.person_reference = post.final_provider
notifymsg2.object_reference = item_number
notifymsg2.content = " paid " + item_amount + ", click to give feedback "
notifymsg2.price = item_amount
notifymsg2.initiator = post.requester
notifymsg2.put()
### Create Transaction Object
newtransaction = Transaction()
newtransaction.transaction_id = transaction_id
newtransaction.payer_email = payer_email
newtransaction.receiver_email = receiver_email
newtransaction.item_amount = item_amount
newtransaction.sales_tax = sales_tax
newtransaction.shipping = shipping
newtransaction.handling = handling
newtransaction.quantity = quantity
newtransaction.item_name = item_name
newtransaction.item_number = item_number
newtransaction.date = date
newtransaction.status = status
newtransaction.payment_type = payment_type
newtransaction.tutee_username = post.requester
newtransaction.tutor_username = post.final_provider
newtransaction.testPeoplewhocanseethis.append(post.requester)
newtransaction.testPeoplewhocanseethis.append(post.final_provider)
newtransaction.put()
post.put()
self.response.out.write(debug_msg)
else:
logging.error('Could not fetch %s (%i)' % (url, result.status_code,))
else:
logging.error("Unknown mode for POST request!")