コード例 #1
0
ファイル: bitpay.py プロジェクト: k2h/Instanssi.org
def start_process(ta):
    """This should be used to start the bitpay payment process. Will redirect as necessary."""

    # Skip extra personal information because Bitpay doesn't require them
    data = {
        'price': str(ta.get_total_price()),
        'currency': 'EUR',
        'posData': str(ta.id),
        'fullNotifications': True,
        'notificationURL': get_url(reverse('store:pm:bitpay-notify')),
        'transactionSpeed': settings.BITPAY_SPEED,
        'notificationEmail': settings.BITPAY_EMAIL,
        'redirectURL': get_url(reverse('store:pm:bitpay-success')),
        'buyerName': ta.firstname + ' ' + ta.lastname,
        'buyerEmail': ta.email
    }

    # Make a request
    try:
        msg = bitpay.request(settings.BITPAY_KEY, data)
    except bitpay.BitpayException as ex:
        a, b = ex.args
        logger.exception('(%s) %s', b, a)
        return reverse('store:pm:bitpay-failure')
    except Exception as ex:
        logger.exception('%s.', ex)
        return reverse('store:pm:bitpay-failure')

    # Save token, redirect
    ta.token = msg['id']
    ta.payment_method_name = 'Bitpay'
    ta.save()

    # All done, redirect user
    return msg['url']
コード例 #2
0
ファイル: views.py プロジェクト: Instanssi/Instanssi.org
def json_event(request, event_id):
    _event = get_object_or_404(Event, pk=int(event_id), archived=True)

    # Get all compos that are active but not hidden from archive
    entries_out = []
    compos_out = []
    for c in Compo.objects.filter(event=_event, active=True, hide_from_archive=False):
        if c.show_voting_results:
            entries = entrysort.sort_by_score(Entry.objects.filter(compo=c))
        else:
            entries = Entry.objects.filter(compo=c).order_by("name")

        compos_out.append({"id": c.pk, "name": c.name, "entry_count": len(entries)})

        for e in entries:
            entries_out.append(
                {
                    "id": e.id,
                    "compo_name": c.name,
                    "compo_id": c.pk,
                    "entry_name": e.name,
                    "entry_author": e.creator,
                    "entry_score": round(e.get_score(), 2),
                    "entry_rank": e.get_rank(),
                    "entry_result_url": get_url(e.entryfile.url),
                    "entry_source_url": get_url(e.sourcefile.url) if e.sourcefile else None,
                    "entry_youtube_url": e.youtube_url if e.youtube_url else None,
                    "entry_image_thumbnail": get_url(e.imagefile_thumbnail.url) if e.imagefile_thumbnail else None,
                    "entry_image_medium": get_url(e.imagefile_medium.url) if e.imagefile_medium else None,
                    "entry_image_original": get_url(e.imagefile_original.url) if e.imagefile_original else None,
                }
            )

    return JsonResponse({"entries": entries_out, "compos": compos_out})
コード例 #3
0
def start_process(ta):
    """This should be used to start the bitpay payment process. Will redirect as necessary."""
    
    # Skip extra personal information because Bitpay doesn't require them
    data = {
        'price': str(ta.get_total_price()),
        'currency': 'EUR',
        'posData': str(ta.id),
        'fullNotifications': True, 
        'notificationURL': get_url(reverse('store:pm:bitpay-notify')),
        'transactionSpeed': settings.BITPAY_SPEED,
        'notificationEmail': settings.BITPAY_EMAIL,
        'redirectURL': get_url(reverse('store:pm:bitpay-success')),
        'buyerName': ta.firstname + ' ' + ta.lastname,
        'buyerEmail': ta.email
    }

    # Make a request
    try:
        msg = bitpay.request(settings.BITPAY_KEY, data)
    except bitpay.BitpayException as ex:
        a, b = ex.args
        logger.error('(%s) %s', b, a)
        return reverse('store:pm:bitpay-failure')
    except Exception as ex:
        logger.error('%s.', ex)
        return reverse('store:pm:bitpay-failure')

    # Save token, redirect
    ta.token = msg['id']
    ta.payment_method_name = 'Bitpay'
    ta.save()

    # All done, redirect user
    return msg['url']
