def create(order_id): result = pdidx.insert().values(source='Website', orderid=order_id).execute() DBSession.flush() regid = License.generate() pdserial = result.inserted_primary_key[0] anlicenses.insert().values( pdserial=pdserial, regid=regid, sequence=1, created=datetime.now(), lastchange=datetime.now(), source='Website', orderid=order_id, ).execute() return pdserial
def order_view(request): if request.POST: v = request.POST order = Order() order.first_name = v['first_name'] order.last_name = v['last_name'] order.email = v['email'] if v['lic'] == 'upgrade': row = anlicenses.select().where(anlicenses.c.regid==v['license']).execute().fetchone() order.pdserial = row['pdserial'] order.total = 0 order.payment = v['method'] order.status = 'pending' order.created = datetime.now() DBSession.add(order) DBSession.flush() if v['bundle'] != '0': bundle = Items() bundle.order_id = order.order_id bundle.sku = v['bundle'] DBSession.add(bundle) DBSession.flush() order.total = bundle.product.price for sku in v.getall('module'): module = Items() module.order_id = order.order_id module.sku = sku DBSession.add(module) DBSession.flush() order.total = order.total + module.product.price if v['method'] == 'paypal': # Paypal processing paypal = _get_paypal(request.registry.settings) #order = DBSession.query(Order).filter(Order.order_id==v['order']).one() description = ', '.join(i.product.name for i in order.items) result = paypal.set_express_checkout( PAYMENTREQUEST_0_AMT=str(order.total), PAYMENTREQUEST_0_ITEMAMT=str(order.total), PAYMENTREQUEST_0_DESC='Total: $' + str(order.total) + ' ' + description, PAYMENTREQUEST_0_PAYMENTACTION='SALE', RETURNURL=request.application_url + '/payment', CANCELURL=request.application_url + '/cancel', ) if result.success: token = result['TOKEN'] order.paypal_token = token return HTTPFound(location=paypal.generate_express_checkout_redirect_url(token)) if v['method'] == 'card': settings = request.registry.settings if settings['braintree.environment'] == 'Production': env = braintree.Environment.Production else: env = braintree.Environment.Sandbox braintree.Configuration.configure(env, merchant_id=settings['braintree.merchant_id'], public_key=settings['braintree.public_key'], private_key=settings['braintree.private_key']) tr_data = braintree.Transaction.tr_data_for_sale( {"transaction": {"type": "sale", "order_id": str(order.order_id), "amount": str(order.total), "options": {"submit_for_settlement": True}}}, request.application_url + '/payment') braintree_url = braintree.TransparentRedirect.url() return render_to_response('templates/payment.pt', {'order': order, 'v': v, 'tr_data':tr_data, 'braintree_url': braintree_url}, request=request) try: bundles = DBSession.query(Product).filter(Product.bundle).order_by(Product.display_order).all() modules = DBSession.query(Product).filter(~Product.bundle).order_by(Product.display_order).all() except DBAPIError: return Response(conn_err_msg, content_type='text/plain', status_int=500) return {'bundles': bundles, 'modules': modules}