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 makeSkinnyJwt(verticalType, classId, objectId, Globalname, Globalmrn, Globaldate, Globaldoctor, Globalhospital, Globalhospitalphone, Globalhospitaladdress, Globallocation, Globalservice): signedJwt = None classResourcePayload = None objectResourcePayload = None classResponse = None objectResponse = None try: # get class definition and object definition classResourcePayload, objectResourcePayload = getClassAndObjectDefinitions( verticalType, classId, objectId, classResourcePayload, objectResourcePayload, Globalname, Globalmrn, Globaldate, Globaldoctor, Globalhospital, Globalhospitalphone, Globalhospitaladdress, Globallocation, Globalservice) print('\nMaking REST call to insert class: (%s)' % (classId)) # 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.insertClass(verticalType, classResourcePayload) print('\nMaking REST call to insert object') # make authorized REST call to explicitly insert object into Google server. objectResponse = restMethods.insertObject(verticalType, objectResourcePayload) # continue based on insert 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 insert response. Will print out if object insert succeeds or not. Throws error if object resource is malformed, or if existing objectId's classId does not match the expected classId handleInsertCallStatusCode(objectResponse, "object", objectId, classId, verticalType) # put into JSON Web Token (JWT) format for Google Pay API for Passes googlePassJwt = jwt.googlePassJwt() # only need to add objectId in JWT because class and object definitions were pre-inserted via REST call loadObjectIntoJWT(verticalType, googlePassJwt, {"id": objectId}) # sign JSON to make signed JWT signedJwt = googlePassJwt.generateSignedJwt() except ValueError as err: print(err.args) # return "skinny" 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 makeObjectJwt(verticalType, classId, objectId): signedJwt = None classResourcePayload = None objectResourcePayload = None classResponse = None objectResponse = None try: # get class definition and object definition classResourcePayload, objectResourcePayload = getClassAndObjectDefinitions( verticalType, classId, objectId, classResourcePayload, objectResourcePayload) 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.insertClass(verticalType, classResourcePayload) # check if object ID exist objectResponse = restMethods.getObject( verticalType, objectId) # if it is a new object Id, expected status is 409 # 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, verticalType) # 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() loadObjectIntoJWT(verticalType, googlePassJwt, objectResourcePayload) # 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: # get class definition and object definition classResourcePayload, objectResourcePayload = getClassAndObjectDefinitions( verticalType, classId, objectId, classResourcePayload, objectResourcePayload) # 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.getClass(verticalType, classId) objectResponse = restMethods.getObject(verticalType, objectId) # 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() # need to add both class and object resource definitions into JWT because no REST calls made to pre-insert loadClassIntoJWT(verticalType, googlePassJwt, classResourcePayload) loadObjectIntoJWT(verticalType, googlePassJwt, objectResourcePayload) # 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