コード例 #4
0
ファイル: views.py プロジェクト: k2h/Instanssi.org
def json_event(request, event_id):
    _event = get_object_or_404(Event, pk=int(event_id), archived=True)

    # Get all compos that are active but not hidden from archive
    entries_out = []
    compos_out = []
    for c in Compo.objects.filter(event=_event,
                                  active=True,
                                  hide_from_archive=False):
        if c.show_voting_results:
            entries = entrysort.sort_by_score(Entry.objects.filter(compo=c))
        else:
            entries = Entry.objects.filter(compo=c).order_by('name')

        compos_out.append({
            'id': c.pk,
            'name': c.name,
            'entry_count': len(entries)
        })

        for e in entries:
            entries_out.append({
                'id':
                e.id,
                'compo_name':
                c.name,
                'compo_id':
                c.pk,
                'entry_name':
                e.name,
                'entry_author':
                e.creator,
                'entry_score':
                round(e.get_score(), 2),
                'entry_rank':
                e.get_rank(),
                'entry_result_url':
                get_url(e.entryfile.url),
                'entry_source_url':
                get_url(e.sourcefile.url) if e.sourcefile else None,
                'entry_youtube_url':
                e.youtube_url if e.youtube_url else None,
                'entry_image_thumbnail':
                get_url(e.imagefile_thumbnail.url)
                if e.imagefile_thumbnail else None,
                'entry_image_medium':
                get_url(e.imagefile_medium.url)
                if e.imagefile_medium else None,
                'entry_image_original':
                get_url(e.imagefile_original.url)
                if e.imagefile_original else None
            })

    return JsonResponse({'entries': entries_out, 'compos': compos_out})
コード例 #5
0
ファイル: tests.py プロジェクト: Instanssi/Instanssi.org
 def test_receipt_params(self):
     """ Test receipt parameter handling logic """
     f = Faker("fi_FI")
     p = ReceiptParams()
     p.receipt_number(randint(10000, 99999))
     p.order_number(randint(10000, 99999))
     p.receipt_date(timezone.now())
     p.order_date(timezone.now())
     p.first_name(f.first_name())
     p.last_name(f.last_name())
     p.email(f.email())
     p.mobile(f.phone_number())
     p.telephone(f.phone_number())
     p.company(f.company())
     p.street(f.street_address())
     p.city(f.city())
     p.postal_code(f.postcode())
     p.country(f.country())
     p.transaction_url(get_url(reverse('store:ta_view', args=("1234abcd",))))
     for k in range(3):
         p.add_item(
             item_id=randint(0, 999999),
             price=Decimal(randint(0, 100)),
             name="Test product name goes here {}".format(k),
             amount=randint(1, 5),
             tax='0%'
         )
     n = ReceiptParams(p.get_json())
     self.assertDictEqual(p.params, n.params)
コード例 #6
0
ファイル: tests.py プロジェクト: mucla/Instanssi.org
 def test_receipt_params(self):
     """ Test receipt parameter handling logic """
     f = Faker("fi_FI")
     p = ReceiptParams()
     p.receipt_number(randint(10000, 99999))
     p.order_number(randint(10000, 99999))
     p.receipt_date(timezone.now())
     p.order_date(timezone.now())
     p.first_name(f.first_name())
     p.last_name(f.last_name())
     p.email(f.email())
     p.mobile(f.phone_number())
     p.telephone(f.phone_number())
     p.company(f.company())
     p.street(f.street_address())
     p.city(f.city())
     p.postal_code(f.postcode())
     p.country(f.country())
     p.transaction_url(
         get_url(reverse('store:ta_view', args=("1234abcd", ))))
     for k in range(3):
         p.add_item(item_id=randint(0, 999999),
                    price=Decimal(randint(0, 100)),
                    name="Test product name goes here {}".format(k),
                    amount=randint(1, 5),
                    tax='0%')
     n = ReceiptParams(p.get_json())
     self.assertDictEqual(p.params, n.params)
