示例#1
0
def thankYou_URL(request):
    """URL: thankyou
  """
    answer = addHeader()
    answer += "after payment.</p>"

    # TODO: Do some fancy reaction 'Hooray you have paid'.
    answer += "<h1>Thank you for your purchase:</h1>"
    answer += printDictAsHtmlPRE(request.GET.dict())
    return HttpResponse(htmlBodyTags(answer))
示例#2
0
def thankYou_URL(request):
    """URL: thankyou
  """
    answer = addHeader()
    answer += "after payment.</p>"

    # TODO: Do some fancy reaction 'Hooray you have paid'.
    answer += "<h1>Thank you for your purchase:</h1>"
    answer += printDictAsHtmlPRE(request.GET.dict())
    return HttpResponse(htmlBodyTags(answer))
示例#3
0
def cancel_URL(request):
    """URL: cancel
  """

    answer = addHeader()
    answer += "after there was no payment for 15 minutes.</p>"

    # TODO: Do some fancy reaction 'You waited too long'.
    answer += "<h1>Checkout was cancelled:</h1>"
    answer += printDictAsHtmlPRE(request.GET.dict())
    return HttpResponse(htmlBodyTags(answer))
示例#4
0
def cancel_URL(request):
    """URL: cancel
  """

    answer = addHeader()
    answer += "after there was no payment for 15 minutes.</p>"

    # TODO: Do some fancy reaction 'You waited too long'.
    answer += "<h1>Checkout was cancelled:</h1>"
    answer += printDictAsHtmlPRE(request.GET.dict())
    return HttpResponse(htmlBodyTags(answer))
示例#5
0
def hook_URL(request, hookname, dbg=DEBUG_MESSAGES, DROP_ALL_BUT_POST = False):
  "URL: receiving webhook, to digest Coinbase answers."
  
  if dbg: print "Received %s request on /hook/%s/" %(request.method, hookname)
  
  if DROP_ALL_BUT_POST and (request.method != 'POST'):
    answer="How dare you fiddle around here. Go away."
    return HttpResponseBadRequest(htmlBodyTags(answer))

  trust = canHookDataBeTrusted(request, hookname, dbg=DEBUG_MESSAGES)
   
  # Store all. Regardless. Later switch off? 
  hook_storeCallbackDataIntoDatabase(request, hookname, trust) 

  # If the notification is really coming from coinbase, do all the fancy stuff:
  if trust: 
    # TODO: Especially if more reactions are added, then this could be done in 
    # its own thread, to be able to quickly answer back to Coinbase: (200, OK)
    if dbg: print "Request is trusted. Calling reactions:" 
    reactions.ifTrustedCallbackData(request, hookname, dbg)
  
  return HttpResponse(htmlBodyTags( "Thanks." )) # (200, OK)
示例#6
0
def hook_URL(request, hookname, dbg=DEBUG_MESSAGES, DROP_ALL_BUT_POST=False):
    "URL: receiving webhook, to digest Coinbase answers."

    if dbg:
        print "Received %s request on /hook/%s/" % (request.method, hookname)

    if DROP_ALL_BUT_POST and (request.method != 'POST'):
        answer = "How dare you fiddle around here. Go away."
        return HttpResponseBadRequest(htmlBodyTags(answer))

    trust = canHookDataBeTrusted(request, hookname, dbg=DEBUG_MESSAGES)

    # Store all. Regardless. Later switch off?
    hook_storeCallbackDataIntoDatabase(request, hookname, trust)

    # If the notification is really coming from coinbase, do all the fancy stuff:
    if trust:
        # TODO: Especially if more reactions are added, then this could be done in
        # its own thread, to be able to quickly answer back to Coinbase: (200, OK)
        if dbg: print "Request is trusted. Calling reactions:"
        reactions.ifTrustedCallbackData(request, hookname, dbg)

    return HttpResponse(htmlBodyTags("Thanks."))  # (200, OK)
