Example #1
0
def main(argv):

    parser = argparse.ArgumentParser(description='Main Test Application')
    # times should be in YYYY-MM-dd format
    parser.add_argument('-s', '--start', required=True)
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    args = parser.parse_args(argv)

    print 'Authenticating with tenant: ' + args.hostname
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    start = dates.date_to_millis(args.start, 'America/Los_Angeles', '%Y-%m-%d')

    response = client.get_events(start_timestamp=start)

    while True:
        process_events(response['events'])
        token = response['pagingToken']
        response = client.get_events(paging_token=token)
        if len(response['events']) == 0:
            break
Example #2
0
def main(argv):

    parser = argparse.ArgumentParser(description='Main Test Application')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u', '--username', required=True)
    parser.add_argument('-p', '--password', required=True)
    parser.add_argument('-i', '--identity', required=False)
    args = parser.parse_args(argv)

    if args.identity:
        provider = cognito_provider.CognitoIdentity(args.identity)
    else:
        provider = None

    print('Authenticating with tenant: ' + args.hostname)
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname,
        args.username,
        args.password,
        debug=False,
        identity=provider)

    # setup for super simple policyholder configuration
    ph_values = {'first_name': ['Gary'], 'last_name': ['Richards']}

    ph = client.create_policyholder(values=ph_values)
    print(ph['locator'])
Example #3
0
def main(argv):
    parser = argparse.ArgumentParser(
        description="Get premiums for a set of perils in JSON")
    parser.add_argument("-c", "--calculation_file", help="Liquid calculation ")
    parser.add_argument("-r", "--peril_request", help="JSON with peril info")
    parser.add_argument("-pr", "--product", help="Product Name", required=True)

    parser.add_argument("-n", "--hostname", help="Tenant host name")
    parser.add_argument("-u", "--username", default="alice.lee")
    parser.add_argument("-p", "--password", default="socotra")
    args = parser.parse_args()

    socotra_client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password, debug=False)

    with open(args.calculation_file, "r") as f:
        calculation = f.read()

    with open(args.peril_request, "r") as f:
        request_json = json.loads(f.read())
    response = socotra_client.check_peril_premium(
        args.product, calculation, request_json["policyCharacteristics"],
        request_json["exposureName"], request_json["exposureCharacteristics"],
        request_json["perilName"], request_json["perilCharacteristics"])
    print json.dumps(response, sort_keys=True, indent=4,
                     separators=(',', ':')) + "\n"
Example #4
0
def main(argv):

    parser = argparse.ArgumentParser(description='Get Policy')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='iag.tester',
                        required=False)
    parser.add_argument('-p',
                        '--password',
                        default='Satellit31!',
                        required=False)
    parser.add_argument('-l', '--locator', required=True)
    parser.add_argument('-a', '--api', required=True)
    args = parser.parse_args(argv)

    print(('Authenticating with tenant: ' + args.hostname))
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname,
        args.username,
        args.password,
        #api_url='https://api-iag.socotra.com')
        api_url=args.api)

    policy = client.get_policy(args.locator)
    print((json.dumps(policy)))
Example #5
0
def main(argv):

    parser = argparse.ArgumentParser(description='Main Test Application')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    args = parser.parse_args(argv)

    # with open('../default_config/products/personal-auto/policy/exposures/vehicle/perils/' +
    #           'a_third_party_liability.premium.liquid', "r") as f:
    #     calculation = f.read()

    print('Authenticating with tenant: ' + args.hostname)
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    ph_values = {'first_name': ['Gary'], 'last_name': ['Richards']}

    ph = client.create_policyholder(values=ph_values)
    ph_locator = ph['locator']

    with open('ref_exposure.json', 'r') as f:
        exp_values = json.load(f)
    with open('ref_policy.json', 'r') as f:
        policy_values = json.load(f)
    with open('ref_driver.json', 'r') as f:
        driver = json.load(f)

    peril = {'name': 'a_third_party_liability'}
    exposure = {
        'exposureName': 'vehicle',
        'fieldValues': exp_values['required'],
        'perils': [peril]
    }

    start_timestamp = dates.date_to_millis('01/10/2019', 'America/Los_Angeles',
                                           "%d/%m/%Y")
    end_timestamp = dates.date_to_millis('01/10/2020', 'America/Los_Angeles',
                                         "%d/%m/%Y")
    policy = client.create_policy('personal-auto',
                                  ph_locator,
                                  policy_start_timestamp=start_timestamp,
                                  policy_end_timestamp=end_timestamp,
                                  field_values=policy_values['required'],
                                  exposures=[exposure, exposure],
                                  finalize=False)

    print(json.dumps(policy))
    policy_locator = policy['locator']
    client.uw_policy(policy_locator)
    client.price_policy(policy_locator)
    client.finalize_policy(policy_locator)
    client.issue_policy(policy_locator)