コード例 #7
0
ファイル: tests.py プロジェクト: Instanssi/Instanssi.org
    def test_create_receipt(self):
        """ Test receipt creation (to database) """
        f = Faker('fi_FI')
        subject = "Test email #{}".format(randint(10000, 99999))
        email_from = 'Instanssi.org <{}>'.format(f.email())
        email_to = f.email()
        p = ReceiptParams()
        p.order_number(randint(10000, 99999))
        p.receipt_date(timezone.now())
        p.order_date(timezone.now())
        p.first_name(f.first_name())
        p.last_name(f.last_name())
        p.email(email_to)
        p.mobile(f.phone_number())
        p.telephone(f.phone_number())
        p.company(f.company())
        p.street(f.street_address())
        p.city(f.city())
        p.postal_code(f.postcode())
        p.country(f.country())
        p.transaction_url(get_url(reverse('store:ta_view', args=("1234abcd",))))
        for k in range(3):
            p.add_item(
                item_id=randint(0, 999999),
                price=Decimal(randint(0, 100)),
                name="Test product name goes here {}".format(k),
                amount=randint(1, 5),
                tax='0%'
            )

        # Just make sure everything looks like it should in the database object
        r = Receipt.create(
            mail_to=email_to,
            mail_from=email_from,
            subject=subject,
            params=p)
        self.assertEquals(r.subject, subject)
        self.assertEquals(r.mail_from, email_from)
        self.assertEquals(r.mail_to, email_to)
        self.assertIsNotNone(r.content)
        self.assertIsNotNone(r.params)
        self.assertIsNone(r.sent)

        # Try to load from database, make sure everything matches
        n = ReceiptParams(r.params)
        self.assertDictEqual(p.params, n.params)

        # Send and make sure date is set
        r.send()
        self.assertIsNotNone(r.sent)
コード例 #8
0
    def test_create_receipt(self):
        """ Test receipt creation (to database) """
        f = Faker('fi_FI')
        subject = "Test email #{}".format(randint(10000, 99999))
        email_from = 'Instanssi.org <{}>'.format(f.email())
        email_to = f.email()
        p = ReceiptParams()
        p.order_number(randint(10000, 99999))
        p.receipt_date(timezone.now())
        p.order_date(timezone.now())
        p.first_name(f.first_name())
        p.last_name(f.last_name())
        p.email(email_to)
        p.mobile(f.phone_number())
        p.telephone(f.phone_number())
        p.company(f.company())
        p.street(f.street_address())
        p.city(f.city())
        p.postal_code(f.postcode())
        p.country(f.country())
        p.transaction_url(get_url(reverse('store:ta_view', args=("1234abcd",))))
        for k in range(3):
            p.add_item(
                item_id=randint(0, 999999),
                price=Decimal(randint(0, 100)),
                name="Test product name goes here {}".format(k),
                amount=randint(1, 5),
                tax='0%'
            )

        # Just make sure everything looks like it should in the database object
        r = Receipt.create(
            mail_to=email_to,
            mail_from=email_from,
            subject=subject,
            params=p)
        self.assertEquals(r.subject, subject)
        self.assertEquals(r.mail_from, email_from)
        self.assertEquals(r.mail_to, email_to)
        self.assertIsNotNone(r.content)
        self.assertIsNotNone(r.params)
        self.assertIsNone(r.sent)

        # Try to load from database, make sure everything matches
        n = ReceiptParams(r.params)
        self.assertDictEqual(p.params, n.params)

        # Send and make sure date is set
        r.send()
        self.assertIsNotNone(r.sent)
コード例 #9
0
ファイル: ta_common.py プロジェクト: k2h/Instanssi.org
def handle_payment(ta: StoreTransaction):
    # If not yet marked as pending, mark it now
    if not ta.time_pending:
        ta.time_pending = timezone.now()

    # Mark as paid right away, so failures later cannot change this
    ta.time_paid = timezone.now()
    ta.save()

    # Deliver email.
    params = ReceiptParams()
    params.order_number(ta.id)
    params.order_date(ta.time_created)
    params.receipt_date(ta.time_paid)
    params.first_name(ta.firstname)
    params.last_name(ta.lastname)
    params.email(ta.email)
    params.company(ta.company)
    params.mobile(ta.mobile)
    params.telephone(ta.telephone)
    params.street(ta.street)
    params.city(ta.city)
    params.postal_code(ta.postalcode)
    params.country(ta.country)
    params.transaction_url(get_url(reverse('store:ta_view', args=(ta.key, ))))

    # Add items to email
    for item, variant, purchase_price in ta.get_distinct_storeitems_and_prices(
    ):
        i_amount = ta.get_storeitem_count(item, variant=variant)
        i_name = '{}, {}'.format(item.name,
                                 variant.name) if variant else item.name
        i_id = '{}:{}'.format(item.id, variant.id) if variant else item.id
        params.add_item(i_id, i_name, purchase_price, i_amount, '0%')

    # Send mail
    try:
        receipt = Receipt.create(
            mail_to=ta.email,
            mail_from='"Instanssi" <*****@*****.**>',
            subject='Instanssi.org: Kuitti tilaukselle #{}'.format(ta.id),
            params=params)
        receipt.send()
    except Exception as ex:
        logger.exception('Store: {}.'.format(ex))
        return False

    logger.info('Store transaction {} confirmed.'.format(ta.id))
    return True
コード例 #10
0
ファイル: ta_common.py プロジェクト: Instanssi/Instanssi.org
def handle_payment(ta: StoreTransaction):
    # If not yet marked as pending, mark it now
    if not ta.time_pending:
        ta.time_pending = timezone.now()

    # Mark as paid right away, so failures later cannot change this
    ta.time_paid = timezone.now()
    ta.save()

    # Deliver email.
    params = ReceiptParams()
    params.order_number(ta.id)
    params.order_date(ta.time_created)
    params.receipt_date(ta.time_paid)
    params.first_name(ta.firstname)
    params.last_name(ta.lastname)
    params.email(ta.email)
    params.company(ta.company)
    params.mobile(ta.mobile)
    params.telephone(ta.telephone)
    params.street(ta.street)
    params.city(ta.city)
    params.postal_code(ta.postalcode)
    params.country(ta.country)
    params.transaction_url(get_url(reverse('store:ta_view', args=(ta.key,))))

    # Add items to email
    for item, variant, purchase_price in ta.get_distinct_storeitems_and_prices():
        i_amount = ta.get_storeitem_count(item, variant=variant)
        i_name = '{}, {}'.format(item.name, variant.name) if variant else item.name
        i_id = '{}:{}'.format(item.id, variant.id) if variant else item.id
        params.add_item(i_id, i_name, purchase_price, i_amount, '0%')

    # Send mail
    try:
        receipt = Receipt.create(
            mail_to=ta.email,
            mail_from='"Instanssi" <*****@*****.**>',
            subject='Instanssi.org: Kuitti tilaukselle #{}'.format(ta.id),
            params=params)
        receipt.send()
    except Exception as ex:
        logger.exception('Store: {}.'.format(ex))
        return False

    logger.info('Store transaction {} confirmed.'.format(ta.id))
    return True
