-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[in_app_purchase] migrate playing billing library to v3 #3636
Changes from all commits
d73dcc5
ea34ac4
d6e49d3
34ecb8b
65a3cbd
102d7cd
d6b65db
df3a45b
822e631
ac4348c
99b4eef
763360d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,9 @@ android { | |
|
||
dependencies { | ||
implementation 'androidx.annotation:annotation:1.0.0' | ||
implementation 'com.android.billingclient:billing:2.0.3' | ||
implementation 'com.android.billingclient:billing:3.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
testImplementation 'org.mockito:mockito-core:2.17.0' | ||
testImplementation 'org.mockito:mockito-core:3.6.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required to mock the objects in the new PBL. |
||
androidTestImplementation 'androidx.test:runner:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import static java.util.stream.Collectors.toList; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.contains; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
|
@@ -60,6 +61,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.json.JSONException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
@@ -79,7 +81,7 @@ public class MethodCallHandlerTest { | |
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
MockitoAnnotations.openMocks(this); | ||
factory = | ||
(@NonNull Context context, | ||
@NonNull MethodChannel channel, | ||
|
@@ -261,14 +263,18 @@ public void querySkuDetailsAsync_clientDisconnected() { | |
verify(result, never()).success(any()); | ||
} | ||
|
||
// Test launchBillingFlow not crash if `accountId` is `null` | ||
// Ideally, we should check if the `accountId` is null in the parameter; however, | ||
// since PBL 3.0, the `accountId` variable is not public. | ||
@Test | ||
public void launchBillingFlow_ok_null_AccountId() { | ||
public void launchBillingFlow_null_AccountId_do_not_crash() { | ||
// Fetch the sku details first and then prepare the launch billing flow call | ||
String skuId = "foo"; | ||
queryForSkus(singletonList(skuId)); | ||
HashMap<String, Object> arguments = new HashMap<>(); | ||
arguments.put("sku", skuId); | ||
arguments.put("accountId", null); | ||
arguments.put("obfuscatedProfileId", null); | ||
MethodCall launchCall = new MethodCall(LAUNCH_BILLING_FLOW, arguments); | ||
|
||
// Launch the billing flow | ||
|
@@ -286,7 +292,6 @@ public void launchBillingFlow_ok_null_AccountId() { | |
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture()); | ||
BillingFlowParams params = billingFlowParamsCaptor.getValue(); | ||
assertEquals(params.getSku(), skuId); | ||
assertNull(params.getAccountId()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getAccountId is not available anymore so we can't really test this value, however, we can still test if the call crashes, so ill leave the test here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename the test then, to better explain what it's doing now? (Probably needs a comment in addition to a new name.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
// Verify we pass the response code to result | ||
verify(result, never()).error(any(), any(), any()); | ||
|
@@ -320,7 +325,6 @@ public void launchBillingFlow_ok_null_OldSku() { | |
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture()); | ||
BillingFlowParams params = billingFlowParamsCaptor.getValue(); | ||
assertEquals(params.getSku(), skuId); | ||
assertEquals(params.getAccountId(), accountId); | ||
assertNull(params.getOldSku()); | ||
// Verify we pass the response code to result | ||
verify(result, never()).error(any(), any(), any()); | ||
|
@@ -374,7 +378,6 @@ public void launchBillingFlow_ok_oldSku() { | |
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture()); | ||
BillingFlowParams params = billingFlowParamsCaptor.getValue(); | ||
assertEquals(params.getSku(), skuId); | ||
assertEquals(params.getAccountId(), accountId); | ||
assertEquals(params.getOldSku(), oldSkuId); | ||
|
||
// Verify we pass the response code to result | ||
|
@@ -408,7 +411,6 @@ public void launchBillingFlow_ok_AccountId() { | |
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture()); | ||
BillingFlowParams params = billingFlowParamsCaptor.getValue(); | ||
assertEquals(params.getSku(), skuId); | ||
assertEquals(params.getAccountId(), accountId); | ||
|
||
// Verify we pass the response code to result | ||
verify(result, never()).error(any(), any(), any()); | ||
|
@@ -420,13 +422,15 @@ public void launchBillingFlow_ok_Proration() { | |
// Fetch the sku details first and query the method call | ||
String skuId = "foo"; | ||
String oldSkuId = "oldFoo"; | ||
String purchaseToken = "purchaseTokenFoo"; | ||
String accountId = "account"; | ||
int prorationMode = BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE; | ||
queryForSkus(unmodifiableList(asList(skuId, oldSkuId))); | ||
HashMap<String, Object> arguments = new HashMap<>(); | ||
arguments.put("sku", skuId); | ||
arguments.put("accountId", accountId); | ||
arguments.put("oldSku", oldSkuId); | ||
arguments.put("purchaseToken", purchaseToken); | ||
arguments.put("prorationMode", prorationMode); | ||
MethodCall launchCall = new MethodCall(LAUNCH_BILLING_FLOW, arguments); | ||
|
||
|
@@ -445,8 +449,8 @@ public void launchBillingFlow_ok_Proration() { | |
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture()); | ||
BillingFlowParams params = billingFlowParamsCaptor.getValue(); | ||
assertEquals(params.getSku(), skuId); | ||
assertEquals(params.getAccountId(), accountId); | ||
assertEquals(params.getOldSku(), oldSkuId); | ||
assertEquals(params.getOldSkuPurchaseToken(), purchaseToken); | ||
assertEquals(params.getReplaceSkusProrationMode(), prorationMode); | ||
|
||
// Verify we pass the response code to result | ||
|
@@ -668,11 +672,7 @@ public void consumeAsync() { | |
|
||
methodChannelHandler.onMethodCall(new MethodCall(CONSUME_PURCHASE_ASYNC, arguments), result); | ||
|
||
ConsumeParams params = | ||
ConsumeParams.newBuilder() | ||
.setDeveloperPayload("mockPayload") | ||
.setPurchaseToken("mockToken") | ||
.build(); | ||
ConsumeParams params = ConsumeParams.newBuilder().setPurchaseToken("mockToken").build(); | ||
|
||
// Verify we pass the data to result | ||
verify(mockBillingClient).consumeAsync(refEq(params), listenerCaptor.capture()); | ||
|
@@ -703,10 +703,7 @@ public void acknowledgePurchase() { | |
methodChannelHandler.onMethodCall(new MethodCall(ACKNOWLEDGE_PURCHASE, arguments), result); | ||
|
||
AcknowledgePurchaseParams params = | ||
AcknowledgePurchaseParams.newBuilder() | ||
.setDeveloperPayload("mockPayload") | ||
.setPurchaseToken("mockToken") | ||
.build(); | ||
AcknowledgePurchaseParams.newBuilder().setPurchaseToken("mockToken").build(); | ||
|
||
// Verify we pass the data to result | ||
verify(mockBillingClient).acknowledgePurchase(refEq(params), listenerCaptor.capture()); | ||
|
@@ -774,6 +771,7 @@ private void queryForSkus(List<String> skusList) { | |
verify(mockBillingClient).querySkuDetailsAsync(any(), listenerCaptor.capture()); | ||
List<SkuDetails> skuDetailsResponse = | ||
skusList.stream().map(this::buildSkuDetails).collect(toList()); | ||
|
||
BillingResult billingResult = | ||
BillingResult.newBuilder() | ||
.setResponseCode(100) | ||
|
@@ -783,8 +781,16 @@ private void queryForSkus(List<String> skusList) { | |
} | ||
|
||
private SkuDetails buildSkuDetails(String id) { | ||
SkuDetails details = mock(SkuDetails.class); | ||
when(details.getSku()).thenReturn(id); | ||
String json = | ||
String.format( | ||
"{\"packageName\": \"dummyPackageName\",\"productId\":\"%s\",\"type\":\"inapp\",\"price\":\"$0.99\",\"price_amount_micros\":990000,\"price_currency_code\":\"USD\",\"title\":\"Example title\",\"description\":\"Example description.\",\"original_price\":\"$0.99\",\"original_price_micros\":990000}", | ||
id); | ||
SkuDetails details = null; | ||
try { | ||
details = new SkuDetails(json); | ||
} catch (JSONException e) { | ||
fail("buildSkuDetails failed with JSONException " + e.toString()); | ||
} | ||
return details; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any useful context to provide about why they are removed? E.g., link to discussion of removal in the SDK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added