def purchases_charge(self, session, id, amount, receipt_id): receipt = session.art_show_receipt(receipt_id) attendee = session.attendee(id) charge = Charge( attendee, amount=amount, description='{}ayment for {}\'s art show purchases'.format( 'P' if int(amount) == receipt.total else 'Partial p', attendee.full_name)) stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: session.add( ArtShowPayment( receipt=receipt, amount=charge.amount, type=c.STRIPE, )) session.commit() return { 'stripe_intent': stripe_intent, 'success_url': 'pieces_bought?id={}&message={}'.format( attendee.id, 'Charge successfully processed') }
def arbitrary_charge(self, session, id, amount, description, email, return_to='arbitrary_charge_form'): charge = Charge(amount=100 * int(amount), description=description, receipt_email=email) stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: session.add( ArbitraryCharge( amount=charge.dollar_amount, what=charge.description, reg_station=cherrypy.session.get('reg_station'))) return { 'stripe_intent': stripe_intent, 'success_url': '{}?message={}'.format(return_to, 'Charge successfully processed'), 'cancel_url': 'cancel_arbitrary_charge' }
def process_art_show_payment(self, session, id): attendee = session.attendee(id) charge = Charge(attendee, description="Art show application payment") stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: for app in attendee.art_show_applications: app.status = c.PAID # This needs to accommodate payment cancellations send_email.delay( c.ADMIN_EMAIL, c.ART_SHOW_EMAIL, 'Art Show Payment Received', render('emails/art_show/payment_notification.txt', {'app': app}, encoding=None), model=app.to_dict('id')) send_email.delay( c.ART_SHOW_EMAIL, app.email, 'Art Show Payment Received', render('emails/art_show/payment_confirmation.txt', {'app': app}, encoding=None), model=app.to_dict('id')) if attendee.paid == c.NOT_PAID: attendee.paid = c.HAS_PAID session.add(session.create_receipt_item(attendee, charge.amount, "Art show payment", charge.stripe_transaction)) session.add(attendee) session.commit() return {'stripe_intent': stripe_intent, 'success_url': 'edit?id={}&message={}'.format(attendee.art_show_applications[0].id, 'Your payment has been accepted')}
def take_payment(self, session, id): attendee = session.attendee(id) charge = Charge(attendee, amount=attendee.amount_unpaid * 100) stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: db_attendee = session.query(Attendee).filter_by( id=attendee.id).first() if db_attendee: attendee = db_attendee session.add( session.create_receipt_item(attendee, charge.amount, "At-door kiosk payment", charge.stripe_transaction)) session.add(attendee) session.commit() return { 'stripe_intent': stripe_intent, 'success_url': 'register?message={}'.format(c.AT_DOOR_PREPAID_MSG) }
def process_marketplace_payment(self, session, id): attendee = session.attendee(id) charge = Charge( attendee, description="Marketplace application payment for {}".format( attendee.full_name)) stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: if attendee.marketplace_cost: for app in attendee.marketplace_applications: cancel_amt = app.amount_unpaid app.amount_paid += app.amount_unpaid send_email.delay( c.ADMIN_EMAIL, c.MARKETPLACE_APP_EMAIL, 'Marketplace Payment Received', render('emails/marketplace/payment_notification.txt', {'app': app}, encoding=None), model=app.to_dict('id')) send_email.delay( c.MARKETPLACE_APP_EMAIL, app.email_to_address, 'Marketplace Payment Received', render('emails/marketplace/payment_confirmation.txt', {'app': app}, encoding=None), model=app.to_dict('id')) if attendee.paid == c.NOT_PAID: attendee.paid = c.HAS_PAID session.add( session.create_receipt_item(attendee, charge.amount, "Marketplace payment", charge.stripe_transaction)) session.add(attendee) session.commit() return { 'stripe_intent': stripe_intent, 'success_url': 'edit?id={}&message={}'.format( attendee.marketplace_applications[0].id, 'Your payment has been accepted'), 'cancel_url': '../preregistration/cancel_payment?model_id={}&cancel_amt={}'. format(attendee.marketplace_applications[0].id, cancel_amt) }
def manual_reg_charge(self, session, id): attendee = session.attendee(id) charge = Charge(attendee, amount=attendee.amount_unpaid * 100) stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: attendee.payment_method = c.MANUAL session.add( session.create_receipt_item(attendee, charge.amount, "At-door desk payment", charge.stripe_transaction)) session.merge(attendee) session.commit() return {'stripe_intent': stripe_intent, 'success_url': ''}
def sales_charge(self, session, id, amount, description): charge = Charge(amount=100 * float(amount), description=description) stripe_intent = charge.create_stripe_intent(session) message = stripe_intent if isinstance(stripe_intent, string_types) else '' if message: return {'error': message} else: session.add( ArbitraryCharge( amount=charge.dollar_amount, what=charge.description, )) return { 'stripe_intent': stripe_intent, 'success_url': 'sales_charge_form?message={}'.format( 'Charge successfully processed'), 'cancel_url': '../merch_admin/cancel_arbitrary_charge' }