コード例 #11
0
def handle_payment(ta):
    # Deliver email.
    mailer = ReceiptMailer('"Instanssi" <noreply@' + settings.DOMAIN + '>', ta.email, 'Instanssi.org kuitti')
    mailer.ordernumber(ta.id)
    mailer.firstname(ta.firstname)
    mailer.lastname(ta.lastname)
    mailer.email(ta.email)
    mailer.company(ta.company)
    mailer.mobile(ta.mobile)
    mailer.telephone(ta.telephone)
    mailer.street(ta.street)
    mailer.city(ta.city)
    mailer.postalcode(ta.postalcode)
    mailer.country(ta.country)

    # Add items to email
    for item, variant, purchase_price in ta.get_distinct_storeitems_and_prices():
        i_amount = ta.get_storeitem_count(item, variant=variant)
        i_name = '{}, {}'.format(item.name, variant.name) if variant else item.name
        i_id = '{}:{}'.format(item.id, variant.id) if variant else item.id
        mailer.add_item(i_id, i_name, purchase_price, i_amount)

    # Form transaction url
    transaction_url = get_url(reverse('store:ta_view', args=(ta.key,)))
    mailer.transactionurl(transaction_url)

    # Send mail
    try:
        mailer.send()
    except Exception as ex:
        logger.error('{}.'.format(ex))
        return False

    # Mark as paid
    ta.time_paid = datetime.now()
    ta.save()
    logger.info('Store transaction {} confirmed.'.format(ta.id))
    return True
コード例 #12
0
ファイル: models.py プロジェクト: Instanssi/Instanssi.org
 def qr_code(self):
     return get_url(reverse('store:ti_view', kwargs={'item_key': self.key}))
コード例 #13
0
ファイル: models.py プロジェクト: Instanssi/Instanssi.org
 def qr_code(self):
     return get_url(reverse('store:ta_view', kwargs={'transaction_key': self.key}))
コード例 #14
0
def start_process(ta):
    """This should be used to start the paytrail payment process.
    Will redirect as necessary."""

    product_list = []

    for store_item, item_variant, purchase_price in ta.get_distinct_storeitems_and_prices():
        count = ta.get_storeitem_count(store_item, variant=item_variant)
        product_list.append({
            'title': '{}, {}'.format(store_item.name, item_variant.name) if item_variant else store_item.name,
            'code': '{}:{}'.format(store_item.id, item_variant.id) if item_variant else str(store_item.id),
            'amount': str(count),
            'price': str(purchase_price),
            'vat': '0',
            'type': 1,
        })

    data = {
        'orderNumber': str(ta.id),
        'currency': 'EUR',
        'locale': 'fi_FI',
        'urlSet': {
            'success': get_url(reverse('store:pm:paytrail-success')),
            'failure': get_url(reverse('store:pm:paytrail-failure')),
            'notification': get_url(reverse('store:pm:paytrail-notify')),
            'pending': '',
        },
        'orderDetails': {
            'includeVat': 1,
            'contact': {
                'telephone': ta.telephone,
                'mobile': ta.mobile,
                'email': ta.email,
                'firstName': ta.firstname,
                'lastName': ta.lastname,
                'companyName': ta.company,
                'address': {
                    'street': ta.street,
                    'postalCode': ta.postalcode,
                    'postalOffice': ta.city,
                    'country': ta.country.code
                }
            },
            'products': product_list,
        },
    }

    # Make a request
    try:
        msg = paytrail.request(settings.VMAKSUT_ID, settings.VMAKSUT_SECRET, data)
    except paytrail.PaytrailException as ex:
        a, b = ex.args
        logger.exception('(%s) %s', b, a)
        return reverse('store:pm:paytrail-failure')
    except Exception as ex:
        logger.exception('%s.', ex)
        return reverse('store:pm:paytrail-failure')

    # Save token, redirect
    ta.token = msg['token']
    ta.payment_method_name = 'Paytrail'
    ta.save()

    # All done, redirect user
    return msg['url']
コード例 #15
0
ファイル: models.py プロジェクト: k2h/Instanssi.org
 def qr_code(self):
     return get_url(reverse('store:ti_view', kwargs={'item_key': self.key}))
コード例 #16
0
ファイル: models.py プロジェクト: k2h/Instanssi.org
 def qr_code(self):
     return get_url(
         reverse('store:ta_view', kwargs={'transaction_key': self.key}))