Example #6
0
def main(argv):

    parser = argparse.ArgumentParser(description='Get Policy')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    parser.add_argument('-l', '--locator', required=True)
    args = parser.parse_args(argv)

    print 'Authenticating with tenant: ' + args.hostname
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    policy = client.get_policy(args.locator)
    print json.dumps(policy)
Example #7
0
def main(argv):

    args = parse_args()

    print('Authenticating with tenant: ' + args.hostname)

    # create a client
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    # retrieve the report text
    report = get_ft_report(args, client)

    # aggregate the report (this is a dictionary)
    aggr_report = get_aggregate_report(report)

    # write aggregate report to file
    write_output(args.outputfile, aggr_report)

    print('Output written to file: ' + args.outputfile)
Example #8
0
def main(argv):

    parser = argparse.ArgumentParser(description='Main Test Application')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-l', '--locator', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    args = parser.parse_args(argv)

    policy_locator = args.locator

    print 'Authenticating with tenant: ' + args.hostname
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    rn1_end = dates.date_to_millis('01/10/2021', 'America/Los_Angeles',
                                   "%d/%m/%Y")
    policy_change = {"channel": "Agent"}
    rn1 = client.create_renewal(policy_locator,
                                field_values=policy_change,
                                end_timestamp=rn1_end)
    rn1_locator = rn1['locator']
    print rn1_locator
    print json.dumps(rn1)

    rn1_price = client.price_renewal(rn1_locator)
    print json.dumps(rn1_price)
    print
    rn1 = client.get_renewal(rn1_locator)
    print json.dumps(rn1)

    accept_result = client.update_renewal(rn1_locator, action='accept')
    print json.dumps(accept_result)
    print
    rn1 = client.get_renewal(rn1_locator)
    print json.dumps(rn1)
    print rn1['documents'][0]['url']
Example #9
0
def main(argv):
    parser = argparse.ArgumentParser(description='Main Test Application')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    parser.add_argument('-i', '--id', required=True)

    args = parser.parse_args(argv)
    hostname = args.hostname
    print('Authenticating with tenant: ' + hostname)
    client = SocotraClient.get_authenticated_client_for_hostname(
        hostname, args.username, args.password)
    policy = client.get_policy(args.id)

    # assumes at least one set of characteristics exists on the policy.
    # Only prices the first exposure.
    policy_char_locator = policy['characteristics'][0]['locator']
    exp_char_locator = policy['exposures'][0]['characteristics'][0]['locator']

    # Create a set of triplets which mocks the payload that will be generated
    # by the payload in the external rater.  A triplet is a set of characteristic
    # locators that will be passed into the rater.

    triplets = []
    for peril in policy['exposures'][0]['perils']:
        peril_char_locator = peril['characteristics'][0]['locator']

        triplets.append({
            'policyCharacteristicsLocator': policy_char_locator,
            'exposureCharacteristicsLocator': exp_char_locator,
            'perilCharacteristicsLocator': peril_char_locator
        })

    output = process_triplets(policy, triplets)
    print(json.dumps(output))
def main(argv):

    parser = argparse.ArgumentParser(description='Pay Invoice')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    parser.add_argument('-ph', '--ph_locator', required=True)
    args = parser.parse_args(argv)

    print('Authenticating with tenant: ' + args.hostname)
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    ph_locator = args.ph_locator
    customer_id, ph_id = get_stripe_customer(client, ph_locator)

    # Iterate through all invoices for this policyholder
    invoices = client.get_invoices_for_policyholder(ph_locator)
    for invoice in invoices:
        # Only worry about outstanding invoices that aren't paid yet.
        if invoice['settlementStatus'] == 'outstanding':
            amount = int(float(invoice['totalDue']) * 100)
            # Try to charge stripe for this invoice
            charge = stripe.Charge.create(amount=amount,
                                          currency=invoice['totalDueCurrency'],
                                          customer=customer_id)
            if charge['status'] == 'succeeded':
                # if Stripe succeeded, mark the invoice paid in Socotra
                client.pay_invoice(invoice['locator'])
                print('Invoice paid for policyholder ' + ph_id + \
                    ' regarding invoice ' + invoice['displayId'])
            else:
                print('Stripe payment failed')
Example #11
0
import argparse
import json
from socotratools.client import SocotraClient

# python scripts/price_existing_peril.py -i 100000309
# -c basic.calculation.liquid
# -n starterkit-testuser.co.sandbox.socotra.com -u alice.lee -p socotra

parser = argparse.ArgumentParser(
    description="Check the premium of an existing peril")

parser.add_argument("-i", "--peril_id", help="Id of peril to price")
parser.add_argument("-c", "--calculation_file", help="liquid file")

parser.add_argument("-n", "--hostname")
parser.add_argument("-u", "--username", default="alice.lee")
parser.add_argument("-p", "--password", default="socotra")
args = parser.parse_args()

