コード例 #1
0
ファイル: views.py プロジェクト: vkaravir/simple-payments
def process_payment(request, ptype, payment_id):
    """
  Processes the payment after user confirmation. Parameter ptype can be one of success,
  cancel, and error. The user will be redirected to the correct URL depending on the ptype.
  """
    payment = get_object_or_404(Payment, pk=payment_id)
    url = getattr(payment, "%s_url" % ptype)
    if url.find("?") == -1:
        url += "?"
    checksum = md5hex("pid=%s&ref=%s&token=%s" % (payment.pid, payment.id, get_secret_key(payment.sid)))
    # pass the checksum along in the redirect for the seller
    url = "%s&pid=%s&ref=%s&checksum=%s" % (url, payment.pid, payment.id, checksum)
    return HttpResponseRedirect(url)
コード例 #2
0
ファイル: views.py プロジェクト: ihantola/simple-payments
def test(request):
  """
  Allows for testing the service without actually calling it from code. Aids in testing in
  understanding the parameters as well as testing the success, error, and cancel urls.
  """
  payment = {'pid':'mytestsale','sid':'tester', 'amount':15, 'success_url': 'http://localhost:8000/shop/success',
            'error_url': 'http://localhost:8000/shop/error','cancel_url': 'http://localhost:8000/shop/cancel'}
  token = get_secret_key(payment['sid'])
  checkstr = "pid=%s&sid=%s&amount=%s&token=%s"%(payment['pid'], payment['sid'], payment['amount'], token)
  from utils import md5hex
  payment['checksum'] = md5hex(checkstr)
  form = PaymentForm(payment)
  return render_to_response('payment/test.html', {'form': form},
            context_instance=RequestContext(request))
コード例 #3
0
def process_payment(request, ptype, payment_id):
    """
  Processes the payment after user confirmation. Parameter ptype can be one of success,
  cancel, and error. The user will be redirected to the correct URL depending on the ptype.
  """
    payment = get_object_or_404(Payment, pk=payment_id)
    url = getattr(payment, '%s_url' % ptype)
    if url.find("?") == -1:
        url += "?"
    checksum = md5hex("pid=%s&ref=%s&token=%s" %
                      (payment.pid, payment.id, get_secret_key(payment.sid)))
    # pass the checksum along in the redirect for the seller
    url = "%s&pid=%s&ref=%s&checksum=%s" % (url, payment.pid, payment.id,
                                            checksum)
    return HttpResponseRedirect(url)
コード例 #4
0
ファイル: views.py プロジェクト: ihantola/simple-payments
def secret_key(request):
  """
  Allows users to generate a secret key for their seller id to use in communication
  with the payment API.
  """
  if request.method == 'GET':
    form = SecretKeyForm()
  else:
    form = SecretKeyForm(request.POST)
    if form.is_valid():
      sid = form.cleaned_data['sid']
      key = get_secret_key(sid)
      return render_to_response('payment/key_created.html', {'sid': sid, 'key': key},
                context_instance=RequestContext(request))

  context = {'form': form}
  context.update(csrf(request))
  return render_to_response('payment/key.html', context,
            context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: vkaravir/simple-payments
def test(request):
    """
  Allows for testing the service without actually calling it from code. Aids in testing in
  understanding the parameters as well as testing the success, error, and cancel urls.
  """
    payment = {
        "pid": "mytestsale",
        "sid": "tester",
        "amount": 15,
        "success_url": "http://localhost:8000/success",
        "error_url": "http://localhost:8000/error",
        "cancel_url": "http://localhost:8000/cancel",
    }
    token = get_secret_key(payment["sid"])
    checkstr = "pid=%s&sid=%s&amount=%s&token=%s" % (payment["pid"], payment["sid"], payment["amount"], token)
    from utils import md5hex

    payment["checksum"] = md5hex(checkstr)
    form = PaymentForm(payment)
    return render_to_response("payment/test.html", {"form": form}, context_instance=RequestContext(request))
コード例 #6
0
def test(request):
    """
  Allows for testing the service without actually calling it from code. Aids in testing in
  understanding the parameters as well as testing the success, error, and cancel urls.
  """
    payment = {
        'pid': 'mytestsale',
        'sid': 'tester',
        'amount': 15,
        'success_url': 'http://localhost:8000/success',
        'error_url': 'http://localhost:8000/error',
        'cancel_url': 'http://localhost:8000/cancel'
    }
    token = get_secret_key(payment['sid'])
    checkstr = "pid=%s&sid=%s&amount=%s&token=%s" % (
        payment['pid'], payment['sid'], payment['amount'], token)
    from utils import md5hex
    payment['checksum'] = md5hex(checkstr)
    form = PaymentForm(payment)
    return render_to_response('payment/test.html', {'form': form},
                              context_instance=RequestContext(request))
コード例 #7
0
def secret_key(request):
    """
  Allows users to generate a secret key for their seller id to use in communication
  with the payment API.
  """
    if request.method == 'GET':
        form = SecretKeyForm()
    else:
        form = SecretKeyForm(request.POST)
        if form.is_valid():
            sid = form.cleaned_data['sid']
            key = get_secret_key(sid)
            return render_to_response('payment/key_created.html', {
                'sid': sid,
                'key': key
            },
                                      context_instance=RequestContext(request))

    context = {'form': form}
    context.update(csrf(request))
    return render_to_response('payment/key.html',
                              context,
                              context_instance=RequestContext(request))
コード例 #8
0
ファイル: app.py プロジェクト: daltonwu/MKS22QJI-homework
                )
            full_name = salary_data['full_name']
            salary = salary_data['salary']
        # Otherwise, only use ratemyteachers.com to get the rating.
        else:
            rating_data = get_rating(
                salary_data['full_name'],
                request.form['school']
                )
            subject = rating_data['subject']
            rating = rating_data['rating']
            num_ratings = rating_data['num_ratings']
        #photo = get_photo(full_name, request.form['school'])
        efficiency = get_efficiency(salary, rating)
        return render_template(
            'results.html',
            full_name = full_name,
            subject = subject,
            salary = salary,
            rating = rating,
            num_ratings = num_ratings,
            photo = None, #photo,
            efficiency = efficiency
            )
    return render_template('index.html')

if __name__ == "__main__":
   app.debug = True
   app.secret_key = get_secret_key()
   app.run(host="0.0.0.0", port=8000)