forked from anjlab/android-inapp-billing-v3
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for GetPurchaseHistory (anjlab#414)
* New API for BillingProcessor: isRequestBillingHistorySupported - to check if request purchase history supported getPurchaseHistory - to request purchase history * Updated code according to checkstyle * Updated README to cover new API with getPurchaseHistory.
- Loading branch information
Showing
7 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
library/src/androidTest/java/com/anjlab/android/iab/v3/BillingHistoryRecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.anjlab.android.iab.v3; | ||
|
||
import android.os.Parcel; | ||
|
||
import com.anjlab.android.iab.v3.util.ResourcesUtil; | ||
|
||
import org.json.JSONException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static junit.framework.Assert.assertEquals; | ||
|
||
public class BillingHistoryRecordTest | ||
{ | ||
|
||
private String historyResponseJson; | ||
|
||
@Before | ||
public void setup() | ||
{ | ||
historyResponseJson = ResourcesUtil.loadFile("purchase_history_response.json"); | ||
} | ||
|
||
@Test | ||
public void testCreatesFromJsonCorrectly() throws JSONException | ||
{ | ||
BillingHistoryRecord record = new BillingHistoryRecord(historyResponseJson, "signature"); | ||
|
||
assertEquals("sample-product-id", record.productId); | ||
assertEquals("sample-purchase-token", record.purchaseToken); | ||
assertEquals(1563441231403L, record.purchaseTime); | ||
assertEquals("sample-developer-payload", record.developerPayload); | ||
assertEquals("signature", record.signature); | ||
} | ||
|
||
@Test | ||
public void testParcelizesCorrectly() throws JSONException | ||
{ | ||
BillingHistoryRecord record = new BillingHistoryRecord(historyResponseJson, "signature"); | ||
|
||
Parcel parcel = Parcel.obtain(); | ||
record.writeToParcel(parcel, 0); | ||
parcel.setDataPosition(0); | ||
|
||
BillingHistoryRecord restoredRecord = BillingHistoryRecord.CREATOR.createFromParcel(parcel); | ||
assertEquals("sample-product-id", restoredRecord.productId); | ||
assertEquals("sample-purchase-token", restoredRecord.purchaseToken); | ||
assertEquals(1563441231403L, restoredRecord.purchaseTime); | ||
assertEquals("sample-developer-payload", restoredRecord.developerPayload); | ||
assertEquals("signature", restoredRecord.signature); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
library/src/androidTest/resources/purchase_history_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"productId":"sample-product-id", | ||
"purchaseToken":"sample-purchase-token", | ||
"purchaseTime":1563441231403, | ||
"developerPayload":"sample-developer-payload" | ||
} |
15 changes: 15 additions & 0 deletions
15
library/src/main/java/com/anjlab/android/iab/v3/BillingCommunicationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.anjlab.android.iab.v3; | ||
|
||
public class BillingCommunicationException extends Exception | ||
{ | ||
|
||
public BillingCommunicationException(Throwable cause) | ||
{ | ||
super(cause); | ||
} | ||
|
||
public BillingCommunicationException(String message) | ||
{ | ||
super(message); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
library/src/main/java/com/anjlab/android/iab/v3/BillingHistoryRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.anjlab.android.iab.v3; | ||
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public class BillingHistoryRecord implements Parcelable | ||
{ | ||
|
||
public final String productId; | ||
public final String purchaseToken; | ||
public final long purchaseTime; | ||
public final String developerPayload; | ||
public final String signature; | ||
|
||
public BillingHistoryRecord(String dataAsJson, String signature) throws JSONException | ||
{ | ||
this(new JSONObject(dataAsJson), signature); | ||
} | ||
|
||
public BillingHistoryRecord(JSONObject json, String signature) throws JSONException | ||
{ | ||
productId = json.getString("productId"); | ||
purchaseToken = json.getString("purchaseToken"); | ||
purchaseTime = json.getLong("purchaseTime"); | ||
developerPayload = json.getString("developerPayload"); | ||
this.signature = signature; | ||
} | ||
|
||
public BillingHistoryRecord(String productId, String purchaseToken, long purchaseTime, | ||
String developerPayload, String signature) | ||
{ | ||
this.productId = productId; | ||
this.purchaseToken = purchaseToken; | ||
this.purchaseTime = purchaseTime; | ||
this.developerPayload = developerPayload; | ||
this.signature = signature; | ||
} | ||
|
||
protected BillingHistoryRecord(Parcel in) | ||
{ | ||
productId = in.readString(); | ||
purchaseToken = in.readString(); | ||
purchaseTime = in.readLong(); | ||
developerPayload = in.readString(); | ||
signature = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) | ||
{ | ||
dest.writeString(productId); | ||
dest.writeString(purchaseToken); | ||
dest.writeLong(purchaseTime); | ||
dest.writeString(developerPayload); | ||
dest.writeString(signature); | ||
} | ||
|
||
@Override | ||
public int describeContents() | ||
{ | ||
return 0; | ||
} | ||
|
||
public static final Creator<BillingHistoryRecord> CREATOR = new Creator<BillingHistoryRecord>() | ||
{ | ||
@Override | ||
public BillingHistoryRecord createFromParcel(Parcel in) | ||
{ | ||
return new BillingHistoryRecord(in); | ||
} | ||
|
||
@Override | ||
public BillingHistoryRecord[] newArray(int size) | ||
{ | ||
return new BillingHistoryRecord[size]; | ||
} | ||
}; | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "BillingHistoryRecord{" + | ||
"productId='" + productId + '\'' + | ||
", purchaseToken='" + purchaseToken + '\'' + | ||
", purchaseTime=" + purchaseTime + | ||
", developerPayload='" + developerPayload + '\'' + | ||
", signature='" + signature + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters