Skip to content

Can not pass verifyNotification because bundleId and environment not be set from new notification version #370

@nicolasopt

Description

@nicolasopt

Hi @alexanderjordanbaker,

Thanks for your team hard working on this library !

I have a problem when I upgrade in-app purchase to newest version with new jwt purchaseToken. I need verify it to see purchase information by verifyAndDecodeNotification method.

But it always can not pass verifyNotification step because the decodedJWT object is not ResponseBodyV2DecodedPayload object interface.

the decodedJWT look like ResponseBodyV2DecodedPayload.data

This is the output of decodedJWT :

Image

So, the bundleId, appAppleId, environment can not be set from decodedJWT. Then they goto verifyNotification method to compare always throw error.

async verifyAndDecodeNotification(signedPayload) {
        const decodedJWT = await this.verifyJWT(signedPayload, this.responseBodyV2DecodedPayloadValidator, this.extractSignedDate);
        let appAppleId;
        let bundleId;
        let environment;
        if (decodedJWT.data) {
            appAppleId = decodedJWT.data.appAppleId;
            bundleId = decodedJWT.data.bundleId;
            environment = decodedJWT.data.environment;
        }
        else if (decodedJWT.summary) {
            appAppleId = decodedJWT.summary.appAppleId;
            bundleId = decodedJWT.summary.bundleId;
            environment = decodedJWT.summary.environment;
        }
        else if (decodedJWT.externalPurchaseToken) {
            appAppleId = decodedJWT.externalPurchaseToken.appAppleId;
            bundleId = decodedJWT.externalPurchaseToken.bundleId;
            if (decodedJWT.externalPurchaseToken.externalPurchaseId && decodedJWT.externalPurchaseToken.externalPurchaseId.startsWith("SANDBOX")) {
                environment = Environment_1.Environment.SANDBOX;
            }
            else {
                environment = Environment_1.Environment.PRODUCTION;
            }
        }
        this.verifyNotification(bundleId, appAppleId, environment);
        return decodedJWT;
    }
    verifyNotification(bundleId, appAppleId, environment) {
        if (this.bundleId !== bundleId || (this.environment === Environment_1.Environment.PRODUCTION && this.appAppleId !== appAppleId)) {
            throw new VerificationException(VerificationStatus.INVALID_APP_IDENTIFIER);
        }
        if (this.environment !== environment) {
            throw new VerificationException(VerificationStatus.INVALID_ENVIRONMENT);
        }
    }

So, please update the output decodedJWT to support token data at the top object not only in decodedJWT.data .

Also, when I test with sandbox token no appAppleId return in decodedJWT, so please update the comparation appAppleId and environment only when appAppleId exist in decodedJWT.

Thank in advance !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions