Exemplo n.º 1
0
def subscription_success(request):
    reference = request.matchdict['reference']
    sub = DBSession.query(Subscription).filter_by(reference=reference).first()
    if not sub:
        return HTTPNotFound()
    paystack_secret_key = buddy_settings("paystack_secret_key")
    paystack = Paystack(secret_key=paystack_secret_key)
    response = paystack.transaction.verify(reference)
    if response['status']:
        success = response['data']['status']
        if success:
            if not sub.status == u'Active':
                sub.status = u'Active'
            pass
        else:
            sub.status = u'Failed'
    return dict(sub=sub, title="Payment Successful")
Exemplo n.º 2
0
def confirm_payment(request, order_id):
    order = get_object_or_404(Order, id=order_id)
    cart = Cart(request)
    paystack = Paystack(secret_key=settings.PAYSTACK_SECRET_KEY)
    response = paystack.transaction.verify(reference=order.tx_ref)

    if response['data']['status'] == "success":
        if response['data']['amount'] == (cart.get_total_price() * 100):
            order.paid = True
            order.save()
            # clear the cart
            cart.clear()
            # launch asynchronous task
            order_created_mail(order.id, order.tx_ref)
            order_created.delay(order.id, order.tx_ref)
            return render(request, 'orders/order/done.html',
                          {'order': order})
    else:
        status = response['data']['status']
        gateway_response = response['data']['gateway_response']
        return render(request, "orders/order/failed.html",
                      {'status': status, "response": gateway_response})
Exemplo n.º 3
0
from paystackapi.paystack import Paystack
from paystackapi.transaction import Transaction
from paystackapi.tcontrol import TransferControl
from paystackapi.misc import Misc
from flask import *

app = Flask(__name__)
paystack_secret_key = "sk_test_b04fca7ba5fee795292b159e9fe527dcaf222c8b"
paystack = Paystack(secret_key=paystack_secret_key)


@app.route("/")
def index():
    return jsonify({
        "success":
        True,
        "message":
        "Hello World!",
        "docs":
        "https://github.com/LordGhostX/viddatech/blob/master/README.md"
    }), 200


@app.route("/new-transaction/", methods=["POST"])
def new_transaction():
    reference = request.form.get("reference")
    amount = request.form.get("amount")
    email = request.form.get("email")
    response = Transaction.initialize(reference=reference,
                                      amount=amount,
                                      email=email)
Exemplo n.º 4
0
def subscribe_plan(request):
    name = request.matchdict['name']
    type = request.matchdict['type']
    plan = DBSession.query(Plans).filter(Plans.name == name).first()
    title = plan.name + " Plan subscription"

    form = Form(request, schema=PaymentSchema)
    if 'submit' in request.POST and form.validate():
        duration = form.data['duration']
        amount = duration * plan.price_per_month
        discount_percent = "-"
        if 5 < duration < 12:
            # total amount to pay
            total = duration * plan.price_per_month
            # 5% discount since it is more than 5 and less than 12
            discount = total * 0.05
            # resultant amount to pay is now:
            amount = total - discount
            discount_percent = u"5%"
        elif duration == 12:
            # total amount to pay
            total = duration * plan.price_per_month
            # 10% discount since it is 12 months
            discount = total * 0.1
            # resultant amount to pay is now:
            amount = total - discount
            discount_percent = u"10%"
        paystack_secret_key = buddy_settings("paystack_secret_key")
        paystack = Paystack(secret_key=paystack_secret_key)
        #Renew
        if type == "Renew":
            # get active subscription
            # set it to Expired. set the expiration date to today
            # set new subscription expiration date to old active subscription expiration date + one month +2days
            active_sub = request.user.active_subscription[0]
            subscription = Subscription(user=request.user,
                                        plan=plan,
                                        amount=amount,
                                        no_of_months=duration,
                                        discount=discount_percent,
                                        start_date=datetime.today())
            DBSession.add(subscription)
            subscription.end_date = active_sub.end_date + timedelta(
                days=duration * 30 + 2)
            active_sub.status = u"Expired"
        else:
            subscription = Subscription(user=request.user,
                                        plan=plan,
                                        amount=amount,
                                        no_of_months=duration,
                                        discount=discount_percent,
                                        start_date=datetime.today(),
                                        end_date=datetime.today() +
                                        timedelta(days=duration * 30))
            DBSession.add(subscription)

        DBSession.flush()
        callback_url = request.route_url('subscription_success',
                                         reference=subscription.reference)
        try:
            response = paystack.transaction.initialize(
                email=request.user.email,
                callback_url=callback_url,
                amount=str(int(amount)) + "00",
                reference=subscription.reference)
        except requests.exceptions.ConnectionError:
            request.session.flash('info; Not enough Network')
            return HTTPFound(location=request.route_url('pricing'))
        if response['status']:
            authorization_url = response['data']['authorization_url']
            return Response(status_int=302, location=authorization_url)
    return dict(form=FormRenderer(form), title=title, plan=plan, type=type)
Exemplo n.º 5
0
from flask_fontawesome import FontAwesome
from flask_bcrypt import Bcrypt
from flask_migrate import Migrate
from flask_uploads import IMAGES, configure_uploads, patch_request_class, UploadSet
from flask_msearch import Search
from flask_login import LoginManager
import secrets
import os
from paystackapi.paystack import Paystack

basedir = os.path.abspath(os.path.dirname(__file__))

app = Flask(__name__)
fa = FontAwesome(app)
bcrypt = Bcrypt(app)
paystack = Paystack(app)
app.config[
    'SQLALCHEMY_DATABASE_URI'] = 'postgres://*****:*****@localhost/shop'
app.config['SQALCHEMY_TRACK_MODIFICATION'] = False
app.config['SECRET_KEY'] = 'SECRET_KEY'
Paystack_SECRET_KEY = 'sk_test_25a564e7f472ec8650770fb6d7d06fc2e7b57285'
Paystack_PUBLIC_KEY = 'pk_test_314dccd680068de3e230b7714972b3637607fbfb'

app.config['UPLOADED_PHOTOS_DEST'] = os.path.join(basedir, 'static/images')

photos = UploadSet('photos', IMAGES)
configure_uploads(app, photos)
patch_request_class(app)

db = SQLAlchemy(app)
search = Search()
Exemplo n.º 6
0
 def __init__(self, email, public_key, amount):
     self.paystack_conn = Paystack(secret_key=settings.PAYSTACK_SECRET_KEY)
     self.__email = email
     self.__public_key = public_key
     self.__amount = amount * 100