/*
 * Copyright 2012-2015 One Platform Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onepf.opfiab.google.model;

import android.support.annotation.NonNull;

import org.json.JSONException;
import org.json.JSONObject;

public class GooglePurchase extends GoogleModel {

    private static final String NAME_ORDER_ID = "orderId";
    private static final String NAME_PACKAGE_NAME = "packageName";
    private static final String NAME_DEVELOPER_PAYLOAD = "purchaseTime";
    private static final String NAME_PURCHASE_TOKEN = "purchaseState";
    private static final String NAME_PURCHASE_STATE = "productId";
    private static final String NAME_PURCHASE_TIME = "developerPayload";
    private static final String NAME_AUTO_RENEWING = "autoRenewing";


    @NonNull
    private final String orderId;
    @NonNull
    private final String packageName;
    @NonNull
    private final String developerPayload;
    @NonNull
    private final String purchaseToken;
    @NonNull
    private final PurchaseState purchaseState;
    private final long purchaseTime;
    private final boolean autoRenewing;


    public GooglePurchase(@NonNull final String originalJson, @NonNull final JSONObject jsonObject)
            throws JSONException {
        super(originalJson, jsonObject);
        this.orderId = jsonObject.getString(NAME_ORDER_ID);
        this.packageName = jsonObject.getString(NAME_PACKAGE_NAME);
        this.developerPayload = jsonObject.getString(NAME_DEVELOPER_PAYLOAD);
        this.purchaseToken = jsonObject.getString(NAME_PURCHASE_TOKEN);
        this.purchaseTime = jsonObject.getLong(NAME_PURCHASE_TIME);
        this.autoRenewing = jsonObject.getBoolean(NAME_AUTO_RENEWING);

        final int purchaseStateCode = jsonObject.getInt(NAME_PURCHASE_STATE);
        final PurchaseState purchaseState = PurchaseState.fromCode(purchaseStateCode);
        if (purchaseState == null) {
            throw new JSONException("Unrecognized purchase state: " + purchaseStateCode);
        }
        this.purchaseState = purchaseState;
    }

    public GooglePurchase(@NonNull final String originalJson)
            throws JSONException {
        this(originalJson, new JSONObject(originalJson));
    }


    @NonNull
    public String getOrderId() {
        return orderId;
    }

    @NonNull
    public String getPackageName() {
        return packageName;
    }

    @NonNull
    public String getDeveloperPayload() {
        return developerPayload;
    }

    @NonNull
    public String getPurchaseToken() {
        return purchaseToken;
    }

    @NonNull
    public PurchaseState getPurchaseState() {
        return purchaseState;
    }

    public long getPurchaseTime() {
        return purchaseTime;
    }

    public boolean isAutoRenewing() {
        return autoRenewing;
    }
}

@@ -688,16 +688,60 @@
 NonNull;
+%0Aimport android.support.annotation.Nullable;
 %0A%0Aimport
@@ -1441,64 +1441,8 @@
 ull%0A
-    private final String developerPayload;%0A    @NonNull%0A
     
@@ -1533,24 +1533,81 @@
 chaseState;%0A
+    @Nullable%0A    private final String developerPayload;%0A
     private 
@@ -1981,86 +1981,8 @@
 E);%0A
-        this.developerPayload = jsonObject.getString(NAME_DEVELOPER_PAYLOAD);%0A
     
@@ -2187,16 +2187,174 @@
 NEWING);
+%0A        this.developerPayload = jsonObject.has(NAME_DEVELOPER_PAYLOAD)%0A                ? jsonObject.optString(NAME_DEVELOPER_PAYLOAD)%0A                : null;
 %0A%0A      
@@ -3029,103 +3029,8 @@
  %7D%0A%0A
-    @NonNull%0A    public String getDeveloperPayload() %7B%0A        return developerPayload;%0A    %7D%0A%0A
     
@@ -3169,24 +3169,24 @@
 seState() %7B%0A
-
         retu
@@ -3202,32 +3202,128 @@
 seState;%0A    %7D%0A%0A
+    @Nullable%0A    public String getDeveloperPayload() %7B%0A        return developerPayload;%0A    %7D%0A%0A
     public long 

Fix GooglePurchase model.