Example #1
0
def run_demo(merchantid, merchantkey, amount, issuerid=None, testmode=True):
    api = SisowAPI(merchantid, merchantkey, testmode)
    
    if issuerid is None:
        # Pick random bank from API
        bank = random.choice(tuple(api.providers))
    else:
        for bank in api.providers:
            if bank['id'] == issuerid:
                break
    print "Picked %(name)s (%(id)s)" % bank
    entrance = datetime.now().strftime("E%Y%m%dT%H%M")
    
    # Build transaction
    t = Transaction(entrance, amount, bank['id'], entrance, 'Some demo product')
    
    #Send transaction
    urls = WebshopURLs('https://github.com/nederhoed/python-sisow/')
    response = api.start_transaction(t, urls)
    if not response.is_valid(merchantid, merchantkey):
        raise ValueError('Invalid SHA1')
    
    # Browser part
    url_ideal = urllib.url2pathname(response.issuerurl)
    print url_ideal
    webbrowser.open(url_ideal)
    
    while True:
        status = api.get_transaction_status(response.trxid)
        if not status.is_valid(merchantid, merchantkey):
            raise ValueError('Invalid SHA1')
        print datetime.now().strftime('%H:%M:%S'), status.status
        if status.status != 'Open':
            break
        time.sleep(5)
Example #2
0
    def start_payment(self, request, *args, **kwargs):
        provider_id = request.POST.get('provider_id')
        if not provider_id:
            raise ValueError('No provider_id')
        cart = Cart(request)

        name = request.POST.get('name')
        organisation = request.POST.get('organisation')

        # Check if order already exist for this cart
        try:
            order = Order.objects.get(cart=cart.cart)
        except ObjectDoesNotExist:
            order = Order(
                order_nr=uuid.uuid4(),
                cart=cart.cart,
                amount='2293',  #todo
                billing_name=name,
                billing_company=organisation,
                paid_date=datetime.datetime.now())
            order.save()

        (merchantid, merchantkey) = _account_from_file('account-sisow.secret')
        api = SisowAPI(merchantid, merchantkey, testmode=True)

        total_without_vat = 0
        for item in order.cart.item_set.all():
            total_without_vat += item.total_price
        total_with_vat = int(total_without_vat * decimal.Decimal(1.21)) * 100

        # Build transaction
        entrance = datetime.datetime.now().strftime("E%Y%m%dT%H%M")
        if settings.FUNDER_SHOW_VAT:
            t = Transaction(entrance, total_with_vat, '06', entrance,
                            'Funder donation')
        else:
            t = Transaction(entrance,
                            int(total_without_vat) * 100, '06', entrance,
                            'Funder donation')
        # Send transaction
        # Todo: create something with a setting:
        urls = WebshopURLs(
            'https://funder.formatics.nl/order/thanks/?order_nr={}'.format(
                order.order_nr))
        #urls = WebshopURLs('http://0.0.0.0:8000/order/thanks/?order_nr={}'.format(order.order_nr))
        response = api.start_transaction(t, urls)
        if not response.is_valid(merchantid, merchantkey):
            raise ValueError('Invalid SHA1')
        url_ideal = urllib.url2pathname(response.issuerurl)
        return TemplateResponse(
            request, 'fundraiser/start_payment.html', {
                "order": order,
                "total_without_vat": total_without_vat,
                "total_with_vat": total_with_vat,
                "provider_id": provider_id,
                "url_ideal": url_ideal,
                "show_vat": settings.FUNDER_SHOW_VAT,
                "vat_percentage": settings.FUNDER_VAT_PERCENTAGE,
            })
Example #3
0
    def start_payment(self, request, *args, **kwargs):
        provider_id = request.POST.get('provider_id')
        if not provider_id:
            raise ValueError('No provider_id')
        cart = Cart(request)

        name = request.POST.get('name')
        organisation = request.POST.get('organisation')

        # Check if order already exist for this cart
        try:
            order = Order.objects.get(cart=cart.cart)
        except ObjectDoesNotExist:
            order = Order(order_nr=uuid.uuid4(), cart=cart.cart, amount='2293', #todo
                          billing_name=name, billing_company=organisation, paid_date=datetime.datetime.now())
            order.save()

        (merchantid, merchantkey) = _account_from_file('account-sisow.secret')
        api = SisowAPI(merchantid, merchantkey, testmode=True)

        total_without_vat = 0
        for item in order.cart.item_set.all():
            total_without_vat += item.total_price
        total_with_vat = int(total_without_vat* decimal.Decimal(1.21))*100

        # Build transaction
        entrance = datetime.datetime.now().strftime("E%Y%m%dT%H%M")
        if settings.FUNDER_SHOW_VAT:
            t = Transaction(entrance, total_with_vat, '06', entrance, 'Funder donation')
        else:
            t = Transaction(entrance, int(total_without_vat)*100, '06', entrance, 'Funder donation')
        # Send transaction
        # Todo: create something with a setting:
        urls = WebshopURLs('https://funder.formatics.nl/order/thanks/?order_nr={}'.format(order.order_nr))
        #urls = WebshopURLs('http://0.0.0.0:8000/order/thanks/?order_nr={}'.format(order.order_nr))
        response = api.start_transaction(t, urls)
        if not response.is_valid(merchantid, merchantkey):
            raise ValueError('Invalid SHA1')
        url_ideal = urllib.url2pathname(response.issuerurl)
        return TemplateResponse(
          request,
           'fundraiser/start_payment.html',
            {
                "order": order,
                "total_without_vat": total_without_vat,
                "total_with_vat": total_with_vat,
                "provider_id": provider_id,
                "url_ideal": url_ideal,
                "show_vat": settings.FUNDER_SHOW_VAT,
                "vat_percentage": settings.FUNDER_VAT_PERCENTAGE,
            }
        )
Example #4
0
def formulier():
    testmode = False
    api = SisowAPI(settings.sisow_merchant_id, settings.sisow_merchant_key,
                   testmode)

    title = 'Sisow iDEAL payment module'
    message = 'U gaat nu een fake betaling doen. Vul daarvoor onderstaande gegevens in!'
    submit = False
    form = SQLFORM.factory(
        Field('description',
              'string',
              label='Omschrijving aankoop',
              default='Web2py T-shirt (XL)',
              requires=IS_NOT_EMPTY()),
        Field('amount',
              'integer',
              label='Wat geeft u voor dit kekke item?',
              default=1099,
              requires=IS_NOT_EMPTY()),
        Field('bank',
              'list:integer',
              label='Uw bank',
              requires=IS_IN_SET((item['id'] for item in api.providers),
                                 [item['name'] for item in api.providers])))
    if form.process().accepted:
        message = 'Een moment geduld graag... Uw fake betaling voor \'%s\' wordt gestart.' % (
            form.vars.description)
        submit = True
    return dict(title=title, message=message, submit=submit, form=form)
Example #5
0
class TestValidateCallbackSignature(TestCase):
    def setUp(self):
        self.api = SisowAPI('0123456', 'b36d8259346eaddb3c03236b37ad3a1d7a67cec6')
    
    def test_values_from_manual(self):
        trxid = '0050000513407955'
        ec = '123456789'
        status = 'Success'
        sha1 = '5c25e106ad73641bec40aec0e9144fe793c274cf'
        self.assertEqual(self.api.validate_callback(trxid, ec, status, sha1),
                         True)
    
    def test_values_from_manual_invalid(self):
        trxid = '0050000513407955'
        ec = '123456789'
        status = 'Success'
        sha1 = 'b36d8259346eaddb3c03236b37ad3a1d7a67cec6'
        self.assertEqual(self.api.validate_callback(trxid, ec, status, sha1),
                         False)
Example #6
0
def list_banks():
    response.view = 'sisow/index.html'
    title = T('Sisow list of banks')
    nav_helper = ""
    messages = []

    testmode = False
    api = SisowAPI(settings.sisow_merchant_id, settings.sisow_merchant_key,
                   testmode)
    messages.append("Available banks")
    # Pick random bank from API
    for item in api.providers:
        messages.append('%s - %s' % (item['id'], item['name']))
    return dict(title=title, nav_helper=nav_helper, messages=messages)
Example #7
0
def run_demo(merchantid, merchantkey, amount, issuerid=None, testmode=True):
    api = SisowAPI(merchantid, merchantkey, testmode)

    if issuerid is None:
        # Pick random bank from API
        bank = random.choice(tuple(api.providers))
    else:
        for bank in api.providers:
            if bank['id'] == issuerid:
                break
    print "Picked %(name)s (%(id)s)" % bank
    entrance = datetime.now().strftime("E%Y%m%dT%H%M")

    # Build transaction
    t = Transaction(entrance, amount, bank['id'], entrance,
                    'Some demo product')

    #Send transaction
    urls = WebshopURLs('https://github.com/nederhoed/python-sisow/')
    response = api.start_transaction(t, urls)
    if not response.is_valid(merchantid, merchantkey):
        raise ValueError('Invalid SHA1')

    # Browser part
    url_ideal = urllib.url2pathname(response.issuerurl)
    print url_ideal
    webbrowser.open(url_ideal)

    while True:
        status = api.get_transaction_status(response.trxid)
        if not status.is_valid(merchantid, merchantkey):
            raise ValueError('Invalid SHA1')
        print datetime.now().strftime('%H:%M:%S'), status.status
        if status.status != 'Open':
            break
        time.sleep(5)
Example #8
0
    def checkout(self, request):
        api = SisowAPI(None, None)
        cart = Cart(request)

        total_without_vat = 0
        for item in cart:
            total_without_vat += item.total_price
        total_with_vat = float(
            total_without_vat *
            decimal.Decimal(1 + settings.FUNDER_VAT_PERCENTAGE / 100))

        return TemplateResponse(
            request, 'fundraiser/checkout.html', {
                "banks": api.providers,
                "cart": cart,
                "total_without_vat": total_without_vat,
                "total_with_vat": total_with_vat,
                "show_vat": settings.FUNDER_SHOW_VAT,
                "vat_percentage": settings.FUNDER_VAT_PERCENTAGE,
            })
Example #9
0
 def setUp(self):
     self.api = SisowAPI('0123456', 'b36d8259346eaddb3c03236b37ad3a1d7a67cec6')
Example #10
0
def list_banks(testmode=True):
    api = SisowAPI(None, None, testmode)
    print "Available banks"
    # Pick random bank from API
    for item in api.providers:
        print item['id'], item['name']