<commit_before>import datetime
from decimal import Decimal
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
import hashlib
import logging
import urllib
import urllib2
from django.utils.timezone import utc
from django.utils.translation import ugettext_lazy as _
import time
from getpaid import signals
from getpaid.backends import PaymentProcessorBase

logger = logging.getLogger('getpaid.backends.paypal')


class paypalTransactionStatus:
    ST_PP_ACTIVE = 'Active'
    ST_PP_CANCELLED = 'Cancelled'
    ST_PP_CLEARED = 'Cleared'
    ST_PP_COMPLETED = 'Completed'
    ST_PP_DENIED = 'Denied'
    ST_PP_PAID = 'Paid'
    ST_PP_PENDING = 'Pending'
    ST_PP_PROCESSED = 'Processed'
    ST_PP_REFUSED = 'Refused'
    ST_PP_REVERSED = 'Reversed'
    ST_PP_REWARDED = 'Rewarded'
    ST_PP_UNCLAIMED = 'Unclaimed'
    ST_PP_UNCLEARED = 'Uncleared'

class PaymentProcessor(PaymentProcessorBase):
    BACKEND = 'getpaid.backends.paypal'
    BACKEND_NAME = _('paypal')
    BACKEND_ACCEPTED_CURRENCY = ('PLN','USD','EUR', 'GPB' )
    BACKEND_LOGO_URL = 'getpaid/backends/paypal/paypal_logo.png'
    # API Endpoints.
    POSTBACK_ENDPOINT = "https://www.paypal.com/cgi-bin/webscr"
    SANDBOX_POSTBACK_ENDPOINT = "https://www.sandbox.paypal.com/cgi-bin/webscr"

    @staticmethod
    def online(ipn_obj, flag, form, secure):

        if flag is not None:
            ipn_obj.set_flag(flag)
        else:
            # Secrets should only be used over SSL.
            if secure:
                ipn_obj.verify_secret(form, secure)
            else:
                ipn_obj.verify(receiver_email=PaymentProcessor.get_backend_setting('business'))

        #if verification ended in error, return it:
        if ipn_obj.flag:
            return ipn_obj.flag_info

        payment = ipn_obj.payment
        payment.external_id = ipn_obj.txn_id
        payment.description = ipn_obj.item_name

        if ipn_obj.payment_status == paypalTransactionStatus.ST_PP_COMPLETED:
            payment.amount_paid = Decimal(ipn_obj.mc_gross)
            payment.paid_on = datetime.datetime.utcnow().replace(tzinfo=utc)<commit_msg>Paypal Payment Channel commit 7: in verification check for corret email in respect to test setting<commit_after>import datetime
from decimal import Decimal
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
import hashlib
import logging
import urllib
import urllib2
from django.utils.timezone import utc
from django.utils.translation import ugettext_lazy as _
import time
from getpaid import signals
from getpaid.backends import PaymentProcessorBase

logger = logging.getLogger('getpaid.backends.paypal')


class paypalTransactionStatus:
    ST_PP_ACTIVE = 'Active'
    ST_PP_CANCELLED = 'Cancelled'
    ST_PP_CLEARED = 'Cleared'
    ST_PP_COMPLETED = 'Completed'
    ST_PP_DENIED = 'Denied'
    ST_PP_PAID = 'Paid'
    ST_PP_PENDING = 'Pending'
    ST_PP_PROCESSED = 'Processed'
    ST_PP_REFUSED = 'Refused'
    ST_PP_REVERSED = 'Reversed'
    ST_PP_REWARDED = 'Rewarded'
    ST_PP_UNCLAIMED = 'Unclaimed'
    ST_PP_UNCLEARED = 'Uncleared'

class PaymentProcessor(PaymentProcessorBase):
    BACKEND = 'getpaid.backends.paypal'
    BACKEND_NAME = _('paypal')
    BACKEND_ACCEPTED_CURRENCY = ('PLN','USD','EUR', 'GPB' )
    BACKEND_LOGO_URL = 'getpaid/backends/paypal/paypal_logo.png'
    # API Endpoints.
    POSTBACK_ENDPOINT = "https://www.paypal.com/cgi-bin/webscr"
    SANDBOX_POSTBACK_ENDPOINT = "https://www.sandbox.paypal.com/cgi-bin/webscr"

    @staticmethod
    def online(ipn_obj, flag, form, secure):

        if flag is not None:
            ipn_obj.set_flag(flag)
        else:
            # Secrets should only be used over SSL.
            if secure:
                ipn_obj.verify_secret(form, secure)
            else:
                business = PaymentProcessor.get_backend_setting('business') if not PaymentProcessor.get_backend_setting('test') \
                       else PaymentProcessor.get_backend_setting('test_business')
                ipn_obj.verify(receiver_email=business)

        #if verification ended in error, return it:
        if ipn_obj.flag:
            return ipn_obj.flag_info

        payment = ipn_obj.payment
        payment.external_id = ipn_obj.txn_id
        payment.description = ipn_obj.item_name

        if ipn_obj.payment_status == paypalTransactionStatus.ST_PP_COMPLETED:
            payment.amount_paid = Decimal(ipn_obj.mc_gross)
            payment.paid_on = datetime.datetime.utcnow().replace(tzinfo=utc)
{'fraction_non_alphanumeric': 0.0833150142888547, 'fraction_numerical': 0.0006594856012310398, 'mean_word_length': 3.272300469483568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '5306497', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1491, 'n_words': 297}