Beispiel #1
0
    def pay(self, payload):
        """Generate paystack payment link."""
        paystack_key = self.env["ir.config_parameter"].sudo().get_param(
            "paystack.key")
        # sk_test_6613ae6de9e50d198ba22637e6df1fecf3611610
        transaction = Transaction(authorization_key=paystack_key)
        partner_id = request.env.user.partner_id
        orders = (request.env["sale.order"].with_user(1).search(
            [
                ("partner_id", "=", partner_id.id),
                ("state", "=", "draft"),
                ("id", "in", payload.ids),
            ],
            limit=len(payload.ids),
        ))
        if not orders:
            resp = request.make_response(
                json.dumps({
                    "error":
                    "No other found for the given id(s) %s" % (payload.ids)
                }))
            resp.status_code = 401
            return resp

        total = sum([o.amount_total for o in orders]) * 100

        initialize = transaction.initialize(
            partner_id.email or request.env.user.company_id.email, total)
        return initialize
Beispiel #2
0
def payment():

    amount = request.form.get('amount')
    email = request.form.get('user-email')
    first_name = request.form.get('first-name')
    last_name = request.form.get('last-name')
    invoice = request.form.get('invoice')

    customer = Customer(
        authorization_key="sk_test_25a564e7f472ec8650770fb6d7d06fc2e7b57285")
    client = customer.create(first_name='first_name',
                             last_name='last_name',
                             email='email')
    init = Transaction.initialize(reference='invoice',
                                  amount='amount',
                                  email='email')
    json.dumps(init)

    charge = Transaction.charge(
        reference='invoice',
        authorization_code='sk_test_25a564e7f472ec8650770fb6d7d06fc2e7b57285',
        email='email',
        amount='amount')

    return render_template('customer/checkout.html',
                           charge=charge,
                           amount=amount,
                           email=email,
                           orders=orders,
                           init=init,
                           client=client,
                           first_name=first_name,
                           last_name=last_name,
                           invoice=invoice)
Beispiel #3
0
def main():
    """
    All Response objects are a tuple containing status_code, status, message and data
    """
    # print(dir(request))
    email = current_user.email

    paystack_secret = os.environ.get("paystack_live")
    bot_price = 25000 * 100
    #Instantiate the transaction object to handle transactions.
    #Pass in your authorization key - if not set as environment variable PAYSTACK_AUTHORIZATION_KEY
    # email = "*****@*****.**" "sk_test_faadf90960bad25e6a2b5c9be940792f928b73ac"
    transaction = Transaction(authorization_key=paystack_secret)
    transaction_table = Transaction_Table.query.filter_by(email=email).first()
    if transaction_table:
        response = transaction.charge(
            email, f"{transaction_table.auth_code}",
            int(transaction_table.amount))  #+rge a customer N100.
        print(response)
        reference = response[3].get('reference')
        transaction = Transaction_Table(ref_no=reference)
        db.session.add(transaction)
        db.session.commit()
        return redirect('/dashboard')
    else:
        init_transaction = transaction.initialize(email, bot_price)
        reference = init_transaction[3].get('reference')
        transaction = Transaction_Table(ref_no=reference)
        db.session.add(transaction)
        db.session.commit()
        return redirect(init_transaction[3].get('authorization_url'))
Beispiel #4
0
 def wallet_paymentlink(self, amount):
     """Get checkout payment link."""
     paystack_key = self.env["ir.config_parameter"].sudo().get_param(
         "paystack.key")
     transaction = Transaction(authorization_key=paystack_key)
     partner_id = request.env.user.partner_id
     initialize = transaction.initialize(
         partner_id.email or request.user.login, amount * 100)
     return initialize[3]
Beispiel #5
0
    def create(self, request, *args, **kwargs):
        user = request.user
        serializer = self.get_serializer(data=request.data)
        if serializer.is_valid():
            transaction = Transaction(
                authorization_key=settings.PAYSTACK_PUBLIC_KEY)
            amount = float(serializer.validated_data.get('amount')) * 100
            if user.paystack_authorization_code:
                response = transaction.charge(user.email,
                                              user.paystack_authorization_code,
                                              amount)
                print("with auth code\n", response)
            else:
                response = transaction.initialize(user.email, int(amount))
                url = response[3]['authorization_url']
            self.perform_create(serializer, response)
            data = serializer.data
            data['paystack_response'] = response[3]
            return Response(data=data, status=status.HTTP_201_CREATED)

        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)