socotra_client = SocotraClient.get_authenticated_client_for_hostname(
    args.hostname, args.username, args.password, debug=False)

with open(args.calculation_file, "r") as f:
    calculation = f.read()

response = socotra_client.check_existing_peril_premium(calculation,
                                                       args.peril_id)
print json.dumps(response, sort_keys=True, indent=4,
                 separators=(',', ':')) + "\n"
Example #12
0
def main(argv):

    parser = argparse.ArgumentParser(description='Main Test Application')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    args = parser.parse_args(argv)

    with open(
            '../default_config/products/auto/policy/exposures/vehicle/perils/'
            + 'bodily_injury.premium.liquid', "r") as f:
        calculation = f.read()

    print 'Authenticating with tenant: ' + args.hostname
    client = SocotraClient.get_authenticated_client_for_hostname(
        args.hostname, args.username, args.password)

    ph_values = {'first_name': ['Gary'], 'last_name': ['Richards']}

    ph = client.create_policyholder(values=ph_values)
    ph_locator = ph['locator']

    with open('ref_exposure.json', 'r') as f:
        exp_values = json.load(f)
    with open('ref_policy.json', 'r') as f:
        policy_values = json.load(f)
    with open('ref_claim.json', 'r') as f:
        claim = json.load(f)

    peril = {'name': 'bodily_injury'}
    exposure = {
        'exposureName': 'vehicle',
        'fieldValues': exp_values['required'],
        'perils': [peril]
    }

    start_timestamp = dates.date_to_millis('30/11/2017', 'America/Los_Angeles',
                                           "%d/%m/%Y")
    end_timestamp = dates.date_to_millis('30/11/2018', 'America/Los_Angeles',
                                         "%d/%m/%Y")
    policy = client.create_policy('auto',
                                  ph_locator,
                                  policy_start_timestamp=start_timestamp,
                                  policy_end_timestamp=end_timestamp,
                                  field_values=policy_values['required'],
                                  field_groups=[claim, claim],
                                  exposures=[exposure, exposure],
                                  finalize=False)

    # print json.dumps(policy)
    policy_locator = policy['locator']
    client.uw_policy(policy_locator)
    client.price_policy(policy_locator)
    client.finalize_policy(policy_locator)

    # print json.dumps(policy)
    peril_id = policy['exposures'][0]['perils'][0]['displayId']
    print 'Policy Locator: ' + policy_locator
    print '-----'
    uw_result = client.uw_policy(policy_locator)
    print json.dumps(uw_result)
    print '----'
    price_result = client.price_policy(policy_locator)
    print json.dumps(price_result)
    print '----'
    detailed_price_result = client.check_existing_peril_premium(
        calculation, peril_id)
    print json.dumps(
        detailed_price_result, sort_keys=True, indent=4,
        separators=(',', ':')) + "\n"
Example #13
0
def main(argv):

    parser = argparse.ArgumentParser(description='Main Test Application')
    parser.add_argument('-n', '--hostname', required=True)
    parser.add_argument('-l', '--locator', required=True)
    parser.add_argument('-u',
                        '--username',
                        default='alice.lee',
                        required=False)
    parser.add_argument('-p', '--password', default='socotra', required=False)
    parser.add_argument('--environment',
                        '-e',
                        help='Environment',
                        choices=['sandbox', 'iag', 'perf'],
                        default='sandbox',
                        required=False)

    args = parser.parse_args(argv)

    policy_locator = args.locator

    with open('ref_driver.json', 'r') as f:
        driver = json.load(f)

    print('Authenticating with tenant: ' + args.hostname)
    environment = args.environment
    if environment == 'iag':
        url = 'https://api-iag.socotra.com'
    elif environment == 'perf':
        url = 'https://api-db-internal.socotra.com'
    else:
        url = 'https://api.sandbox.socotra.com'
    print(url)
    client = SocotraClient.get_authenticated_client_for_hostname(args.hostname,
                                                                 args.username,
                                                                 args.password,
                                                                 api_url=url,
                                                                 debug=False)

    en1_eff = dates.date_to_millis('01/04/2020', 'America/Los_Angeles',
                                   '%d/%m/%Y')
    policy_change = {"channel": "Agent"}
    en1 = client.create_endorsement(policy_locator,
                                    'generic',
                                    effective_timestamp=en1_eff,
                                    field_values=policy_change)
    print(json.dumps(en1))
    en1_locator = en1['locator']
    print(en1_locator)

    en1_price = client.price_endorsement(en1_locator)
    print(json.dumps(en1_price))
    print()
    en1 = client.get_endorsement(en1_locator)
    print(json.dumps(en1))

    accept_result = client.update_endorsement(en1_locator, action='accept')
    print(json.dumps(accept_result))
    print()
    en1 = client.get_endorsement(en1_locator)
    print(json.dumps(en1))
    print(en1['documents'][0]['url'])