-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Experimental] Web purchase redemption (#1889)
### Description This adds experimental support to redeeming anonymous web purchases performed through RCBilling. The main API changes here are: - Adds a new `Purchases.parseAsDeepLink` that parses the intent and returns a deep link if it needs to be handled - Adds a new `Purchases.sharedInstance.redeemWebPurchase` that uses a parsed deep link to perform the redemption. - Adds a new `DeepLink` sealed class with the types of deep links - Adds a new `RedeemWebPurchaseListener` to listen to the result of the redemption. - Adds a new `RedeemWebPurchaseListener.Result` sealed class with the result of the redemption. All these are currently experimental APIs
- Loading branch information
Showing
22 changed files
with
761 additions
and
3 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
27 changes: 27 additions & 0 deletions
27
api-tester/src/defaults/java/com/revenuecat/apitester/java/RedeemWebPurchaseListenerAPI.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,27 @@ | ||
package com.revenuecat.apitester.java; | ||
|
||
import androidx.annotation.OptIn; | ||
|
||
import com.revenuecat.purchases.CustomerInfo; | ||
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI; | ||
import com.revenuecat.purchases.PurchasesError; | ||
import com.revenuecat.purchases.interfaces.RedeemWebPurchaseListener; | ||
|
||
@OptIn(markerClass = ExperimentalPreviewRevenueCatPurchasesAPI.class) | ||
@SuppressWarnings({"unused"}) | ||
final class RedeemWebPurchaseListenerAPI { | ||
static void checkListener(RedeemWebPurchaseListener listener, | ||
RedeemWebPurchaseListener.Result result) { | ||
listener.handleResult(result); | ||
} | ||
|
||
static void checkRedeemResult(RedeemWebPurchaseListener.Result result) { | ||
if (result instanceof RedeemWebPurchaseListener.Result.Success) { | ||
CustomerInfo customerInfo = ((RedeemWebPurchaseListener.Result.Success) result).getCustomerInfo(); | ||
} else if (result instanceof RedeemWebPurchaseListener.Result.Error) { | ||
PurchasesError error = ((RedeemWebPurchaseListener.Result.Error) result).getError(); | ||
} | ||
|
||
boolean isSuccess = result.isSuccess(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
api-tester/src/defaults/kotlin/com/revenuecat/apitester/kotlin/IntentExtensionsAPI.kt
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,14 @@ | ||
package com.revenuecat.apitester.kotlin | ||
|
||
import android.content.Intent | ||
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI | ||
import com.revenuecat.purchases.Purchases | ||
import com.revenuecat.purchases.parseAsDeepLink | ||
|
||
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class) | ||
@Suppress("unused", "UNUSED_VARIABLE") | ||
private class IntentExtensionsAPI { | ||
fun check(intent: Intent) { | ||
val deepLink: Purchases.DeepLink? = intent.parseAsDeepLink() | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...ester/src/defaults/kotlin/com/revenuecat/apitester/kotlin/RedeemWebPurchaseListenerAPI.kt
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,32 @@ | ||
package com.revenuecat.apitester.kotlin | ||
|
||
import com.revenuecat.purchases.CustomerInfo | ||
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI | ||
import com.revenuecat.purchases.PurchasesError | ||
import com.revenuecat.purchases.interfaces.RedeemWebPurchaseListener | ||
|
||
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class) | ||
@Suppress("unused", "UNUSED_VARIABLE") | ||
private class RedeemWebPurchaseListenerAPI { | ||
fun checkListener( | ||
redeemWebPurchaseListener: RedeemWebPurchaseListener, | ||
result: RedeemWebPurchaseListener.Result, | ||
) { | ||
redeemWebPurchaseListener.handleResult(result) | ||
} | ||
|
||
fun checkResult(result: RedeemWebPurchaseListener.Result): Boolean { | ||
val isSuccess: Boolean = result.isSuccess | ||
|
||
when (result) { | ||
is RedeemWebPurchaseListener.Result.Success -> { | ||
val customerInfo: CustomerInfo = result.customerInfo | ||
return true | ||
} | ||
is RedeemWebPurchaseListener.Result.Error -> { | ||
val error: PurchasesError = result.error | ||
return false | ||
} | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
examples/purchase-tester/src/main/java/com/revenuecat/purchasetester/MainActivity.kt
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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
package com.revenuecat.purchasetester | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.revenuecat.purchases.ExperimentalPreviewRevenueCatPurchasesAPI | ||
import com.revenuecat.purchases.Purchases | ||
import com.revenuecat.purchases_sample.R | ||
|
||
@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class) | ||
class MainActivity : AppCompatActivity() { | ||
|
||
internal var rcDeepLink: Purchases.DeepLink? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
rcDeepLink = Purchases.parseAsDeepLink(intent) | ||
} | ||
|
||
override fun onNewIntent(intent: Intent?) { | ||
super.onNewIntent(intent) | ||
if (intent != null) { | ||
rcDeepLink = Purchases.parseAsDeepLink(intent) | ||
} | ||
} | ||
|
||
fun clearDeepLink() { | ||
rcDeepLink = null | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
purchases/src/defaults/kotlin/com/revenuecat/purchases/IntentExtensions.kt
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,9 @@ | ||
package com.revenuecat.purchases | ||
|
||
import android.content.Intent | ||
|
||
@ExperimentalPreviewRevenueCatPurchasesAPI | ||
@JvmSynthetic | ||
fun Intent.parseAsDeepLink(): Purchases.DeepLink? { | ||
return Purchases.parseAsDeepLink(this) | ||
} |
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
Oops, something went wrong.