Esempio n. 1
0
def create_checkout(subscription_id):
    subscription = Subscription.get_or_none(Subscription.id == subscription_id)
    user = User.get_by_id(current_user.id)
    nonce_from_the_client = request.form["payment_method_nonce"]
    result = gateway.customer.create({
        "first_name": current_user.name,
        "email": current_user.email,
        "payment_method_nonce": nonce_from_the_client
    })
    
    if result.is_success :
        result_subscription = gateway.subscription.create({
            "id" : current_user.id,
            "payment_method_token": result.customer.payment_methods[0].token,
            "plan_id": subscription.id
        })

    if type(result_subscription) == SuccessfulResult:
        new_transaction = Transaction(amount = subscription.price, subscription = subscription.id , user = current_user.id)

        if new_transaction.save():
            user.is_valid = True
            user.save()
            flash ("Transaction Successful", "success")
            send_message_first_payment.delay(email = current_user.email, name = current_user.name)
            return redirect(url_for('home'))

    else :
        flash ("Transaction Failed, check your card details and try again", "danger")
        return redirect(url_for('home'))    
Esempio n. 2
0
def exclusive():
    client_token = generate_client_token()
    price = 125
    subscriptiontype = "exclusive"

    subscription = Subscription.get_or_none(
        Subscription.user == current_user.id)
    if subscription:
        flash(
            "You already have a subscription. Contact us in case you would like to change."
        )
    else:
        return render_template('subscriptions/new.html',
                               client_token=client_token,
                               price=price,
                               subscriptiontype=subscriptiontype)
Esempio n. 3
0
def premium():
    client_token = generate_client_token()
    price = 109
    subscriptiontype = "premium"

    subscription = Subscription.get_or_none(
        Subscription.user == current_user.id)
    if subscription:
        flash(
            "You already have a subscription. Contact us in case you would like to change."
        )
        return redirect(url_for('home'))
    else:
        return render_template('subscriptions/new.html',
                               client_token=client_token,
                               price=price,
                               subscriptiontype=subscriptiontype)
Esempio n. 4
0
def show_checkout(subscription_id, transaction_id):
    subscription = Subscription.get_or_none(Subscription.id == subscription_id)
    transaction = gateway.transaction.find(transaction_id)
    user = User.get_by_id(current_user.id)
    result = {}
    if transaction.status in TRANSACTION_SUCCESS_STATUSES :
        result = {
            'header' : "Transaction Successful",
            'icon' : "success",
            'message' : "Your transaction has been successfully processed."
        }

    else :
        result = {
            'header' : "Transaction Failed",
            'icon' : "failed",
            'message' : "Your transaction cannot be processed"
        }
    return render_template("transactions/show.html", transaction = transaction, result = result, subscription = subscription)
Esempio n. 5
0
def payment(subscription_id):
    user_id = get_jwt_identity()
    user = User.get_or_none(User.id == user_id)
    subscription = Subscription.get_or_none(Subscription.id == subscription_id)
    nonce_from_the_client = request.json["temp"]
    # result = gateway.customer.create({
    #     "first_name": user.name,
    #     "email": user.email,
    #     "payment_method_nonce": nonce_from_the_client
    # })
    # print(result)

    # if result.is_success :
    #     result_subscription = gateway.subscription.create({
    #         "id" : user.id,
    #         "payment_method_token": result.customer.payment_methods[0].token,
    #         "plan_id": subscription.id
    #     })
    
    result = gateway.transaction.sale({
    "amount": subscription.price,
    "payment_method_nonce": nonce_from_the_client,
    "options": {
      "submit_for_settlement": True
    }
    })
    
    

    if type(result) == SuccessfulResult:
        user.is_valid = True
        user.subscription = subscription.id
        user.save()
        new_transaction = Transaction(amount = subscription.price, subscription = subscription.id , user = user.id)

        if new_transaction.save() and user.save():
            
            send_message_first_payment.delay(email = user.email, name = user.name)
            return jsonify({"message" : "Payment has been processed successfully"})

        else :
            return jsonify({"message" : "Payment failed, try again"})        
Esempio n. 6
0
def new_2():
    client_token = generate_client_token()
    price = request.form.get('price')
    if price == 93:
        subscriptiontype = 'standard'
    elif price == 109:
        subscriptiontype = 'premium'
    else:
        subscriptiontype = 'exclusive'

    subscription = Subscription.get_or_none(
        Subscription.user == current_user.id)
    if subscription:
        flash(
            "You already have a subscription. Contact us in case you would like to change."
        )
        return redirect(url_for('home'))
    else:
        return render_template('subscriptions/new.html',
                               client_token=client_token,
                               price=price,
                               subscriptiontype=subscriptiontype)
Esempio n. 7
0
def show():
    admin = False
    authentic = False
    if current_user.is_authenticated:
        authentic = True
        user = User.get_or_none(User.id == current_user.id)
        if user.Admin == True:
            admin = True
    outfits = Outfit.select()
    size = Size.select()
    out = Outfit.select()
    outfits_cart = Outfit.select().order_by(Outfit.outfit_price.asc())
    subscription = None
    amount = 0
    # outfits = []
    discount = 0
    # user = None
    surplus = []
    sub = []
    sess = []
    price = 0

    if 'cart' in session:
        sess = session['cart']
        if current_user.is_authenticated:
            # user= User.select().where(User.id == current_user.id)
            subscription = Subscription.get_or_none(
                Subscription.user == current_user.id)
            if subscription:

                sub_length = int(subscription.subscription_type)

                if len(sess) > sub_length:
                    sess2 = len(sess) - sub_length
                    count = 0
                    for item in outfits_cart:
                        if count < sess2:
                            if item.id in sess:
                                amount = amount + item.outfit_price
                                if item.id not in surplus:
                                    surplus.append(item.id)
                                count += 1
                        else:
                            break
                    discount = int(amount) / count * 0.33 * (count - 1)

                # if len(sess) > (sub_length+1):
                #     sess2 = len(sess) - (sub_length+1)
                #     count = 0
                #     for item in outfits_cart:
                #         if count < sess2:
                #             if item.id in sess:
                #                 price = float(item.outfit_price)
                #                 discount = discount + price*0.35
                #                 count = count-1
                #                 count = count+1
                #         else:
                #             break

                if len(surplus) > 0:
                    for s in sess:
                        if s not in surplus:
                            sub.append(s)

                else:
                    for s in sess:
                        sub.append(s)

            else:
                count = 0
                for s in sess:
                    item = Outfit.get(Outfit.id == s).outfit_price
                    amount = amount + item
                    item = float(item)
                    # outfits.append(outfit)
                    if count > 0:
                        discount = discount + item * 0.33
                    count = count + 1
        else:
            count = 0
            for s in sess:
                item = Outfit.get(Outfit.id == s).outfit_price
                amount = amount + item
                item = float(item)
                # outfits.append(outfit)
                if count > 0:
                    discount = discount + item * 0.33
                count = count + 1

    if amount > 0:
        amount = float(amount)
        price = amount - discount

    if subscription:
        subscriptiontype = subscription.subscription_type
        subtype = int(subscriptiontype)
    else:
        subtype = 0
    return object_list('outfits/show.html',
                       outfits,
                       admin=admin,
                       authentic=authentic,
                       size=size,
                       price=price,
                       subtype=subtype,
                       out=out,
                       sub=sub,
                       subscription=subscription,
                       surplus=surplus,
                       discount=discount,
                       amount=amount,
                       sess=sess,
                       paginate_by=9)
Esempio n. 8
0
def detail(id):
    pictures = Outfit_Picture.select().where(Outfit_Picture.outfit == id)
    outfit = Outfit.select().where(Outfit.id == id)
    size = Size.select().where(Size.outfit == id)
    admin = False
    authentic = False
    if current_user.is_authenticated:
        authentic = True
        user = User.get_or_none(User.id == current_user.id)
        if user.Admin == True:
            admin = True
    out = Outfit.select()
    outfits_cart = Outfit.select().order_by(Outfit.outfit_price.desc())
    subscription = None
    amount = 0
    # outfits = []
    discount = 0
    # user = None
    surplus = []
    sub = []
    sess = []
    price = 0

    if 'cart' in session:
        sess = session['cart']
        if current_user.is_authenticated:
            # user= User.select().where(User.id == current_user.id)
            subscription = Subscription.get_or_none(
                Subscription.user == current_user.id)
            if subscription:

                sub_length = int(subscription.subscription_type)

                if len(sess) > sub_length:
                    sess2 = len(sess) - sub_length
                    count = 0
                    for item in outfits_cart:
                        if count < sess2:
                            if item.id in sess:
                                amount = amount + item.outfit_price
                                if item.id not in surplus:
                                    surplus.append(item.id)
                                count += 1
                        else:
                            break

                if len(sess) > (sub_length + 1):
                    sess2 = len(sess) - (sub_length + 1)
                    count = 0
                    for item in outfits_cart:
                        if count < sess2:
                            if item.id in sess:
                                price = float(item.outfit_price)
                                discount = discount + price * 0.35
                                count = count + 1
                        else:
                            break

                if len(surplus) > 0:
                    for s in sess:
                        if s not in surplus:
                            sub.append(s)

                else:
                    for s in sess:
                        sub.append(s)

            else:
                count = 0
                for s in sess:
                    item = Outfit.get(Outfit.id == s).outfit_price
                    amount = amount + item
                    item = float(item)
                    # outfits.append(outfit)
                    if count > 0:
                        discount = discount + item * 0.33
                    count = count + 1
        else:
            count = 0
            for s in sess:
                item = Outfit.get(Outfit.id == s).outfit_price
                amount = amount + item
                item = float(item)
                # outfits.append(outfit)
                if count > 0:
                    discount = discount + item * 0.33
                count = count + 1

    if amount > 0:
        amount = float(amount)
        price = amount - discount

    if subscription:
        subscriptiontype = subscription.subscription_type
        subtype = int(subscriptiontype)
    else:
        subtype = 0
    return render_template('outfits/detail.html',
                           size=size,
                           pictures=pictures,
                           outfit=outfit,
                           admin=admin,
                           authentic=authentic,
                           price=price,
                           subtype=subtype,
                           out=out,
                           sub=sub,
                           subscription=subscription,
                           surplus=surplus,
                           discount=discount,
                           amount=amount,
                           sess=sess)
Esempio n. 9
0
def new_checkout(subscription_id):
    subscription = Subscription.get_or_none(Subscription.id == subscription_id)
    client_token = gateway.client_token.generate()
    return render_template('transactions/new.html',client_token = client_token, subscription = subscription)