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 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)