Exemplo n.º 1
0
def purchase_do(request, product):
    if not product:
        raise Http404("Product cannot be found")
    if UserProduct.get_product(auth.get_current_user(request), product):
        return render_to_response('store/details.html', 
                                  {'p': product, 
                                   'msg': "You already own this application - to associate with a different device please contact support or use another account."},
                                   RequestContext(request))
    if request.method == "POST":
        form = PurchaseForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            pin = data["pin"]
            email = data["email"]
            user = auth.get_current_user(request)
            user.preferred_email = email
            user.put()
        else:
            return render_to_response('store/purchase_info.html', 
                                      { 'form': form },
                                      RequestContext(request)) 
    else:
        pin = request.GET.get("pin", None)
        email = auth.get_current_user(request).preferred_email
    if not (pin and email):
        form = PurchaseForm(data={'email': email, 'pin': pin})
        return render_to_response('store/purchase_info.html', 
                                  { 'form': form, 'product': product },
                                  RequestContext(request))        
    tx = PaypalRequest.prepare(product, auth.get_current_user(request), pin)
    return render_to_response('store/purchase.html', 
                              {'product': product, 
                               'pin': pin, 
                               'txid': tx.key() },
                              RequestContext(request))
Exemplo n.º 2
0
def thankyou(request, txid):
    tx = PaypalRequest.get(txid)
    if not tx:
        raise Http404("Transaction not found")    
    return render_to_response('store/thankyou.html', 
                              { 'tx' : tx }, 
                              RequestContext(request))
Exemplo n.º 3
0
def paypal_ipn(request):
    """
    Make sure this is a valid request, and activate the corresponding record.
    The transaction id is passed as a custom variable.
    """
    if PaypalRequest.validate_ipn(request):
        def tran():
            #tx = PaypalRequest.get_by_id(request.POST["item_number"])
            tx = PaypalRequest.get(request.POST["custom"])
            if not tx:
                raise Http404("Transaction not found")
            return tx.process_ipn(request)
        userprod = db.run_in_transaction(tran)
        if userprod:
            userprod.send_thankyou_mail()
    return HttpResponse("OK", mimetype="text/plain")
Exemplo n.º 4
0
 def tran():
     #tx = PaypalRequest.get_by_id(request.POST["item_number"])
     tx = PaypalRequest.get(request.POST["custom"])
     if not tx:
         raise Http404("Transaction not found")
     return tx.process_ipn(request)