Structure for OnePak requests. Untested

master
Griffiths Lott 3 years ago
commit 4a4d724cf9
  1. 1
      .gitignore
  2. 1
      JSON Samples/CancelReturnPayload.json
  3. 3
      JSON Samples/CancelReturnResp.json
  4. 1
      JSON Samples/RetrieveReturnPayload.json
  5. 108
      JSON Samples/RetrieveReturnReturn.json
  6. 60
      OnePakRequests.py
  7. 29
      ReturnObjectDetails.txt
  8. 4
      config.json

1
.gitignore vendored

@ -0,0 +1 @@
venv/

@ -0,0 +1 @@
{"action": "cancel", "ra_number": "RCTR1406-000001", "reason": "Lessee Purchase"}

@ -0,0 +1,3 @@
{
"ra_number": "RCTR1406-000001"
}

@ -0,0 +1 @@
{"action": "get", "lease_number": "123-4567876-001", "details": "yes"}

@ -0,0 +1,108 @@
{
"ra_number": "RCTR1406-000001",
"lease_number": "123-4567876-001",
"termination_date": "2014-05-12",
"ra_date": "2014-05-22",
"sent_date": "2014-05-26",
"due_date": "2014-06-26",
"type": "KEEP: Full trade-up",
"sent_to": "lessee",
"comments": "",
"status": "RA Pending",
"url": "http://www.returncenter.com/portal/r/538f888964bde",
"account": {
"identifier": "AI1234567",
"company": "Acme Insurance",
"address1": "123 Main Street",
"address2": "Suite 233",
"city": "Boulder",
"state": "CO",
"zip": "80301",
"contact": "James Smith",
"phone": "(301) 555-1212",
"cell_phone": "(301) 555-1212",
"fax": "(301) 555-1212",
"email": "james.smith@example.com"
},
"pickup_location": {
"identifier": "AI1273459",
"company": "Acme Insurance",
"address1": "5555 Industrial",
"city": "Boulder",
"state": "CO",
"zip": "80302",
"contact": "Robert Allen",
"phone": "(301) 555-1212",
"cell_phone": "(301) 555-1212",
"fax": "(301) 555-1212",
"email": "robert.allen@example.com"
},
"destination": {
"identifier": "AR7734092",
"company": "Apex Remarketing",
"address1": "6789 Commerce St.",
"city": "Denver",
"state": "CO",
"zip": "80201",
"contact": "Samantha Potter",
"phone": "(720) 555-1212",
"cell_phone": "(720) 555-1212",
"fax": "(720) 555-1212",
"email": "samantha.potter@example.com"
},
"lessor": {
"identifier": "PL1234567",
"company": "Pinnacle Leasing",
"address1": "555 Elm Street",
"address2": "Suite 101",
"city": "Omaha",
"state": "NE",
"zip": "68127",
"contact": "Jane Jones",
"phone": "(402) 555-1212",
"cell_phone": "(402) 555-1212",
"fax": "(402) 555-1212",
"email": "jane.jones@example.com"
},
"lessee": {
"identifier": "AI1234567",
"company": "Acme Insurance",
"address1": "123 Main Street",
"address2": "Suite 233",
"city": "Boulder",
"state": "CO",
"zip": "80301",
"contact": "James Smith",
"phone": "(301) 555-1212",
"cell_phone": "(301) 555-1212",
"fax": "(301) 555-1212",
"email": "james.smith@example.com"
},
"dealer": {
"identifier": "SC523656",
"company": "Summit Copiers",
"address1": "8072 Oak Ave.",
"city": "Boulder",
"state": "CO",
"zip": "80302",
"contact": "Ben Brady",
"phone": "(302) 555-1212",
"cell_phone": "(302) 555-1212",
"fax": "(302) 555-1212",
"email": "ben.brady@example.com"
},
"expected_assets": [
{
"make": "Canon",
"model_number": "IR2351",
"serial_number": "KB67QR37472",
"insurance_value": "525"
},
{
"make": "Canon",
"model_number": "IR202I",
"serial_number": "MQR23477BCD",
"insurance_value": "487"
}
]
}

