Search in sources :

Example 1 with MarketplaceConnectBodyData

use of com.zype.fire.api.Model.MarketplaceConnectBodyData in project zype-firebuilder by zype.

the class ZypeReceiptVerificationService method validateReceipt.

/**
 * {@inheritDoc}
 */
@Override
public String validateReceipt(Context context, String requestId, String sku, UserData userData, Receipt receipt, IPurchase.PurchaseListener listener) {
    // }
    if (ZypeConfiguration.marketplaceConnectSvodEnabled(context)) {
        Log.i(TAG, "validateReceipt(): Subscription");
        MarketplaceConnectBody body = new MarketplaceConnectBody();
        body.amount = "";
        body.appId = ZypeConfiguration.getAppId(context);
        body.consumerId = Preferences.getString("ZypeConsumerId");
        body.planId = receipt.getExtras().getString("PlanId");
        body.siteId = ZypeConfiguration.getSiteId(context);
        body.transactionType = "subscription";
        MarketplaceConnectBodyData bodyData = new MarketplaceConnectBodyData();
        bodyData.receiptId = receipt.getReceiptId();
        bodyData.userId = userData.getUserId();
        body.data = bodyData;
        Log.i(TAG, "validateReceipt(): body=" + (new Gson()).toJson(body));
        try {
            retrofit2.Response response = ZypeApi.getInstance().getApi().verifySubscriptionPurchaseAmazon(body).execute();
            if (response.isSuccessful()) {
                Log.i(TAG, "validateReceipt(): Receipt is valid");
                Response purchaseResponse = new Response(requestId, Response.Status.SUCCESSFUL, null);
                listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, true, userData);
                return requestId;
            } else {
                Log.i(TAG, "validateReceipt(): Receipt is not valid");
                Response purchaseResponse = new Response(requestId, Response.Status.FAILED, null);
                listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, false, userData);
                return requestId;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Log.i(TAG, "validateReceipt(): Error marketplace connect call");
            Response purchaseResponse = new Response(requestId, Response.Status.FAILED, null);
            listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, false, userData);
            return requestId;
        }
    } else if (ZypeConfiguration.isUniversalTVODEnabled(context)) {
        MarketplaceConnectBody body = new MarketplaceConnectBody();
        body.amount = "";
        body.appId = ZypeConfiguration.getAppId(context);
        body.consumerId = Preferences.getString("ZypeConsumerId");
        body.playlistId = receipt.getExtras().getString("PlaylistId");
        body.siteId = ZypeConfiguration.getSiteId(context);
        body.transactionType = "purchase";
        body.productId = receipt.getExtras().getString("VideoId");
        body.videoId = receipt.getExtras().getString("VideoId");
        MarketplaceConnectBodyData bodyData = new MarketplaceConnectBodyData();
        bodyData.receiptId = receipt.getReceiptId();
        bodyData.userId = userData.getUserId();
        body.data = bodyData;
        Log.i(TAG, "validateReceipt(): body=" + (new Gson()).toJson(body));
        try {
            retrofit2.Response response = ZypeApi.getInstance().getApi().verifyPurchaseAmazon(body).execute();
            if (response.isSuccessful()) {
                Log.i(TAG, "validateReceipt(): Receipt is valid");
                Response purchaseResponse = new Response(requestId, Response.Status.SUCCESSFUL, null);
                listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, true, userData);
                return requestId;
            } else {
                Log.i(TAG, "validateReceipt(): Receipt is not valid");
                // Response purchaseResponse = new Response(requestId, Response.Status.SUCCESSFUL, null);
                // listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, true, userData);
                Response purchaseResponse = new Response(requestId, Response.Status.FAILED, null);
                listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, false, userData);
                return requestId;
            }
        } catch (IOException e) {
            e.printStackTrace();
            Log.i(TAG, "validateReceipt(): Error marketplace connect call");
            Response purchaseResponse = new Response(requestId, Response.Status.FAILED, null);
            listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, false, userData);
            return requestId;
        }
    } else {
        Response purchaseResponse = new Response(requestId, Response.Status.SUCCESSFUL, null);
        listener.isPurchaseValidResponse(purchaseResponse, sku, receipt, true, userData);
        return requestId;
    }
}
Also used : Response(com.amazon.purchase.model.Response) MarketplaceConnectBodyData(com.zype.fire.api.Model.MarketplaceConnectBodyData) Gson(com.google.gson.Gson) IOException(java.io.IOException) MarketplaceConnectBody(com.zype.fire.api.Model.MarketplaceConnectBody)

Aggregations

Response (com.amazon.purchase.model.Response)1 Gson (com.google.gson.Gson)1 MarketplaceConnectBody (com.zype.fire.api.Model.MarketplaceConnectBody)1 MarketplaceConnectBodyData (com.zype.fire.api.Model.MarketplaceConnectBodyData)1 IOException (java.io.IOException)1