def on_get(self): code = self.get_argument("code", None) try: c = Coupon.objects(code=code, redeemed=False, expiration_date__gte=datetime.now()).get() discount = PRODUCT_PRICE * float(c.discount) / 100 new_price = "{0:.2f}".format(PRODUCT_PRICE - discount) success = True return (new_price, success) except DoesNotExist: success = False return (PRODUCT_PRICE, success)
def on_get(self): try: #Calculate price code = self.get_argument("code", None) try: c = Coupon.objects(code=code, redeemed=False, expiration_date__gte=datetime.now()).get() discount = PRODUCT_PRICE * float(c.discount) / 100 price = PRODUCT_PRICE - discount c.redeemed = True c.save() except DoesNotExist: price = PRODUCT_PRICE if price == 0: redir_url = "/dashboard" self.current_user.record_payment("Free voucher transaction", "Free voucher transaction") self.current_user.price = str("{0:.2f}".format(price)) self.current_user.save() self.log.info("User with id " + str(self.current_user.id) + "has paid. The transaction id is " + "Free voucher transaction") else: ppi = get_paypal_interface() email = self.current_user and self.current_user.email or "" self.current_user.price = str("{0:.2f}".format(price)) self.current_user.save() setexp_response = ppi.set_express_checkout( PAYMENTREQUEST_0_AMT=str("{0:.2f}".format(price)), PAYMENTREQUEST_0_CURRENCYCODE='GBP', returnurl=RETURN_URL, cancelurl=CANCEL_URL, PAYMENTREQUEST_0_PAYMENTACTION='Order', email=email, PAYMENTREQUEST_0_DESC='Intheory Web App - ' + '£' + str("{0:.2f}".format(price)) + ' - Full Access', landingpage="Billing") token = setexp_response.token getexp_response = ppi.get_express_checkout_details(token=token) # Redirect client to this URL for approval. redir_url = ppi.generate_express_checkout_redirect_url(token) return (redir_url, ) except Exception, e: self.log.warning("Error while redirecting user with id " + str(self.current_user.id) + " to PayPal: " + str(e))
def on_get(self): try: # Calculate price code = self.get_argument("code", None) try: c = Coupon.objects(code=code, redeemed=False, expiration_date__gte=datetime.now()).get() discount = PRODUCT_PRICE * float(c.discount) / 100 price = PRODUCT_PRICE - discount c.redeemed = True c.save() except DoesNotExist: price = PRODUCT_PRICE if price == 0: redir_url = "/dashboard" self.current_user.record_payment("Free voucher transaction", "Free voucher transaction") self.current_user.price = str("{0:.2f}".format(price)) self.current_user.save() self.log.info( "User with id " + str(self.current_user.id) + "has paid. The transaction id is " + "Free voucher transaction" ) else: ppi = get_paypal_interface() email = self.current_user and self.current_user.email or "" self.current_user.price = str("{0:.2f}".format(price)) self.current_user.save() setexp_response = ppi.set_express_checkout( PAYMENTREQUEST_0_AMT=str("{0:.2f}".format(price)), PAYMENTREQUEST_0_CURRENCYCODE="GBP", returnurl=RETURN_URL, cancelurl=CANCEL_URL, PAYMENTREQUEST_0_PAYMENTACTION="Order", email=email, PAYMENTREQUEST_0_DESC="Intheory Web App - " + "£" + str("{0:.2f}".format(price)) + " - Full Access", landingpage="Billing", ) token = setexp_response.token getexp_response = ppi.get_express_checkout_details(token=token) # Redirect client to this URL for approval. redir_url = ppi.generate_express_checkout_redirect_url(token) return (redir_url,) except Exception, e: self.log.warning( "Error while redirecting user with id " + str(self.current_user.id) + " to PayPal: " + str(e) )