def test_options(): payment = eopayment.Payment('sips2', {'capture_mode': 'VALIDATION'}) assert payment.backend.get_data()['captureMode'] == 'VALIDATION' payment = eopayment.Payment('sips2', {}) assert not 'captureDay' in payment.backend.get_data() payment = eopayment.Payment('sips2', {'capture_day': '10'}) assert 'captureDay' in payment.backend.get_data()
def test_request(self): ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS) amount = '42.42' order_id = 'myorder' reference, kind, what = ogone_backend.request(amount=amount, orderid=order_id, email='*****@*****.**') self.assertEqual(len(reference), 30) assert reference.startswith(order_id) from xml.etree import ElementTree as ET root = ET.fromstring(str(what)) self.assertEqual(root.tag, 'form') self.assertEqual(root.attrib['method'], 'POST') self.assertEqual(root.attrib['action'], ogone.ENVIRONMENT_TEST_URL) values = { 'CURRENCY': 'EUR', 'ORDERID': reference, 'PSPID': PSPID, 'EMAIL': '*****@*****.**', 'AMOUNT': amount.replace('.', ''), 'LANGUAGE': 'fr_FR', } values.update({'SHASIGN': ogone_backend.backend.sha_sign_in(values)}) for node in root: self.assertIn(node.attrib['type'], ('hidden', 'submit')) self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value'])) name = node.attrib['name'] if node.attrib['type'] == 'hidden': self.assertIn(name, values) self.assertEqual(node.attrib['value'], values[name])
def test_iso_8859_1_response(self): ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS) order_id = 'lRXK4Rl1N2yIR3R5z7Kc' backend_response = 'orderID=lRXK4Rl1N2yIR3R5z7Kc¤cy=EUR&amount=7%2E5&PM=CreditCard&ACCEPTANCE=test123&STATUS=9&CARDNO=XXXXXXXXXXXX9999&ED=0118&CN=Miha%EF+Serghe%EF&TRXDATE=10%2F24%2F16&PAYID=3011228911&NCERROR=0&BRAND=MasterCard&IP=80%2E12%2E92%2E47&SHASIGN=435D5E36E1F4B17739C1054FFD204218E65C15AB' response = ogone_backend.response(backend_response) assert response.signed self.assertEqual(response.order_id, order_id)
def test_response(self): backend = eopayment.Payment('paybox', BACKEND_PARAMS) order_id = '20160216' transaction = '1234' reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction data = {'montant': '4242', 'reference': reference, 'code_autorisation': 'A', 'erreur': '00000'} response = backend.response(urllib.urlencode(data)) self.assertEqual(response.order_id, order_id)
def test_response(self): ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS) order_id = 'myorder' data = { 'orderid': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + 'RtEpMXZn4dX8k1rYbwLlby', 'payid': '32100123', 'status': 9, 'ncerror': 0 } response = ogone_backend.response(urllib.urlencode(data)) self.assertEqual(response.order_id, order_id)
def test_unicode_response(self): ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS) order_id = 'myorder' data = {'orderid': 'myorder', 'status': '9', 'payid': '3011229363', 'cn': 'Usér', 'ncerror': '0', 'trxdate': '10/24/16', 'acceptance': 'test123', 'currency': 'eur', 'amount': '7.5', 'shasign': '3EE0CF69B5A8514962C9CF8A545861F0CA1C6891'} # uniformize to utf-8 first for k in data: data[k] = eopayment.common.force_byte(data[k]) response = ogone_backend.response(urllib.parse.urlencode(data)) assert response.signed self.assertEqual(response.order_id, order_id)
def test_request(self): backend = eopayment.Payment('paybox', BACKEND_PARAMS) time = '2015-07-15T18:26:32+02:00' email = '*****@*****.**' order_id = '20160216' transaction = '1234' amount = '19.99' transaction_id, kind, what = backend.request( Decimal(amount), email=email, orderid=order_id, transaction_id=transaction, time=time) self.assertEqual(kind, eopayment.FORM) self.assertEqual(transaction_id, '1234') from xml.etree import ElementTree as ET root = ET.fromstring(str(what)) self.assertEqual(root.tag, 'form') self.assertEqual(root.attrib['method'], 'POST') self.assertEqual(root.attrib['action'], paybox.URLS['test']) for node in root: self.assertIn(node.attrib['type'], ('hidden', 'submit')) if node.attrib['type'] == 'submit': self.assertEqual(set(node.attrib.keys()), set(['type', 'value'])) if node.attrib['type'] == 'hidden': self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value'])) name = node.attrib['name'] reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction values = { 'PBX_RANG': '01', 'PBX_SITE': '12345678', 'PBX_IDENTIFIANT': '12345678', 'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;signature:K', 'PBX_TIME': time, 'PBX_PORTEUR': email, 'PBX_CMD': reference, 'PBX_TOTAL': amount.replace('.', ''), 'PBX_DEVISE': '978', 'PBX_HASH': 'SHA512', 'PBX_HMAC': '173483CFF84A7ECF21039F99E9A95C5FB53D98A1562184F5B2C4543E4F87BFA227CC2CA10DE989D6C8B4DC03BC2ED44B7D7BDF5B4FABA8274D5D37C2F6445F36', 'PBX_ARCHIVAGE': '1234', 'PBX_REPONDRE_A': 'http://example.com/callback', } self.assertIn(name, values) self.assertEqual(node.attrib['value'], values[name])
def test_build_request(): backend = eopayment.Payment('sips2', {}) transaction, f, form = backend.request(amount='12', last_name='Foo', first_name='Félix000000') data = [f for f in form.fields if f['name'] == 'Data'] assert not 'lix000000' in data[0]['value'] transaction, f, form = backend.request(amount='12') data = [f for f in form.fields if f['name'] == 'Data'] assert 'statementReference=%s' % transaction in data[0]['value'] transaction, f, form = backend.request(amount='12', info1='foobar') data = [f for f in form.fields if f['name'] == 'Data'] assert 'statementReference=foobar' in data[0]['value']
def test_bad_response(self): ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS) order_id = 'myorder' data = {'payid': '32100123', 'status': 9, 'ncerror': 0} with self.assertRaises(ResponseError): response = ogone_backend.response(urllib.urlencode(data))
def test_build_request(): backend = eopayment.Payment('sips2', {}) assert backend.request(amount='12')
def test_parse_response(): qs = '''Data=captureDay%3D0%7CcaptureMode%3DAUTHOR_CAPTURE%7CcurrencyCode%3D978%7CmerchantId%3D002001000000001%7CorderChannel%3DINTERNET%7CresponseCode%3D00%7CtransactionDateTime%3D2016-02-01T17%3A44%3A20%2B01%3A00%7CtransactionReference%3D668930%7CkeyVersion%3D1%7CacquirerResponseCode%3D00%7Camount%3D1200%7CauthorisationId%3D12345%7CcardCSCResultCode%3D4E%7CpanExpiryDate%3D201605%7CpaymentMeanBrand%3DMASTERCARD%7CpaymentMeanType%3DCARD%7CcustomerIpAddress%3D82.244.203.243%7CmaskedPan%3D5100%23%23%23%23%23%23%23%23%23%23%23%2300%7CorderId%3Dd4903de7027f4d56ac01634fd7ab9526%7CholderAuthentRelegation%3DN%7CholderAuthentStatus%3D3D_ERROR%7CtransactionOrigin%3DINTERNET%7CpaymentPattern%3DONE_SHOT&Seal=6ca3247765a19b45d25ad54ef4076483e7d55583166bd5ac9c64357aac097602&InterfaceVersion=HP_2.0&Encode=''' backend = eopayment.Payment('sips2', {}) assert backend.response(qs)