Skip to content

Commit

Permalink
fixes subscription upgrade/downgrade (#1438)
Browse files Browse the repository at this point in the history
* fixes subscription upgrade/downgrade

* Made the breaking change at once

* fix lint

* updated versions to reflect breaking change

* removing from amazon module as well

Co-authored-by: andres.aguilar <andres.aguilar@nfl.com>
  • Loading branch information
andresesfm and andres.aguilar authored Jul 30, 2021
1 parent 5424257 commit 0763c81
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelogs

# 7.1.0

*Breaking Change*: Removed oldAndroidSku from requestSubscription. This field was passed for Android only

## 7.0.5

Remove init on main thread as it is no longer needed in this version of the SDK [#1427](https://github.com/dooboolab/react-native-iap/pull/1427).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void getPurchaseHistoryByType(final String type, final Promise promise) {
public void buyItemByType(
final String type,
final String sku,
final String oldSku,
final String purchaseToken,
final Integer prorationMode,
final String obfuscatedAccountId,
Expand Down
7 changes: 3 additions & 4 deletions android/src/play/java/com/dooboolab/RNIap/RNIapModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ public void onPurchaseHistoryResponse(
public void buyItemByType(
final String type,
final String sku,
final String oldPurchaseToken,
final String purchaseToken,
final Integer prorationMode,
final String obfuscatedAccountId,
Expand Down Expand Up @@ -467,8 +466,8 @@ public void buyItemByType(
BillingFlowParams.SubscriptionUpdateParams.Builder subscriptionUpdateParamsBuilder =
BillingFlowParams.SubscriptionUpdateParams.newBuilder();

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

if (obfuscatedAccountId != null) {
Expand Down Expand Up @@ -518,7 +517,7 @@ public void buyItemByType(
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api_reference/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
`requestPurchase(sku: string, andDangerouslyFinishTransactionAutomatically: boolean, obfuscatedAccountIdAndroid: string, obfuscatedProfileIdAndroid: string)`<ul></ul> | `Promise<ProductPurchase>` | Request a purchase. `purchaseUpdatedListener` will receive the result.<br/> `andDangerouslyFinishTransactionAutomatically` defaults to `true` for backwards compatibility but this is deprecated and you should set it to false once you're [manually finishing your transactions](../usage_instructions/purchase).
`requestPurchaseWithQuantityIOS(sku: string, quantity: number)`<ul><li>sku: product ID/sku</li><li>quantity: Quantity</li></ul> | `void` | **iOS only** Buy a product with a specified quantity. `purchaseUpdatedListener` will receive the result
_*deprecated_ ~~`buySubscription(sku: string)`~~<ul><li>sku: subscription ID/sku</li></ul> | `void` | Create (buy) a subscription to a sku.
`requestSubscription(sku: string, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, oldSkuAndroid: string, purchaseTokenAndroid: string, prorationModeAndroid: ProrationModesAndroid, obfuscatedAccountIdAndroid: string, obfuscatedProfileIdAndroid: string)`<ul><li>sku: subscription ID/sku</li><li>prorationModeAndroid: one of undefined, UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED</li></ul> | `Promise<SubscriptionPurchase | null>` | Create (buy) a subscription to a sku. **Note:** Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
`requestSubscription(sku: string, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, /**oldSkuAndroid: string **WARNING** this parameter has been removed*/, purchaseTokenAndroid: string, prorationModeAndroid: ProrationModesAndroid, obfuscatedAccountIdAndroid: string, obfuscatedProfileIdAndroid: string)`<ul><li>sku: subscription ID/sku</li><li>prorationModeAndroid: one of undefined, UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED</li></ul> | `Promise<SubscriptionPurchase | null>` | Create (buy) a subscription to a sku. **Note:** Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
`clearTransactionIOS()` | `void` | **iOS only** Clear up unfinished transanctions which sometimes cause problems. Read more in [#257](https://github.com/dooboolab/react-native-iap/issues/257), [#801](https://github.com/dooboolab/react-native-iap/issues/801).
`clearProductsIOS()` | `void` | **iOS only** Clear all products and subscriptions. Read more in below README.
`getReceiptIOS()` | `Promise<string>` | **iOS only** Get the current receipt.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-iap",
"version": "7.0.5",
"version": "7.1.0",
"description": "React Native In App Purchase Module.",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -9,6 +9,7 @@
"build": "tsc && flowgen index.d.ts -o index.js.flow",
"flow": "flow",
"lint": "eslint src --ext .ts,.tsx",
"lint:android": "cd android && ./gradlew goJF",
"test": "jest",
"test:flow": "flow",
"test:typescript": "tsc --noEmit",
Expand Down
3 changes: 0 additions & 3 deletions src/iap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ export const requestPurchase = (
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
* @param {string} [sku] The product's sku/ID
* @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.
* @param {string} [oldSkuAndroid] SKU that the user is upgrading or downgrading from.
* @param {string} [purchaseTokenAndroid] purchaseToken that the user is upgrading or downgrading from (Android).
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
Expand All @@ -344,7 +343,6 @@ export const requestPurchase = (
export const requestSubscription = (
sku: string,
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean,
oldSkuAndroid?: string,
purchaseTokenAndroid?: string,
prorationModeAndroid?: ProrationModesAndroid,
obfuscatedAccountIdAndroid?: string,
Expand Down Expand Up @@ -378,7 +376,6 @@ export const requestSubscription = (
return getAndroidModule().buyItemByType(
ANDROID_ITEM_TYPE_SUBSCRIPTION,
sku,
oldSkuAndroid,
purchaseTokenAndroid,
prorationModeAndroid,
obfuscatedAccountIdAndroid,
Expand Down

0 comments on commit 0763c81

Please sign in to comment.