o
    	i                     @   sB   d dl mZ d dlmZ d dlmZ d dlmZ G dd dZdS )    )settings)build)service_account)loggerc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	GooglePlayVerifierau  Google Play in-app purchase/subscription verification via AndroidPublisher API.
    Requires a service account JSON and the Android Publisher API enabled in google console.
    Environment variables expected (set in settings or env):
    - ANDROID_PACKAGE (e.g., 'com.app.projectname')
    - GOOGLE_APPLICATION_CREDENTIALS (path to service account JSON) in settings.py
    c                 C   s,   dg}t jjtj|d}tdd|d| _d S )Nz0https://www.googleapis.com/auth/androidpublisher)filenamescopesandroidpublisherv3)credentials)r   Credentialsfrom_service_account_filer   GOOGLE_PLAY_SERVICE_ACCOUNTr   service)selfSCOPESr    r   +/var/www/html/premium_crap/api/googlepay.py__init__   s   zGooglePlayVerifier.__init__c              
   C   sx   z| j   jtj|d }td d|dW S  t	y; } ztd|  dt
|dW  Y d }~S d }~ww )N)packageNametokenz%Google verify_subscription succeeded.TisSuccessfulpayloadz%Error in Google verify_subscription: Fr   errorMessage)r   	purchasessubscriptionsv2getr   PACKAGE_NAMEexecuter   info	Exceptionstr)r   
product_idpurchase_tokensubscriptioner   r   r   verify_subscription   s   
z&GooglePlayVerifier.verify_subscriptionc              
   C   sv   z| j   jtj||d }td| d|dW S  t	y: } zt
|d dt|dW  Y d }~S d }~ww )N)r   	productIdr   zGoogle inapp payload: %sTr   z>>>>>>>>>>>>>>>>>>>>>>ERRORFr   )r   r   productsr   r   r   r    r   r!   r"   printr#   )r   r$   r%   inappr'   r   r   r   verify_inapp$   s   

zGooglePlayVerifier.verify_inappN)__name__
__module____qualname____doc__r   r(   r-   r   r   r   r   r      s
    r   N)	django.confr   googleapiclient.discoveryr   google.oauth2r   core.loggerr   r   r   r   r   r   <module>   s
    