Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] It does not work #86

Open
vporton opened this issue Apr 11, 2023 · 1 comment
Open

[BUG] It does not work #86

vporton opened this issue Apr 11, 2023 · 1 comment
Labels

Comments

@vporton
Copy link

vporton commented Apr 11, 2023

In my case the purchase is never validated:
https://stackoverflow.com/q/75766712/856090

@vporton vporton added the bug label Apr 11, 2023
@vporton
Copy link
Author

vporton commented Apr 11, 2023

import json

from flask import request, jsonify
from inapppy import GooglePlayVerifier, errors

from common import app, config, OurDB, fund_account


try:
    with open("google_credentials.json") as f:
        google_credentials = json.load(f)
except FileNotFoundError:
    google_credentials = None


@app.route('/google_play_purchase', methods=['POST'])
def playmarket_purchase():
    """Send by the client to notify that a product was purchased."""
    if google_credentials is None:
        app.logger.error("No Google credentials file!")
        return "No Google credentials file!", 500

    purchase_token = request.form['purchaseToken']
    product_sku = request.form['productId']
    app_guid = request.form['appGuid']

    verifier = GooglePlayVerifier(
        config['android']['bundleId'],
        google_credentials,
    )
    try:
        result = verifier.verify(
            purchase_token,
            product_sku,
            is_subscription=False,
        )
    except errors.GoogleError as exc:
        app.logger.error('Purchase validation failed {}'.format(exc))
        return jsonify(success=False, reason='validationFailed'), 402  # payment required
    try:
        amount = config['products'][product_sku]['amount'] * result['quantity']
    except KeyError:
        app.logger.error("ERROR: Unknown product!!")
        return jsonify(success=False, reason='unknownProduct'), 400   # bad request
    with OurDB() as our_db:
        fund_account(our_db, app_guid, amount)
        # FIXME: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.products/consume
    return jsonify(success=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant