<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

import stripe
from django.conf import settings
from django.contrib.auth.models import User
from django.http import JsonResponse, HttpResponseBadRequest, HttpResponse
from django.shortcuts import get_object_or_404
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_GET, require_POST
from paypal.standard.ipn.models import PayPalIPN
from subscription.models import Subscription, handle_payment_was_successful

from common.services import AppRedirectionService

log = logging.getLogger("apps")


@require_GET
def stripe_config(request):
    return JsonResponse({'publicKey': settings.STRIPE_PUBLISHABLE_KEY}, safe=False)


@csrf_exempt
@require_POST
def create_checkout_session(request, user_pk, product):
    if not request.is_ajax():
        return HttpResponseBadRequest()

    stripe.api_key = settings.STRIPE_SECRET_KEY
    user = get_object_or_404(User, pk=user_pk)

    if product == 'lite':
        price = settings.STRIPE_PRICE_LITE
    elif product == 'premium':
        price = settings.STRIPE_PRICE_PREMIUM
    elif product == 'ultimate':
        price = settings.STRIPE_PRICE_ULTIMATE
    else:
        return HttpResponseBadRequest()

    log.info("create_checkout_session: %d, %s, %s" % (user.pk, product, price))

    try:
        customer_result = stripe.Customer.list(email=user.email, limit=1)
        customer = None
        if len(customer_result['data']) == 1:
            customer = customer_result['data'][0]['id']

        checkout_session = stripe.checkout.Session.create(
            success_url=AppRedirectionService.redirect(
                request,
                '/subscriptions/success?product=' + product + '&session_id={CHECKOUT_SESSION_ID}'),
            cancel_url=AppRedirectionService.redirect(request, '/subscriptions/cancelled/'),
            mode='payment',
            payment_method_types=['card'],
            client_reference_id=user.pk,<commit_msg>(payments) Remove ajax check<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

import stripe
from django.conf import settings
from django.contrib.auth.models import User
from django.http import JsonResponse, HttpResponseBadRequest, HttpResponse
from django.shortcuts import get_object_or_404
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_GET, require_POST
from paypal.standard.ipn.models import PayPalIPN
from subscription.models import Subscription, handle_payment_was_successful

from common.services import AppRedirectionService

log = logging.getLogger("apps")


@require_GET
def stripe_config(request):
    return JsonResponse({'publicKey': settings.STRIPE_PUBLISHABLE_KEY}, safe=False)


@csrf_exempt
@require_POST
def create_checkout_session(request, user_pk, product):
    stripe.api_key = settings.STRIPE_SECRET_KEY
    user = get_object_or_404(User, pk=user_pk)

    if product == 'lite':
        price = settings.STRIPE_PRICE_LITE
    elif product == 'premium':
        price = settings.STRIPE_PRICE_PREMIUM
    elif product == 'ultimate':
        price = settings.STRIPE_PRICE_ULTIMATE
    else:
        return HttpResponseBadRequest()

    log.info("create_checkout_session: %d, %s, %s" % (user.pk, product, price))

    try:
        customer_result = stripe.Customer.list(email=user.email, limit=1)
        customer = None
        if len(customer_result['data']) == 1:
            customer = customer_result['data'][0]['id']

        checkout_session = stripe.checkout.Session.create(
            success_url=AppRedirectionService.redirect(
                request,
                '/subscriptions/success?product=' + product + '&session_id={CHECKOUT_SESSION_ID}'),
            cancel_url=AppRedirectionService.redirect(request, '/subscriptions/cancelled/'),
            mode='payment',
            payment_method_types=['card'],
            client_reference_id=user.pk,
{'fraction_non_alphanumeric': 0.0959244532803181, 'fraction_numerical': 0.004970178926441352, 'mean_word_length': 3.9145299145299144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4128056', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1159, 'n_words': 245}