def process_acceptance(user_id): """Change status of transaction depending on seller acceptance""" acceptance = request.form.get("agree_or_disagree") transaction_id = session["transaction"] current_transaction = Transaction.fetch(transaction_id) seller_user = User.fetch(user_id) payer_user = User.fetch(current_transaction.payer_id) if acceptance == "agree": current_transaction.status = "awaiting payment from payer" html = "<html><h2>Good Cheddar</h2><br><p>Hi " + payer_user.fullname \ + ",</p><br>" + seller_user.fullname + " has approved your contract." \ + "Please<a href='http://*****:*****@hotmail.com", "to": '*****@*****.**', "subject": "Contract approved!", "html": html }) else: Transaction.new_status(transaction_id, "declined by seller") db.session.commit() # At this stage an email is sent to the buyer with prompt to pay. return redirect("/dashboard")
def payment_process(transaction_id): token = request.form.get("stripeToken") transfer = Transaction.fetch(transaction_id) payer_id = transfer.payer_id seller_id = transfer.seller_id seller_email = transfer.seller.email amount = transfer.amount * 100 currency = transfer.currency date = transfer.date description = "payment from %d to %d" % (payer_id, seller_id) # Any way to check if this payment causes error? charge = create_charge(amount, token, description) if charge.to_dict()['paid'] is not True: flash("Your payment has not gone through. Please try again.") else: Transaction.new_status(transaction_id, "payment from payer received") # As soon as payment is successfull, stripe account set up for seller. try: new_account = create_seller_account(currency, seller_email) account_id = new_account.to_dict()['id'] s_key = new_account.to_dict()['keys']['secret'] # Add account_id and s_key to database User.fetch(seller_id).account_id = account_id User.fetch(seller_id).secret_key = s_key db.session.commit() #Send prompt email to seller for him to put in account details. html = "<html><h2>Good Cheddar</h2><br><p>Hi " + transfer.seller.fullname \ + ",</p><br>" + transfer.payer.fullname + " has transfered the \ agreed amount of funds to Good Cheddar. \ <br> To get paid on the scheduled date, please log in to your \ Good Cheddar account and enter your account details.\ <br><br> From the Good Cheddar team!</html>" # for test purposes, the same seller email will be used. when live, use '"to": seller_email' requests.post( "https://api.mailgun.net/v3/sandbox9ba71cb39eb046f798ee4676ad972946.mailgun.org/messages", auth=('api', mailgun_key), data={ "from": "*****@*****.**", "to": seller_email, "subject": "Log in to Good Cheddar", "html": html }) except stripe.InvalidRequestError as e: flash(e.message) # send email to seller telling them to put their details in stripe print("***the token is", token) return redirect("/dashboard")
def show_approved_form(transaction_id): transaction = Transaction.fetch(transaction_id) user_id = session["user_id"] payer_seller = session["payer_seller"] session["transaction"] = transaction_id return render_template('approved-contract.html', transaction=transaction, user_id=user_id, payer_seller=payer_seller)
def account_process(transaction_id): name = request.form.get("name") routing_number = request.form.get("routing-number") account_number = request.form.get("account-number") response = create_seller_token(name, routing_number, account_number) user_id = session['user_id'] user = User.fetch(user_id) seller_email = user.email s_key = user.secret_key account_token = response.to_dict()['id'] amount = Transaction.fetch(transaction_id).amount currency = Transaction.fetch(transaction_id).currency account_id = user.account_id create_customer(seller_email, s_key) Transaction.new_status(transaction_id, "payment to seller scheduled") return redirect("/dashboard")