def _get(subpath, **kwargs): url = _build(subpath, kwargs) log.debug('get -> %s', url) f = urllib.urlopen(url) b = Bag() b.fromXml(f.read()) return b
def _post(subpath, bag=None): url = settings.BACKEND + subpath body = {} if bag is not None: body['data'] = bag.toXml() log.debug('post -> %s data: %s', unicode(url).encode('utf-8'), body['data'] if isinstance(body['data'], str) else body['data'].encode('utf-8')) else: log.debug('post -> %s', url) f = urllib.urlopen(url, urllib.urlencode(body)) b = Bag() b.fromXml(f.read()) return b
def _post(subpath, bag=None): url = settings.BACKEND + subpath body = {} if bag is not None: body['data'] = bag.toXml() log.debug( 'post -> %s data: %s', unicode(url).encode('utf-8'), body['data'] if isinstance( body['data'], str) else body['data'].encode('utf-8')) else: log.debug('post -> %s', url) f = urllib.urlopen(url, urllib.urlencode(body)) b = Bag() b.fromXml(f.read()) return b
def create_order(order, return_url=None): b = Bag() assert order.user.assopy_id rows = list(order.orderitem_set.select_related('ticket__fare')) b['event'] = rows[0].ticket.fare.conference b['user_id'] = order.user.assopy_id #b['coupon'] = #b['discount'] = payment_method = { 'paypal': 'paypal', 'cc': 'paypal', 'bank': 'bank', 'admin': 'bank', }[order.method] b['payment_method'] = payment_method # Se order.deducibile() == False l'acquirente ha comprato biglietti ad uso # "personale" e non vogliamo che possa dedurli. Questo flag informa il # software di fatturazione di riportare in fattura una dicitura apposita. # b['personal'] = not order.deductible() # Aggiornamento, il flag personal non viene più usato dal backend b['personal'] = False b['billing_notes'] = order.billing_notes b['vat_rate'] = 20.0 if return_url: b['return_url'] = return_url tickets = defaultdict(lambda: 0) for r in rows: if r.ticket: tickets[r.ticket.fare.code] += 1 ix = 0 #for t in tickets: # b['order_rows.r%s.fare_code' % ix] = t # b['order_rows.r%s.quantity' % ix] = tickets[t] # ix += 1 for r in rows: if r.ticket: b['order_rows.r%s.fare_code' % ix] = r.ticket.fare.code b['order_rows.r%s.quantity' % ix] = 1 b['order_rows.r%s.description' % ix] = r.description b['order_rows.r%s.price' % ix] = r.price ix += 1 result = _post('/orders/', b) order.assopy_id = result['order_id'] order.code = result['order_code'] order.payment_url = result['paypal_url'] order.save()
def update_fare(fare): name = fare.name if fare.ticket_type == 'conference': if fare.recipient_type == 's': name += ' (for students only)' elif fare.recipient_type == 'p': name += ' (for individuals)' b = Bag() b['price'] = fare.price b['description'] = name[:140] b['personal_fare'] = fare.recipient_type != 'c' b['deposit_fare'] = fare.payment_type == 'd' b['long_desc'] = fare.description b['start_date'] = fare.start_validity b['end_date'] = fare.end_validity return _post('/fares/%s/%s/' % (fare.conference, fare.code), b)
def confirm_order(id, value, date=None): b = Bag() b['payment_value'] = value b['payment_date'] = date return _post('/orders/confirm/%s/' % (id, ), b)
def create_user(firstname, lastname, email): b = Bag() b['firstname'] = firstname b['lastname'] = lastname b['email'] = email return _post('/users/', b)['id']
def set_user_data(id, data): return _post('/users/%s' % id, Bag(data))