Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to android billing client 4.0.0 #326

Merged
merged 11 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Flutter CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: "14.x"

- uses: subosito/flutter-action@v1
with:
channel: "stable"
flutter-version: "2.x"

- run: flutter pub get

- run: flutter format --set-exit-if-changed .

# - run: flutter analyze .

- run: flutter test --coverage

- name: Coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GH_TOKEN }}
path-to-lcov: coverage/lcov.info

- run: flutter build apk

# Upload generated apk to the artifacts.
# - uses: actions/upload-artifact@v1
# with:
# name: release-apk
# path: build/app/outputs/apk/release/app-release.apk
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ flutter_inapp_android.iml
flutter_export_environment*
launch.json
.flutter-plugins-*

coverage
90 changes: 0 additions & 90 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 5.1.0

- Upgrade android billing client to `4.0.0` (#326)

- Remove `orderId` in `Purchase`
- This is duplicate of `transactionId`.

## 5.0.4

- Add iOS promo codes (#325)
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# flutter_inapp_purchase

[![Pub Version](https://img.shields.io/pub/v/flutter_inapp_purchase.svg?style=flat-square)](https://pub.dartlang.org/packages/flutter_inapp_purchase)
[![Build Status](https://travis-ci.com/dooboolab/flutter_inapp_purchase.svg?branch=master)](https://travis-ci.com/dooboolab/flutter_inapp_purchase)
![License](https://img.shields.io/badge/license-MIT-blue.svg)
[![Flutter CI](https://github.com/dooboolab/flutter_inapp_purchase/actions/workflows/ci.yml/badge.svg)](https://github.com/dooboolab/flutter_inapp_purchase/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/dooboolab/flutter_inapp_purchase/badge.svg?branch=master)](https://coveralls.io/github/dooboolab/flutter_inapp_purchase?branch=master)
![License](https://img.shields.io/badge/license-MIT-blue.svg)

## Flutter V2

Expand Down Expand Up @@ -114,15 +114,13 @@ For help on editing plugin code, view the [documentation](https://flutter.io/dev
final DateTime transactionDate;
final String transactionReceipt;
final String purchaseToken;
final String orderId;

// Android only
final String dataAndroid;
final String signatureAndroid;
final bool autoRenewingAndroid;
final bool isAcknowledgedAndroid;
final int purchaseStateAndroid;
final String originalJsonAndroid;

// iOS only
final DateTime originalTransactionDateIOS;
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

dependencies {
implementation 'com.android.billingclient:billing:3.0.0'
implementation 'com.android.billingclient:billing:4.0.0'
implementation files('jars/in-app-purchasing-2.0.76.jar')
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Bundle;
import android.util.Log;

import com.android.billingclient.api.AccountIdentifiers;
import com.android.billingclient.api.AcknowledgePurchaseParams;
import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
import com.android.billingclient.api.BillingClient;
Expand Down Expand Up @@ -316,11 +317,10 @@ else if (call.method.equals("getAvailableItemsByType")) {
if (purchases != null) {
for (Purchase purchase : purchases) {
JSONObject item = new JSONObject();
item.put("productId", purchase.getSku());
item.put("productId", purchase.getSkus().get(0));
item.put("transactionId", purchase.getOrderId());
item.put("transactionDate", purchase.getPurchaseTime());
item.put("transactionReceipt", purchase.getOriginalJson());
item.put("orderId", purchase.getOrderId());
item.put("purchaseToken", purchase.getPurchaseToken());
item.put("signatureAndroid", purchase.getSignature());
item.put("purchaseStateAndroid", purchase.getPurchaseState());
Expand Down Expand Up @@ -362,7 +362,7 @@ public void onPurchaseHistoryResponse(BillingResult billingResult, List<Purchase
try {
for (PurchaseHistoryRecord purchase : purchaseHistoryRecordList) {
JSONObject item = new JSONObject();
item.put("productId", purchase.getSku());
item.put("productId", purchase.getSkus().get(0));
item.put("transactionDate", purchase.getPurchaseTime());
item.put("transactionReceipt", purchase.getOriginalJson());
item.put("purchaseToken", purchase.getPurchaseToken());
Expand Down Expand Up @@ -398,53 +398,79 @@ else if (call.method.equals("buyItemByType")) {

BillingFlowParams.Builder builder = BillingFlowParams.newBuilder();

if (type.equals(BillingClient.SkuType.SUBS) && oldSku != null && !oldSku.isEmpty()) {
// Subscription upgrade/downgrade
builder.setOldSku(oldSku, purchaseToken);
}

if (type.equals(BillingClient.SkuType.SUBS) && oldSku != null && !oldSku.isEmpty()) {
// Subscription upgrade/downgrade
if (prorationMode != -1) {
builder.setOldSku(oldSku, purchaseToken);
if (prorationMode == BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE) {
builder.setReplaceSkusProrationMode(BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE);
} else if (prorationMode == BillingFlowParams.ProrationMode.IMMEDIATE_WITHOUT_PRORATION) {
builder.setReplaceSkusProrationMode(BillingFlowParams.ProrationMode.IMMEDIATE_WITHOUT_PRORATION);
} else {
builder.setOldSku(oldSku, purchaseToken);
}
} else {
builder.setOldSku(oldSku, purchaseToken);
}
}

if (prorationMode != 0 && prorationMode != -1) {
builder.setReplaceSkusProrationMode(prorationMode);
}

SkuDetails selectedSku = null;
for (SkuDetails skuDetail : skus) {
if (skuDetail.getSku().equals(sku)) {
selectedSku = skuDetail;
break;
}
}

if (selectedSku == null) {
String debugMessage = "The sku was not found. Please fetch products first by calling getItems";
String debugMessage = "The sku was not found. Please fetch setObfuscatedAccountIdproducts first by calling getItems";
result.error(TAG, "buyItemByType", debugMessage);
return;
}
builder.setSkuDetails(selectedSku);

BillingFlowParams.SubscriptionUpdateParams.Builder subscriptionUpdateParamsBuilder =
BillingFlowParams.SubscriptionUpdateParams.newBuilder();

if (purchaseToken != null) {
subscriptionUpdateParamsBuilder.setOldSkuPurchaseToken(purchaseToken);
}

if (obfuscatedAccountId != null) {
builder.setObfuscatedAccountId(obfuscatedAccountId);
}

if (obfuscatedProfileId != null) {
builder.setObfuscatedProfileId(obfuscatedProfileId);
}

builder.setSkuDetails(selectedSku);
if (prorationMode != -1) {
if (prorationMode
== BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE) {
subscriptionUpdateParamsBuilder.setReplaceSkusProrationMode(
BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE);
if (!type.equals(BillingClient.SkuType.SUBS)) {
String debugMessage =
"IMMEDIATE_AND_CHARGE_PRORATED_PRICE for proration mode only works in"
+ " subscription purchase.";
result.error(TAG, "buyItemByType", debugMessage);
return;
}
} else if (prorationMode
== BillingFlowParams.ProrationMode.IMMEDIATE_WITHOUT_PRORATION) {
subscriptionUpdateParamsBuilder.setReplaceSkusProrationMode(
BillingFlowParams.ProrationMode.IMMEDIATE_WITHOUT_PRORATION);
} else if (prorationMode == BillingFlowParams.ProrationMode.DEFERRED) {
subscriptionUpdateParamsBuilder.setReplaceSkusProrationMode(
BillingFlowParams.ProrationMode.DEFERRED);
} else if (prorationMode
== BillingFlowParams.ProrationMode.IMMEDIATE_WITH_TIME_PRORATION) {
subscriptionUpdateParamsBuilder.setReplaceSkusProrationMode(
BillingFlowParams.ProrationMode.IMMEDIATE_WITHOUT_PRORATION);
} else if (prorationMode
== BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_FULL_PRICE) {
subscriptionUpdateParamsBuilder.setReplaceSkusProrationMode(
BillingFlowParams.ProrationMode.IMMEDIATE_AND_CHARGE_FULL_PRICE);
} else {
subscriptionUpdateParamsBuilder.setReplaceSkusProrationMode(
BillingFlowParams.ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY);
}
}

if (purchaseToken != null) {
BillingFlowParams.SubscriptionUpdateParams subscriptionUpdateParams =
subscriptionUpdateParamsBuilder.build();

builder.setSubscriptionUpdateParams(subscriptionUpdateParams);
}

BillingFlowParams flowParams = builder.build();
BillingResult billingResult = billingClient.launchBillingFlow(activity, flowParams);

if (activity != null) {
billingClient.launchBillingFlow(activity, flowParams);
}
Expand Down Expand Up @@ -555,20 +581,24 @@ public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purch
if (purchases != null) {
for (Purchase purchase : purchases) {
JSONObject item = new JSONObject();
item.put("productId", purchase.getSku());
item.put("productId", purchase.getSkus().get(0));
item.put("transactionId", purchase.getOrderId());
item.put("transactionDate", purchase.getPurchaseTime());
item.put("transactionReceipt", purchase.getOriginalJson());
item.put("purchaseToken", purchase.getPurchaseToken());
item.put("orderId", purchase.getOrderId());

item.put("dataAndroid", purchase.getOriginalJson());
item.put("signatureAndroid", purchase.getSignature());
item.put("purchaseStateAndroid", purchase.getPurchaseState());
item.put("autoRenewingAndroid", purchase.isAutoRenewing());
item.put("isAcknowledgedAndroid", purchase.isAcknowledged());
item.put("purchaseStateAndroid", purchase.getPurchaseState());
item.put("originalJsonAndroid", purchase.getOriginalJson());
item.put("packageNameAndroid", purchase.getPackageName());
item.put("developerPayloadAndroid", purchase.getDeveloperPayload());
AccountIdentifiers accountIdentifiers = purchase.getAccountIdentifiers();

if (accountIdentifiers != null) {
item.put("obfuscatedAccountIdAndroid", accountIdentifiers.getObfuscatedAccountId());
item.put("obfuscatedProfileIdAndroid", accountIdentifiers.getObfuscatedProfileId());
}

channel.invokeMethod("purchase-updated", item.toString());
}
Expand Down
Loading