def get(self, mode=""):

    if mode == "do_ec_payment":

      if memcache.get(self.request.get("sid")) is not None: # Without an account reference, we can't credit the purchase
        payerid = self.request.get("PayerID")

        product = Product.getProduct()

        nvp_params = { 
                'PAYERID' : payerid, 

                'L_PAYMENTREQUEST_0_NAME0' : str(product['quantity']) + ' ' + product['units'],
                'L_PAYMENTREQUEST_0_AMT0' : str(product['price']),
                'L_PAYMENTREQUEST_0_QTY0' : 1,
                'L_PAYMENTREQUEST_0_ITEMCATEGORY0' : 'Digital',

                'PAYMENTREQUEST_0_AMT' : str(product['price'])
        }

        response = EC.do_express_checkout_payment(
                        self.request.get("token"), 
                        nvp_params
                   )

        if response.status_code != 200:
          logging.error("Failure for DoExpressCheckoutPayment")

          template_values = {
            'title' : 'Error',
            'operation' : 'DoExpressCheckoutPayment'
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unknown_error.html')
          return self.response.out.write(template.render(path, template_values))


        # Ensure that the payment was successful
  
        parsed_qs = cgi.parse_qs(response.content)
  
        if parsed_qs['ACK'][0] != 'Success':
          logging.error("Unsuccessful DoExpressCheckoutPayment")
  
          template_values = {
            'title' : 'Error',
            'details' : parsed_qs['L_LONGMESSAGE0'][0]
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unsuccessful_payment.html')
          return self.response.out.write(template.render(path, template_values))

        if parsed_qs['PAYMENTINFO_0_PAYMENTSTATUS'][0] != 'Completed':
          logging.error("Unsuccessful DoExpressCheckoutPayment")
          logging.error(parsed_qs)
  
          template_values = {
            'title' : 'Error',
            'details' : 'Sorry, but there was an unexpected problem processing your payment.'
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unsuccessful_payment.html')
          return self.response.out.write(template.render(path, template_values))


        # Credit the user's account

        user_info = memcache.get(self.request.get("sid"))
        twitter_username = user_info['username']
        product = Product.getProduct()

        AppHandler.creditUserAccount(twitter_username, product['quantity'])

        template_values = {
          'title' : 'Successful Payment',
          'quantity' : product['quantity'],
          'units' : product['units']
        }
        
        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'successful_payment.html')
        self.response.out.write(template.render(path, template_values))

      else:
        logging.error("Invalid/expired session in /do_ec_payment")

        template_values = {
          'title' : 'Session Expired',
        }

        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'session_expired.html')
        self.response.out.write(template.render(path, template_values))

    elif mode == "cancel_ec":
      template_values = {
        'title' : 'Cancel Purchase',
      }

      path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'cancel_purchase.html')
      self.response.out.write(template.render(path, template_values))
    def post(self, mode=""):

        if mode == "do_direct_payment":

            # To be on the safe side, filter through a pre-defined list of fields
            # to pass through to DoDirectPayment. i.e. prevent the client from
            # potentially overriding IPADDRESS, AMT, etc.

            valid_fields = [
                "FIRSTNAME",
                "LASTNAME",
                "STREET",
                "CITY",
                "STATE",
                "ZIP",
                "COUNTRYCODE",
                "CREDITCARDTYPE",
                "ACCT",
                "EXPDATE",
                "CVV2",
            ]

            product = Product.getProduct()

            nvp_params = {"AMT": str(product["price"]), "IPADDRESS": self.request.remote_addr}

            for field in valid_fields:
                nvp_params[field] = self.request.get(field)

            response = DP.do_direct_payment(nvp_params)

            if response.status_code != 200:
                logging.error("Failure for DoDirectPayment")

                template_values = {"title": "Error", "operation": "DoDirectPayment"}

                path = os.path.join(os.path.dirname(__file__), "..", "templates", "unknown_error.html")
                return self.response.out.write(template.render(path, template_values))

            # Ensure that the payment was successful

            parsed_qs = cgi.parse_qs(response.content)

            if parsed_qs["ACK"][0] != "Success":
                logging.error("Unsuccessful DoDirectPayment")

                template_values = {"title": "Error", "details": parsed_qs["L_LONGMESSAGE0"][0]}

                path = os.path.join(os.path.dirname(__file__), "..", "templates", "unsuccessful_payment.html")
                return self.response.out.write(template.render(path, template_values))

            # Credit the user's account

            user_info = memcache.get(self.request.get("sid"))
            twitter_username = user_info["username"]
            product = Product.getProduct()

            AppHandler.creditUserAccount(twitter_username, product["quantity"])

            template_values = {
                "title": "Successful Payment",
                "quantity": product["quantity"],
                "units": product["units"],
            }

            path = os.path.join(os.path.dirname(__file__), "..", "templates", "successful_payment.html")
            self.response.out.write(template.render(path, template_values))

        else:
            logging.error("Unknown mode for POST request!")
  def get(self, mode=""):

    if mode == "completed_payment":

      if memcache.get(self.request.get("sid")) is not None: # Without an account reference, we can't credit the purchase
        user_info = memcache.get(self.request.get("sid"))

        payKey = user_info["payKey"]

        response = AP.get_payment_details(payKey)
        result = json.loads(response.content)
        logging.info(result)

        if result['responseEnvelope']['ack'] == 'Failure' or \
           result['status'] != 'COMPLETED': # Something went wrong!

          logging.error("Failure for PaymentDetails")

          template_values = {
            'title' : 'Error',
            'operation' : 'ExecutePayment'
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unknown_error.html')
          return self.response.out.write(template.render(path, template_values))


        if result['paymentInfoList']['paymentInfo'][0]['transactionStatus'] != 'COMPLETED': # An eCheck?

          logging.error("Payment transaction status is not complete!")

          template_values = {
            'title' : 'Error',
            'details' : 'Sorry, eChecks are not accepted. Please send an instant payment.'
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unsuccessful_payment.html')
          return self.response.out.write(template.render(path, template_values))


        # Credit the user's account

        twitter_username = user_info['username']
        product = Product.getProduct()

        AppHandler.creditUserAccount(twitter_username, product['quantity'])

        template_values = {
          'title' : 'Successful Payment',
          'quantity' : product['quantity'],
          'units' : product['units']
        }
        
        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'successful_payment.html')
        self.response.out.write(template.render(path, template_values))

      else:
        logging.error("Invalid/expired session in /completed_payment")

        template_values = {
          'title' : 'Session Expired',
        }

        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'session_expired.html')
        self.response.out.write(template.render(path, template_values))

    elif mode == "cancelled_payment":
      template_values = {
        'title' : 'Cancel Purchase',
      }

      path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'cancel_purchase.html')
      self.response.out.write(template.render(path, template_values))
  def get(self, mode=""):

    if mode == "get_ec_details":
      response = EC.get_express_checkout_details(self.request.get("token"))

      if response.status_code != 200:
        logging.error("Failure for GetExpressCheckoutDetails")

        template_values = {
          'title' : 'Error',
          'operation' : 'GetExpressCheckoutDetails'
        }
        
        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unknown_error.html')
        return self.response.out.write(template.render(path, template_values))

      product = Product.getProduct()

      parsed_qs = cgi.parse_qs(response.content)

      template_values = {
        'title' : 'Confirm Purchase',
        'quantity' : product['quantity'], 
        'units' : product['units'], 
        'email' : parsed_qs['EMAIL'][0], 
        'amount' : parsed_qs['PAYMENTREQUEST_0_AMT'][0],
        'query_string_params' : self.request.query_string
      }

      path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'confirm_purchase.html')
      self.response.out.write(template.render(path, template_values))

    elif mode == "do_ec_payment":

      if memcache.get(self.request.get("sid")) is not None: # Without an account reference, we can't credit the purchase
        payerid = self.request.get("PayerID")

        product = Product.getProduct()

        nvp_params = { 
                'PAYERID' : payerid, 
                'PAYMENTREQUEST_0_AMT' : str(product['price'])
        }

        response = EC.do_express_checkout_payment(
                        self.request.get("token"), 
                        nvp_params
                   )

        if response.status_code != 200:
          logging.error("Failure for DoExpressCheckoutPayment")

          template_values = {
            'title' : 'Error',
            'operation' : 'DoExpressCheckoutPayment'
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unknown_error.html')
          return self.response.out.write(template.render(path, template_values))


        # Ensure that the payment was successful
  
        parsed_qs = cgi.parse_qs(response.content)

        if parsed_qs['ACK'][0] != 'Success': 
          logging.error("Unsuccessful DoExpressCheckoutPayment")
  
          template_values = {
            'title' : 'Error',
            'details' : parsed_qs['L_LONGMESSAGE0'][0]
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unsuccessful_payment.html')
          return self.response.out.write(template.render(path, template_values))

        if parsed_qs['PAYMENTINFO_0_PAYMENTSTATUS'][0] != 'Completed': # Probably an eCheck
          logging.error("Unsuccessful DoExpressCheckoutPayment")
          logging.error(parsed_qs)
  
          template_values = {
            'title' : 'Error',
            'details' : 'Sorry, eChecks are not accepted. Please send an instant payment.'
          }
        
          path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unsuccessful_payment.html')
          return self.response.out.write(template.render(path, template_values))


        # Credit the user's account

        user_info = memcache.get(self.request.get("sid"))
        twitter_username = user_info['username']
        product = Product.getProduct()

        AppHandler.creditUserAccount(twitter_username, product['quantity'])

        template_values = {
          'title' : 'Successful Payment',
          'quantity' : product['quantity'],
          'units' : product['units']
        }
        
        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'successful_payment.html')
        self.response.out.write(template.render(path, template_values))

      else:
        logging.error("Invalid/expired session in /do_ec_payment")

        template_values = {
          'title' : 'Session Expired',
        }

        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'session_expired.html')
        self.response.out.write(template.render(path, template_values))

    elif mode == "cancel_ec":
      template_values = {
        'title' : 'Cancel Purchase',
      }

      path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'cancel_purchase.html')
      self.response.out.write(template.render(path, template_values))