示例#7
0
def buy_URL(request, dbg=DEBUG_MESSAGES):
    """URL: webpage with form.
     First access (GET): Send form to user browser.
     Second access (POST, but invalid): Send form with red missing fields.
     Third access (POST, valid): Create Coinbase checkout, redirect there.
  """

    if request.method == 'GET':
        if dbg: print "showing webpage with form to input credentials"
        form = newBuyForm()
        return renderBuyForm(request, form)

    elif request.method == 'POST':
        if dbg: print "POST request received."
        form = newBuyForm(request.POST)

        if not form.is_valid():  # then report the missing fields:
            if dbg: print "Form validation failed."
            return renderBuyForm(request, form)

        else:  # form entries are valid, hooray :-)

            newbuy = form.save()

            if dbg:
                print "Valid. Saved. Taking form entries, and creating a coinbase checkout."
            duration = form.cleaned_data['duration']
            price = [p["price"] for p in CHOICES
                     if p["name"] == duration][0]  # take first!

            metadata = {
                "id": newbuy.
                id,  # primary key can later be used to identify (paid --> newbuy) 
                "duration": duration,
                "price": "%s %s" % (price, CURRENCY)
            }  # most important data into payment

            presets = None if not SHOW_ALL_PRICES_AGAIN else [
                p["price"] for p in CHOICES
            ]

            hook = hookname()  # automatically creates new random .name
            hook.NewBuy = newbuy  # set foreign key, then
            hook.save()

            try:
                checkout = createCoinbaseCheckout(amount=price,
                                                  metadata=metadata,
                                                  amount_presets=presets,
                                                  hook=hook.name)
            except Exception as e:
                answer = "Problem. Please tell us: (%s) %s" % (str(type(e)), e)
                print answer
                return HttpResponse(htmlBodyTags(answer))

            if dbg:
                print "client.create_checkout.warnings=%s" % checkout.warnings
            # print checkout
            embed_code = checkout["embed_code"]

            payment_url = '%s/checkouts/%s' % (API_FRONTEND_URL, embed_code)
            if dbg: print "redirecting to coinbase: %s" % payment_url

            return redirect(payment_url)
示例#8
0
def buy_URL(request, dbg=DEBUG_MESSAGES):
    """URL: webpage with form.
     First access (GET): Send form to user browser.
     Second access (POST, but invalid): Send form with red missing fields.
     Third access (POST, valid): Create Coinbase checkout, redirect there.
  """

    if request.method == "GET":
        if dbg:
            print "showing webpage with form to input credentials"
        form = newBuyForm()
        return renderBuyForm(request, form)

    elif request.method == "POST":
        if dbg:
            print "POST request received."
        form = newBuyForm(request.POST)

        if not form.is_valid():  # then report the missing fields:
            if dbg:
                print "Form validation failed."
            return renderBuyForm(request, form)

        else:  # form entries are valid, hooray :-)

            newbuy = form.save()

            if dbg:
                print "Valid. Saved. Taking form entries, and creating a coinbase checkout."
            duration = form.cleaned_data["duration"]
            price = [p["price"] for p in CHOICES if p["name"] == duration][0]  # take first!

            metadata = {
                "id": newbuy.id,  # primary key can later be used to identify (paid --> newbuy)
                "duration": duration,
                "price": "%s %s" % (price, CURRENCY),
            }  # most important data into payment

            presets = None if not SHOW_ALL_PRICES_AGAIN else [p["price"] for p in CHOICES]

            hook = hookname()  # automatically creates new random .name
            hook.NewBuy = newbuy  # set foreign key, then
            hook.save()

            try:
                checkout = createCoinbaseCheckout(
                    amount=price, metadata=metadata, amount_presets=presets, hook=hook.name
                )
            except Exception as e:
                answer = "Problem. Please tell us: (%s) %s" % (str(type(e)), e)
                print answer
                return HttpResponse(htmlBodyTags(answer))

            if dbg:
                print "client.create_checkout.warnings=%s" % checkout.warnings
            # print checkout
            embed_code = checkout["embed_code"]

            payment_url = "%s/checkouts/%s" % (API_FRONTEND_URL, embed_code)
            if dbg:
                print "redirecting to coinbase: %s" % payment_url

            return redirect(payment_url)