Example #1
0
def getClassAndObjectDefinitions(verticalType, classId, objectId,
                                 classResourcePayload, objectResourcePayload):
    # get class definition and object definition
    if verticalType == VerticalType.FLIGHT:
        classResourcePayload = resourceDefinitions.makeFlightClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeFlightObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.EVENTTICKET:
        classResourcePayload = resourceDefinitions.makeEventTicketClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeEventTicketObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.GIFTCARD:
        classResourcePayload = resourceDefinitions.makeGiftCardClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeGiftCardObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.LOYALTY:
        classResourcePayload = resourceDefinitions.makeLoyaltyClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeLoyaltyObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.OFFER:
        classResourcePayload = resourceDefinitions.makeOfferClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeOfferObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.TRANSIT:
        classResourcePayload = resourceDefinitions.makeTransitClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeTransitObjectResource(
            classId, objectId)
    return classResourcePayload, objectResourcePayload
def makeObjectJwt(verticalType, classId, objectId):
    signedJwt = None
    classResourcePayload = None
    objectResourcePayload = None
    classResponse = None
    objectResponse = None

    try:
        if verticalType == VerticalType.OFFER:
            # get class definition
            classResourcePayload = resourceDefinitions.makeOfferClassResource(
                classId)

            # get object definition
            objectResourcePayload = resourceDefinitions.makeOfferObjectResource(
                classId, objectId)

            print('\nMaking REST call to insert class')
            # make authorized REST call to explicitly insert class into Google server.
            # if this is successful, you can check/update class definitions in Merchant Center GUI: https://pay.google.com/gp/m/issuer/list
            classResponse = restMethods.insertOfferClass(classResourcePayload)

            # check if object ID exist
            objectResponse = restMethods.getOfferObject(
                objectId)  # if it is a new object Id, expected status is 409
        else:
            raise ValueError(
                "resource definition for vertical: (%s) not implemented yet. Check README.md > Implementing other verticals"
                % (verticalType))

        # continue based on response status. Check https://developers.google.com/pay/passes/reference/v1/statuscodes
        # check class insert response. Will print out if class insert succeeds or not. Throws error if class resource is malformed.
        handleInsertCallStatusCode(classResponse, "class", classId, None, None)

        # check object get response. Will print out if object exists or not. Throws error if object resource is malformed, or if existing objectId's classId does not match the expected classId
        handleGetCallStatusCode(objectResponse, "object", objectId, classId)

        # put into JSON Web Token (JWT) format for Google Pay API for Passes
        googlePassJwt = jwt.googlePassJwt()
        if verticalType == VerticalType.OFFER:
            # only need to add object resource definition in JWT because class was pre-inserted via REST call
            googlePassJwt.addOfferObject(objectResourcePayload)
        else:
            raise ValueError(
                'JWT format for %s is not implemented yet. For proper JWT format, check %s'
                %
                (verticalType,
                 'https://developers.google.com/pay/passes/reference/s2w-reference#google-pay-api-for-passes-jwt'
                 ))

        # sign JSON to make signed JWT
        signedJwt = googlePassJwt.generateSignedJwt()

    except ValueError as err:
        print(err.args)

    # return "object" JWT. Try putting it into save link.
    # See https://developers.google.com/pay/passes/guides/get-started/implementing-the-api/save-to-google-pay#add-link-to-email
    return signedJwt
def makeFatJwt(verticalType, classId, objectId):
    signedJwt = None
    classResourcePayload = None
    objectResourcePayload = None
    classResponse = None
    objectResponse = None

    try:
        if verticalType == VerticalType.OFFER:
            # get class definition
            classResourcePayload = resourceDefinitions.makeOfferClassResource(
                classId)

            # get object definition
            objectResourcePayload = resourceDefinitions.makeOfferObjectResource(
                classId, objectId)

            # see if Ids exist in Google backend
            ## for a Fat JWT, the first time a user hits the save button, the class and object are inserted
            classResponse = restMethods.getOfferClass(classId)
            objectResponse = restMethods.getOfferObject(objectId)
        else:
            raise ValueError(
                "resource definition for vertical: (%s) not implemented yet. Check README.md > Implementing other verticals"
                % (verticalType))

        # check response status. Check https://developers.google.com/pay/passes/reference/v1/statuscodes
        # check class get response. Will print out if class exists or not. Throws error if class resource is malformed.
        handleGetCallStatusCode(classResponse, "class", classId, None)

        # check object get response. Will print out if object exists or not. Throws error if object resource is malformed, or if existing objectId's classId does not match the expected classId
        handleGetCallStatusCode(objectResponse, "object", objectId, classId)

        # put into JSON Web Token (JWT) format for Google Pay API for Passes
        googlePassJwt = jwt.googlePassJwt()
        if verticalType == VerticalType.OFFER:
            # need to add both class and object resource definitions into JWT because no REST calls made to pre-insert
            googlePassJwt.addOfferClass(classResourcePayload)
            googlePassJwt.addOfferObject(objectResourcePayload)
        else:
            raise ValueError(
                'JWT format for %s is not implemented yet. For proper JWT format, check %s'
                %
                (verticalType,
                 'https://developers.google.com/pay/passes/reference/s2w-reference#google-pay-api-for-passes-jwt'
                 ))

        # sign JSON to make signed JWT
        signedJwt = googlePassJwt.generateSignedJwt()

    except ValueError as err:
        print(err.args)

    # return "fat" JWT. Try putting it into JS web button
    # note button needs to be rendered in local web server who's domain matched the ORIGINS
    # defined in the JWT. See https://developers.google.com/pay/passes/reference/s2w-reference
    return signedJwt
def getClassAndObjectDefinitions(verticalType, classId, objectId,
                                 classResourcePayload, objectResourcePayload,
                                 Globalname, Globalmrn, Globaldate,
                                 Globaldoctor, Globalhospital,
                                 Globalhospitalphone, Globalhospitaladdress,
                                 Globallocation, Globalservice):
    # get class definition and object definition
    if verticalType == VerticalType.FLIGHT:
        classResourcePayload = resourceDefinitions.makeFlightClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeFlightObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.EVENTTICKET:
        classResourcePayload = resourceDefinitions.makeEventTicketClassResource(
            classId, Globalname, Globalmrn, Globaldate, Globaldoctor,
            Globalhospital, Globalhospitalphone, Globalhospitaladdress,
            Globallocation, Globalservice)
        objectResourcePayload = resourceDefinitions.makeEventTicketObjectResource(
            classId, objectId, Globalname, Globalmrn, Globaldate, Globaldoctor,
            Globalhospital, Globallocation, Globalservice)
    elif verticalType == VerticalType.GIFTCARD:
        classResourcePayload = resourceDefinitions.makeGiftCardClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeGiftCardObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.LOYALTY:
        classResourcePayload = resourceDefinitions.makeLoyaltyClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeLoyaltyObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.OFFER:
        classResourcePayload = resourceDefinitions.makeOfferClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeOfferObjectResource(
            classId, objectId)
    elif verticalType == VerticalType.TRANSIT:
        classResourcePayload = resourceDefinitions.makeTransitClassResource(
            classId)
        objectResourcePayload = resourceDefinitions.makeTransitObjectResource(
            classId, objectId)
    return classResourcePayload, objectResourcePayload