Beispiel #5
0
    def get(self, mode=""):

        if mode == "do_ec_payment":

            if memcache.get(
                    self.request.get("sid")
            ) is not None:  # Without an account reference, we can't credit the purchase
                payerid = self.request.get("PayerID")

                product = Product.getProduct()

                nvp_params = {
                    'PAYERID':
                    payerid,
                    'L_PAYMENTREQUEST_0_NAME0':
                    str(product['quantity']) + ' ' + product['units'],
                    'L_PAYMENTREQUEST_0_AMT0':
                    str(product['price']),
                    'L_PAYMENTREQUEST_0_QTY0':
                    1,
                    'L_PAYMENTREQUEST_0_ITEMCATEGORY0':
                    'Digital',
                    'PAYMENTREQUEST_0_AMT':
                    str(product['price'])
                }

                response = EC.do_express_checkout_payment(
                    self.request.get("token"), nvp_params)

                if response.status_code != 200:
                    logging.error("Failure for DoExpressCheckoutPayment")

                    template_values = {
                        'title': 'Error',
                        'operation': 'DoExpressCheckoutPayment'
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates', 'unknown_error.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                # Ensure that the payment was successful

                parsed_qs = cgi.parse_qs(response.content)

                if parsed_qs['ACK'][0] != 'Success':
                    logging.error("Unsuccessful DoExpressCheckoutPayment")

                    template_values = {
                        'title': 'Error',
                        'details': parsed_qs['L_LONGMESSAGE0'][0]
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates',
                                        'unsuccessful_payment.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                if parsed_qs['PAYMENTINFO_0_PAYMENTSTATUS'][0] != 'Completed':
                    logging.error("Unsuccessful DoExpressCheckoutPayment")
                    logging.error(parsed_qs)

                    template_values = {
                        'title':
                        'Error',
                        'details':
                        'Sorry, but there was an unexpected problem processing your payment.'
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates',
                                        'unsuccessful_payment.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                # Credit the user's account

                user_info = memcache.get(self.request.get("sid"))
                twitter_username = user_info['username']
                product = Product.getProduct()

                AppHandler.creditUserAccount(twitter_username,
                                             product['quantity'])

                template_values = {
                    'title': 'Successful Payment',
                    'quantity': product['quantity'],
                    'units': product['units']
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'successful_payment.html')
                self.response.out.write(template.render(path, template_values))

            else:
                logging.error("Invalid/expired session in /do_ec_payment")

                template_values = {
                    'title': 'Session Expired',
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'session_expired.html')
                self.response.out.write(template.render(path, template_values))

        elif mode == "cancel_ec":
            template_values = {
                'title': 'Cancel Purchase',
            }

            path = os.path.join(os.path.dirname(__file__), '..', 'templates',
                                'cancel_purchase.html')
            self.response.out.write(template.render(path, template_values))
    def get(self, mode=""):

        if mode == "completed_payment":

            if memcache.get(
                    self.request.get("sid")
            ) is not None:  # Without an account reference, we can't credit the purchase
                user_info = memcache.get(self.request.get("sid"))

                payKey = user_info["payKey"]

                response = AP.get_payment_details(payKey)
                result = json.loads(response.content)
                logging.info(result)

                if result['responseEnvelope']['ack'] == 'Failure' or \
                   result['status'] != 'COMPLETED': # Something went wrong!

                    logging.error("Failure for PaymentDetails")

                    template_values = {
                        'title': 'Error',
                        'operation': 'ExecutePayment'
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates', 'unknown_error.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                if result['paymentInfoList']['paymentInfo'][0][
                        'transactionStatus'] != 'COMPLETED':  # An eCheck?

                    logging.error(
                        "Payment transaction status is not complete!")

                    template_values = {
                        'title':
                        'Error',
                        'details':
                        'Sorry, eChecks are not accepted. Please send an instant payment.'
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates',
                                        'unsuccessful_payment.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                # Credit the user's account

                twitter_username = user_info['username']
                product = Product.getProduct()

                AppHandler.creditUserAccount(twitter_username,
                                             product['quantity'])

                template_values = {
                    'title': 'Successful Payment',
                    'quantity': product['quantity'],
                    'units': product['units']
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'successful_payment.html')
                self.response.out.write(template.render(path, template_values))

            else:
                logging.error("Invalid/expired session in /completed_payment")

                template_values = {
                    'title': 'Session Expired',
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'session_expired.html')
                self.response.out.write(template.render(path, template_values))

        elif mode == "cancelled_payment":
            template_values = {
                'title': 'Cancel Purchase',
            }

            path = os.path.join(os.path.dirname(__file__), '..', 'templates',
                                'cancel_purchase.html')
            self.response.out.write(template.render(path, template_values))
Beispiel #7
0
    def get(self, mode=""):

        if mode == "get_ec_details":
            response = EC.get_express_checkout_details(
                self.request.get("token"))

            if response.status_code != 200:
                logging.error("Failure for GetExpressCheckoutDetails")

                template_values = {
                    'title': 'Error',
                    'operation': 'GetExpressCheckoutDetails'
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'unknown_error.html')
                return self.response.out.write(
                    template.render(path, template_values))

            product = Product.getProduct()

            parsed_qs = cgi.parse_qs(response.content)

            template_values = {
                'title': 'Confirm Purchase',
                'quantity': product['quantity'],
                'units': product['units'],
                'email': parsed_qs['EMAIL'][0],
                'amount': parsed_qs['PAYMENTREQUEST_0_AMT'][0],
                'query_string_params': self.request.query_string
            }

            path = os.path.join(os.path.dirname(__file__), '..', 'templates',
                                'confirm_purchase.html')
            self.response.out.write(template.render(path, template_values))

        elif mode == "do_ec_payment":

            if memcache.get(
                    self.request.get("sid")
            ) is not None:  # Without an account reference, we can't credit the purchase
                payerid = self.request.get("PayerID")

                product = Product.getProduct()

                nvp_params = {
                    'PAYERID': payerid,
                    'PAYMENTREQUEST_0_AMT': str(product['price'])
                }

                response = EC.do_express_checkout_payment(
                    self.request.get("token"), nvp_params)

                if response.status_code != 200:
                    logging.error("Failure for DoExpressCheckoutPayment")

                    template_values = {
                        'title': 'Error',
                        'operation': 'DoExpressCheckoutPayment'
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates', 'unknown_error.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                # Ensure that the payment was successful

                parsed_qs = cgi.parse_qs(response.content)

                if parsed_qs['ACK'][0] != 'Success':
                    logging.error("Unsuccessful DoExpressCheckoutPayment")

                    template_values = {
                        'title': 'Error',
                        'details': parsed_qs['L_LONGMESSAGE0'][0]
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates',
                                        'unsuccessful_payment.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                if parsed_qs['PAYMENTINFO_0_PAYMENTSTATUS'][
                        0] != 'Completed':  # Probably an eCheck
                    logging.error("Unsuccessful DoExpressCheckoutPayment")
                    logging.error(parsed_qs)

                    template_values = {
                        'title':
                        'Error',
                        'details':
                        'Sorry, eChecks are not accepted. Please send an instant payment.'
                    }

                    path = os.path.join(os.path.dirname(__file__), '..',
                                        'templates',
                                        'unsuccessful_payment.html')
                    return self.response.out.write(
                        template.render(path, template_values))

                # Credit the user's account

                user_info = memcache.get(self.request.get("sid"))
                twitter_username = user_info['username']
                product = Product.getProduct()

                AppHandler.creditUserAccount(twitter_username,
                                             product['quantity'])

                template_values = {
                    'title': 'Successful Payment',
                    'quantity': product['quantity'],
                    'units': product['units']
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'successful_payment.html')
                self.response.out.write(template.render(path, template_values))

            else:
                logging.error("Invalid/expired session in /do_ec_payment")

                template_values = {
                    'title': 'Session Expired',
                }

                path = os.path.join(os.path.dirname(__file__), '..',
                                    'templates', 'session_expired.html')
                self.response.out.write(template.render(path, template_values))

        elif mode == "cancel_ec":
            template_values = {
                'title': 'Cancel Purchase',
            }

            path = os.path.join(os.path.dirname(__file__), '..', 'templates',
                                'cancel_purchase.html')
            self.response.out.write(template.render(path, template_values))
Beispiel #8
0
  def post(self, mode=""):

    if mode == "do_direct_payment":

     # To be on the safe side, filter through a pre-defined list of fields
     # to pass through to DoDirectPayment. i.e. prevent the client from
     # potentially overriding IPADDRESS, AMT, etc.

      valid_fields = [
          'FIRSTNAME',
          'LASTNAME',
          'STREET',
          'CITY',
          'STATE',
          'ZIP',
          'COUNTRYCODE',
          'CREDITCARDTYPE',
          'ACCT',
          'EXPDATE',
          'CVV2',
      ]
      
      product = Product.getProduct()

      nvp_params = {'AMT' : str(product['price']), 'IPADDRESS' : self.request.remote_addr}

      for field in valid_fields:
        nvp_params[field] = self.request.get(field)

      response = DP.do_direct_payment(nvp_params)

      if response.status_code != 200:
        logging.error("Failure for DoDirectPayment")

        template_values = {
          'title' : 'Error',
          'operation' : 'DoDirectPayment'
        }
        
        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unknown_error.html')
        return self.response.out.write(template.render(path, template_values))

      # Ensure that the payment was successful

      parsed_qs = cgi.parse_qs(response.content)

      if parsed_qs['ACK'][0] != 'Success':
        logging.error("Unsuccessful DoDirectPayment")

        template_values = {
          'title' : 'Error',
          'details' : parsed_qs['L_LONGMESSAGE0'][0]
        }
        
        path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'unsuccessful_payment.html')
        return self.response.out.write(template.render(path, template_values))


      # Credit the user's account

      user_info = memcache.get(self.request.get("sid"))
      twitter_username = user_info['username']
      product = Product.getProduct()

      AppHandler.creditUserAccount(twitter_username, product['quantity'])

      template_values = {
        'title' : 'Successful Payment',
        'quantity' : product['quantity'],
        'units' : product['units']
      }
        
      path = os.path.join(os.path.dirname(__file__), '..', 'templates', 'successful_payment.html')
      self.response.out.write(template.render(path, template_values))

    else:
      logging.error("Unknown mode for POST request!")