1 |
torben |
2123 |
/* Copyright (c) 2012 Google Inc. |
2 |
|
|
* |
3 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
4 |
|
|
* you may not use this file except in compliance with the License. |
5 |
|
|
* You may obtain a copy of the License at |
6 |
|
|
* |
7 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
8 |
|
|
* |
9 |
|
|
* Unless required by applicable law or agreed to in writing, software |
10 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
11 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 |
|
|
* See the License for the specific language governing permissions and |
13 |
|
|
* limitations under the License. |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
package com.example.android.trivialdrivesample.util; |
17 |
|
|
|
18 |
|
|
import org.json.JSONException; |
19 |
|
|
import org.json.JSONObject; |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* Represents an in-app billing purchase. |
23 |
|
|
*/ |
24 |
|
|
public class Purchase { |
25 |
|
|
String mItemType; // ITEM_TYPE_INAPP or ITEM_TYPE_SUBS |
26 |
|
|
String mOrderId; |
27 |
|
|
String mPackageName; |
28 |
|
|
String mSku; |
29 |
|
|
long mPurchaseTime; |
30 |
|
|
int mPurchaseState; |
31 |
|
|
String mDeveloperPayload; |
32 |
|
|
String mToken; |
33 |
|
|
String mOriginalJson; |
34 |
|
|
String mSignature; |
35 |
|
|
|
36 |
|
|
public Purchase(String itemType, String jsonPurchaseInfo, String signature) throws JSONException { |
37 |
|
|
mItemType = itemType; |
38 |
|
|
mOriginalJson = jsonPurchaseInfo; |
39 |
|
|
JSONObject o = new JSONObject(mOriginalJson); |
40 |
|
|
mOrderId = o.optString("orderId"); |
41 |
|
|
mPackageName = o.optString("packageName"); |
42 |
|
|
mSku = o.optString("productId"); |
43 |
|
|
mPurchaseTime = o.optLong("purchaseTime"); |
44 |
|
|
mPurchaseState = o.optInt("purchaseState"); |
45 |
|
|
mDeveloperPayload = o.optString("developerPayload"); |
46 |
|
|
mToken = o.optString("token", o.optString("purchaseToken")); |
47 |
|
|
mSignature = signature; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
public String getItemType() { return mItemType; } |
51 |
|
|
public String getOrderId() { return mOrderId; } |
52 |
|
|
public String getPackageName() { return mPackageName; } |
53 |
|
|
public String getSku() { return mSku; } |
54 |
|
|
public long getPurchaseTime() { return mPurchaseTime; } |
55 |
|
|
public int getPurchaseState() { return mPurchaseState; } |
56 |
|
|
public String getDeveloperPayload() { return mDeveloperPayload; } |
57 |
|
|
public String getToken() { return mToken; } |
58 |
|
|
public String getOriginalJson() { return mOriginalJson; } |
59 |
|
|
public String getSignature() { return mSignature; } |
60 |
|
|
|
61 |
|
|
@Override |
62 |
|
|
public String toString() { return "PurchaseInfo(type:" + mItemType + "):" + mOriginalJson; } |
63 |
|
|
} |