def create(cls, params): """ Return whether or not the coupon was created successfully. :return: bool """ payment_params = params payment_params['code'] = payment_params['code'].upper() if payment_params.get('amount_off'): payment_params['amount_off'] = \ dollars_to_cents(payment_params['amount_off']) PaymentCoupon.create(**payment_params) if 'id' in payment_params: payment_params['code'] = payment_params['id'] del payment_params['id'] if 'redeem_by' in payment_params: if payment_params.get('redeem_by') is not None: params['redeem_by'] = payment_params.get('redeem_by').replace( tzinfo=pytz.UTC) coupon = Coupon(**payment_params) db.session.add(coupon) db.session.commit() return True
def create(cls, params): """ Create a coupon code and return true is successful """ payment_params = params payment_params['code'] = payment_params['code'].upper() if payment_params.get('amount_off'): payment_params['amount_off'] = dollars_to_cents( payment_params['amount_off']) PaymentCoupon.create(**payment_params) # Stripe will save the coupon to id field on stripe while on our database, we want it to save on code field if 'id' in payment_params: payment_params['code'] = payment_params['id'] del payment_params['id'] # Converting th eunix time to day stim stamp that is acceptable by the databse if 'redeem_by' in payment_params: if payment_params.get('redeem_by') is not None: params['redeem_by'] = payment_params.get('redeem_by').replace( datetime.datetime.utcnow) coupon = Coupon(**payment_params) db.session.add(coupon) db.session.commit() return True
def test_cents_dollars_to_cents(self): """ Dollars become cents. """ assert dollars_to_cents(2.33) == 233 assert dollars_to_cents(-4) == -400 assert dollars_to_cents(1) == 100 assert dollars_to_cents(-0) == 0