コード例 #1
0
def deal_checkout_complete(request, slug, quantity):

  user_msg = ""
  quantity = int(quantity)

  try:
    deal = Deal.objects.get(slug=slug)
  except:
    return Http404()

  token = request.GET.get('token', None)
  payerid = request.GET.get('PayerID', None)

  if token and payerid:

    # TODO: i have no idea how many they bought!
    p = PayPal()
    rc = p.DoExpressCheckoutPayment("CAD", quantity * deal.deal_price, token, payerid, PAYMENTACTION="Authorization")

    if rc:  # payment is looking good

      response = PayPalResponse()
      response.fill_from_response(p.GetPaymentResponse())
      response.status = PayPalResponse.get_default_status()
      response.save()

      num_sold = deal.num_sold()

      # check if it's sold out!
      if num_sold > deal.max_available:
        pass
        #setup form error
        # Sold out!


      for i in range(quantity):
        coupon = Coupon()
        coupon.user = request.user
        coupon.deal = deal

        coupon.status = STATUS_ONHOLD

        coupon.save()
        num_sold = num_sold + 1

        # update the deal object 
        if not deal.is_deal_on and num_sold >= deal.tipping_point:
          deal.tipped_at = datetime.datetime.now()
          deal.is_deal_on = True
          deal.save()


      user_msg = 'Thanks for purchasing a Massive Coupon! It will arrive in your profile within 24 hours'
      return HttpResponseRedirect('/deals/nearby/?user_msg=' + user_msg )
    else:
      return Http404()

  else:
    return Http404()
コード例 #2
0
ファイル: views.py プロジェクト: anarbek/django-groupon-clone
def _paypal_checkout_complete(request, deal, quantity, token):
    result = {'error': True}
    token = request.GET.get('token', None)
    payerid = request.GET.get('PayerID', None)
    
    if token and payerid:
        # TODO: i have no idea how many they bought!
        p = PayPal()
        rc = p.DoExpressCheckoutPayment("CAD", quantity * deal.deal_price, token, payerid, PAYMENTACTION="Authorization")
        if rc:  # payment is looking good
            response = PayPalResponse()
            response.fill_from_response(p.GetPaymentResponse())
            response.status = PayPalResponse.get_default_status()
            response.save()
            result['error'] = False
        else:
            result['message'] = 'Empty payment'
    else:
        result['message']= 'Token or payerid are empty.'
コード例 #3
0
def _paypal_checkout_complete(request, deal, quantity, token):
    result = {'error': True}
    token = request.GET.get('token', None)
    payerid = request.GET.get('PayerID', None)

    if token and payerid:
        # TODO: i have no idea how many they bought!
        p = PayPal()
        rc = p.DoExpressCheckoutPayment("CAD",
                                        quantity * deal.deal_price,
                                        token,
                                        payerid,
                                        PAYMENTACTION="Authorization")
        if rc:  # payment is looking good
            response = PayPalResponse()
            response.fill_from_response(p.GetPaymentResponse())
            response.status = PayPalResponse.get_default_status()
            response.save()
            result['error'] = False
        else:
            result['message'] = 'Empty payment'
    else:
        result['message'] = 'Token or payerid are empty.'
コード例 #4
0
def process_payment_request(amount, currency, token, payerid):
    """
    utility function to perform PayPal payment
    """
    #################
    # BEGIN ROUTINE #
    #################
    
    # call PayPal driver and perform the relevant PayPal API method to charge the money
    driver = PayPal()
    result = driver.DoExpressCheckoutPayment(currency = currency, amount = str(amount), token = token, payerid = payerid)

    # persist the response to the db with PayPalResponse instance
    paypal_response = PayPalResponse()
    paypal_response.fill_from_response(driver.GetPaymentResponse())
    paypal_response.status = PayPalResponse.get_default_status()

    if result == True:
        # Amount charged successfully.
        paypal_response.payment_received = True
        paypal_response.save()
        return True, paypal_response
    else:
        # Amount charged could not be charged successfully. Note that
        # the paypal_response is going to be saved.
        paypal_response.error = _(driver.doexpresscheckoutpaymenterror)
        paypal_response.save()
        return False, paypal_response
コード例 #5
0
def process_refund_request(response, amount):
    """
    utility function to perform PayPal refund
    """
    #################
    # BEGIN ROUTINE #
    #################
    
    # call PayPal driver and perform the relevant PayPal API method to refund the money
    driver = PayPal()
    result = driver.RefundTransaction(response.trans_id, refundtype = "Partial", amount = str(amount), currency = response.currencycode)
    
    # persist the response to the db with PayPalResponse instance
    paypal_response = PayPalResponse()
    paypal_response.fill_from_response(driver.GetRefundResponse(), action = "Refund")
    paypal_response.status = PayPalResponse.get_cancel_status()
    
    if result == True:
        # Amount refunded successfully.
        paypal_response.payment_received = True
        paypal_response.save()
        return True, paypal_response
    else:
        # Amount charged could not be refunded successfully. Note that
        # the paypal_response is going to be saved
        paypal_response.error = _(driver.refundtransactionerror)
        paypal_response.save()
        return False, paypal_response
コード例 #6
0
def process_payment_request(amount, currency, token, payerid):
    """
    utility function to perform PayPal payment
    """
    #################
    # BEGIN ROUTINE #
    #################

    # call PayPal driver and perform the relevant PayPal API method to charge the money
    driver = PayPal()
    result = driver.DoExpressCheckoutPayment(currency=currency,
                                             amount=str(amount),
                                             token=token,
                                             payerid=payerid)

    # persist the response to the db with PayPalResponse instance
    paypal_response = PayPalResponse()
    paypal_response.fill_from_response(driver.GetPaymentResponse())
    paypal_response.status = PayPalResponse.get_default_status()

    if result == True:
        # Amount charged successfully.
        paypal_response.payment_received = True
        paypal_response.save()
        return True, paypal_response
    else:
        # Amount charged could not be charged successfully. Note that
        # the paypal_response is going to be saved.
        paypal_response.error = _(driver.doexpresscheckoutpaymenterror)
        paypal_response.save()
        return False, paypal_response
コード例 #7
0
def process_refund_request(response, amount):
    """
    utility function to perform PayPal refund
    """
    #################
    # BEGIN ROUTINE #
    #################

    # call PayPal driver and perform the relevant PayPal API method to refund the money
    driver = PayPal()
    result = driver.RefundTransaction(response.trans_id,
                                      refundtype="Partial",
                                      amount=str(amount),
                                      currency=response.currencycode)

    # persist the response to the db with PayPalResponse instance
    paypal_response = PayPalResponse()
    paypal_response.fill_from_response(driver.GetRefundResponse(),
                                       action="Refund")
    paypal_response.status = PayPalResponse.get_cancel_status()

    if result == True:
        # Amount refunded successfully.
        paypal_response.payment_received = True
        paypal_response.save()
        return True, paypal_response
    else:
        # Amount charged could not be refunded successfully. Note that
        # the paypal_response is going to be saved
        paypal_response.error = _(driver.refundtransactionerror)
        paypal_response.save()
        return False, paypal_response