def create(**kwargs): manager = ListingManager(request) forms = kwargs.pop("forms") listing_form = find_form(forms, ListingForm) guest_listing_form = find_form(forms, GuestListingForm) bank_account_form = find_form(forms, BankAccountForm) if request.user.is_authenticated: form = listing_form else: form = guest_listing_form session["email"] = form.email.data if not form.validate(): return index(**kwargs) try: listing_id = manager.create(form, bank_account_form) except balanced.exc.HTTPError as ex: if ex.status_code == 300: # we've created the user locally, persist this information Session.commit() return redirect( url_for( "redirect.show", listing=form.listing_id.data, redirect_uri=ex.response.headers["location"], email=session.get("email"), ) ) elif ex.status_code == 400: if "merchant.postal_code" in ex.description: form["postal_code"].errors.append(ex.description) return index(**kwargs) elif "merchant.phone" in ex.description: form["phone"].errors.append(ex.description) return index(**kwargs) raise except Exception as ex: if ex.message == "Password mismatch": flash( "Sorry, this email address is already assigned to an " "account and your password does not match, please try " "again.", "error", ) return self.index(**kwargs) raise Session.commit() return redirect(url_for("listing.complete", listing=listing_id))
def create(**kwargs): manager = ListingManager(request) forms = kwargs.pop('forms') listing_form = find_form(forms, ListingForm) guest_listing_form = find_form(forms, GuestListingForm) bank_account_form = find_form(forms, BankAccountForm) if request.user.is_authenticated: form = listing_form else: form = guest_listing_form session['email_address'] = form.email_address.data if not form.validate(): return index(**kwargs) try: listing_id = manager.create(form, bank_account_form) except balanced.exc.HTTPError as ex: if ex.status_code == 300: # we've created the user locally, persist this information Session.commit() return redirect( url_for('redirect.show', listing=form.listing_id.data, redirect_uri=ex.response.headers['location'], email_address=session.get('email_address'))) elif ex.status_code == 400: if 'merchant.postal_code' in ex.description: form['postal_code'].errors.append(ex.description) return index(**kwargs) elif 'merchant.phone_number' in ex.description: form['phone_number'].errors.append(ex.description) return index(**kwargs) raise except Exception as ex: if ex.message == 'Password mismatch': flash( 'Sorry, this email address is already assigned to an ' 'account and your password does not match, please try ' 'again.', 'error') return self.index(**kwargs) raise Session.commit() return redirect(url_for('listing.complete', listing=listing_id))
def create(**kwargs): manager = ListingManager(request) forms = kwargs.pop('forms') listing_form = find_form(forms, ListingForm) guest_listing_form = find_form(forms, GuestListingForm) bank_account_form = find_form(forms, BankAccountForm) if request.user.is_authenticated: form = listing_form else: form = guest_listing_form session['email_address'] = form.email_address.data if not form.validate(): return index(**kwargs) try: listing_id = manager.create(form, bank_account_form) except balanced.exc.HTTPError as ex: if ex.status_code == 300: # we've created the user locally, persist this information Session.commit() return redirect(url_for('redirect.show', listing=form.listing_id.data, redirect_uri=ex.response.headers['location'], email_address=session.get('email_address'))) elif ex.status_code == 400: if 'merchant.postal_code' in ex.description: form['postal_code'].errors.append(ex.description) return index(**kwargs) elif 'merchant.phone_number' in ex.description: form['phone_number'].errors.append(ex.description) return index(**kwargs) raise except Exception as ex: if ex.message == 'Password mismatch': flash('Sorry, this email address is already assigned to an ' 'account and your password does not match, please try ' 'again.', 'error') return self.index(**kwargs) raise Session.commit() return redirect(url_for('listing.complete', listing=listing_id))
def update(listing, **kwargs): manager = RentalManager(request) forms = kwargs.pop('forms') purchase_form = find_form(forms, PurchaseForm) guest_purchase_form = find_form(forms, GuestPurchaseForm) card_href = request.form.get('card_href', None) name = None if request.user.is_authenticated: email_address = request.user.email else: email_address = guest_purchase_form.email.data name = guest_purchase_form.name.data try: rental = manager.rent(listing, email_address, card_href, name) except balanced.exc.HTTPError as ex: msg = 'Error debiting account, your card has not been charged "{}"' flash(msg.format(ex.message), 'error') Session.rollback() except Exception as ex: if ex.message == 'No card on file': return show(listing, purchase_form, guest_purchase_form, True) raise else: Session.commit() email.send_email(rental.buyer.email, 'Rental Receipt', 'receipt.mako', name=rental.buyer.email, listing=listing, charge=balanced.Order.fetch(rental.order_href)) session['rental_user_guid'] = rental.buyer.guid session['rental_email'] = rental.buyer.email return redirect( url_for('rent.confirmed', listing=listing, rental=rental)) return show(listing, purchase_form, guest_purchase_form)
def update(listing, **kwargs): manager = RentalManager(request) forms = kwargs.pop('forms') purchase_form = find_form(forms, PurchaseForm) guest_purchase_form = find_form(forms, GuestPurchaseForm) card_uri = request.form.get('card_uri', None) name = None if request.user.is_authenticated: email_address = request.user.email_address else: email_address = guest_purchase_form.email_address.data name = guest_purchase_form.name.data try: rental = manager.rent(listing, email_address, card_uri, name) except balanced.exc.HTTPError as ex: msg = 'Error debiting account, your card has not been charged "{}"' flash(msg.format(ex.message), 'error') Session.rollback() except Exception as ex: if ex.message == 'No card on file': return show(listing, purchase_form, guest_purchase_form, True) raise else: Session.commit() email.send_email(rental.buyer.email_address, 'Rental Receipt', 'receipt.mako', name=rental.buyer.email_address, listing=listing, charge=balanced.Transaction.find(rental.debit_uri) ) session['rental_user_guid'] = rental.buyer.guid session['rental_email_address'] = rental.buyer.email_address return redirect(url_for('rent.confirmed', listing=listing, rental=rental)) return show(listing, purchase_form, guest_purchase_form)