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, })
class TestTransactionSha1FromManual(unittest.TestCase): """\ # SHA! value copied from the Sisow manual 3.2.1 page 10 https://www.sisow.nl/Sisow/iDeal/RestHandler.ashx/TransactionRequest?shopid=&merchantid =0123456&purchaseid=123456789&amount=1000&payment=ecare&entrancecode=uniqueentrance&descriptio n=Bestelling+webshop.nl&returnurl=http%3a%2f%2fwww.webshop.nl&callbackurl=http%3a%2f%2fwww.webshop.nl%2f/ca llback&sha1=cb2461bd40ed1a77a6d837a560bfcbc3e03d6c3c #sha1("123456789uniqueentrance10000123456b36d8259346eaddb3c03236b37ad3a1d7a67cec6") """ def setUp(self): self.transaction = Transaction('123456789', 1000, '01', 'uniqueentrance') self.transaction.merchantid = '0123456' self.merchantkey = 'b36d8259346eaddb3c03236b37ad3a1d7a67cec6' def test_sha1_value(self): outcome = 'cb2461bd40ed1a77a6d837a560bfcbc3e03d6c3c' self.assertEqual(self.transaction.sha1(self.merchantkey), outcome)
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)
def setUp(self): self.transaction = Transaction('123456789', 1000, '01', 'uniqueentrance') self.transaction.merchantid = '0123456' self.merchantkey = 'b36d8259346eaddb3c03236b37ad3a1d7a67cec6'