コード例 #1
0
    def setUpClass(cls):
        with app.app_context():
            db.drop_all()
            db.create_all()

            cls.test_dao = EventDAO()

            cls.scheduling_user = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduling_user',
            )

            cls.scheduled_user = User(
                "*****@*****.**",
                "testpw",
                'US/Central',
                'scheduled_user',
            )

            db.session.add(cls.scheduling_user)
            db.session.add(cls.scheduled_user)

            db.session.commit()

            cls.scheduled_user = User.query.filter_by(
                public_id=cls.scheduled_user.public_id).first().public_id

            cls.scheduling_user = User.query.filter_by(
                public_id=cls.scheduling_user.public_id).first().public_id

            User.query.filter_by(public_id=cls.scheduled_user).update(
                {'sixty_min_price': 15})

            db.session.add(
                Submerchant(
                    cls.scheduled_user,
                    'testaccountid',
                    'firstName',
                    'LastName',
                    'email',
                    datetime.utcnow() + timedelta(days=-365 * 20),
                    'address_street',
                    'address_locality',
                    'address_region',
                    'address_zip',
                ))

            db.session.commit()

            new_schedule = Schedule(
                datetime.utcnow().replace(hour=0) + timedelta(days=1),
                datetime.utcnow().replace(hour=12) + timedelta(days=1),
                cls.scheduled_user, 'US/Central')

            db.session.add(new_schedule)
            db.session.commit()
コード例 #2
0
    def create_new_event(
        self,
        scheduling_user_id,
        scheduled_user_id,
        localized_start_time,
        localized_end_time,
        local_tz,
        notes,
        nonce,
        address_id=None,
    ):
        """
        Handles creation of a new event and payment processing.

        :param str scheduling_user_id: The user who is booking another's time
        :param str scheduled_user_id: Their time is being booked.
        :param datetime.datetime localized_start_time: Localized start
        :param datetime.datetime localized_end_time: The localized end
        :param str local_tz: The timezone which this was booked in.
        :param str notes: Any additional notes to add onto the event.
        :param str nonce: The nonce which determines the payment method
        being used.
        :param str address_id: An address to be used whenever billing. If not
        provided, then we attempt to find a default address.
        :rtype: EventTable
        :return: The newly created event.
        """
        if address_id is None:
            address = AddressDAO().get_default_for_user(scheduling_user_id)
        else:
            address = AddressDAO().get_by_public_id(address_id,
                                                    scheduling_user_id)

        try:
            new_event = EventDAO().create_new_event(scheduling_user_id,
                                                    scheduled_user_id,
                                                    localized_start_time,
                                                    localized_end_time,
                                                    local_tz,
                                                    notes,
                                                    skip_commit=True)

            BraintreePaymentFacade().issue_new_payment(new_event, nonce,
                                                       address)
        except IntegrationException as e:
            db.session.rollback()
            logging.error('Failed to create new transaction with exc of {0}.'
                          'Rolling back event creation for event {1}'.format(
                              e, new_event.public_id))
            raise FacadeException('Failed to finish sale.')
        except DAOException as e:
            raise e

        return new_event
コード例 #3
0
    def get(self, user_id):
        arg_fields = {
            'is_scheduling': Boolean(required=True),
            'time_period_offset': Int(missing=0)
        }
        args = parser.parse(arg_fields)

        if args['is_scheduling']:
            event_info = EventDAO().get_for_scheduling_user(
                user_id,
                args['time_period_offset']
            )
        else:
            event_info = EventDAO().get_for_scheduled_user(
                user_id,
                args['time_period_offset']
            )

        logging.info('Retrieved all events for user {0} as a {1}'.format(
            user_id,
            'scheduler.' if args['is_scheduling'] else 'scheduling user.'
        ))

        return jsonify({'events': EventMarshal(many=True).dump(event_info).data})
コード例 #4
0
    def get(self, user_id, event_id):
        event_info = EventDAO().get_by_event_id(user_id, event_id)

        logging.info('Retrieved event {0} for user {1}'.format(
            event_id,
            user_id
        ))

        scheduled = [x for x in event_info if x.public_id == event_info.EventTable.scheduled_user_id]
        scheduling = [x for x in event_info if x.public_id == event_info.EventTable.scheduling_user_id]

        return jsonify({
            'event': EventMarshal().dump(event_info.EventTable).data,
            'scheduled_user': UserSanitizedMarshal().dump(scheduled[0]).data,
            'scheduling_user': UserMarshal().dump(scheduling[0]).data,
        })
コード例 #5
0
    def post():
        arg_fields = {
            'scheduled_user_id': String(required=True),
            'localized_start_time': String(required=True),
            'localized_end_time': String(required=True),
            'local_tz': String(
                required=True,
                validate=validate.OneOf(pytz.all_timezones)
            ),
            'notes': String(
                required=False,
                validate=validate.Length(max=512),
                missing=None,
                default=None
            ),
            'is_paid': Boolean(default=True, missing=True),
            'nonce': String(
                required=False,
                default='',
                missing='',
            ),
            'address_id': String(
                required=False,
            )
        }
        args = parser.parse(arg_fields)
        args['scheduling_user_id'] = g.user_info['user_id']

        if args['is_paid']:
            if args.get('nonce') is None or args.get('nonce') == '':
                raise EndpointException(
                    'For paid scheduling, a payment nonce must be supplied.'
                )

            del args['is_paid']
            event_info = EventFacade().create_new_event(**args)
        else:
            if not current_app.config.get('TESTING'):
                logging.error(
                    'Attempted to create unpaid event in prod: {0}'.format(
                        args
                    )
                )
                raise EndpointException(
                    'Non-paid events are not allowed.'
                )

            del args['is_paid']
            del args['nonce']
            event_info = EventDAO().create_new_event(
                **args
            )

        logging.info(
            'Created event for user {0} with user {1} for time range: {2}->{3}'
            'at timezone {4}.',
            args['scheduling_user_id'],
            args['scheduling_user_id'],
            args['localized_start_time'],
            args['localized_end_time'],
            args['local_tz']
        )

        return jsonify(EventMarshal().dump(event_info).data)