Пример #1
0
def payment(request, user=None, access_token=None):
    post_data = request.POST or json.loads(request.body)
    coupon_code = post_data.get("coupon_code")

    # TODO move to its own function or something
    if coupon_code:
        coupon = Coupon.get_by_code(coupon_code)
        if coupon.valid and coupon.stripe_plan_id is None:
            user.make_free_membership()
            return render_to_json({"access_token": access_token}, status=200)

    stripe_token = post_data['tokenId']
    stripe_email = post_data['tokenEmail']
    if user.stripe_customer_id is None:
        success, customer_id_or_message = create_subscription(stripe_token, stripe_email)
        if not success:
            return render_to_json({
                "error": customer_id_or_message
            }, status=400)

        user.update_stripe_customer_id(customer_id_or_message)
    else:
        change_credit_card(user)

    return render_to_json({"access_token": access_token}, status=200)
Пример #2
0
def coupon(request, coupon_code):
    return render_to_json(
        Coupon.get_by_code(coupon_code).to_json(),
        status=200)
Пример #3
0
import datetime

from workout_generator.coupon.models import Coupon

Coupon.create("GRANDFATHER550",
              datetime.datetime(year=2016, month=3, day=1, hour=0, minute=0),
              "Hey, alright!  Your membership is free, just finish the signup!",
              None)
'''
Coupon.create("GRANDFATHER500",
              datetime.datetime(year=2015, month=3, day=1, hour=0, minute=0),
              "Hey, alright!  Your membership is free, just finish the signup!",
              None)
Coupon.create("HACKERNEWS2015",
              datetime.datetime(year=2015, month=2, day=7, hour=0, minute=0),
              "Hey, I read Hacker News too!  Your membership is free, just finish the signup!",
              None)
Coupon.create("FACEBOOK_DJLTEVMKGDDVJKLF",
              datetime.datetime(year=2015, month=2, day=14, hour=0, minute=0),
              "Hey, alright!  Your membership is free, just finish the signup!",
              None)
'''