Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Created June 14, 2018 03:20
Show Gist options
  • Save DustinAlandzes/2ea491f67e23eabc4a6d5991d9e5b4ee to your computer and use it in GitHub Desktop.
Save DustinAlandzes/2ea491f67e23eabc4a6d5991d9e5b4ee to your computer and use it in GitHub Desktop.
import requests
import json
class CoPilotAPI:
def __init__(self, client_secret, username, password, base_url="https://accountsuat.cardconnect.com/"):
self.base_url = "https://accountsuat.cardconnect.com/"
# load this from config file or environment variables
self.client_secret = client_secret
self.username = username
self.password = password
self.access_token = None
def get_access_token(self):
'''
https://developer.cardconnect.com/copilotapi#get-access-token-endpoint
'''
endpoint = "auth/realms/cardpointe/protocol/openid-connect/token"
data = {
"grant_type": "password",
"client_id": "copilot",
"client_secret": self.client_secret,
"username": self.username,
"password": self.password
}
headers = {"content-type": "application/x-www-form-urlencoded"}
r = requests.post("{}{}".format(self.base_url, endpoint), data=data, headers=headers)
response = json.loads(r.text)
self.access_token = response["access_token"]
if 'error' in response and 'error_description' in response:
raise Exception(response['error_description'])
return response
def refresh_access_token(self):
endpoint = "auth/realms/cardpointe/protocol/openid-connect/token"
data = {
"grant_type": "password",
"client_id": "copilot",
"refresh_token": self.access_token,
"client_secret": self.client_secret,
}
headers = {"content-type": "application/x-www-form-urlencoded"}
r = requests.post("{}{}".format(self.base_url, endpoint), data=data, headers=headers)
response = json.loads(r.text)
self.access_token = response["access_token"]
if 'error' in response and 'error_description' in response:
raise Exception(response['error_description'])
return response
def make_merchant(self):
'''
https://developer.cardconnect.com/copilotapi#create-merchant-endpoint
'''
endpoint = "https://copilot-api-uat.cardconnect.com/merchant"
data = {
"templateId": 9999,
"merchant": {
"salesCode": "API1",
"akaBusinessName": "Mikes API Merchant AKA1",
"custPrimaryAcctFlg": False,
"dbaName": "Mikes API Merchant DBA",
"legalBusinessName": "Mikes API Legal Biz Name",
"taxFilingMethod": "EIN",
"taxFilingName": "Mike API Legal Biz Name",
"demographic": {
"businessIncorporatedStateCd": "CO",
"merchantTimeZone": "MT",
"websiteAddress": "www.test.com",
"businessPhone": "555-555-5555",
"businessFax": "444-444-4444",
"businessAddress": {
"address1": "123 Fake St",
"address2": "Apt. 23",
"city": "Fakeville",
"countryCd": "US",
"stateCd": "IL",
"zip": "11111"
},
"mailingAddress": {
"address1": "123 Main St.",
"address2": "Suite 3001",
"city": "Boulder",
"countryCd": "US",
"stateCd": "CO",
"zip": "11223"
}
},
"businessIdTypeCd": "ARTICLE",
"businessStartDate": "04/26/2002",
"bankDetail": {
"depositBank": {
"bankAcctNum": "12345678",
"bankRoutingNum": "445566778",
"bankAcctTypeCd": "BIZ",
"bankName": "Deposit Bank"
},
"withdrawalBank": {
"bankAcctNum": "87654321",
"bankRoutingNum": "887766554",
"bankAcctTypeCd": "BIZ",
"bankName": "Withdrawal Bank"
}
},
"ownership": {
"owner": {
"ownerAddress": {
"address1": "123 Fake St",
"address2": "Apt 121",
"city": "Boulder",
"countryCd": "US",
"stateCd": "CO",
"zip": "19335"
},
"ownerEmail": "[email protected]",
"ownerName": "Mike Owner",
"ownerDob": "09/22/1997",
"ownerPhone": "555-555-5555",
"ownerMobilePhone": "555-555-5555",
"ownerSSN": "111-22-3333",
"ownerTitle": "CEO"
},
"ownershipTypeCd": "INDIVSOLE",
"driversLicenseNumber": "2342343243",
"driversLicenseStateCd": "CO",
"ownerOwnershipPct": 100
},
"merchantContactInfo": {
"contactName": "John Doe",
"contactEmail": "[email protected]",
"contactPhone": "555-555-5555"
},
"processing": {
"platformDetails": {
"backEndMid": None,
"frontEndMid": None,
"processorReportingMid": None,
"backEndPlatformCd": None,
"frontEndPlatformCd": None,
"amexProgramAssetCd": "OPTBLUE",
"amexProgramMid": "2341251235434",
"discoverMid": "2134123423555",
"discoverProgramCd": "EASI",
"acquiringFlg": True,
"taxId": "485968574",
"tid": "968596859",
"busnsId": "234444234234",
"busnsIdPlaceOfIssue": "CO",
"currencyCode": "USD",
"mccId": "3076",
"businessDescription": "Business Description"
},
"businessDetails": {
"customerBillPriorToShipFlg": False,
"depositReqForFulfillFlg": True,
"whenCustomerChargedCd": "INADVANCE",
"refundPolicyCd": "EXCHONLY",
"serviceProvidedInCd": "30LESS"
},
"volumeDetails": {
"averageMonthlyVolume": 9999.00,
"highTicketAmount": 99.99,
"averageTicketAmount": 9.99
},
"deliveryPercentages": {
"dlvry0To7DaysPct": 97,
"dlvry15To30DaysPct": 1,
"dlvry8To14DaysPct": 1,
"dlvryOver30DaysPct": 1
},
"modeOfTransaction": {
"eCommercePct": 0,
"keyedPct": 20,
"mailOrderPct": 30,
"swipedPct": 50
}
},
"webLeadFlg": True,
"pricing": {
"flatPricing": {
"amex": {
"esaQualDiscountPct": 22.00,
"optBlueQualDiscountPct": 11.00
},
"discover": {
"qualCreditDiscountPct": 1.00
},
"mastercard": {
"qualCreditDiscountPct": 5.00
},
"visa": {
"qualCreditDiscountPct": 4.00
}
}
},
"fees": {
"achBatchFee": 1.11,
"addressVerifFee": 2.22,
"annualMembershipFee": 3.33,
"appFee": 4.44,
"authFee": 5.55,
"chargebackFee": 6.66,
"dataBreachFee": 7.77,
"ddaRejectFee": 8.88,
"earlyCancelFee": 9.99,
"minProcessFee": 20.00,
"monthlyEquipmentRentalFee": 10.00,
"pciAnnualFee": 21.00,
"pciNonComplianceFee": 100.00,
"regProdMonthlyFee": 200.00,
"retrievalFee": 10.00,
"statementFee": 27.99,
"transactionFee": 0.05,
"voiceAuthFee": 0.10,
"wirelessActivationFee": 0.10,
"wirelessFee": 50.00,
"duesAndAssessmentsFlg": True,
"passthruInterchgCostsFlg": True
}
},
"ownerSiteUser": {
"firstName": "Mike",
"lastName": "Owner",
"email": "[email protected]"
}
}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {}".format(self.access_token),
"X-CopilotAPI-Version": "1.0"
}
r = requests.post("{}".format(endpoint), json=data, headers=headers)
print(r.request.headers)
response = json.loads(r.text)
if 'error' in response and 'error_description' in response:
raise Exception(response['error_description'])
return json.dumps(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment