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):
        """
        Return whether or not the coupon was created successfully.

        :return: bool
        """
        payment_params = params

        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):
        """
        Return whether or not the coupon was created successfully.

        :return: bool
        """
        payment_params = params

        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']

        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