Skip to content

Commit

Permalink
Merge pull request #2 from anmol-sakarda/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
VantivSDK authored Oct 7, 2020
2 parents 773838e + 3eba720 commit 022b9a5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CHANGELOG
* **Feature** Support for Payfac MP API version 13.1

## 13.0.0
* **Feature** Support for PayFac MP API version 13.0
* **Feature** Support for PayFac MP API version 13.0
6 changes: 5 additions & 1 deletion payfacMPSdk/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


def http_get_retrieval_request(url_suffix, config=conf):

url = getattr(config, 'url')
# print("url -> "+url+"\n")
request_url = url + url_suffix
Expand Down Expand Up @@ -109,8 +110,11 @@ def validate_response(http_response, config=conf):
# Check empty response
if http_response is None:
raise utils.PayfacError("There was an exception while fetching the response")
if http_response.headers._store.get('content-type') is not None:
content_type = http_response.headers._store['content-type'][1]
else:
content_type = ''

content_type = http_response.headers._store['content-type'][1]
if (http_response.status_code != 200) & (http_response.status_code !=201):
if PAYFAC_CONTENT_TYPE in content_type:
error_response = utils.generate_error_response(http_response)
Expand Down
2 changes: 1 addition & 1 deletion payfacMPSdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, conf_dict=dict()):
'password': '',
'printXml': False,
'proxy': '',
'url': '',
'url': 'https://www.testvantivcnp.com/sandbox/payfac',
'username': ''}

for k in attr_dict:
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
'unittest2>=1.1.0',
'python-dateutil>=2.7.3',
'setuptools',
'mock', 'lxml'
'mock', 'lxml',
'wheel'
],
license='MIT',
classifiers=[
Expand Down
40 changes: 21 additions & 19 deletions test/functional/test_communication.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import unittest
from payfacMPSdk import communication, utils


class TestCommunication(unittest.TestCase):

def test_http_get_retrieval_request(self):
Expand All @@ -11,53 +11,55 @@ def test_http_get_retrieval_request(self):

def test_http_get_retrieval_request_with_PayfacError(self):
new_conf = utils.Configuration()
new_conf.__setattr__("url","https://")
self.assertRaises(utils.PayfacError, communication.http_get_retrieval_request, "/legalentity/1000293",new_conf)
new_conf.__setattr__("url", "https://")
self.assertRaises(utils.PayfacError, communication.http_get_retrieval_request, "/legalentity/1000293", new_conf)

def test_http_post_request(self):
agreementPostRequest = '<legalEntityAgreementCreateRequest xmlns="http://payfac.vantivcnp.com/api/merchant/onboard"><legalEntityAgreement><legalEntityAgreementType>MERCHANT_AGREEMENT</legalEntityAgreementType><agreementVersion>agreementVersion1</agreementVersion><userFullName>userFullName</userFullName><userSystemName>systemUserName</userSystemName><userIPAddress>196.198.100.100</userIPAddress><manuallyEntered>false</manuallyEntered><acceptanceDateTime>2017-02-11T12:00:00-06:00</acceptanceDateTime></legalEntityAgreement></legalEntityAgreementCreateRequest>'
response = communication.http_post_request("/legalentity/21003/agreement".encode('utf-8'),agreementPostRequest)
response = communication.http_post_request("/legalentity/21003/agreement".encode('utf-8'), agreementPostRequest)
self.assertIsNotNone(response["transactionId"])

def test_http_post_request_with_PayfacError(self):
agreementPostRequest = '<legalEntityAgreementCreateRequest xmlns="http://payfac.vantivcnp.com/api/merchant/onboard"><legalEntityAgreement><legalEntityAgreementType>MERCHANT_AGREEMENT</legalEntityAgreementType><agreementVersion>agreementVersion1</agreementVersion><userFullName>userFullName</userFullName><userSystemName>systemUserName</userSystemName><userIPAddress>196.198.100.100</userIPAddress><manuallyEntered>false</manuallyEntered><acceptanceDateTime>2017-02-11T12:00:00-06:00</acceptanceDateTime></legalEntityAgreement></legalEntityAgreementCreateRequest>'
new_conf = utils.Configuration()
new_conf.__setattr__("url","https://")
self.assertRaises(utils.PayfacError, communication.http_post_request, "/legalentity/21003/agreement".encode('utf-8'), agreementPostRequest,new_conf)
new_conf.__setattr__("url", "https://")
self.assertRaises(utils.PayfacError, communication.http_post_request,
"/legalentity/21003/agreement".encode('utf-8'), agreementPostRequest, new_conf)

def test_http_put_request(self):
legalEntityPutRequest = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><legalEntityUpdateRequest xmlns="http://payfac.vantivcnp.com/api/merchant/onboard"><address><streetAddress1>LE Street Address 1</streetAddress1><streetAddress2>LE Street Address 2</streetAddress2><city>LE City</city><stateProvince>MA</stateProvince><postalCode>01730</postalCode><countryCode>USA</countryCode></address><contactPhone>9785550101</contactPhone><doingBusinessAs>Other Name Co.</doingBusinessAs><annualCreditCardSalesVolume>10000000</annualCreditCardSalesVolume><hasAcceptedCreditCards>true</hasAcceptedCreditCards><principal><principalId>9</principalId><title>CEO</title><emailAddress>[email protected]</emailAddress><contactPhone>9785551234</contactPhone><address><streetAddress1>p street address 1</streetAddress1><streetAddress2>p street address 2</streetAddress2><city>Boston</city><stateProvince>MA</stateProvince><postalCode>01890</postalCode><countryCode>USA</countryCode></address><backgroundCheckFields><firstName>p first</firstName><lastName>p last</lastName><ssn>123459876</ssn><dateOfBirth>1980-10-12</dateOfBirth><driversLicense>892327409832</driversLicense><driversLicenseState>MA</driversLicenseState></backgroundCheckFields></principal><backgroundCheckFields><legalEntityName>Company Name</legalEntityName><legalEntityType>INDIVIDUAL_SOLE_PROPRIETORSHIP</legalEntityType><taxId>123456789</taxId></backgroundCheckFields><legalEntityOwnershipType>PUBLIC</legalEntityOwnershipType><yearsInBusiness>10</yearsInBusiness></legalEntityUpdateRequest>'
response = communication.http_put_request("/legalentity/1000293".encode('utf-8'),legalEntityPutRequest)
response = communication.http_put_request("/legalentity/1000293".encode('utf-8'), legalEntityPutRequest)
self.assertIsNotNone(response["transactionId"])
self.assertEquals("1000293",response["legalEntityId"])
self.assertEquals(10,response["responseCode"])
self.assertEquals("Approved",response["responseDescription"])
self.assertEquals("1000293", response["legalEntityId"])
self.assertEquals(10, response["responseCode"])
self.assertEquals("Approved", response["responseDescription"])

def test_http_put_request_with_PayfacError(self):
legalEntityPutRequest = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><legalEntityUpdateRequest xmlns="http://payfac.vantivcnp.com/api/merchant/onboard"><address><streetAddress1>LE Street Address 1</streetAddress1><streetAddress2>LE Street Address 2</streetAddress2><city>LE City</city><stateProvince>MA</stateProvince><postalCode>01730</postalCode><countryCode>USA</countryCode></address><contactPhone>9785550101</contactPhone><doingBusinessAs>Other Name Co.</doingBusinessAs><annualCreditCardSalesVolume>10000000</annualCreditCardSalesVolume><hasAcceptedCreditCards>true</hasAcceptedCreditCards><principal><principalId>9</principalId><title>CEO</title><emailAddress>[email protected]</emailAddress><contactPhone>9785551234</contactPhone><address><streetAddress1>p street address 1</streetAddress1><streetAddress2>p street address 2</streetAddress2><city>Boston</city><stateProvince>MA</stateProvince><postalCode>01890</postalCode><countryCode>USA</countryCode></address><backgroundCheckFields><firstName>p first</firstName><lastName>p last</lastName><ssn>123459876</ssn><dateOfBirth>1980-10-12</dateOfBirth><driversLicense>892327409832</driversLicense><driversLicenseState>MA</driversLicenseState></backgroundCheckFields></principal><backgroundCheckFields><legalEntityName>Company Name</legalEntityName><legalEntityType>INDIVIDUAL_SOLE_PROPRIETORSHIP</legalEntityType><taxId>123456789</taxId></backgroundCheckFields><legalEntityOwnershipType>PUBLIC</legalEntityOwnershipType><yearsInBusiness>10</yearsInBusiness></legalEntityUpdateRequest>'
new_conf = utils.Configuration()
new_conf.__setattr__("url","https://")
self.assertRaises(utils.PayfacError, communication.http_put_request, "/legalentity/1000293".encode('utf-8'), legalEntityPutRequest,new_conf)
new_conf.__setattr__("url", "https://")
self.assertRaises(utils.PayfacError, communication.http_put_request, "/legalentity/1000293".encode('utf-8'),
legalEntityPutRequest, new_conf)

def test_http_delete_request(self):
response = communication.http_delete_request("/legalentity/2018/principal/9")
self.assertIsNotNone(response["transactionId"])
self.assertEquals("2018",response["legalEntityId"])
self.assertEquals(9,response["principalId"])
self.assertEquals("Legal Entity Principal successfully deleted",response["responseDescription"])
self.assertEquals("2018", response["legalEntityId"])
self.assertEquals(9, response["principalId"])
self.assertEquals("Legal Entity Principal successfully deleted", response["responseDescription"])

def test_http_delete_request_with_PayfacError(self):
new_conf = utils.Configuration()
new_conf.__setattr__("url", "https://")
self.assertRaises(utils.PayfacError, communication.http_delete_request, "/legalentity/2018/principal/9", new_conf)
self.assertRaises(utils.PayfacError, communication.http_delete_request, "/legalentity/2018/principal/9",
new_conf)

def test_validate_response_with_PayfacWebError(self):
self.assertRaises(utils.PayfacWebError, communication.http_get_retrieval_request, "/legalentity")

def test_validate_response_with_PayfacWebError_generateErrorResponse(self):
self.assertRaises(utils.PayfacWebError, communication.http_get_retrieval_request, "/legalentity/10002930000000000000000000000000000")

self.assertRaises(utils.PayfacWebError, communication.http_get_retrieval_request,
"/legalentity/10002930000000000000000000000000000")

def test_validate_response_with_PayfacError(self):
self.assertRaises(utils.PayfacError, communication.validate_response, None)

0 comments on commit 022b9a5

Please sign in to comment.