@ -0,0 +1,60 @@
import requests as rq
import re
from logging import debug, error, basicConfig
import json
with open("config.json") as configFile:
config = json.load(configFile)
basicConfig(filename=config["logLocation"], encoding='utf-8', level=config["logging"])
RETURNCENTER_BASE_RL = config["OnePakUrl"]
def retrieve_return_data(lease_number: str, apiKey: str, details: bool = False) -> dict:
"""
Reaches out to OnePak API and searches for the given lease number.
Returns only summary data by default, use details = True to get full return object
"""
debug(f"[I] retrieve_return_data: {lease_number} | deatils: {details}")
if re.match("\d{3}-\d{7}-\d{3}", lease_number) == None:
error(f"[!E!] Invalid lease number: {lease_number}")
return {"error": f"Invalid lease number: {lease_number}"}
resp = rq.post(RETURNCENTER_BASE_RL,
json={"action": "get", "lease_number": lease_number, "details": "yes" if details else "no"},
headers={"Content-Type": "application/json"},
auth=(apiKey, ''))
if not resp.ok():
error(f"[!E!] retrieve_return_data: response was unsuccessful: {resp.text}")
return {"error": f"{resp.text}"}
debug(f"[I] retrieve_return_data: resp: {resp}\n{resp.json()}")
return dict(resp.json())
def cancel_return(ra_number: str, apiKey: str, cancel_reason: str = "No longer needed") -> dict:
"""
Cancels a return authorization based on the ra_number
"""
debug(f"[I] cancel_return: {ra_number} | cancel reason: {cancel_reason}")
if re.match("^RCTR.*", ra_number) == None:
error(f"[!E] Invalid RA Number: {ra_number}")
return {"error": f"Invalid RA number: {ra_number}"}
resp = rq.post(RETURNCENTER_BASE_RL,
json={"action": "cancel", "ra_number": ra_number, "reason": cancel_reason},
headers={"Content-Type": "application/json"},
auth=(apiKey, ''))
if not resp.ok():
error(f"[!E!] cancel_return: response was unsuccessful: {resp.text}")
return {"error": f"{resp.text}"}
debug(f"[I] cancel_return: resp: {resp}\n{resp.json()}")
return dict(resp.json())
def search_and_cancel(lease_number: str, apiKey: str, details: bool = False, cancel_reason: str = "No longer needed") -> dict:
searchResult = retrieve_return_data(lease_number, apiKey, details, cancel_reason)
if "error" in searchResult.keys():
error(f"[!E!] search_and_cancel: Failed to find lease number: {lease_number}\n{searchResult}")
return searchResult
cancelresult = cancel_return(searchResult["ra_number"], apiKey, cancel_return)
if "error" in cancelresult.keys():
error(f"[!E!] search_and_cancel: Failed to cancel RA: {lease_number} | {searchResult['ra_number']}\n{cancelresult}")
return searchResult
return {"success": "RA has been canceled"}

@ -0,0 +1,29 @@
ra_number: A unique return authorization number assigned by the ReturnCenter.
lease_number: The lease number or contract number provided by the lessor
termination_date: The date when the lease will be terminated.
ra_date: The date when the Return Authorization was issued.
sent_date: The date when the Return Authorization was sent.
due_date: The date by which the Return Authorization must be processed by the lessee or dealer.
type: Type of return.
Valid types are:
KEEP: Full trade-up
KEEP: Partial trade-up
TRADE-UP: Full with return
TRADE-UP: Partial with return
EOL BUYOUT: Full with return
EOL BUYOUT: Partial with return
BUYOUT: Full with return
BUYOUT: Partial with return
sent_to: To whom the RA was sent -- either "dealer" or "lessee"
comments: Comments about the return
status: Status of the return
url: The URL for accessing the return in the ReturnCenter.
account: An organization object for the account holder. The account holder is the person who processes and pays for the return.
pickup_location: An organization object for the location where the assets are located and will be picked up for shipment.
destination: An organization object for the destination to which the assets will be shipped.
lessor: An organization object for the lessor.
lessee: An organization object for the lessee.
dealer: An organization object for the dealer or vendor associated with the assets on this return.
expected_assets: One or more asset objects for the assets that are expected to be shipped with this return.
received_assets: One or more asset objects that were received at the destination for this return.

@ -0,0 +1,4 @@
{"logging": "DEBUG",
"logLocation": "OnePakRequests.log",
"OnePakUrl": "https://api.returncenter.com/1/returns",
"APIKey": ""}
Loading…
Cancel
Save