def auth_payment(self, **post): """ Customer returns from PayEx. Look up status of order. """ _logger.warn(post) ref = post.get('orderRef', '') if not ref: _logger.warn("Error in PayEx return. No reference found!") return "Error when contacting PayEx!" tx = request.env['payment.transaction'].sudo( )._payex_form_get_tx_from_data(post) if not tx: _logger.warn("Error in PayEx return. No transaction found!") return "Error when contacting PayEx!" service = PayEx(merchant_number=tx.acquirer_id.payex_account_nr, encryption_key=tx.acquirer_id.payex_key, production=tx.acquirer_id.environment == 'prod') response = service.complete(orderRef=ref) _logger.warn("PayEx response: %s" % response) if response: if request.env['payment.transaction'].sudo().with_context({ 'orderRef': ref }).form_feedback(response, 'payex'): return werkzeug.utils.redirect('/shop/payment/validate', 302) return "Couldn't verify your payment!" _logger.warn( "Error when contacting PayEx! Didn't get a response.\n%s" % response) return 'Error when contacting PayEx!'
def testPayment(self): """ Test the initialize7 and complete methods. """ # Needs credentials to test self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY])) service = PayEx(merchant_number=MERCHANT_NUMBER, encryption_key=ENCRYPTION_KEY, production=False) # Initialize a payment response = service.initialize( purchaseOperation='AUTHORIZATION', price='5000', currency='NOK', vat='2500', orderID='test1', productNumber='123', description=u'This is a test. åâaä', clientIPAddress='127.0.0.1', clientIdentifier='USERAGENT=test&username=testuser', additionalValues='PAYMENTMENU=TRUE', returnUrl='http://example.org/return', view='PX', cancelUrl='http://example.org/cancel') # Check the response self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertTrue('orderRef' in response) self.assertTrue(response['redirectUrl'].startswith( 'https://test-account.payex.com/MiscUI/PxMenu.aspx')) # Try to complete the order (even if it's not started by user) response = service.complete(orderRef=response['orderRef']) self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # Get the transaction details response = service.get_transaction_details(transactionNumber='0') self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # Try to capture a transaction response = service.capture(transactionNumber='0', amount='1000', vatAmount='250') self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # Try to cancel a transaction response = service.cancel(transactionNumber='1') self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'Error_Generic')
def testAgreementHandlers(self): """ Test the various agreement handlers. """ # Needs credentials to test self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY])) service = PayEx(merchant_number=MERCHANT_NUMBER, encryption_key=ENCRYPTION_KEY, production=False) # Create an agreement response = service.create_agreement( merchantRef='oneclick', description=u'One-click shopping æøåÆØÅ', purchaseOperation='AUTHORIZATION', maxAmount='100000', ) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertTrue('agreementRef' in response) self.assertFalse('existingAgreementRef' in response) agreement_ref = response['agreementRef'] # Initialize the payment response = service.initialize( purchaseOperation='AUTHORIZATION', price='5000', currency='NOK', vat='2500', orderID='test2', productNumber='123', description=u'This is a test with øæå.', clientIPAddress='127.0.0.1', clientIdentifier='USERAGENT=test&username=testuser', additionalValues='PAYMENTMENU=TRUE', returnUrl='http://example.org/return', view='PX', agreementRef=agreement_ref, cancelUrl='http://example.org/cancel') self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertTrue('redirectUrl' in response) self.assertTrue(response['orderRef'] in response['redirectUrl']) # Try to complete the order (even if it's not started by user) response = service.complete(orderRef=response['orderRef']) self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # AutoPay with the agreement response = service.autopay(purchaseOperation='SALE', agreementRef=agreement_ref, price='1000', productNumber='123', description=u'This is a test with øæå.', orderId='900') self.assertEquals(response['status']['errorCode'], 'AgreementNotVerified') # Check the agreement response = service.check_agreement(agreementRef=agreement_ref) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertEquals(response['agreementStatus'], '0') # Delete the agreement response = service.delete_agreement(agreementRef=agreement_ref) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK')
def testPayment(self): """ Test the initialize7 and complete methods. """ # Needs credentials to test self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY])) service = PayEx( merchant_number=MERCHANT_NUMBER, encryption_key=ENCRYPTION_KEY, production=False ) # Initialize a payment response = service.initialize( purchaseOperation='AUTHORIZATION', price='5000', currency='NOK', vat='2500', orderID='test1', productNumber='123', description=u'This is a test. åâaä', clientIPAddress='127.0.0.1', clientIdentifier='USERAGENT=test&username=testuser', additionalValues='PAYMENTMENU=TRUE', returnUrl='http://example.org/return', view='PX', cancelUrl='http://example.org/cancel' ) # Check the response self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertTrue('orderRef' in response) self.assertTrue(response['redirectUrl'].startswith('https://test-account.payex.com/MiscUI/PxMenu.aspx')) # Try to complete the order (even if it's not started by user) response = service.complete(orderRef=response['orderRef']) self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # Get the transaction details response = service.get_transaction_details(transactionNumber='0') self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # Try to capture a transaction response = service.capture( transactionNumber='0', amount='1000', vatAmount='250' ) self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # Try to cancel a transaction response = service.cancel(transactionNumber='1') self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'Error_Generic')
def testAgreementHandlers(self): """ Test the various agreement handlers. """ # Needs credentials to test self.assertTrue(all([MERCHANT_NUMBER, ENCRYPTION_KEY])) service = PayEx( merchant_number=MERCHANT_NUMBER, encryption_key=ENCRYPTION_KEY, production=False ) # Create an agreement response = service.create_agreement( merchantRef='oneclick', description=u'One-click shopping æøåÆØÅ', purchaseOperation='AUTHORIZATION', maxAmount='100000', ) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertTrue('agreementRef' in response) self.assertFalse('existingAgreementRef' in response) agreement_ref = response['agreementRef'] # Initialize the payment response = service.initialize( purchaseOperation='AUTHORIZATION', price='5000', currency='NOK', vat='2500', orderID='test2', productNumber='123', description=u'This is a test with øæå.', clientIPAddress='127.0.0.1', clientIdentifier='USERAGENT=test&username=testuser', additionalValues='PAYMENTMENU=TRUE', returnUrl='http://example.org/return', view='PX', agreementRef=agreement_ref, cancelUrl='http://example.org/cancel' ) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertTrue('redirectUrl' in response) self.assertTrue(response['orderRef'] in response['redirectUrl']) # Try to complete the order (even if it's not started by user) response = service.complete(orderRef=response['orderRef']) self.assertEquals(type(response), XmlDictConfig) self.assertEquals(response['status']['errorCode'], 'NoRecordFound') # AutoPay with the agreement response = service.autopay( purchaseOperation='SALE', agreementRef=agreement_ref, price='1000', productNumber='123', description=u'This is a test with øæå.', orderId='900' ) self.assertEquals(response['status']['errorCode'], 'AgreementNotVerified') # Check the agreement response = service.check_agreement(agreementRef=agreement_ref) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK') self.assertEquals(response['agreementStatus'], '0') # Delete the agreement response = service.delete_agreement(agreementRef=agreement_ref) self.assertEquals(response['status']['description'], 'OK') self.assertEquals(response['status']['errorCode'], 'OK')